diff --git a/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomer.java b/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomer.java new file mode 100644 index 0000000..66e6dfa --- /dev/null +++ b/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomer.java @@ -0,0 +1,35 @@ +package com.yxt.yyth.api.lpkcustomer; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.util.Date; +import java.util.UUID; + +/** + * @author wangpengfei + * @date 2023/11/21 15:06 + */ +@ApiModel(value = "客户信息", description = "客户信息") +@TableName("lpk_customer") +@Data +public class LpkCustomer { + private String id; + private String sid=UUID.randomUUID().toString(); + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") + private Date createTime; + private String remarks; + private String isEnable; + @TableField(value = "wx_mp_openid") + private String wxMpOpenid; + private String unionId; + private String mobile; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") + private String bindDate; + private String realName; + private String nick; + private String photo; +} diff --git a/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomerDto.java b/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomerDto.java new file mode 100644 index 0000000..f356c74 --- /dev/null +++ b/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomerDto.java @@ -0,0 +1,14 @@ +package com.yxt.yyth.api.lpkcustomer; + +import com.yxt.common.core.dto.Dto; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +/** + * @author wangpengfei + * @date 2023/11/21 15:13 + */ +@ApiModel(value = "客户信息 数据传输对象", description = "客户信息 数据传输对象") +@Data +public class LpkCustomerDto implements Dto { +} diff --git a/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomerQuery.java b/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomerQuery.java new file mode 100644 index 0000000..80d00b6 --- /dev/null +++ b/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomerQuery.java @@ -0,0 +1,16 @@ +package com.yxt.yyth.api.lpkcustomer; + +import com.yxt.common.core.query.Query; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +/** + * @author wangpengfei + * @date 2023/11/21 15:31 + */ +@ApiModel(value = "客户信息 查询条件", description = "客户信息 查询条件") +@Data +public class LpkCustomerQuery implements Query { + private String realName; + private String mobile; +} diff --git a/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomerVo.java b/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomerVo.java new file mode 100644 index 0000000..98c2dcb --- /dev/null +++ b/src/main/java/com/yxt/yyth/api/lpkcustomer/LpkCustomerVo.java @@ -0,0 +1,22 @@ +package com.yxt.yyth.api.lpkcustomer; + +import com.yxt.common.core.vo.Vo; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author wangpengfei + * @date 2023/11/21 15:12 + */ +@Data +@ApiModel(value = "客户信息 视图数据对象", description = "客户信息 视图数据对象") +@NoArgsConstructor +public class LpkCustomerVo implements Vo { + private String sid; + private String mobile; + private String bindDate; + private String realName; + private String nick; + private String photo; +} diff --git a/src/main/java/com/yxt/yyth/api/lpkcustomer/WxBindMobileDto.java b/src/main/java/com/yxt/yyth/api/lpkcustomer/WxBindMobileDto.java new file mode 100644 index 0000000..1ab9506 --- /dev/null +++ b/src/main/java/com/yxt/yyth/api/lpkcustomer/WxBindMobileDto.java @@ -0,0 +1,17 @@ +package com.yxt.yyth.api.lpkcustomer; + +import com.yxt.common.core.dto.Dto; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class WxBindMobileDto implements Dto { + + @ApiModelProperty(value = "手机号") + private String mobile; + @ApiModelProperty(value = "验证码") + private String code; + //微信id + private String openid; + private String unionid; +} diff --git a/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerMapper.java b/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerMapper.java new file mode 100644 index 0000000..539ac33 --- /dev/null +++ b/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerMapper.java @@ -0,0 +1,20 @@ +package com.yxt.yyth.biz.lpkcustomer; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Constants; +import com.yxt.yyth.api.lpkcustomer.LpkCustomer; +import com.yxt.yyth.api.lpkcustomer.LpkCustomerVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * @author wangpengfei + * @date 2023/11/21 15:03 + */ +@Mapper +public interface LpkCustomerMapper extends BaseMapper { + + IPage customerListPage(IPage page, @Param(Constants.WRAPPER) QueryWrapper qw); +} diff --git a/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerMapper.xml b/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerMapper.xml new file mode 100644 index 0000000..77fd1a1 --- /dev/null +++ b/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerRest.java b/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerRest.java new file mode 100644 index 0000000..3cf90af --- /dev/null +++ b/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerRest.java @@ -0,0 +1,47 @@ +package com.yxt.yyth.biz.lpkcustomer; + +import com.yxt.common.core.query.PagerQuery; +import com.yxt.common.core.result.ResultBean; +import com.yxt.common.core.vo.PagerVo; +import com.yxt.yyth.api.lpkcustomer.LpkCustomer; +import com.yxt.yyth.api.lpkcustomer.LpkCustomerQuery; +import com.yxt.yyth.api.lpkcustomer.LpkCustomerVo; +import com.yxt.yyth.api.lpkcustomer.WxBindMobileDto; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * @author wangpengfei + * @date 2023/11/21 15:03 + */ + +@Api(tags = "用户信息") +@RestController +@RequestMapping("lpkcustomer") +public class LpkCustomerRest { + + @Autowired + LpkCustomerService lpkCustomerService; + + @PostMapping("/wxBindMobile") + @ApiOperation(value = "微信绑定手机") + public ResultBean wxBindMobile(@RequestBody WxBindMobileDto wxBindMobileDto) { + return lpkCustomerService.wxBindMobile(wxBindMobileDto); + } + + @ApiOperation(value = "微信静默登录") + @GetMapping("/wxSilentLogin") + public ResultBean wxSilentLogin(@RequestParam(value = "wxCode") String wxCode) { + return lpkCustomerService.wxSilentLogin(wxCode); + } + + @ApiOperation("客户信息列表") + @PostMapping("/customerListPage") + public ResultBean> customerListPage(@RequestBody PagerQuery pq) { + return lpkCustomerService.customerListPage(pq); + } + + +} diff --git a/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerService.java b/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerService.java new file mode 100644 index 0000000..dbfb19b --- /dev/null +++ b/src/main/java/com/yxt/yyth/biz/lpkcustomer/LpkCustomerService.java @@ -0,0 +1,136 @@ +package com.yxt.yyth.biz.lpkcustomer; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.yxt.common.base.config.component.FileUploadComponent; +import com.yxt.common.base.service.MybatisBaseService; +import com.yxt.common.base.utils.PagerUtil; +import com.yxt.common.base.utils.StringUtils; +import com.yxt.common.core.query.PagerQuery; +import com.yxt.common.core.result.ResultBean; +import com.yxt.common.core.vo.PagerVo; +import com.yxt.yyth.api.lpkcustomer.LpkCustomer; +import com.yxt.yyth.api.lpkcustomer.LpkCustomerQuery; +import com.yxt.yyth.api.lpkcustomer.LpkCustomerVo; +import com.yxt.yyth.api.lpkcustomer.WxBindMobileDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * @author wangpengfei + * @date 2023/11/21 15:03 + */ +@Service +public class LpkCustomerService extends MybatisBaseService { + + @Autowired + private FileUploadComponent fileUploadComponent; + + String APP_ID = "wx4724e3a3c27f36b5"; + String SECRET = "971fd3b8aa7b08ce3e8a5f3e502b1a8d"; + private static final String WX_URL_LOGIN = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code "; + + public ResultBean wxLogin(String jsCode, String appid, String secret) { + ResultBean rb = new ResultBean(); + String url = WX_URL_LOGIN.replace("APPID", appid).replace("SECRET", secret).replace("JSCODE", jsCode).replace("authorization_code", "authorization_code"); + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity forEntity = restTemplate.getForEntity(url, String.class); + JSONObject jsonObject = JSONObject.parseObject(forEntity.getBody()); + System.out.println(jsonObject); + return rb.success().setData(jsonObject); + } + + /** + * 微信静默登录 + * @param wxCode 临时凭证code值 + * @return ResultBean data:Token + * 登陆成功后data返回用户Sid + * 聂金毅 2022/6/8 20:30 创建 + */ + public ResultBean wxSilentLogin(String wxCode) { + ResultBean rb = ResultBean.fireFail(); + // 通过wxCode获取unionid,失败返回微信的错误提示。 + + ResultBean rbJsonObject = wxLogin(wxCode,APP_ID,SECRET); + if (!rbJsonObject.getSuccess()){ + JSONObject jsonObject = rbJsonObject.getData(); + String errcode = jsonObject.get("errcode").toString(); + String errmsg = jsonObject.get("errmsg").toString(); + return rb.setMsg(errmsg).setCode(errcode); + } + // 判断存在不存在unionid,用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台帐号下会返回,详见 UnionID 机制说明。、 + JSONObject jsonObject = rbJsonObject.getData(); + if (!jsonObject.containsKey("openid")){ + return rb.setMsg("未获得openid,请联系管理员"); + } +// String unionid = jsonObject.get("unionid").toString(); + String openid = jsonObject.get("openid").toString(); + Map map=new HashMap<>(); +// map.put("unionid",unionid); + map.put("openid",openid); + LpkCustomer lpkCustomer= baseMapper.selectOne(new QueryWrapper().eq("wx_mp_openid",openid)); + //查询用户是否存在 + if(null==lpkCustomer){ + //新增用户 + LpkCustomer newCustomer=new LpkCustomer(); + newCustomer.setWxMpOpenid(openid); +// newCustomer.setUnionId(unionid); + newCustomer.setCreateTime(new Date()); + baseMapper.insert(newCustomer); + return rb.setData(newCustomer).setCode("110"); + } + //判断是否绑定手机号 + if(StringUtils.isBlank(lpkCustomer.getMobile())){ + return rb.setData(lpkCustomer).setCode("110"); + } + return rb.success().setData(lpkCustomer); + } + public ResultBean wxBindMobile(WxBindMobileDto wxBindMobileDto) { + ResultBean rb = ResultBean.fireFail(); + String mobile = wxBindMobileDto.getMobile(); + LpkCustomer lpkCustomer= baseMapper.selectOne(new QueryWrapper().eq("wx_mp_openid",wxBindMobileDto.getOpenid())); + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + lpkCustomer.setBindDate(sdf.format(new Date())); + lpkCustomer.setMobile(mobile); + baseMapper.updateById(lpkCustomer); + return rb.success().setMsg("绑定成功").setData(lpkCustomer.getSid()); + } +// public ResultBean wxBindMobile(String sid) { +// ResultBean rb = ResultBean.fireFail(); +// +// // LpkCustomer lpkCustomer= baseMapper.selectOne(new QueryWrapper().eq("wx_mp_openid",wxBindMobileDto.getOpenid())); +// +// return rb.success().setMsg("绑定成功").setData(lpkCustomer.getSid()); +// } + + public ResultBean> customerListPage(PagerQuery pq) { + ResultBean rb = ResultBean.fireFail(); + LpkCustomerQuery query = pq.getParams(); + QueryWrapper qw = new QueryWrapper<>(); + if (StringUtils.isNotBlank(query.getMobile())) { + qw.like("mobile", query.getMobile()); + } + if (StringUtils.isNotBlank(query.getRealName())) { + qw.like("realName", query.getRealName()); + } + IPage page = PagerUtil.queryToPage(pq); + IPage pagging = baseMapper.customerListPage(page, qw); + PagerVo p = PagerUtil.pageToVo(pagging, null); + List records = pagging.getRecords(); + records.removeAll(Collections.singleton(null)); + if (!records.isEmpty()) { + for (LpkCustomerVo record : records) { + if (StringUtils.isNotBlank(record.getPhoto())) { + record.setPhoto(fileUploadComponent.getUrlPrefix() + record.getPhoto()); + } + } + } + return rb.success().setData(p); + } +}