diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxCUserController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxCUserController.java new file mode 100755 index 000000000..3a9aa427c --- /dev/null +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxCUserController.java @@ -0,0 +1,198 @@ +package com.iformall.controller; + +import com.alibaba.fastjson.JSONObject; +import com.iformall.common.ErrorCode; +import com.iformall.common.IdWorker; +import com.iformall.common.ResultData; +import com.iformall.domain.dto.WxCUserFromBDto; +import com.iformall.domain.po.WxCUser; +import com.iformall.domain.po.WxCUserBasicInfo; +import com.iformall.domain.po.WxCUserFromB; +import com.iformall.domain.po.WxMerchantBUser; +import com.iformall.enums.EnumAssignTagsTrigger; +import com.iformall.enums.EnumScoreType; +import com.iformall.service.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Date; +import java.util.List; + +/** + * @author gongbiao + */ +@RestController +@RequestMapping("/api/cuser") +@Api(description = "B端来源用户") +public class WxCUserController extends BaseController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + + @Autowired + private WxCUserBasicInfoService wxCUserBasicInfoService; + + @Autowired + private WxScoreRulesService wxScoreRulesService; + + @Autowired + private WxCUserTagsService wxCUserTagsService; + + @Autowired + private WxMerchantBUserService wxMerchantBUserService; + + @Autowired + private WxCUserFromBService wxCUserFromBService; + + @Autowired + private WxCUserService wxCUserService; + + + /** + * 会员更新信息 + * @return + */ + @PostMapping("/updateUserInfo") + @ApiOperation(value = "用户更新信息", notes="") + public ResultData updateUserInfo(@RequestBody WxCUserFromBDto wxCUserFromBDto) { + logger.info("WxCUserController::updateUserInfo"); + if (wxCUserFromBDto == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"没有传入用户信息"); + } + if (StringUtils.isEmpty(wxCUserFromBDto.getOpenid())){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"C端openid不能为空"); + } + if (wxCUserFromBDto.getbUserId()==null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"bUserId不能为空"); + } + //根据bUserId查询B端用户是否存在 + WxMerchantBUser bUser = wxMerchantBUserService.getById(wxCUserFromBDto.getbUserId()); + if(bUser==null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"B端用户不存在"); + } + final IdWorker idWorker = IdWorker.get(); + + WxCUserFromB wxCUserFromB = wxCUserFromBService.getByOpenid(wxCUserFromBDto.getOpenid()); + if(wxCUserFromB==null){ + //查询C端微信信息 + WxCUser wxCUser = new WxCUser(); + wxCUser.setOpenId(wxCUserFromBDto.getOpenid()); + wxCUser = wxCUserService.getByOpenId(wxCUser); + //不存在时 + if(wxCUser==null){ + //新增来自B端的会员 + long cUserId = idWorker.nextId(); + WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); + wxCUserBasicInfo.setId(cUserId); + wxCUserBasicInfo.setName(wxCUserFromBDto.getName()); + wxCUserBasicInfo.setBirthdate(wxCUserFromBDto.getBirthdate()); + wxCUserBasicInfo.setSex(wxCUserFromBDto.getSex() ); + wxCUserBasicInfo.setAddress(wxCUserFromBDto.getAddress()); + wxCUserBasicInfo.setPhone(wxCUserFromBDto.getPhone()); + wxCUserBasicInfo.setUpdateDate(new Date()); + wxCUserBasicInfoService.save(wxCUserBasicInfo); + //新增来自B端的会员关联数据 + WxCUserFromB record = new WxCUserFromB(); + record.setbUserId(wxCUserFromBDto.getbUserId()); + record.setcUserId(cUserId); + record.setOpenid(wxCUserFromBDto.getOpenid()); + record.setMerchantId(bUser.getMerchantId()); + record.setTenantId(bUser.getTenantId()); + record.setInfo(JSONObject.toJSONString(wxCUserBasicInfo)); + wxCUserFromBService.saveOrUpdate(record); + }else{ + String phone = wxCUser.getPhone(); + String tenantId = wxCUser.getTenantId(); + //查询会员信息 + List byPhone = wxCUserBasicInfoService.findByPhone(tenantId, phone); + //存在会员信息 + if(!byPhone.isEmpty()){ + //更新会员信息 + WxCUserBasicInfo wxCUserBasicInfo = byPhone.get(0); + wxCUserBasicInfo.setName(wxCUserFromBDto.getName()); + wxCUserBasicInfo.setBirthdate(wxCUserFromBDto.getBirthdate()); + wxCUserBasicInfo.setSex(wxCUserFromBDto.getSex() ); + wxCUserBasicInfo.setAddress(wxCUserFromBDto.getAddress()); + wxCUserBasicInfo.setPhone(wxCUserFromBDto.getPhone()); + wxCUserBasicInfo.setUpdateDate(new Date()); + wxCUserBasicInfoService.update(wxCUserBasicInfo); + wxScoreRulesService.addScore(EnumScoreType.COMPLETE_INFO, wxCUserBasicInfo); + wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_IMPORT, wxCUserBasicInfo); + //新增来自B端的会员关联数据 + wxCUserFromB = new WxCUserFromB(); + wxCUserFromB.setbUserId(wxCUserFromBDto.getbUserId()); + wxCUserFromB.setcUserId(wxCUserBasicInfo.getId()); + wxCUserFromB.setOpenid(wxCUserFromBDto.getOpenid()); + wxCUserFromB.setMerchantId(bUser.getMerchantId()); + wxCUserFromB.setTenantId(bUser.getTenantId()); + wxCUserFromB.setInfo(JSONObject.toJSONString(wxCUserBasicInfo)); + wxCUserFromBService.saveOrUpdate(wxCUserFromB); + }else{ + //新增来自B端的会员 + long cUserId = idWorker.nextId(); + WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); + wxCUserBasicInfo.setId(cUserId); + wxCUserBasicInfo.setName(wxCUserFromBDto.getName()); + wxCUserBasicInfo.setBirthdate(wxCUserFromBDto.getBirthdate()); + wxCUserBasicInfo.setSex(wxCUserFromBDto.getSex() ); + wxCUserBasicInfo.setAddress(wxCUserFromBDto.getAddress()); + wxCUserBasicInfo.setPhone(wxCUserFromBDto.getPhone()); + wxCUserBasicInfo.setUpdateDate(new Date()); + wxCUserBasicInfoService.save(wxCUserBasicInfo); + //新增来自B端的会员关联数据 + WxCUserFromB record = new WxCUserFromB(); + record.setbUserId(wxCUserFromBDto.getbUserId()); + record.setcUserId(cUserId); + record.setOpenid(wxCUserFromBDto.getOpenid()); + record.setMerchantId(bUser.getMerchantId()); + record.setTenantId(bUser.getTenantId()); + record.setInfo(JSONObject.toJSONString(wxCUserBasicInfo)); + wxCUserFromBService.saveOrUpdate(record); + } + } + }else{ + WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(wxCUserFromB.getcUserId()); + wxCUserBasicInfo.setName(wxCUserFromBDto.getName()); + wxCUserBasicInfo.setBirthdate(wxCUserFromBDto.getBirthdate()); + wxCUserBasicInfo.setSex(wxCUserFromBDto.getSex() ); + wxCUserBasicInfo.setAddress(wxCUserFromBDto.getAddress()); + wxCUserBasicInfo.setPhone(wxCUserFromBDto.getPhone()); + wxCUserBasicInfoService.update(wxCUserBasicInfo); + wxScoreRulesService.addScore(EnumScoreType.COMPLETE_INFO, wxCUserBasicInfo); + wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_IMPORT, wxCUserBasicInfo); + //更新B端来源会员 + wxCUserFromB.setInfo(JSONObject.toJSONString(wxCUserBasicInfo)); + wxCUserFromBService.saveOrUpdate(wxCUserFromB); + } + return new ResultData(); + } + + + /** + * 会员信息 + * @return + */ + @PostMapping("/findUserInfo") + @ApiOperation(value = "获取会员信息", notes="") + public ResultData findUserInfo(@RequestBody WxCUserFromBDto wxCUserFromBDto) { + logger.info("WxCUserController::updateUserInfo"); + if (wxCUserFromBDto == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"没有传入用户信息"); + } + if (StringUtils.isEmpty(wxCUserFromBDto.getOpenid())){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"C端openid不能为空"); + } + WxCUserFromB wxCUserFromB = wxCUserFromBService.getByOpenid(wxCUserFromBDto.getOpenid()); + WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(wxCUserFromB.getcUserId()); + return new ResultData(wxCUserBasicInfo); + } + + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/dto/WxCUserFromBDto.java b/mallinkService/src/main/java/com/iformall/domain/dto/WxCUserFromBDto.java new file mode 100644 index 000000000..f1a0c3bb2 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/dto/WxCUserFromBDto.java @@ -0,0 +1,80 @@ +package com.iformall.domain.dto; + + +import java.io.Serializable; +import java.util.Date; + +public class WxCUserFromBDto implements Serializable { + private static final long serialVersionUID = 1L; + + @io.swagger.annotations.ApiModelProperty(value="B端登录者ID",name="bUserId") + private Long bUserId; + @io.swagger.annotations.ApiModelProperty(value="C端openid",name="openid") + private String openid; + @io.swagger.annotations.ApiModelProperty(value="C端会员姓名",name="name") + private String name; + @io.swagger.annotations.ApiModelProperty(value="C端会员性别",name="sex") + private Integer sex; + @io.swagger.annotations.ApiModelProperty(value="C端会员生日",name="birthdate") + private Date birthdate; + @io.swagger.annotations.ApiModelProperty(value="C端会员地址",name="address") + private String address; + @io.swagger.annotations.ApiModelProperty(value="C端会员手机号",name="phone") + private String phone; + + public Long getbUserId() { + return bUserId; + } + + public void setbUserId(Long bUserId) { + this.bUserId = bUserId; + } + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getSex() { + return sex; + } + + public void setSex(Integer sex) { + this.sex = sex; + } + + public Date getBirthdate() { + return birthdate; + } + + public void setBirthdate(Date birthdate) { + this.birthdate = birthdate; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCUserFromB.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCUserFromB.java new file mode 100644 index 000000000..86da3a6da --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCUserFromB.java @@ -0,0 +1,184 @@ +package com.iformall.domain.po; + +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Transient; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Table(name = "wx_c_user_from_b") +public class WxCUserFromB implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + protected Long id; + + @Transient + protected List ids; + @Transient + protected String sortColumns; + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getSortColumns() { + return sortColumns; + } + + public List getIds() { + return ids; + } + public void setIds(List ids) { + this.ids = ids; + } + + + + /***/ + @io.swagger.annotations.ApiModelProperty(value="",name="tenantId") + private String tenantId; + /*商户ID**/ + @io.swagger.annotations.ApiModelProperty(value="商户ID",name="merchantId") + private Long merchantId; + /*b_user_id**/ + @io.swagger.annotations.ApiModelProperty(value="b_user_id",name="bUserId") + private Long bUserId; + /*c_user_id**/ + @io.swagger.annotations.ApiModelProperty(value="c_user_id",name="cUserId") + private Long cUserId; + /*会员信息**/ + @io.swagger.annotations.ApiModelProperty(value="会员信息",name="info") + private String info; + /***/ + @io.swagger.annotations.ApiModelProperty(value="",name="createTime") + private Date createTime; + /***/ + @io.swagger.annotations.ApiModelProperty(value="",name="updateTime") + private Date updateTime; + /*openid**/ + @io.swagger.annotations.ApiModelProperty(value="openid",name="openid") + private String openid; + public String getTenantId() { + return tenantId; + } + public void setTenantId(String _tenantId) { + tenantId = _tenantId; + } + public Long getMerchantId() { + return merchantId; + } + public void setMerchantId(Long _merchantId) { + merchantId = _merchantId; + } + + public Long getbUserId() { + return bUserId; + } + + public void setbUserId(Long bUserId) { + this.bUserId = bUserId; + } + + public Long getcUserId() { + return cUserId; + } + + public void setcUserId(Long cUserId) { + this.cUserId = cUserId; + } + + public String getInfo() { + return info; + } + public void setInfo(String _info) { + info = _info; + } + public Date getCreateTime() { + return createTime; + } + public void setCreateTime(Date _createTime) { + createTime = _createTime; + } + public Date getUpdateTime() { + return updateTime; + } + public void setUpdateTime(Date _updateTime) { + updateTime = _updateTime; + } + public String getOpenid() { + return openid; + } + public void setOpenid(String _openid) { + openid = _openid; + } + + + + public static enum Field + { + Id_ASC("`id` ASC"),Id_DESC("`id` DESC") + ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") + ,MerchantId_ASC("`merchantId` ASC"),MerchantId_DESC("`merchantId` DESC") + ,BUserId_ASC("`bUserId` ASC"),BUserId_DESC("`bUserId` DESC") + ,CUserId_ASC("`cUserId` ASC"),CUserId_DESC("`cUserId` DESC") + ,Info_ASC("`info` ASC"),Info_DESC("`info` DESC") + ,CreateTime_ASC("`createTime` ASC"),CreateTime_DESC("`createTime` DESC") + ,UpdateTime_ASC("`updateTime` ASC"),UpdateTime_DESC("`updateTime` DESC") + ,Openid_ASC("`openid` ASC"),Openid_DESC("`openid` DESC") + ; + private String value; + Field(String value){ + this.value = value; + } + public String getValue() { + return value; + } + public void setCol(String value) { + this.value = value; + } + @Override + public String toString() { + return this.getValue(); + } + } + + public void setSortColumns(Field... fields) + { + if (fields == null || fields.length == 0) { + return; + } + for (int k = 0; k < fields.length; k++) { + if (fields[k] == null) { + return; + } + } + StringBuilder sb = new StringBuilder(fields[0].toString()); + for (int k = 1; k < fields.length; k++) { + sb.append(","); + sb.append(fields[k].toString()); + } + + } + + public void setSortColumns(String sortColumns) + { + if (sortColumns == null || "".equals(sortColumns.trim())) { + return; + } + if (sortColumns.contains(",")) { + String[] cols = sortColumns.split(","); + List fList = new ArrayList(); + for (int k = 0; k < cols.length; k++) { + fList.add(Field.valueOf(cols[k])); + } + this.setSortColumns(fList.toArray(new Field[fList.size()])); + } else { + this.setSortColumns(Field.valueOf(sortColumns)); + } + } +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCUserFromBMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCUserFromBMapper.java new file mode 100644 index 000000000..f3a7d3c1f --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCUserFromBMapper.java @@ -0,0 +1,18 @@ +package com.iformall.mapper; + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.WxCUserFromB; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * @author gongbiao + */ +public interface WxCUserFromBMapper extends CommonMapper { + + List findList(WxCUserFromB wxCUserFromB); + + @Select("select * from wx_c_user_from_b where openid=#{openid}") + WxCUserFromB getByOpenid(String openid); +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxCUserFromBService.java b/mallinkService/src/main/java/com/iformall/service/WxCUserFromBService.java new file mode 100644 index 000000000..ea86d2816 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/WxCUserFromBService.java @@ -0,0 +1,46 @@ +package com.iformall.service; + +import com.github.pagehelper.PageInfo; +import com.iformall.domain.po.WxCUserFromB; + +/** + * @author gongbiao + */ +public interface WxCUserFromBService { + + /** + * 根据实体查询分页列表 + * + * @param record + * @param offset + * @param limit + * @return + */ + PageInfo listAsPage(WxCUserFromB record, Integer pageIndex, Integer pageSize); + + /** + * 根据Id获得实体 + * + * @param id + * @return + */ + WxCUserFromB getById(Long id); + + /** + * 保存或更新实体 + * + * @param record + */ + void saveOrUpdate(WxCUserFromB record); + + /** + * 根据Id删除实体 + * + * @param id + */ + void deleteById(Long id); + + + WxCUserFromB getByOpenid(String openid); + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserFromBServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserFromBServiceImpl.java new file mode 100644 index 000000000..83d77ce26 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserFromBServiceImpl.java @@ -0,0 +1,58 @@ +package com.iformall.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.domain.po.WxCUserFromB; +import com.iformall.mapper.WxCUserFromBMapper; +import com.iformall.service.WxCUserFromBService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.UUID; + +/** + * @author gongbiao + */ +@Service +public class WxCUserFromBServiceImpl implements WxCUserFromBService { + + @Autowired + WxCUserFromBMapper wxCUserFromBMapper; + + + @Override + public PageInfo listAsPage(WxCUserFromB record, Integer pageIndex, Integer pageSize) { + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCUserFromBMapper.findList(record)); + } + + @Override + public WxCUserFromB getById(Long id) { + return wxCUserFromBMapper.selectByPrimaryKey(id); + } + + @Override + public void saveOrUpdate(WxCUserFromB record) { + if (record.getId() == null) { + Date date = new Date(); + record.setCreateTime(date); + record.setUpdateTime(date); + wxCUserFromBMapper.insertSelective(record); + } else { + record.setUpdateTime(new Date()); + wxCUserFromBMapper.updateByPrimaryKeySelective(record); + } + } + + @Override + public void deleteById(Long id) { + wxCUserFromBMapper.deleteByPrimaryKey(id); + } + + @Override + public WxCUserFromB getByOpenid(String openid) { + return wxCUserFromBMapper.getByOpenid(openid); + } + + +} diff --git a/mallinkService/src/main/resources/mapper/WxCUserFromBMapper.xml b/mallinkService/src/main/resources/mapper/WxCUserFromBMapper.xml new file mode 100644 index 000000000..96e91e10f --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxCUserFromBMapper.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + `id`,`tenant_id`,`merchant_id`,`b_user_id`,`c_user_id`,`info`,`create_time`,`update_time`,`openid` + + + + where 1 = 1 + and `id` = #{id} + and `tenant_id` = #{tenantId} + and `merchant_id` = #{merchantId} + and `b_user_id` = #{bUserId} + and `c_user_id` = #{cUserId} + and `info` = #{info} + and `create_time` = #{createTime} + and `update_time` = #{updateTime} + and `openid` = #{openid} + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + + + + + +