diff --git a/anrui-base/anrui-base-biz/src/main/java/com/yxt/anrui/base/biz/commoncontract/CommonContractService.java b/anrui-base/anrui-base-biz/src/main/java/com/yxt/anrui/base/biz/commoncontract/CommonContractService.java index f0aee2a4e8..de68c2c3eb 100644 --- a/anrui-base/anrui-base-biz/src/main/java/com/yxt/anrui/base/biz/commoncontract/CommonContractService.java +++ b/anrui-base/anrui-base-biz/src/main/java/com/yxt/anrui/base/biz/commoncontract/CommonContractService.java @@ -1756,7 +1756,10 @@ public class CommonContractService extends MybatisBaseService { int updateEmail(@Param("sid") String sid, @Param("email") String email); int updateRemarks(@Param("sid") String sid, @Param("remarks") String remarks); + + /** + * 根据客户编码查询客户信息 + * @param customerNo 客户编码 + * @return + */ + CrmCustomerTemp selectByCustomerNo(String customerNo); } \ No newline at end of file diff --git a/anrui-crm/anrui-crm-biz/src/main/java/com/yxt/anrui/crm/biz/crmcustomertemp/CrmCustomerTempMapper.xml b/anrui-crm/anrui-crm-biz/src/main/java/com/yxt/anrui/crm/biz/crmcustomertemp/CrmCustomerTempMapper.xml index 480f6b9cbd..5015f1809a 100644 --- a/anrui-crm/anrui-crm-biz/src/main/java/com/yxt/anrui/crm/biz/crmcustomertemp/CrmCustomerTempMapper.xml +++ b/anrui-crm/anrui-crm-biz/src/main/java/com/yxt/anrui/crm/biz/crmcustomertemp/CrmCustomerTempMapper.xml @@ -231,4 +231,8 @@ update crm_customer_temp set remarks = #{remarks} where sid = #{sid} + + \ No newline at end of file diff --git a/anrui-crm/anrui-crm-biz/src/main/java/com/yxt/anrui/crm/biz/crmcustomertemp/CrmCustomerTempService.java b/anrui-crm/anrui-crm-biz/src/main/java/com/yxt/anrui/crm/biz/crmcustomertemp/CrmCustomerTempService.java index 4cadb31dbc..6c6e603647 100644 --- a/anrui-crm/anrui-crm-biz/src/main/java/com/yxt/anrui/crm/biz/crmcustomertemp/CrmCustomerTempService.java +++ b/anrui-crm/anrui-crm-biz/src/main/java/com/yxt/anrui/crm/biz/crmcustomertemp/CrmCustomerTempService.java @@ -270,83 +270,66 @@ public class CrmCustomerTempService extends MybatisBaseService map = new HashMap<>(); - map.put("staffSid", userOrgInfoVo.getStaffSid()); - if (StringUtils.isBlank(dto.getSid())) { // 新增 - if (StringUtils.isNotBlank(dto.getMobile())) { // 有手机号 - //查询业务员的分公司简称和部门简称 - String customerNo = getPrefix(userOrgInfoVo.getStaffSid(), dto.getName(), dto.getMobile()); - CrmCustomerTempVo customerTempVo = baseMapper.selectNo(customerNo); -// map.put("mobile", dto.getMobile()); -// CrmCustomerTempVo customerTempVo = baseMapper.selectByMobileOrWx(map); - if (customerTempVo != null) { - // 是否为当前用户的客户 - if (customerTempVo.getStaffSid().equals(userOrgInfoVo.getStaffSid())) { - // 返回潜在客户sid,跳转维护信息页面 - return new ResultBean().fail().setCode(HttpStatusEnum.CRM_ERROR_EXIST.getCode()).setMsg(HttpStatusEnum.CRM_ERROR_EXIST.getMsg()).setData(customerTempVo.getSid()); - } else { - // 不是当前用户的客户,提示 - SysUserVo userVo = sysUserFeign.selectByStaffsid(customerTempVo.getStaffSid()).getData(); - return new ResultBean().fail().setCode(HttpStatusEnum.CRM_ERROR_NOTBELONG.getCode()).setMsg("该手机号客户为" + userVo.getName() - + "的客户,如需更改,请联系" + userVo.getName()); + String sid = dto.getSid(); + //业务员sid + String staffSid = sysUserVo.getStaffSid(); + //姓名 + String name = dto.getName(); + String mobile = dto.getMobile(); + if(StringUtils.isBlank(sid)){//新增 + //生成客户编码:分公司简称+部门编码+手机号+姓名首字母大写拼写 + String customerNo = getPrefix(staffSid,name,mobile); + //查询该客户编码是否存在 + CrmCustomerTemp crmCustomerTemp = baseMapper.selectByCustomerNo(customerNo); + if(crmCustomerTemp != null){//存在 + //查询是否是当前用户客户 + if(!dto.getUserSid().equals(crmCustomerTemp.getCreateBySid())){ + String staffName = ""; + SysUserVo sysCrmVo = sysUserFeign.fetchBySid(crmCustomerTemp.getCreateBySid()).getData(); + if(sysCrmVo != null){ + staffName = sysCrmVo.getName(); + return rb.setCode(HttpStatusEnum.CRM_ERROR_NOTBELONG.getCode()).setMsg("为"+staffName+"销售专员客户"); } - } else { - // 新增 - CrmCustomerTemp customerTemp = insertCrmCustomerTemp(dto, userOrgInfoVo); - return new ResultBean().success().setMsg("添加成功").setData(customerTemp.getSid()); - } - } else { // 无手机号,有微信号 - map.put("weixin", dto.getWeixin()); - CrmCustomerTempVo customerTempVo = baseMapper.selectByMobileOrWx(map); - if (customerTempVo != null) { - return new ResultBean().fail().setCode(HttpStatusEnum.CRM_ERROR_WXEXIST.getCode()).setMsg(HttpStatusEnum.CRM_ERROR_WXEXIST.getMsg()); - } else { - // 新增 - CrmCustomerTemp customerTemp = insertCrmCustomerTemp(dto, userOrgInfoVo); - return new ResultBean().success().setMsg("添加成功").setData(customerTemp.getSid()); + }else{ + // 返回潜在客户sid,跳转维护信息页面 + return rb.setCode(HttpStatusEnum.CRM_ERROR_EXIST.getCode()).setMsg(HttpStatusEnum.CRM_ERROR_EXIST.getMsg()).setData(crmCustomerTemp.getSid()); } + + }else{//不存在 + // 新增 + CrmCustomerTemp customerTemp = insertCrmCustomerTemp(dto, sysUserVo); + sid = customerTemp.getSid(); + } - } else { // 修改 - if (StringUtils.isNotBlank(dto.getMobile())) { - //查询业务员的分公司简称和部门简称 - String customerNo = getPrefix(userOrgInfoVo.getStaffSid(), dto.getName(), dto.getMobile()); - CrmCustomerTempVo customerTempVo = baseMapper.selectNo1(customerNo, dto.getSid()); - if (customerTempVo != null) { - return new ResultBean().fail().setMsg("该手机号已绑定其它客户,请重新添加"); - } - /* AppCrmCustomerTempInfoVo appCrmCustomerTempInfoVo = baseMapper.selectBySid(dto.getSid()); - String mobile = appCrmCustomerTempInfoVo.getMobile(); - if (!mobile.equals(dto.getMobile())) { - int count = baseMapper.selBySidAndMobile(dto.getSid(), dto.getMobile()); - if (count > 0) { - return new ResultBean().fail().setMsg("该手机号已绑定其它客户,请重新添加"); - } - }*/ + + }else{//修改 + CrmCustomerTemp customerTemp = fetchBySid(sid); + if(customerTemp == null){ + return rb.setMsg("该客户不存在"); + } + //对比客户名称以及手机号是否变化 + if(!customerTemp.getName().equals(dto.getName())){ + return rb.setMsg("客户名称不允许修改"); + } + if(!customerTemp.getMobile().equals(dto.getMobile())){ + return rb.setMsg("客户手机号不允许修改"); } -// if (StringUtils.isNotBlank(dto.getWeixin())) { -// AppCrmCustomerTempInfoVo appCrmCustomerTempInfoVo = baseMapper.selectBySid(dto.getSid()); -// String weiXin = appCrmCustomerTempInfoVo.getWeiXin(); -// if (!weiXin.equals(dto.getWeixin())) { -// int count = baseMapper.selBySidAndWeixin(dto.getSid(), dto.getWeixin()); -// if (count > 0) { -// return new ResultBean().fail().setMsg("该微信已绑定其它客户,请重新添加"); -// } -// } -// } -// if (StringUtils.isNotBlank(dto.getWeixin())) { -// map.put("weixin", dto.getWeixin()); -// CrmCustomerTempVo crmCustomerTempVo = baseMapper.selectByMobileOrWx(map); -// if (crmCustomerTempVo != null && crmCustomerTempVo.getStaffSid().equals(userOrgInfoVo.getStaffSid())) { -// if (crmCustomerTempVo.getWeixin().equals(dto.getWeixin())) { -// return new ResultBean().fail().setMsg("该微信号已绑定其它客户,请重新添加"); -// } -// } -// } - CrmCustomerTemp customerTemp = fetchBySid(dto.getSid()); BeanUtil.copyProperties(dto, customerTemp); String adCode = dto.getAdCode(); if (StringUtils.isNotBlank(adCode)) { @@ -358,46 +341,12 @@ public class CrmCustomerTempService extends MybatisBaseService staffOrgResultBean = sysStaffOrgFeign.getOrgByStaffSid(customerTemp.getStaffSid()); - if (staffOrgResultBean.getSuccess()) { - SysStaffOrg sysStaffOrg = staffOrgResultBean.getData(); - if (sysStaffOrg != null) { - ResultBean resultBean1 = sysStaffOrgFeign.getOrgSidByPath(sysStaffOrg.getOrgSidPath()); - if (resultBean1.getSuccess()) { - String osid = resultBean1.getData(); - if (StringUtils.isNotBlank(osid)) { - ResultBean sysOrganizationVoResultBean = sysOrganizationFeign.fetchBySid(osid); - if (sysOrganizationVoResultBean.getSuccess()) { - SysOrganizationVo sysOrganizationVo = sysOrganizationVoResultBean.getData(); - customerNoPrefix = customerNoPrefix + sysOrganizationVo.getOrgAbbre(); - } - } - } - String orgSid1 = sysStaffOrg.getOrgSid(); - ResultBean sysOrganizationVoResultBean = sysOrganizationFeign.fetchBySid(orgSid1); - if (sysOrganizationVoResultBean.getSuccess()) { - SysOrganizationVo sysOrganizationVo = sysOrganizationVoResultBean.getData(); - customerNoPrefix = customerNoPrefix + sysOrganizationVo.getOrgCode(); - } - } - } - String customerNo = getPrefix(customerTemp.getStaffSid(),customerTemp.getName(),customerTemp.getMobile()); -// String customerNo = customerNoPrefix + HanZiConverterPinYin.getPinYinFirst(customerTemp.getName()) + customerTemp.getMobile(); - customerTemp.setCustomerNo(customerNo); boolean updateBoolean = updateById(customerTemp); - if (updateBoolean) { - // 更新附件表 -// if (!dto.getFilePaths().isEmpty()) { -// updateCrmFile(dto, customerTemp); -// } - return new ResultBean().success().setMsg("更新成功").setData(customerTemp.getSid()); - } else { - return new ResultBean().fail().setMsg("更新失败"); + if (!updateBoolean) { + return rb.fail().setMsg("更新失败"); } } + return rb.success().setData(sid); } /** @@ -708,7 +657,7 @@ public class CrmCustomerTempService extends MybatisBaseService map = genetrateCustomerNum(dto.getCustomerTypeKey(), userOrgInfoVo); customerTemp.setCreateBySid(dto.getUserSid()); customerTemp.setStaffSid(userOrgInfoVo.getStaffSid()); -// String orgSid = sysStaffOrgFeign.getPathSidByUserSid(dto.getUserSid()).getData(); -// customerTemp.setCreateOrgSid(orgSid); -// customerTemp.setCreateOrgSid(userOrgInfoVo.getOrgSid()); -// customerTemp.setCustomerNo(map.get("code")); customerTemp.setCertificateTypeKey(customerTemp.getCustomerTypeKey().equals("1") ? "01" : "02"); customerTemp.setCertificateType(customerTemp.getCustomerTypeKey().equals("1") ? "身份证" : "营业执照"); ResultBean resultBean = dictCommonFeign.getFirstDictKeyByType(DictCommonType.FOLLOW_STATE, "0"); @@ -750,34 +694,7 @@ public class CrmCustomerTempService extends MybatisBaseService staffOrgResultBean = sysStaffOrgFeign.getOrgByStaffSid(customerTemp.getStaffSid()); - if (staffOrgResultBean.getSuccess()) { - SysStaffOrg sysStaffOrg = staffOrgResultBean.getData(); - if (sysStaffOrg != null) { - ResultBean resultBean1 = sysStaffOrgFeign.getOrgSidByPath(sysStaffOrg.getOrgSidPath()); - if (resultBean1.getSuccess()) { - String osid = resultBean1.getData(); - if (StringUtils.isNotBlank(osid)) { - ResultBean sysOrganizationVoResultBean = sysOrganizationFeign.fetchBySid(osid); - if (sysOrganizationVoResultBean.getSuccess()) { - SysOrganizationVo sysOrganizationVo = sysOrganizationVoResultBean.getData(); - customerNoPrefix = customerNoPrefix + sysOrganizationVo.getOrgAbbre(); - } - } - } - String orgSid1 = sysStaffOrg.getOrgSid(); - ResultBean sysOrganizationVoResultBean = sysOrganizationFeign.fetchBySid(orgSid1); - if (sysOrganizationVoResultBean.getSuccess()) { - SysOrganizationVo sysOrganizationVo = sysOrganizationVoResultBean.getData(); - customerNoPrefix = customerNoPrefix + sysOrganizationVo.getOrgCode(); - } - } - } - //客户编码 String customerNo = getPrefix(customerTemp.getStaffSid(),customerTemp.getName(),customerTemp.getMobile()); -// String customerNo = customerNoPrefix + HanZiConverterPinYin.getPinYinFirst(customerTemp.getName()) + customerTemp.getMobile(); customerTemp.setCustomerNo(customerNo); save(customerTemp); // 增加跟进记录 @@ -839,27 +756,13 @@ public class CrmCustomerTempService extends MybatisBaseService sysUserInfoVoResultBean = sysUserFeign.selectUserInfoByUserSid(userSid); - if (!sysUserInfoVoResultBean.getSuccess()) { - return rb.setMsg(sysUserInfoVoResultBean.getMsg()); - } - //用户所属组织信息 - SysUserInfoVo sysUserInfoVo = sysUserInfoVoResultBean.getData(); - if (StringUtils.isBlank(sysUserInfoVo.getOrgSid())) { - return rb.setMsg("请先设置该员工所属部门"); - } + String sid = ""; //手机号 String mobile = dto.getMobile(); //微信号 String weixin = dto.getWeixin(); - if (StringUtils.isBlank(mobile)) { - return rb.setMsg("请输入联系电话"); - } if ("1".equals(dto.getCustomerType())) { - if (!weixin.matches("^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$")) { + if (!mobile.matches("^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$")) { return rb.setMsg("手机号格式不正确"); } if (StringUtils.isNotBlank(dto.getIDNumber())) { @@ -891,46 +794,37 @@ public class CrmCustomerTempService extends MybatisBaseService sysUserVoResultBean = sysUserFeign.selectByStaffsid(crmCustomerTempVo.getStaffSid()); - if (sysUserVoResultBean.getSuccess()) { - return rb.setMsg("该手机号客户为" + sysUserVoResultBean.getData().getName() + "的客户,如需更改,请联系" + sysUserVoResultBean.getData().getName()); - } else { - return rb.setMsg(sysUserInfoVoResultBean.getMsg()); - } + //根据用户sid获取业务员信息 + SysUserVo sysUserVo = sysUserFeign.fetchBySid(dto.getUserSid()).getData(); + if(sysUserVo == null){ + return rb.setMsg("该用户不存在"); + } + String staffSid = sysUserVo.getStaffSid(); + String name = dto.getName(); + //生成客户编码:分公司简称+部门编码+手机号+姓名首字母大写拼写 + String customerNo = getPrefix(staffSid,name,mobile); + //查询该客户编码是否存在 + CrmCustomerTemp crmCustomerTemp = baseMapper.selectByCustomerNo(customerNo); + if(crmCustomerTemp != null){//存在 + //查询是否是当前用户客户 + if(!dto.getUserSid().equals(crmCustomerTemp.getCreateBySid())){ + String staffName = ""; + SysUserVo sysCrmVo = sysUserFeign.fetchBySid(crmCustomerTemp.getCreateBySid()).getData(); + if(sysCrmVo != null){ + staffName = sysCrmVo.getName(); + return rb.setCode(HttpStatusEnum.CRM_ERROR_NOTBELONG.getCode()).setMsg("为"+staffName+"销售专员客户"); } - - } - } else if (StringUtils.isNotBlank(weixin)) { -// String staffSid = sysUserInfoVo.getStaffSid(); - //根据客户的微信号以及当前登录者所在部门的sid和登录者所关联的员工sid查询 - CrmCustomerTempVo crmCustomerTempVo = baseMapper.selectByWx(staffSid, weixin); - if (crmCustomerTempVo == null) { - //新增潜在客户信息 - CrmCustomerTemp crmCustomerTemp = saveCrmCustomerTemp(dto, sysUserInfoVo); - return rb.success().setData(crmCustomerTemp.getSid()); - } else { - return rb.setCode(HttpStatusEnum.CRM_ERROR_WXEXIST.getCode()).setMsg(HttpStatusEnum.CRM_ERROR_WXEXIST.getMsg()); + }else{ + // 返回潜在客户sid,跳转维护信息页面 + return rb.setCode(HttpStatusEnum.CRM_ERROR_EXIST.getCode()).setMsg(HttpStatusEnum.CRM_ERROR_EXIST.getMsg()).setData(crmCustomerTemp.getSid()); } + + }else{//不存在 + // 新增 + CrmCustomerTemp customerTemp = saveCrmCustomerTemp(dto, sysUserVo); + sid = customerTemp.getSid(); } - return rb.success(); + return rb.success().setData(crmCustomerTemp.getSid()); } /** @@ -940,47 +834,19 @@ public class CrmCustomerTempService extends MybatisBaseService map = genetrateCustomerNumO(dto.getCustomerTypeKey(), sysUserInfoVo); - crmCustomerTemp.setCustomerNo(map.get("code"));*/ ResultBean resultBean = dictCommonFeign.getFirstDictKeyByType(DictCommonType.FOLLOW_STATE, "0"); if (resultBean.getSuccess() && resultBean.getData() != null) { String key = resultBean.getData().toString(); crmCustomerTemp.setFollow_state_key(key); crmCustomerTemp.setFollow_state(dictCommonFeign.selectBykey(key, DictCommonType.FOLLOW_STATE).getData().getDictValue()); } - String customerNoPrefix = ""; - //查询业务员的分公司简称和部门编码 - ResultBean staffOrgResultBean = sysStaffOrgFeign.getOrgByStaffSid(sysUserInfoVo.getStaffSid()); - if (staffOrgResultBean.getSuccess()) { - SysStaffOrg sysStaffOrg = staffOrgResultBean.getData(); - if (sysStaffOrg != null) { - ResultBean resultBean1 = sysStaffOrgFeign.getOrgSidByPath(sysStaffOrg.getOrgSidPath()); - if (resultBean1.getSuccess()) { - String osid = resultBean1.getData(); - if (StringUtils.isNotBlank(osid)) { - ResultBean sysOrganizationVoResultBean = sysOrganizationFeign.fetchBySid(osid); - if (sysOrganizationVoResultBean.getSuccess()) { - SysOrganizationVo sysOrganizationVo = sysOrganizationVoResultBean.getData(); - customerNoPrefix = customerNoPrefix + sysOrganizationVo.getOrgAbbre(); - } - } - } - String orgSid1 = sysStaffOrg.getOrgSid(); - ResultBean sysOrganizationVoResultBean = sysOrganizationFeign.fetchBySid(orgSid1); - if (sysOrganizationVoResultBean.getSuccess()) { - SysOrganizationVo sysOrganizationVo = sysOrganizationVoResultBean.getData(); - customerNoPrefix = customerNoPrefix + sysOrganizationVo.getOrgCode(); - } - } - } //客户编码 String customerNo = getPrefix(crmCustomerTemp.getStaffSid(), crmCustomerTemp.getName(), crmCustomerTemp.getMobile()); crmCustomerTemp.setCustomerNo(customerNo); @@ -1055,55 +921,23 @@ public class CrmCustomerTempService extends MybatisBaseService sysUserInfoVoResultBean = sysUserFeign.selectUserInfoByUserSid(userSid); - if (!sysUserInfoVoResultBean.getSuccess()) { - return rb.setMsg(sysUserInfoVoResultBean.getMsg()); - } - //用户所属组织信息 - SysUserInfoVo sysUserInfoVo = sysUserInfoVoResultBean.getData(); - if (StringUtils.isBlank(sysUserInfoVo.getOrgSid())) { - return rb.setMsg("请先设置该员工所属部门"); - } - String staffSid = sysUserInfoVo.getStaffSid(); - String mobile = dto.getMobile(); - String weixin = dto.getWeixin(); - if (StringUtils.isBlank(mobile) && StringUtils.isBlank(weixin)) { - return rb.setMsg("联系电话和微信号二选一必填"); + CrmCustomerTemp customerTemp = fetchBySid(sid); + if(customerTemp == null){ + return rb.setMsg("该客户不存在"); } - if (StringUtils.isNotBlank(mobile)) { - String customerNo = getPrefix(staffSid, dto.getName(), dto.getMobile()); - CrmCustomerTempVo crmCustomerTempVo = baseMapper.selectNo1(customerNo, sid); -// CrmCustomerTempVo crmCustomerTempVo = baseMapper.selectByMobile(staffSid, mobile); - if (crmCustomerTempVo != null && !crmCustomerTempVo.getStaffSid().equals(sysUserInfoVo.getStaffSid())) { - return rb.setMsg("该手机号已绑定其他客户,请重新添加"); - } - } else { - //根据客户的微信号以及当前登录者所在部门的sid和登录者所关联的员工sid查询 - CrmCustomerTempVo crmCustomerTempVo = baseMapper.selectByWx(staffSid, weixin); - if (crmCustomerTempVo != null && !crmCustomerTempVo.getStaffSid().equals(sysUserInfoVo.getStaffSid())) { - return rb.setMsg("该微信号已绑定其他客户,请重新添加"); - } + //对比客户名称以及手机号是否变化 + if(!customerTemp.getName().equals(dto.getName())){ + return rb.setMsg("客户名称不允许修改"); } - CrmCustomerTemp customerTemp = fetchBySid(sid); - if (customerTemp == null) { - return rb.setMsg("该客户信息不存在"); + if(!customerTemp.getMobile().equals(dto.getMobile())){ + return rb.setMsg("客户手机号不允许修改"); } BeanUtil.copyProperties(dto, customerTemp); - //客户编码 - String customerNoPrefix = ""; - //查询业务员的分公司简称和部门简称 - String customerNo = getPrefix(staffSid, dto.getName(), dto.getMobile()); -// CrmCustomerTempVo crmCustomerTempVo = baseMapper.selectNo(customerNo); -// String customerNo = customerNoPrefix + HanZiConverterPinYin.getPinYinFirst(customerTemp.getName()) + customerTemp.getMobile(); - customerTemp.setCustomerNo(customerNo); baseMapper.updateById(customerTemp); //更新运营信息 CrmBusinessDto crmBusinessDto = dto.getCrmBusinessDto(); crmBusinessService.updateByCusSid(crmBusinessDto, sid); - return rb.success().setMsg("更新成功"); + return rb.success(); } /**