package com.hx.phip.service.impl; import javax.annotation.Resource; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hx.common.service.CommonService; import com.hx.phiappt.common.PlatformConstants; import com.hx.phiappt.common.UserChannelType; import com.hx.phiappt.common.UserStatusConstants; import com.hx.phiappt.constants.tool.UserInfoTool; import com.hx.phiappt.constants.tool.UserStatusTool; import com.hx.phiappt.constants.tool.user.UserAgeTool; import com.hx.phiappt.constants.tool.user.UserRegisterRecordTool; import com.hx.phiappt.constants.tool.user.UserLevelTool; import com.hx.phiappt.dao.mapper.GzhFocusRecordMapper; import com.hx.phiappt.dao.mapper.TransferRecordMapper; import com.hx.phiappt.dto.label.UserLabelDcpAddDto; import com.hx.phiappt.dto.label.UserLabelDcpDto; import com.hx.phiappt.dto.userPretriage.UserPretriageInfoDto; import com.hx.phiappt.model.*; import com.hx.phiappt.model.channels.Channels; import com.hx.phiappt.model.memberLevel.MemberLevel; import com.hx.phiappt.model.user.UserWakeUpLog; import com.hx.phiappt.model.userLevel.UserLevelRecord; import com.hx.phiappt.model.userLevel.UserLevelRule; import com.hx.phiappt.model.userStatus.UserStatusLog; import com.hx.phiappt.model.wechat.gzh.GzhFocusRecord; import com.hx.phiappt.util.UserPretriageAdminMpTool; import com.hx.phiappt.vo.wechat.GzhUnionDto; import com.hx.phip.config.CustomParameter; import com.hx.phip.config.FeignRequestInterceptor; import com.hx.phip.config.GlobalExceptionHandler; import com.hx.phip.dao.mapper.*; import com.hx.phip.entity.user.UserDto; import com.hx.phip.service.SystemParameterService; import com.hx.phip.service.UserUnionHisService; import com.hx.resultTool.Result; import com.hx.util.DateUtil; import com.hx.util.HttpUtil; import com.hx.util.SimpleTool; import com.hx.util.StringUtils; import com.hx.util.mysql.aes.MysqlHexAesTool; import com.hz.his.dto.dcp.UserTagInfoDto; import com.hz.his.dto.token.GetTokenDto; import com.hz.his.dto.user.UserParamDto; import com.hz.his.dto.user.usercompleteInfo.UserInfoCompleteDto; import com.hz.his.feign.service.dcp.SUserTagInfoService; import com.hz.his.feign.service.platform.SWxTokenService; import com.hz.his.feign.service.sync.SyncUserService; import com.platform.exception.PlatTipsException; import com.platform.resultTool.PlatformCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.hx.exception.TipsException; import com.hx.phip.service.UserService; import com.hx.mybatisTool.SqlSentence; import org.springframework.web.bind.annotation.RequestMapping; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; @Transactional @Service public class UserServiceImpl implements UserService { //log4j日志 private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class.getName()); @Resource protected CommonService commonService; @Resource private ShopMapper shopMapper; @Resource private UserMapper userMapper; @Resource private EmployeeMapper employeeMapper; @Resource private CustomParameter customParameter; @Resource private UserInfoMapper userInfoMapper; @Resource private UserPhoneBookMapper userPhoneBookMapper; @Resource private UserAddressBookMapper userAddressBookMapper; @Resource private UserGeneralLabelMapper userGeneralLabelMapper; @Resource private UserInterestsMapper userInterestsMapper; @Resource private UserContactInformationMapper userContactInformationMapper; @Resource private UserUnionHisService userUnionHisService; @Resource private UserMoneyMapper userMoneyMapper; @Resource private UserUpdateLogMapper userUpdateLogMapper; @Resource private SyncUserService syncUserService; @Resource private SystemParameterService systemParameterService; @Resource private UserWakeUpLogMapper userWakeUpLogMapper; @Resource private FamiliesRoomMapper familiesRoomMapper; @Resource private UserFamiliesRoomMapper userFamiliesRoomMapper; @Resource private SUserTagInfoService sUserTagInfoService; /**查询列表*/ @Override public List selectList(SqlSentence sqlSentence) { return userMapper.selectList(sqlSentence); } /**查询列表*/ @Override public List> selectListMap(SqlSentence sqlSentence) { return userMapper.selectListMap(sqlSentence); } /**查询单个*/ @Override public User selectOne(SqlSentence sqlSentence) { return userMapper.selectOne(sqlSentence); } /** * 校验电话号码 * @param object 电话号码 * @return 返回 */ @Override public List selectOneByTel(Object object) { SqlSentence sqlSentence = new SqlSentence(); Map sqlValue = new HashMap<>(); String sql = "select * from user WHERE tel = #{m.tel} and isDel = #{m.isDel}"; sqlValue.put("isDel", BaseEntity.NO); sqlValue.put("tel", object); sqlSentence.sqlSentence(sql,sqlValue); return userMapper.selectList(sqlSentence); } /**查询单个*/ @Override public Map selectOneMap(SqlSentence sqlSentence) { return userMapper.selectOneMap(sqlSentence); } /**查询单个,大数据不拿取*/ @Override public User selectOneByKey(Object object) { return userMapper.selectOneByKey(object); } /**查询单个,大数据拿取*/ @Override public User selectOneByKeyBlob(Object object) { return userMapper.selectOneByKeyBlob(object); } /**新增*/ @Override public void insert(User user) { int count = userMapper.insert(user); if(count != 1) { throw new TipsException("新增失败!"); } } /**修改*/ @Override public void updateAll(User user) { int count = userMapper.updateAll(user); if(count!=1) { throw new TipsException("保存失败!"); } } /**修改*/ @Override public void updateWhere(SqlSentence sqlSentence) { int count = userMapper.updateWhere(sqlSentence); if(count!=1) { throw new TipsException("保存失败!"); } } /**删除一个*/ @Override public void deleteOne(String delId) { int count = userMapper.deleteById(delId); if(count!=1) { throw new TipsException("删除失败!"); } } /**查询条数*/ @Override public int selectCount(SqlSentence sqlSentence) { int count = userMapper.selectCount(sqlSentence); return count; } /**新增*/ @Override public synchronized String insertInfo(UserDto userDto,String appId) { // 20230105 荣爷说:新增,修改客户,同步领键的时候,“所属tmk”字段分别赋值给领键的“电网咨询师”和“所属客服”字段 userDto.setChatCorpUserId(userDto.getInternetCorpUserId()); // 用户对象 User user = new User(); // 处理用户对象 user.setName(userDto.getName()); user.setImgUrl(userDto.getImgUrl()); // 默认新建会员为准会员 if (!StringUtils.isEmpty(userDto.getUserLevel())) { user.setUserLevel(userDto.getUserLevel()); } else { user.setUserLevel("普卡"); // 获取默认会员等级 MemberLevel memberLevel = UserInfoTool.getMemberLevelByHisNo(commonService, null); if (memberLevel != null) { user.setMemberLevelId(memberLevel.getId()); user.setUserLevel(memberLevel.getName()); } } user.setStarLevel(userDto.getStarLevel()); user.setUserType(userDto.getUserType()); user.setChannelCategory(userDto.getChannelCategory()); user.setChannelId(userDto.getChannelId()); user.setChannelType(userDto.getChannelType()); user.setChannel2Id(userDto.getChannel2Id()); user.setChannelType2(userDto.getChannelType2()); // 获取冗余渠道信息 if (!StringUtils.isEmpty(userDto.getChannel2Id())){ String channelInfo = UserInfoTool.getChannelInfo(commonService, userDto.getChannel2Id()); user.setChannelInfo(channelInfo); } user.setChannelAssistId(userDto.getChannelAssistId()); user.setChannelAssistName(userDto.getChannelAssistName()); user.setChannelAssist2Id(userDto.getChannelAssist2Id()); user.setChannelAssist2Name(userDto.getChannelAssist2Name()); // 获取冗余副渠道信息 if (!StringUtils.isEmpty(userDto.getChannelAssist2Id())){ String channelInfo = UserInfoTool.getChannelInfo(commonService, userDto.getChannelAssist2Id()); user.setChannelAssist2Json(channelInfo); } user.setQQ(userDto.getQQ()); user.setGender(userDto.getGender()); user.setCIQ(userDto.getCIQ()); user.setTel(userDto.getTel()); user.setRemark(userDto.getRemark()); //user.setMoney(userDto.getMoney()); user.setLastDoctorId(userDto.getLastDoctorId()); user.setLastCorpUserId(userDto.getLastCorpUserId()); user.setCertificateType(userDto.getCertificateType()); user.setCertificateNo(userDto.getCertificateNo()); user.setBirthDay(userDto.getBirthDay()); user.setCorpUserId(userDto.getCorpUserId()); //user.setApiId(userDto.getApiId()); user.setHisCorpUserId(userDto.getHisCorpUserId()); user.setShopId(userDto.getShopId()); // 生成会员号 废弃 /*String memberNO = UserInfoTool.getCreateMemberNO(commonService, null); user.setMemberNO(memberNO);*/ // 生成CIQ 要把CIQ和客户唯一编号融合 禅道:933 String ciqNo = systemParameterService.createCIQNo(userDto.getShopId()); user.setCIQ(ciqNo); user.setMemberNO(ciqNo); user.setUserRole(userDto.getUserRole()); user.setPinyinCode(userDto.getPinyinCode()); user.setCustomerDeveloperId(userDto.getCustomerDeveloperId()); user.setInternetCorpUserId(userDto.getInternetCorpUserId()); user.setBeauticianCorpUserId(userDto.getBeauticianCorpUserId()); user.setChatCorpUserId(userDto.getChatCorpUserId()); user.setConsultCorpUserId(userDto.getConsultCorpUserId()); user.setShareCustomer(userDto.getShareCustomer()); user.setNurseCorpUserId(userDto.getNurseCorpUserId()); user.setDoctorCorpUserId(userDto.getDoctorCorpUserId()); user.setConsultBelonging(userDto.getConsultBelonging()); user.setAppId(appId); user.setInviteeId(userDto.getInviteeId()); user.setCreatePersonType(BaseEntity.NO); user.setCreatePersonId(userDto.getCreatePersonId()); user.setCreatePersonName(userDto.getCreatePersonName()); // 处理下用户渠道信息 UserInfoTool.handlerChanelInfo(commonService, user); // 添加用户 int count = userMapper.insert(user); if (count != 1) { throw new TipsException("新增失败!"); } else { // 处理用户信息 UserInfo userInfo = new UserInfo(); userInfo.setUserId(user.getId()); userInfo.setCountryTypeName(userDto.getCountryTypeName()); userInfo.setLanguageTypeName(userDto.getLanguageTypeName()); userInfo.setYear(userDto.getYear()); userInfo.setConstellationTypeName(userDto.getConstellationTypeName()); userInfo.setNationalityTypeName(userDto.getNationalityTypeName()); userInfo.setProfessionTypeName(userDto.getProfessionTypeName()); userInfo.setIncomeTypeName(userDto.getIncomeTypeName()); userInfo.setMarriageTypeName(userDto.getMarriageTypeName()); userInfo.setGrowthTypeName(userDto.getGrowthTypeName()); userInfo.setNativePlaceTypeName(userDto.getNativePlaceTypeName()); userInfo.setUnitName(userDto.getUnitName()); userInfo.setIsHaveCar(userDto.getIsHaveCar()); userInfo.setCarNumber(userDto.getCarNumber()); userInfo.setAllergyLabel(userDto.getAllergyLabel()); int userInfoCount = userInfoMapper.insert(userInfo); if (userInfoCount != 1) { throw new TipsException("新增用户信息失败!"); } //保存平台来源信息-cjh-2022-04-19 userUnionHisService.insertUnion(user.getId(), userDto.getUserUnion()); // 处理用户联系信息 UserContactInformation userContactInformation = new UserContactInformation(); userContactInformation.setUserId(user.getId()); userContactInformation.setQQ(userDto.getQQ()); userContactInformation.setEmail(userDto.getEmail()); userContactInformation.setMerchantNo(userDto.getMerchantNo()); userContactInformation.setTelPhone(userDto.getTelPhone()); userContactInformation.setWechat(userDto.getWechat()); userContactInformation.setLine(userDto.getLine()); userContactInformation.setContactType(userDto.getContactType()); int userContactInsert = userContactInformationMapper.insert(userContactInformation); if (userContactInsert != 1) { throw new TipsException("新增用户联系信息失败!"); } // 处理新增用户是否触发赠送增值金接口 /* if(!StringUtils.isEmpty(userDto.getBirthDay())){ Calendar calendar=Calendar.getInstance(); String year = String.valueOf(calendar.get(Calendar.YEAR)); String month= BirthdayValueAddedFundTool.handleMonth(calendar.get(Calendar.MONTH)+1); if(userDto.getBirthDay().indexOf("-"+month+"-")!=-1){ BirthdayValueAddedFundTool.handleUserMoney(user,year); } }*/ // 处理用户兴趣标签 List userInterestsList = JSONArray.parseArray(userDto.getUserInterestsJson(), UserInterests.class); if (userInterestsList != null) { userInterestsList.forEach(userInterests -> { userInterests.setUserId(user.getId()); int insertUserInterests = userInterestsMapper.insert(userInterests); if (insertUserInterests != 1) { throw new TipsException("新增用户标签信息失败!"); } }); } // 刷新下用户信息 User checkUser = userMapper.selectOneByKey(user.getId()); // 处理用户电话簿信息 List userPhoneBookList = JSONArray.parseArray(userDto.getPhoneBooksJson(), UserPhoneBook.class); if (userPhoneBookList == null || userPhoneBookList.size() <= 0) { userPhoneBookList = new ArrayList<>(); // 主号码处理 if (!StringUtils.isEmpty(checkUser.getTel())) { UserPhoneBook primary = new UserPhoneBook(); primary.setUserId(checkUser.getId()); primary.setTel(checkUser.getTel()); primary.setIsPrimary(BaseEntity.YES); userPhoneBookList.add(primary); } } // 处理电话簿号码 userPhoneBookList.forEach(userPhoneBook -> { // 电话号码不为空才添加 if (!StringUtils.isEmpty(userPhoneBook.getTel())) { if (userPhoneBook.getTel().contains("****")) { throw new TipsException("手机号码格式请检查,不能是加密号码!"); } // 判断主要号码 if (!userPhoneBook.getTel().equals(user.getTel())) { List userList = this.selectOneByTel(userPhoneBook.getTel()); if (userList != null && userList.size() > 0) { throw new TipsException(String.format("电话号码:%s,手机号码已有其他客户使用!", userPhoneBook.getTel())); } } // 判断次要号码 UserPhoneBook checkUserPhoneBook = UserInfoTool.selectOneByTelOtherUser(commonService, userPhoneBook.getAreaCode(), userPhoneBook.getTel(), user.getId()); if (checkUserPhoneBook != null) { throw new TipsException(String.format("电话号码:%s,手机号码已有其他客户使用!", userPhoneBook.getTel())); } // 新增加电话簿号码 userPhoneBook.setUserId(user.getId()); int insertUserPhoneBook = userPhoneBookMapper.insert(userPhoneBook); if (insertUserPhoneBook != 1) { throw new TipsException("新增用户次要手机号码失败!"); } // 判断主要号码 更新用户信息主号码 改其他方式处理 /*if (BaseEntity.YES.equals(userPhoneBook.getIsPrimary())) { SqlSentence sqlSentence = new SqlSentence(); Map sqlValue = new HashMap<>(); String sql = " tel = #{m.tel} WHERE id = #{m.userId}"; sqlValue.put("userId", userPhoneBook.getUserId()); sqlValue.put("tel", userPhoneBook.getTel()); sqlSentence.sqlSentence(sql, sqlValue); int i = userMapper.updateWhere(sqlSentence); if (i != 1) { throw new TipsException("更新用户主号码失败!"); } }*/ } }); // 处理用户地址 List userAddressBookList = JSONArray.parseArray(userDto.getAddressJson(), UserAddressBook.class); if (userAddressBookList != null) { userAddressBookList.forEach(userAddressBook -> { if (!StringUtils.isEmpty(userAddressBook.getCountry())) { userAddressBook.setUserId(user.getId()); int insertUserAddressBook = userAddressBookMapper.insert(userAddressBook); if (insertUserAddressBook != 1) { throw new TipsException("新增用户地址信息失败!"); } } }); } // 处理用户标签 List userGeneralLabelList = JSONArray.parseArray(userDto.getImpressionLabelJson(), UserGeneralLabel.class); if (userGeneralLabelList != null) { userGeneralLabelList.forEach(userGeneralLabel -> { userGeneralLabel.setUserId(user.getId()); userGeneralLabel.setType(UserGeneralLabel.TYPE_IMPRESSION_LABEL); int insertUserGeneralLabel = userGeneralLabelMapper.insert(userGeneralLabel); if (insertUserGeneralLabel != 1) { throw new TipsException("新增用户标签信息失败!"); } }); } } // 关闭同步领建代码 /*//处理门店信息 String hisShopId = ""; if (!StringUtils.isEmpty(userDto.getShopId())) { Shop shop = commonService.selectOneByKey(ShopMapper.class, userDto.getShopId()); if (shop == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "门店标识错误,门店信息不存在!"); } if (shop.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his门店信息不存在!"); } hisShopId = shop.getApiId(); } //处理所属顾问信息 String consultantId = ""; if (!StringUtils.isEmpty(userDto.getHisCorpUserId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getHisCorpUserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "所属顾问标识错误,顾问信息不存在!"); } if (employee.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his顾问信息不存在!"); } consultantId = employee.getApiId(); } //处理所属医生信息 String doctorId = ""; if (!StringUtils.isEmpty(userDto.getDoctorCorpUserId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getDoctorCorpUserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "所属医生标识错误,顾问信息不存在!"); } if (employee.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his医生信息不存在!"); } doctorId = employee.getApiId(); } //处理所属美容师信息 String beauticianId = ""; if (!StringUtils.isEmpty(userDto.getBeauticianCorpUserId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getBeauticianCorpUserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "所属美容师标识错误,顾问信息不存在!"); } if (employee.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his美容师信息不存在!"); } beauticianId = employee.getApiId(); } //处理所属客服信息 String customerServiceId = ""; if (!StringUtils.isEmpty(userDto.getChatCorpUserId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getChatCorpUserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "所属客服标识错误,顾问信息不存在!"); } if (employee.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his客服信息不存在!"); } customerServiceId = employee.getApiId(); } //处理所属电网咨询师信息 String serviceConsultantId = ""; if (!StringUtils.isEmpty(userDto.getInternetCorpUserId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getInternetCorpUserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "所属电网咨询师标识错误,顾问信息不存在!"); } if (employee.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his电网咨询师信息不存在!"); } serviceConsultantId = employee.getApiId(); }*/ //处理用户资金 Map sqlMap = new HashMap<>(); sqlMap.put("isDel", BaseEntity.NO); sqlMap.put("userId", user.getId()); SqlSentence sqlSentence = new SqlSentence(); sqlSentence.sqlSentence(" SELECT * FROM user_money WHERE isDel = #{m.isDel} AND userId = #{m.userId}", sqlMap); UserMoney userMoney = userMoneyMapper.selectOne(sqlSentence); if (userMoney == null) { userMoney = new UserMoney(); userMoney.setUserId(user.getId()); userMoney.setValueAddedFund(MysqlHexAesTool.encryptData("0", customParameter.getAesFixedKey(), null)); userMoney.setStoredValueFund(MysqlHexAesTool.encryptData("0", customParameter.getAesFixedKey(), null)); userMoney.setDeposit(MysqlHexAesTool.encryptData("0", customParameter.getAesFixedKey(), null)); userMoney.setIntegral(MysqlHexAesTool.encryptData("0", customParameter.getAesFixedKey(), null)); if (userMoneyMapper.insert(userMoney) != 1) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "初始化用户资金信息错误!"); } } // 添加用户日志 JSONArray logArray = new JSONArray(); // 创建客户的时候,记录变更日志时,同时记录选择的所属顾问和所属tmk,所属门店 if (!StringUtils.isEmpty(userDto.getHisCorpUserId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "添加所属顾问"); jsonObject.put("before", "无"); Employee after = employeeMapper.selectOneByKey(userDto.getHisCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } else { jsonObject.put("after", String.format("找不到员工信息,员工id:%s", userDto.getHisCorpUserId())); } logArray.add(jsonObject); } if (!StringUtils.isEmpty(userDto.getInternetCorpUserId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "添加所属TMK"); jsonObject.put("before", "无"); Employee after = employeeMapper.selectOneByKey(userDto.getInternetCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } else { jsonObject.put("after", String.format("找不到员工信息,员工id:%s", userDto.getInternetCorpUserId())); } logArray.add(jsonObject); } if (!StringUtils.isEmpty(userDto.getShopId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "添加所属门店"); jsonObject.put("before", "无"); Shop after = shopMapper.selectOneByKey(userDto.getShopId()); if (after != null) { jsonObject.put("after", after.getName()); } else { jsonObject.put("after", String.format("找不到门店信息,门店id:%s", userDto.getShopId())); } logArray.add(jsonObject); } // 获取操作员工名称 JSONObject jsonObjectData = new JSONObject(); Employee opEmployee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getCreatePersonId()); String name = opEmployee != null ? opEmployee.getCnName() : ""; jsonObjectData.put("key", String.format("【%s】员工在【%s】创建Phis平台客户账户", name, PlatformConstants.getName(userDto.getAppIdCode()))); logArray.add(jsonObjectData); // 记录编号 String recordNo = UserInfoTool.createUSLGNo(commonService, user.getId(), user.getCIQ()); // 调用工具类处理 UserInfoTool.addUserUpdateLog(commonService, userDto.getAppIdCode(), user, userDto.getShopId(), userDto.getCreatePersonId(), null, null, "创建账户", logArray, null, recordNo); // 处理用户登记记录 UserRegisterRecordTool.handlerUserRegisterRecord(commonService, user.getId(), userDto.getAppIdCode(), BaseEntity.NO); //处理新增或者更新用户初诊卡 if(userDto.getUserPretriageInfoDto()!= null){ UserPretriageInfoDto userPretriageInfoDto = userDto.getUserPretriageInfoDto(); userPretriageInfoDto.setUserId(user.getId()); UserPretriageAdminMpTool.insertOrEditPretriageInfo(userPretriageInfoDto,commonService); } // 切换领建屏蔽代码 date:20230108 /*// 同步用户到his系统 注释 正式区在开放 String returnHisData; // 构建请求his同步请求参数 JSONObject jsonObject = buildSyncUserHisData(user, hisShopId, consultantId, doctorId, beauticianId, customerServiceId, serviceConsultantId, userDto.getRemark(), BaseEntity.NO); try { jsonObject.put("appIdCode", userDto.getAppIdCode()); returnHisData = ApiPlatformUtil.syncHisUser(customParameter, userDto.getAppIdCode(), jsonObject.toJSONString()); } catch (Exception ex) { logger.error("同步用户到his系统出现失败!错误消息:", ex); throw new PlatTipsException(PlatformCode.ERROR_TIPS, "同步用户到his系统出现失败!"); } if (!StringUtils.isEmpty(returnHisData)) { JSONObject jsonHisObject = JSONObject.parseObject(returnHisData); if (jsonHisObject != null) { String code = jsonHisObject.getString("code"); if ("100".equals(code)) { String apiId = jsonHisObject.getString("data"); if (!StringUtils.isEmpty(apiId)) { if (apiId.contains("Internal Server Error")) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "同步用户到his系统失败!"); } this.updateUserApiId(user.getId(), apiId); } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "同步用户到his系统获取hisId失败!"); } } else { String error = jsonHisObject.getString("msg"); throw new PlatTipsException(PlatformCode.ERROR_TIPS, "同步his用户信息失败! 返回错误消息:" + error); } } } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "同步his用户信息失败! 返回为空消息!"); }*/ return user.getId(); } /**编辑*/ @Override public synchronized void updateInfo(User user, UserDto userDto) { // 20230105 荣爷说:新增,修改客户,同步领键的时候,“所属tmk”字段分别赋值给领键的“电网咨询师”和“所属客服”字段 userDto.setChatCorpUserId(userDto.getInternetCorpUserId()); //转诊 turnTreat(user,userDto); JSONArray logArray = new JSONArray(); // 处理用户对象 if (!StringUtils.isEmpty(userDto.getName())) { if (!userDto.getName().equals(user.getName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改姓名"); jsonObject.put("before", user.getName()); jsonObject.put("after", userDto.getName()); logArray.add(jsonObject); // 修改数据 user.setName(userDto.getName()); } } if (!StringUtils.isEmpty(userDto.getImgUrl())) { if (!userDto.getImgUrl().equals(user.getImgUrl())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改头像"); jsonObject.put("before", user.getImgUrl()); jsonObject.put("after", userDto.getImgUrl()); logArray.add(jsonObject); // 修改数据 user.setImgUrl(userDto.getImgUrl()); } } if (!StringUtils.isEmpty(userDto.getUserLevel())) { if (!userDto.getUserLevel().equals(user.getUserLevel())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改用户等级"); jsonObject.put("before", user.getUserLevel()); jsonObject.put("after", userDto.getUserLevel()); logArray.add(jsonObject); // 获取等级配置信息 UserLevelRule userLevelRule = UserLevelTool.getUserLevelRuleByName(commonService, userDto.getUserLevel()); // 添加会员等级记录 UserLevelTool.addUserLevelRecord(commonService, user, userLevelRule, null, userDto.getOpId()); // 修改数据 user.setUserLevel(userDto.getUserLevel()); user.setMemberLevelId(userLevelRule.getMemberLevelId()); } } if (userDto.getStarLevel() != null) { if (!userDto.getStarLevel().equals(user.getStarLevel())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改用户星级"); jsonObject.put("before", user.getStarLevel()); jsonObject.put("after", userDto.getStarLevel()); logArray.add(jsonObject); // 修改数据 user.setStarLevel(userDto.getStarLevel()); } } if (!StringUtils.isEmpty(userDto.getUserType())) { if (!userDto.getUserType().equals(user.getUserType())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改用户类型"); jsonObject.put("before", user.getUserType()); jsonObject.put("after", userDto.getUserType()); logArray.add(jsonObject); // 修改数据 user.setUserType(userDto.getUserType()); } } if (!StringUtils.isEmpty(userDto.getTel())) { // 先删除电话薄的子号码 UserInfoTool.deleteUserPhoneBookTel(commonService, user.getTel(), user.getId()); if (!StringUtils.isEmpty(userDto.getTel())) { if (!userDto.getTel().equals(user.getTel())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改手机号码"); jsonObject.put("before", user.getTel()); jsonObject.put("after", userDto.getTel()); logArray.add(jsonObject); // 修改数据 user.setTel(userDto.getTel()); } } } // 渠道处理 if (!StringUtils.isEmpty(userDto.getChannelId()) && !StringUtils.isEmpty(userDto.getChannel2Id())) { // 用户所属信息变更记录 String beCommonId = String.format("%s/%s", user.getChannelId(), user.getChannel2Id()); String commonId = String.format("%s/%s", userDto.getChannelId(), userDto.getChannel2Id()); UserInfoTool.userBeChangeLogAdd(user.getId(), UserBeChangeLog.CHANGE_TYPE_CHANNEL, beCommonId, commonId, userDto.getAppIdCode(), UserBeChangeLog.OPERATOR_TYPE_EMPLOYEE, userDto.getOpId(), userDto.getShopId(), userDto.getRemark(), commonService); } if (!StringUtils.isEmpty(userDto.getChannelId()) && !StringUtils.isEmpty(userDto.getChannelType())) { if (!userDto.getChannelType().equals(user.getChannelType())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改用户一级渠道"); jsonObject.put("before", user.getChannelType()); jsonObject.put("after", userDto.getChannelType()); logArray.add(jsonObject); // 修改数据 user.setChannelId(userDto.getChannelId()); user.setChannelType(userDto.getChannelType()); } } if (!StringUtils.isEmpty(userDto.getChannel2Id()) && !StringUtils.isEmpty(userDto.getChannelType2())) { if (!userDto.getChannelType2().equals(user.getChannelType2())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改用户二级渠道"); jsonObject.put("before", user.getChannelType2()); jsonObject.put("after", userDto.getChannelType2()); logArray.add(jsonObject); // 修改数据 user.setChannel2Id(userDto.getChannel2Id()); user.setChannelType2(userDto.getChannelType2()); // 获取冗余渠道信息 String channelInfo = UserInfoTool.getChannelInfo(commonService, userDto.getChannel2Id()); user.setChannelInfo(channelInfo); } } // 副渠道处理 if (!StringUtils.isEmpty(userDto.getChannelAssistId()) && !StringUtils.isEmpty(userDto.getChannelAssist2Id())) { // 用户所属信息变更记录 String beCommonId = String.format("%s/%s", user.getChannelAssistId(), user.getChannelAssist2Id()); String commonId = String.format("%s/%s", userDto.getChannelAssistId(), userDto.getChannelAssist2Id()); UserInfoTool.userBeChangeLogAdd(user.getId(), UserBeChangeLog.CHANGE_TYPE_CHANNEL_ASSIST, beCommonId, commonId, userDto.getAppIdCode(), UserBeChangeLog.OPERATOR_TYPE_EMPLOYEE, userDto.getOpId(), userDto.getShopId(), userDto.getRemark(), commonService); } if(!StringUtils.isEmpty(userDto.getChannelAssistId()) && !StringUtils.isEmpty(userDto.getChannelAssistName())) { if (!userDto.getChannelAssistName().equals(user.getChannelAssistName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改用户一级副渠道"); jsonObject.put("before", user.getChannelAssistName()); jsonObject.put("after", userDto.getChannelAssistName()); logArray.add(jsonObject); // 修改数据 user.setChannelAssistId(userDto.getChannelAssistId()); user.setChannelAssistName(userDto.getChannelAssistName()); } } if(!StringUtils.isEmpty(userDto.getChannelAssist2Id()) && !StringUtils.isEmpty(userDto.getChannelAssist2Name())) { if (!userDto.getChannelAssist2Name().equals(user.getChannelAssist2Name())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改用户二级副渠道"); jsonObject.put("before", user.getChannelAssist2Name()); jsonObject.put("after", userDto.getChannelAssist2Name()); logArray.add(jsonObject); // 修改数据 user.setChannelAssist2Id(userDto.getChannelAssist2Id()); user.setChannelAssist2Name(userDto.getChannelAssist2Name()); // 获取冗余渠道信息 String channelInfo = UserInfoTool.getChannelInfo(commonService, userDto.getChannelAssist2Id()); user.setChannelAssist2Json(channelInfo); } } if (!StringUtils.isEmpty(userDto.getQQ())) { if (!userDto.getQQ().equals(user.getQQ())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改QQ号码"); jsonObject.put("before", user.getQQ()); jsonObject.put("after", userDto.getQQ()); logArray.add(jsonObject); // 修改数据 user.setQQ(userDto.getQQ()); } } if (userDto.getGender() != null) { if (!userDto.getGender().equals(user.getGender())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改性别(0 未知 1 男 2 女)"); jsonObject.put("before", user.getGender()); jsonObject.put("after", userDto.getGender()); logArray.add(jsonObject); // 修改数据 user.setGender(userDto.getGender()); } } if (!StringUtils.isEmpty(userDto.getCIQ())) { if (!userDto.getCIQ().equals(user.getCIQ())) { // 判断用户是否有使用CIQ UserInfoTool.checkCIQHasUse(commonService, userDto.getCIQ()); // 用户日志 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改CIQ号码"); jsonObject.put("before", user.getCIQ()); jsonObject.put("after", userDto.getCIQ()); logArray.add(jsonObject); // 用户所属信息变更记录 UserInfoTool.userBeChangeLogAdd(user.getId(), UserBeChangeLog.CHANGE_TYPE_CIQ, user.getCIQ(), userDto.getCIQ(), userDto.getAppIdCode(), UserBeChangeLog.OPERATOR_TYPE_EMPLOYEE, userDto.getOpId(), userDto.getShopId(), userDto.getRemark(), commonService); // 修改数据 user.setCIQ(userDto.getCIQ()); } } if (!StringUtils.isEmpty(userDto.getMemberNO())) { if (!userDto.getMemberNO().equals(user.getMemberNO())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改会员号码"); jsonObject.put("before", user.getMemberNO()); jsonObject.put("after", userDto.getMemberNO()); logArray.add(jsonObject); // 修改数据 user.setMemberNO(userDto.getMemberNO()); } } //user.setMoney(userDto.getMoney()); if (!StringUtils.isEmpty(userDto.getLastDoctorId())) { if (!userDto.getLastDoctorId().equals(user.getLastDoctorId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改上一次预约的医生"); Employee before; if (!StringUtils.isEmpty(user.getLastDoctorId())) { before = employeeMapper.selectOneByKey(user.getLastDoctorId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getLastDoctorId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 修改数据 user.setLastDoctorId(userDto.getLastDoctorId()); } } if (!StringUtils.isEmpty(userDto.getCustomerDeveloperId())) { if (!userDto.getCustomerDeveloperId().equals(user.getCustomerDeveloperId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改客户开发人"); Employee before; if (!StringUtils.isEmpty(user.getCustomerDeveloperId())) { before = employeeMapper.selectOneByKey(user.getCustomerDeveloperId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getCustomerDeveloperId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 修改数据 user.setCustomerDeveloperId(userDto.getCustomerDeveloperId()); } } if (!StringUtils.isEmpty(userDto.getLastCorpUserId())) { if (!userDto.getLastCorpUserId().equals(user.getLastCorpUserId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改上一次预约的顾问"); Employee before; if (!StringUtils.isEmpty(user.getLastCorpUserId())) { before = employeeMapper.selectOneByKey(user.getLastCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getLastCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 修改数据 user.setLastCorpUserId(userDto.getLastCorpUserId()); } } if (userDto.getCertificateType() != null) { if (!StringUtils.isEmpty(userDto.getCertificateNo())) { // 修改证件或者证件编号 if (!userDto.getCertificateType().equals(user.getCertificateType()) || !userDto.getCertificateNo().equals(user.getCertificateNo())) { // 构建日志 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改证件信息"); jsonObject.put("before", String.format("修改证件类型:%s,证件编号:%s", User.getCertificateTypeName(user.getCertificateType()), user.getCertificateNo())); jsonObject.put("after", String.format("修改证件类型:%s,证件编号:%s", User.getCertificateTypeName(userDto.getCertificateType()), userDto.getCertificateNo())); logArray.add(jsonObject); // 修改数据 user.setCertificateType(userDto.getCertificateType()); user.setCertificateNo(userDto.getCertificateNo()); } } else { // 原来的证件信息不为空可以修改为空 -1 为空 if (-1 == userDto.getCertificateType() && !StringUtils.isEmpty(user.getCertificateNo())) { // 修改证件信息为空 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改证件信息"); jsonObject.put("before", user.getCertificateNo()); jsonObject.put("after", ""); logArray.add(jsonObject); // 修改数据 user.setCertificateType(null); user.setCertificateNo(null); } } } if (!StringUtils.isEmpty(userDto.getBirthDay())) { // 判断生日时间格式 try{ DateUtil.parseString(userDto.getBirthDay(), "yyyy-MM-dd"); } catch (Exception ex){ throw new TipsException("生日时间格式不正确!"); } if (!userDto.getBirthDay().equals(user.getBirthDay())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改生日"); jsonObject.put("before", user.getBirthDay()); jsonObject.put("after", userDto.getBirthDay()); logArray.add(jsonObject); // 用户所属信息变更记录 UserInfoTool.userBeChangeLogAdd(user.getId(), UserBeChangeLog.CHANGE_TYPE_BIRTHDAY, user.getBirthDay(), userDto.getBirthDay(), userDto.getAppIdCode(), UserBeChangeLog.OPERATOR_TYPE_EMPLOYEE, userDto.getOpId(), userDto.getShopId(), userDto.getRemark(), commonService); // 修改数据 user.setBirthDay(userDto.getBirthDay()); // 更新用户年龄 this.updateUserAge(user.getId(), userDto.getBirthDay()); } } /*if(!StringUtils.isEmpty(userDto.getApiId())) { user.setApiId(userDto.getApiId()); }*/ if (!StringUtils.isEmpty(userDto.getCorpUserId())) { if (!userDto.getCorpUserId().equals(user.getCorpUserId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改工作人员"); Employee before; if (!StringUtils.isEmpty(user.getCorpUserId())) { before = employeeMapper.selectOneByKey(user.getCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 修改数据 user.setCorpUserId(userDto.getCorpUserId()); } } if (!StringUtils.isEmpty(userDto.getHisCorpUserId())) { if (!userDto.getHisCorpUserId().equals(user.getHisCorpUserId())) { // -1 值咨询师修改为空 if ("-1".equals(userDto.getHisCorpUserId())){ userDto.setHisCorpUserId(null); } JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改所属顾问"); if (!StringUtils.isEmpty(user.getHisCorpUserId())) { Employee before = employeeMapper.selectOneByKey(user.getHisCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } if (!StringUtils.isEmpty(userDto.getHisCorpUserId())) { Employee after = employeeMapper.selectOneByKey(userDto.getHisCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } } else { jsonObject.put("after", "无"); } logArray.add(jsonObject); // 用户所属信息变更记录 UserInfoTool.userBeChangeLogAdd(user.getId(), UserBeChangeLog.CHANGE_TYPE_ADVISER, user.getHisCorpUserId(), userDto.getHisCorpUserId(), userDto.getAppIdCode(), UserBeChangeLog.OPERATOR_TYPE_EMPLOYEE, userDto.getOpId(), userDto.getShopId(), userDto.getRemark(), commonService); // 修改数据 user.setHisCorpUserId(userDto.getHisCorpUserId()); } } if (!StringUtils.isEmpty(userDto.getShopId())) { if (!userDto.getShopId().equals(user.getShopId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改所属门店"); Shop before; if (!StringUtils.isEmpty(user.getShopId())) { before = shopMapper.selectOneByKey(user.getShopId()); if (before != null) { jsonObject.put("before", before.getName()); } } Shop after = shopMapper.selectOneByKey(userDto.getShopId()); if (after != null) { jsonObject.put("after", after.getName()); } logArray.add(jsonObject); // 用户所属信息变更记录 UserInfoTool.userBeChangeLogAdd(user.getId(), UserBeChangeLog.CHANGE_TYPE_SHOP, user.getShopId(), userDto.getShopId(), userDto.getAppIdCode(), UserBeChangeLog.OPERATOR_TYPE_EMPLOYEE, userDto.getOpId(), userDto.getShopId(), userDto.getRemark(), commonService); // 修改数据 user.setShopId(userDto.getShopId()); } } if (userDto.getUserRole() != null) { user.setUserRole(userDto.getUserRole()); } if (!StringUtils.isEmpty(userDto.getPinyinCode())) { user.setPinyinCode(userDto.getPinyinCode()); } if (!StringUtils.isEmpty(userDto.getInternetCorpUserId())) { if (!userDto.getInternetCorpUserId().equals(user.getInternetCorpUserId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改电网咨询顾问"); Employee before; if (!StringUtils.isEmpty(user.getInternetCorpUserId())) { before = employeeMapper.selectOneByKey(user.getInternetCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getInternetCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 用户所属信息变更记录 UserInfoTool.userBeChangeLogAdd(user.getId(), UserBeChangeLog.CHANGE_TYPE_TMK, user.getInternetCorpUserId(), userDto.getInternetCorpUserId(), userDto.getAppIdCode(), UserBeChangeLog.OPERATOR_TYPE_EMPLOYEE, userDto.getOpId(), userDto.getShopId(), userDto.getRemark(), commonService); // 修改数据 user.setInternetCorpUserId(userDto.getInternetCorpUserId()); } } if (!StringUtils.isEmpty(userDto.getBeauticianCorpUserId())) { if (!userDto.getBeauticianCorpUserId().equals(user.getBeauticianCorpUserId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改所属美容师"); Employee before; if (!StringUtils.isEmpty(user.getBeauticianCorpUserId())) { before = employeeMapper.selectOneByKey(user.getBeauticianCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getBeauticianCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 修改数据 user.setBeauticianCorpUserId(userDto.getBeauticianCorpUserId()); } } if (!StringUtils.isEmpty(userDto.getChatCorpUserId())) { if (!userDto.getChatCorpUserId().equals(user.getChatCorpUserId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改客服专员"); Employee before; if (!StringUtils.isEmpty(user.getChatCorpUserId())) { before = employeeMapper.selectOneByKey(user.getChatCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getChatCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 修改数据 user.setChatCorpUserId(userDto.getChatCorpUserId()); } } if (!StringUtils.isEmpty(userDto.getConsultCorpUserId())) { if (!userDto.getConsultCorpUserId().equals(user.getConsultCorpUserId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改咨询助理"); Employee before; if (!StringUtils.isEmpty(user.getConsultCorpUserId())) { before = employeeMapper.selectOneByKey(user.getConsultCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getConsultCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 修改数据 user.setConsultCorpUserId(userDto.getConsultCorpUserId()); } } if (userDto.getShareCustomer() != null) { if (!userDto.getShareCustomer().equals(user.getShareCustomer())) { // 默认否 if (user.getShareCustomer() == null) { user.setShareCustomer(BaseEntity.NO); } JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改咨询助理"); jsonObject.put("before", user.getShareCustomer() == 0 ? "否" : "是"); jsonObject.put("after", userDto.getShareCustomer() == 0 ? "否" : "是"); logArray.add(jsonObject); // 修改数据 user.setShareCustomer(userDto.getShareCustomer()); } } if (!StringUtils.isEmpty(userDto.getNurseCorpUserId())) { if (!userDto.getNurseCorpUserId().equals(user.getNurseCorpUserId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改所属护士"); Employee before; if (!StringUtils.isEmpty(user.getNurseCorpUserId())) { before = employeeMapper.selectOneByKey(user.getNurseCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getNurseCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 修改数据 user.setNurseCorpUserId(userDto.getNurseCorpUserId()); } } if (!StringUtils.isEmpty(userDto.getDoctorCorpUserId())) { if (!userDto.getDoctorCorpUserId().equals(user.getDoctorCorpUserId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改所属医生"); Employee before; if (!StringUtils.isEmpty(user.getDoctorCorpUserId())) { before = employeeMapper.selectOneByKey(user.getDoctorCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getDoctorCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 修改数据 user.setDoctorCorpUserId(userDto.getDoctorCorpUserId()); } } if(!StringUtils.isEmpty(userDto.getConsultBelonging())) { if (!userDto.getConsultBelonging().equals(user.getConsultBelonging())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改咨询师隶属"); jsonObject.put("before", user.getConsultBelonging()); jsonObject.put("after", userDto.getConsultBelonging()); logArray.add(jsonObject); // 修改数据 user.setConsultBelonging(userDto.getConsultBelonging()); } } // 渠道来源类型(UserChannelType) if (!StringUtils.isEmpty(userDto.getChannelCategory())) { user.setChannelCategory(userDto.getChannelCategory()); } String inviteeName = null; if(!StringUtils.isEmpty(userDto.getInviteeId())) { if (!userDto.getInviteeId().equals(user.getInviteeId())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改客户推荐人"); User before; if (!StringUtils.isEmpty(user.getInviteeId())) { before = userMapper.selectOneByKey(user.getInviteeId()); if (before != null) { jsonObject.put("before", before.getName()); } } User after = userMapper.selectOneByKey(userDto.getInviteeId()); if (after != null) { jsonObject.put("after", after.getName()); inviteeName = after.getName(); } logArray.add(jsonObject); // 用户所属信息变更记录 UserInfoTool.userBeChangeLogAdd(user.getId(), UserBeChangeLog.CHANGE_TYPE_INVITE, user.getInviteeId(), userDto.getInviteeId(), userDto.getAppIdCode(), UserBeChangeLog.OPERATOR_TYPE_EMPLOYEE, userDto.getOpId(), userDto.getShopId(), userDto.getRemark(), commonService); // 修改数据 user.setInviteeId(userDto.getInviteeId()); } } if (!StringUtils.isEmpty(userDto.getRemark())) { if (!userDto.getRemark().equals(user.getRemark())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改备注"); jsonObject.put("before", user.getRemark()); jsonObject.put("after", userDto.getRemark()); logArray.add(jsonObject); // 修改数据 user.setRemark(userDto.getRemark()); } } // 处理下用户渠道信息 UserInfoTool.handlerChanelInfo(commonService, user); // 修改用户信息 user.setUpdateTime(new Date()); int count = userMapper.updateAll(user); if (count != 1) { throw new TipsException("修改失败!"); } else { // 处理新增用户是否触发赠送增值金接口 /* if(!StringUtils.isEmpty(userDto.getBirthDay())){ Calendar calendar=Calendar.getInstance(); String year = String.valueOf(calendar.get(Calendar.YEAR)); String month= BirthdayValueAddedFundTool.handleMonth(calendar.get(Calendar.MONTH)+1); if(userDto.getBirthDay().indexOf("-"+month+"-")!=-1){ BirthdayValueAddedFundTool.handleUserMoney(user,year); } }*/ // 处理用户信息 UserInfo userInfo = userInfoMapper.selectOneByUserId(user.getId()); // 旧数据没有用户信息处理 boolean flag = false; if (userInfo == null) { userInfo = new UserInfo(); userInfo.setUserId(user.getId()); flag = true; } if (!StringUtils.isEmpty(userDto.getCountryTypeName())) { if (!userDto.getCountryTypeName().equals(userInfo.getCountryTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改国家类型名称"); jsonObject.put("before", userInfo.getCountryTypeName()); jsonObject.put("after", userDto.getCountryTypeName()); logArray.add(jsonObject); // 修改数据 userInfo.setCountryTypeName(userDto.getCountryTypeName()); } } if (!StringUtils.isEmpty(userDto.getLanguageTypeName())) { if (!userDto.getLanguageTypeName().equals(userInfo.getLanguageTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改语言类型名称"); jsonObject.put("before", userInfo.getLanguageTypeName()); jsonObject.put("after", userDto.getLanguageTypeName()); logArray.add(jsonObject); // 修改数据 userInfo.setLanguageTypeName(userDto.getLanguageTypeName()); } } if (userDto.getYear() != null) { if (!userDto.getYear().equals(userInfo.getYear())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改年龄"); jsonObject.put("before", userInfo.getYear()); jsonObject.put("after", userDto.getYear()); logArray.add(jsonObject); // 修改数据 userInfo.setYear(userDto.getYear()); } } if (!StringUtils.isEmpty(userDto.getConstellationTypeName())) { if (!userDto.getConstellationTypeName().equals(userInfo.getConstellationTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改星座类型名称"); jsonObject.put("before", userInfo.getConstellationTypeName()); jsonObject.put("after", userDto.getConstellationTypeName()); logArray.add(jsonObject); // 修改数据 userInfo.setConstellationTypeName(userDto.getConstellationTypeName()); } } if (!StringUtils.isEmpty(userDto.getNationalityTypeName())) { if (!userDto.getNationalityTypeName().equals(userInfo.getNationalityTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改民族类型名称"); jsonObject.put("before", userInfo.getNationalityTypeName()); jsonObject.put("after", userDto.getNationalityTypeName()); logArray.add(jsonObject); // 修改数据 userInfo.setNationalityTypeName(userDto.getNationalityTypeName()); } } if (!StringUtils.isEmpty(userDto.getProfessionTypeName())) { if (!userDto.getProfessionTypeName().equals(userInfo.getProfessionTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改职业类型名称"); jsonObject.put("before", userInfo.getProfessionTypeName()); jsonObject.put("after", userDto.getProfessionTypeName()); logArray.add(jsonObject); // 修改数据 userInfo.setProfessionTypeName(userDto.getProfessionTypeName()); } } if (!StringUtils.isEmpty(userDto.getIncomeTypeName())) { if (!userDto.getIncomeTypeName().equals(userInfo.getIncomeTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改收入类型名称"); jsonObject.put("before", userInfo.getIncomeTypeName()); jsonObject.put("after", userDto.getIncomeTypeName()); logArray.add(jsonObject); // 修改数据 userInfo.setIncomeTypeName(userDto.getIncomeTypeName()); } } if (!StringUtils.isEmpty(userDto.getMarriageTypeName())) { if (!userDto.getMarriageTypeName().equals(userInfo.getMarriageTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改婚姻类型名称"); jsonObject.put("before", userInfo.getMarriageTypeName()); jsonObject.put("after", userDto.getMarriageTypeName()); logArray.add(jsonObject); // 修改数据 userInfo.setMarriageTypeName(userDto.getMarriageTypeName()); } } if (!StringUtils.isEmpty(userDto.getGrowthTypeName())) { if (!userDto.getGrowthTypeName().equals(userInfo.getGrowthTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改生育类型名称"); jsonObject.put("before", userInfo.getGrowthTypeName()); jsonObject.put("after", userDto.getGrowthTypeName()); logArray.add(jsonObject); // 修改数据 userInfo.setGrowthTypeName(userDto.getGrowthTypeName()); } } if (!StringUtils.isEmpty(userDto.getNativePlaceTypeName())) { if (!userDto.getNativePlaceTypeName().equals(userInfo.getNativePlaceTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改籍贯类型名称"); jsonObject.put("before", userInfo.getNativePlaceTypeName()); jsonObject.put("after", userDto.getNativePlaceTypeName()); logArray.add(jsonObject); // 修改数据 userInfo.setNativePlaceTypeName(userDto.getNativePlaceTypeName()); } } if (!StringUtils.isEmpty(userDto.getUnitName())) { if (!userDto.getUnitName().equals(userInfo.getUnitName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改单位名称"); jsonObject.put("before", userInfo.getUnitName()); jsonObject.put("after", userDto.getUnitName()); logArray.add(jsonObject); // 修改数据 userInfo.setUnitName(userDto.getUnitName()); } } if (userDto.getIsHaveCar() != null) { if (!userDto.getIsHaveCar().equals(userInfo.getIsHaveCar())) { // 默认值 if (null == userInfo.getIsHaveCar()){ userInfo.setIsHaveCar(BaseEntity.NO); } // 处理数据 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改泊车需求"); jsonObject.put("before", userInfo.getIsHaveCar().equals(BaseEntity.NO) ? "否" : "是"); jsonObject.put("after", userDto.getIsHaveCar().equals(BaseEntity.NO) ? "否" : "是"); logArray.add(jsonObject); // 修改数据 userInfo.setIsHaveCar(userDto.getIsHaveCar()); } } if (!StringUtils.isEmpty(userDto.getCarNumber())) { if (!userDto.getCarNumber().equals(userInfo.getCarNumber())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改车牌号码"); jsonObject.put("before", userInfo.getCarNumber()); jsonObject.put("after", userDto.getCarNumber()); logArray.add(jsonObject); // 修改数据 userInfo.setCarNumber(userDto.getCarNumber()); } } if (!StringUtils.isEmpty(userDto.getAllergyLabel())) { if (!userDto.getAllergyLabel().equals(userInfo.getAllergyLabel())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改过敏标签"); jsonObject.put("before", userInfo.getAllergyLabel()); jsonObject.put("after", userDto.getAllergyLabel()); logArray.add(jsonObject); // 修改数据 userInfo.setAllergyLabel(userDto.getAllergyLabel()); } } if (!StringUtils.isEmpty(userDto.getMainAppeal())) { if (!userDto.getMainAppeal().equals(userInfo.getMainAppeal())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改主要诉求名称"); jsonObject.put("before", userInfo.getMainAppeal()); jsonObject.put("after", userDto.getMainAppeal()); logArray.add(jsonObject); // 修改数据 userInfo.setMainAppeal(userDto.getMainAppeal()); } } if (!StringUtils.isEmpty(userDto.getMinorAppeal())) { if (!userDto.getMinorAppeal().equals(userInfo.getMinorAppeal())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改次要诉求名称"); jsonObject.put("before", userInfo.getMinorAppeal()); jsonObject.put("after", userDto.getMinorAppeal()); logArray.add(jsonObject); // 修改数据 userInfo.setMinorAppeal(userDto.getMinorAppeal()); } } if (!StringUtils.isEmpty(userDto.getChannelType2())) { if (!userDto.getChannelType2().equals(userInfo.getSourceName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改冗余来源名称"); jsonObject.put("before", userInfo.getSourceName()); jsonObject.put("after", userDto.getChannelType2()); logArray.add(jsonObject); // 修改数据 userInfo.setSourceName(userDto.getChannelType2()); } } if (!StringUtils.isEmpty(inviteeName)) { if (!inviteeName.equals(userInfo.getFriendName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改冗余好友名称"); jsonObject.put("before", userInfo.getFriendName()); jsonObject.put("after", inviteeName); logArray.add(jsonObject); // 修改数据 userInfo.setFriendName(inviteeName); } } int userInfoCount; if (!flag) { userInfoCount = userInfoMapper.updateAll(userInfo); } else { userInfoCount = userInfoMapper.insert(userInfo); } if (userInfoCount != 1) { throw new TipsException("修改用户信息失败!"); } // 处理用户联系信息 UserContactInformation userContactInformation = userContactInformationMapper.selectOneByUserId(user.getId()); // 旧数据没有用户信息处理 flag = false; if (userContactInformation == null) { userContactInformation = new UserContactInformation(); userContactInformation.setUserId(user.getId()); flag = true; } if (!StringUtils.isEmpty(userDto.getQQ())) { if (!userDto.getQQ().equals(userContactInformation.getQQ())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改QQ号码"); jsonObject.put("before", userContactInformation.getQQ()); jsonObject.put("after", userDto.getQQ()); logArray.add(jsonObject); // 修改数据 userContactInformation.setQQ(userDto.getQQ()); } } if (!StringUtils.isEmpty(userDto.getEmail())) { if (!userDto.getEmail().equals(userContactInformation.getEmail())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改电子邮件"); jsonObject.put("before", userContactInformation.getEmail()); jsonObject.put("after", userDto.getEmail()); logArray.add(jsonObject); // 修改数据 userContactInformation.setEmail(userDto.getEmail()); } } if (!StringUtils.isEmpty(userDto.getMerchantNo())) { if (!userDto.getMerchantNo().equals(userContactInformation.getMerchantNo())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改商务通编号"); jsonObject.put("before", userContactInformation.getMerchantNo()); jsonObject.put("after", userDto.getMerchantNo()); logArray.add(jsonObject); // 修改数据 userContactInformation.setMerchantNo(userDto.getMerchantNo()); } } if (!StringUtils.isEmpty(userDto.getTelPhone())) { if (!userDto.getTelPhone().equals(userContactInformation.getTelPhone())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改固定号码"); jsonObject.put("before", userContactInformation.getTelPhone()); jsonObject.put("after", userDto.getTelPhone()); logArray.add(jsonObject); // 修改数据 userContactInformation.setTelPhone(userDto.getTelPhone()); } } if (!StringUtils.isEmpty(userDto.getWechat())) { if (!userDto.getWechat().equals(userContactInformation.getWechat())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改微信号"); jsonObject.put("before", userContactInformation.getWechat()); jsonObject.put("after", userDto.getWechat()); logArray.add(jsonObject); // 修改数据 userContactInformation.setWechat(userDto.getWechat()); } } if (!StringUtils.isEmpty(userDto.getLine())) { if (!userDto.getLine().equals(userContactInformation.getLine())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改Line"); jsonObject.put("before", userContactInformation.getLine()); jsonObject.put("after", userDto.getLine()); logArray.add(jsonObject); // 修改数据 userContactInformation.setLine(userDto.getLine()); } } if (!StringUtils.isEmpty(userDto.getContactType())) { if (!userDto.getContactType().equals(userContactInformation.getContactType())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改联络方式"); jsonObject.put("before", userContactInformation.getContactType()); jsonObject.put("after", userDto.getContactType()); logArray.add(jsonObject); // 修改数据 userContactInformation.setContactType(userDto.getContactType()); } } int userContactInsert; if (!flag) { userContactInsert = userContactInformationMapper.updateAll(userContactInformation); } else { userContactInsert = userContactInformationMapper.insert(userContactInformation); } if (userContactInsert != 1) { throw new TipsException("修改用户联系信息失败!"); } // 处理用户兴趣标签 List userInterestsList = JSONArray.parseArray(userDto.getUserInterestsJson(), UserInterests.class); if (userInterestsList != null) { // 先删除原有记录 userInterestsMapper.deleteByUserId(user.getId()); // 添加新的记录 userInterestsList.forEach(userInterests -> { userInterests.setUserId(user.getId()); int insertUserInterests = userInterestsMapper.insert(userInterests); if (insertUserInterests != 1) { throw new TipsException("新增用户标签信息失败!"); } }); } // 刷新下用户信息 User checkUser = userMapper.selectOneByKey(user.getId()); // 处理用户电话簿信息 List userPhoneBookList = JSONArray.parseArray(userDto.getPhoneBooksJson(), UserPhoneBook.class); if (userPhoneBookList != null && userPhoneBookList.size() > 0) { // 先删除原有记录 userPhoneBookMapper.deleteByUserId(user.getId()); // 添加新的记录 userPhoneBookList.forEach(userPhoneBook -> { // 电话号码不为空才添加 if (!StringUtils.isEmpty(userPhoneBook.getTel())) { if (userPhoneBook.getTel().contains("****")) { throw new TipsException("手机号码格式请检查,不能是加密号码!"); } // 判断主要号码 if (!userPhoneBook.getTel().equals(user.getTel())) { List userList = this.selectOneByTel(userPhoneBook.getTel()); if (userList != null && userList.size() > 0) { throw new TipsException(String.format("电话号码:%s,手机号码已有其他客户使用!", userPhoneBook.getTel())); } } // 判断次要号码 UserPhoneBook checkUserPhoneBook = UserInfoTool.selectOneByTelOtherUser(commonService, userPhoneBook.getAreaCode(), userPhoneBook.getTel(), user.getId()); if (checkUserPhoneBook != null) { throw new TipsException(String.format("电话号码:%s,手机号码已有其他客户使用!", userPhoneBook.getTel())); } // 新增加电话簿号码 userPhoneBook.setUserId(user.getId()); int insertUserPhoneBook = userPhoneBookMapper.insert(userPhoneBook); if (insertUserPhoneBook != 1) { throw new TipsException("新增用户次要手机号码失败!"); } // 次要号码添加日志 if (BaseEntity.NO.equals(userPhoneBook.getIsPrimary())) { // 添加日志 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", String.format("添加次要手机号码:%s", userPhoneBook.getTel())); logArray.add(jsonObject); } // 判断主要号码更新用户信息主号码 if (BaseEntity.YES.equals(userPhoneBook.getIsPrimary())) { if (!userPhoneBook.getTel().equals(user.getTel())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改手机号码"); jsonObject.put("before", user.getTel()); jsonObject.put("after", userPhoneBook.getTel()); logArray.add(jsonObject); } SqlSentence sqlSentence = new SqlSentence(); Map sqlValue = new HashMap<>(); String sql = " tel = #{m.tel} WHERE id = #{m.userId}"; sqlValue.put("userId", userPhoneBook.getUserId()); sqlValue.put("tel", userPhoneBook.getTel()); sqlSentence.sqlSentence(sql, sqlValue); int i = userMapper.updateWhere(sqlSentence); if (i != 1) { throw new TipsException("更新用户主号码失败!"); } } } }); } else { // 修改手机号码处理 if (!StringUtils.isEmpty(userDto.getTel())) { // 校验id String checkId; // 校验电话号码 UserPhoneBook checkUserPhoneBook = UserInfoTool.selectOneByTelUser(commonService, userDto.getTel(), user.getId()); if (checkUserPhoneBook == null) { UserPhoneBook primary = new UserPhoneBook(); primary.setUserId(checkUser.getId()); primary.setTel(userDto.getTel()); primary.setIsPrimary(BaseEntity.YES); userPhoneBookMapper.insert(primary); checkUserPhoneBook = primary; } // 调整下主号码状态 checkId = checkUserPhoneBook.getId(); if (BaseEntity.NO.equals(checkUserPhoneBook.getIsPrimary())) { checkUserPhoneBook.setIsPrimary(BaseEntity.YES); userPhoneBookMapper.updateAll(checkUserPhoneBook); } // 其他号码处理下状态 SqlSentence sqlSentence = new SqlSentence(); Map sqlValue = new HashMap<>(); sqlValue.put("isDel", BaseEntity.NO); sqlValue.put("id", checkId); sqlValue.put("isPrimary", BaseEntity.NO); sqlValue.put("userId", checkUser.getId()); String sql = " isPrimary=#{m.isPrimary} WHERE userId=#{m.userId} AND id !=#{m.id} AND isDel=#{m.isDel}"; sqlSentence.sqlSentence(sql, sqlValue); userPhoneBookMapper.updateWhere(sqlSentence); } } // 处理用户地址 List userAddressBookList = JSONArray.parseArray(userDto.getAddressJson(), UserAddressBook.class); if (userAddressBookList != null) { // 先删除原有记录 userAddressBookMapper.deleteByUserId(user.getId()); // 添加新的记录 userAddressBookList.forEach(userAddressBook -> { userAddressBook.setUserId(user.getId()); int insertUserAddressBook = userAddressBookMapper.insert(userAddressBook); if (insertUserAddressBook != 1) { throw new TipsException("新增用户地址信息失败!"); } }); } // 处理用户标签 List userGeneralLabelList = JSONArray.parseArray(userDto.getImpressionLabelJson(), UserGeneralLabel.class); if (userGeneralLabelList != null) { // 先删除原有记录 userGeneralLabelMapper.deleteByUserId(user.getId()); // 添加新的记录 userGeneralLabelList.forEach(userGeneralLabel -> { userGeneralLabel.setUserId(user.getId()); userGeneralLabel.setType(UserGeneralLabel.TYPE_IMPRESSION_LABEL); int insertUserGeneralLabel = userGeneralLabelMapper.insert(userGeneralLabel); if (insertUserGeneralLabel != 1) { throw new TipsException("新增用户标签信息失败!"); } }); } //处理用户修改日志 if (!StringUtils.isEmpty(userDto.getNote()) || !StringUtils.isEmpty(userDto.getOpId()) || !StringUtils.isEmpty(userDto.getOpMan())) { UserLog userLog = new UserLog(); userLog.setUserId(user.getId()); userLog.setLogType(UserLog.LOG_TYPE_UPDATE); userLog.setContent("[" + userDto.getOpMan() + "]:编辑客户信息"); userLog.setOpMan(userDto.getOpMan()); userLog.setOpId(userDto.getOpId()); userLog.setRemark(userDto.getNote()); if (commonService.insert(UserLogMapper.class, userLog) != 1) { throw new TipsException("新增客户修改日志记录失败!"); } } // 关闭同步领建代码 /*//处理门店信息 String hisShopId = ""; if (!StringUtils.isEmpty(userDto.getShopId())) { Shop shop = commonService.selectOneByKey(ShopMapper.class, userDto.getShopId()); if (shop == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "门店标识错误,门店信息不存在!"); } if (shop.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his门店信息不存在!"); } hisShopId = shop.getApiId(); } //处理所属咨询信息 String consultantId = ""; if (!StringUtils.isEmpty(userDto.getHisCorpUserId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getHisCorpUserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "所属顾问标识错误,顾问信息不存在!"); } if (employee.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his顾问信息不存在!"); } consultantId = employee.getApiId(); } //处理所属医生信息 String doctorId = ""; if (!StringUtils.isEmpty(userDto.getDoctorCorpUserId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getDoctorCorpUserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "所属医生标识错误,顾问信息不存在!"); } if (employee.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his医生信息不存在!"); } doctorId = employee.getApiId(); } //处理所属美容师信息 String beauticianId = ""; if (!StringUtils.isEmpty(userDto.getBeauticianCorpUserId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getBeauticianCorpUserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "所属美容师标识错误,顾问信息不存在!"); } if (employee.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his美容师信息不存在!"); } beauticianId = employee.getApiId(); } //处理所属客服信息 String customerServiceId = ""; if (!StringUtils.isEmpty(userDto.getChatCorpUserId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getChatCorpUserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "所属客服标识错误,顾问信息不存在!"); } if (employee.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his客服信息不存在!"); } customerServiceId = employee.getApiId(); } //处理所属电网咨询师信息 String serviceConsultantId = ""; if (!StringUtils.isEmpty(userDto.getInternetCorpUserId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getInternetCorpUserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "所属电网咨询师标识错误,顾问信息不存在!"); } if (employee.getApiId() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "his电网咨询师信息不存在!"); } serviceConsultantId = employee.getApiId(); }*/ // 记录编号 String recordNo = UserInfoTool.createUSLGNo(commonService, user.getId(), user.getCIQ()); // 添加用户日志 UserInfoTool.addUserUpdateLog(commonService, userDto.getAppIdCode(), user, userDto.getShopId(), userDto.getOpId(), null, null, "修改用户信息", logArray, null, recordNo); // 处理用户登记记录 UserRegisterRecordTool.handlerUserRegisterRecord(commonService, user.getId(), userDto.getAppIdCode(), BaseEntity.YES); // 切换领建屏蔽代码 date:20230108 /*// 同步更新his用户系统 注释 正式区在开放 String returnHisData; // 构建请求his同步请求参数 JSONObject jsonObject = buildSyncUserHisData(user, hisShopId, consultantId, doctorId, beauticianId, customerServiceId, serviceConsultantId, userDto.getRemark(), BaseEntity.YES); try { jsonObject.put("appIdCode", userDto.getAppIdCode()); returnHisData = ApiPlatformUtil.syncHisUser(customParameter, userDto.getAppIdCode(), jsonObject.toJSONString()); } catch (Exception ex) { logger.error("同步用户编辑到his系统出现失败!错误消息:", ex); throw new PlatTipsException(PlatformCode.ERROR_TIPS, "同步用户编辑到his系统出现失败!"); } if (!StringUtils.isEmpty(returnHisData)) { JSONObject jsonHisObject = JSONObject.parseObject(returnHisData); String code = jsonHisObject.getString("code"); if (!"100".equals(code)) { String error = jsonHisObject.getString("msg"); throw new PlatTipsException(PlatformCode.ERROR_TIPS, "更新his编辑用户信息失败! 返回错误消息:" + error); } } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "更新his编辑用户信息失败! 返回为空消息!"); }*/ } } /** * 更新用户年龄 * @param userId 用户id * @param birthDay 生日 */ public void updateUserAge(String userId, String birthDay) { if (!StringUtils.isEmpty(birthDay)) { // 计算年龄 int age = UserAgeTool.getAge(birthDay, 1); if (age > 0) { // 获取年龄 UserInfo userInfo = userInfoMapper.selectOneByUserId(userId); // 判断年龄是否 为空或者不是正确年龄 if (userInfo != null && (userInfo.getYear() == null || age != userInfo.getYear())) { // 更新年龄 SqlSentence sqlSentence = new SqlSentence(); Map sqlValues = new HashMap<>(); sqlValues.put("year", age); sqlValues.put("userId", userId); sqlSentence.sqlSentence(" year=#{m.year},editTime=NOW() WHERE userId=#{m.userId}", sqlValues); userInfoMapper.updateWhere(sqlSentence); } } } } /**转诊新增*/ private void turnTreat(User user,UserDto userDto) { if (userDto.getIsTransfer() != null && userDto.getIsTransfer().equals(1)){ TransferRecord parameter = userDto.getTransferRecord(); if (parameter == null){ throw new TipsException("转诊信息为空!"); } TransferRecord transferRecord = new TransferRecord(); transferRecord.setUserId(user.getId()); transferRecord.setStatus(TransferRecord.STATUS_AGREE); transferRecord.setType(0); transferRecord.setTransferOutShopId(user.getShopId()); Shop outShop = shopMapper.selectOneByKey(user.getShopId()); if (outShop != null){ transferRecord.setTransferOutShopName(outShop.getName()); } transferRecord.setTransferIntoShopId(userDto.getShopId()); Shop inShop = shopMapper.selectOneByKey(userDto.getShopId()); if (inShop != null){ transferRecord.setTransferIntoShopName(inShop.getName()); } transferRecord.setApplyAdminType(parameter.getApplyAdminType()); transferRecord.setApplyAdminId(parameter.getApplyAdminId()); transferRecord.setApplyAdminName(parameter.getApplyAdminName()); transferRecord.setApprovedAdminType(parameter.getApprovedAdminType()); transferRecord.setApprovedAdminId(parameter.getApprovedAdminId()); transferRecord.setApprovedAdminName(parameter.getApprovedAdminName()); transferRecord.setApprovedTime(parameter.getApprovedTime()); transferRecord.setRemark(parameter.getRemark()); transferRecord.setIsNotice(parameter.getIsNotice()); transferRecord.setOperatorType(parameter.getOperatorType()); transferRecord.setOperatorId(parameter.getOperatorId()); transferRecord.setOperatorName(parameter.getOperatorName()); if (commonService.insert(TransferRecordMapper.class,transferRecord) != 1){ throw new TipsException("新增转诊记录失败!"); } } } /**到访更新用户信息*/ @Override public JSONObject arriveInfo(User user, UserDto userDto) { //返回部分数据时间 JSONObject data = new JSONObject(); data.put("CIQ", user.getCIQ()); // 四个值不能都为空 if (!StringUtils.isEmpty(userDto.getHisCorpUserId()) || !StringUtils.isEmpty(userDto.getNurseCorpUserId()) || !StringUtils.isEmpty(userDto.getDoctorCorpUserId()) || !StringUtils.isEmpty(userDto.getShopId()) || userDto.getLastArriveTime() != null ) { JSONArray logArray = new JSONArray(); SqlSentence sqlSentence = new SqlSentence(); Map sqlValue = new HashMap<>(); sqlValue.put("userId", user.getId()); sqlValue.put("isLoss", BaseEntity.NO); sqlValue.put("editTime", new Date()); StringBuilder sql = new StringBuilder(); sql.append(" isLoss=#{m.isLoss},editTime=#{m.editTime}"); // 有到访会员无消费和无执行 String status = null; if (!StringUtils.isEmpty(user.getUserStatus()) && UserStatusConstants.USER_STATUS_NON_MEMBER.equals(user.getUserStatus()) && user.getLastPayOrderTime() == null && user.getLastDeductionTime() == null) { // 旧方案 /*Date lastDate = DateUtil.addMonth(new Date(), -3); // 新会员:近3个月成为会员有到访和(没有消费和没有执行) <=3 界定于有没有到访 if (user.getCreateTime().compareTo(lastDate) >= 0 && user.getLastPayOrderTime() == null && user.getLastDeductionTime() == null) { // 会员状态有消费或执行的会员 status = UserStatusConstants.USER_STATUS_NEW_MEMBER; sqlValue.put("userStatus", status); sql.append(",userStatus=#{m.userStatus}"); }*/ // 新方案 // 有到访和(没有消费和没有执行) 准会员 status = UserStatusConstants.USER_STATUS_NEW_MEMBER; sqlValue.put("userStatus", status); sql.append(",userStatus=#{m.userStatus}"); } // 最后到店时间 if (null != userDto.getLastArriveTime()) { sqlValue.put("lastArriveTime", userDto.getLastArriveTime()); sql.append(",lastArriveTime=#{m.lastArriveTime}"); //判断如果用户初次到店时间为空,则更新 if(user.getFirstArriveTime() == null){ sql.append(" , firstArriveTime = #{m.lastArriveTime} "); } } // CIQ 用户CIQ为空处理CIQ if (StringUtils.isEmpty(user.getCIQ())) { // 三少说 用到访门店生成初诊用户CIQ 20230129 String ciqNo = systemParameterService.createCIQNo(userDto.getArriveShopId()); data.put("CIQ", ciqNo); if (!StringUtils.isEmpty(ciqNo)) { sqlValue.put("CIQ", ciqNo); sql.append(",CIQ=#{m.CIQ},memberNO=#{m.CIQ}"); // 添加日志 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改CIQ"); jsonObject.put("before", user.getCIQ()); jsonObject.put("after", user.getMemberNO()); logArray.add(jsonObject); } } // 所属顾问 if (!StringUtils.isEmpty(userDto.getHisCorpUserId())) { sqlValue.put("hisCorpUserId", userDto.getHisCorpUserId()); sql.append(",hisCorpUserId=#{m.hisCorpUserId}"); // 添加日志 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改所属顾问"); Employee before; if (!StringUtils.isEmpty(user.getHisCorpUserId())) { before = employeeMapper.selectOneByKey(user.getHisCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getHisCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); // 用户所属信息变更记录 UserInfoTool.userBeChangeLogAdd(user.getId(), UserBeChangeLog.CHANGE_TYPE_ADVISER, user.getHisCorpUserId(), userDto.getHisCorpUserId(), userDto.getAppIdCode(), UserBeChangeLog.OPERATOR_TYPE_EMPLOYEE, userDto.getOpId(), userDto.getOpShopId(), "用户到访修改信息", commonService); } //2023-01-16新增逻辑:用户所属顾问为空,则同步更新用户的所属门店为顾问门店 if(!StringUtils.isEmpty(userDto.getShopId())){ sqlValue.put("shopId", userDto.getShopId()); sql.append(" , shopId = #{m.shopId} "); JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改所属门店"); Shop beforeShop; if (!StringUtils.isEmpty(user.getShopId())) { beforeShop = shopMapper.selectOneByKey(user.getShopId()); if (beforeShop != null) { jsonObject.put("before", beforeShop.getName()); } } Shop afterShop = shopMapper.selectOneByKey(userDto.getShopId()); if (afterShop != null) { jsonObject.put("after", afterShop.getName()); } logArray.add(jsonObject); // 用户所属信息变更记录 UserInfoTool.userBeChangeLogAdd(user.getId(), UserBeChangeLog.CHANGE_TYPE_SHOP, user.getShopId(), userDto.getShopId(), userDto.getAppIdCode(), UserBeChangeLog.OPERATOR_TYPE_EMPLOYEE, userDto.getOpId(), userDto.getShopId(), userDto.getRemark(), commonService); } // 所属护士 if (!StringUtils.isEmpty(userDto.getNurseCorpUserId())) { sqlValue.put("nurseCorpUserId", userDto.getNurseCorpUserId()); sql.append(",nurseCorpUserId=#{m.nurseCorpUserId}"); // 添加日志 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改所属护士"); Employee before; if (!StringUtils.isEmpty(user.getNurseCorpUserId())) { before = employeeMapper.selectOneByKey(user.getNurseCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getNurseCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); } // 所属医生 if (!StringUtils.isEmpty(userDto.getDoctorCorpUserId())) { sqlValue.put("doctorCorpUserId", userDto.getDoctorCorpUserId()); sql.append(",doctorCorpUserId=#{m.doctorCorpUserId}"); // 添加日志 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改所属医生"); Employee before; if (!StringUtils.isEmpty(user.getDoctorCorpUserId())) { before = employeeMapper.selectOneByKey(user.getDoctorCorpUserId()); if (before != null) { jsonObject.put("before", before.getCnName()); } } Employee after = employeeMapper.selectOneByKey(userDto.getDoctorCorpUserId()); if (after != null) { jsonObject.put("after", after.getCnName()); } logArray.add(jsonObject); } sql.append(" WHERE id=#{m.userId}"); sqlSentence.sqlSentence(sql.toString(), sqlValue); int count = userMapper.updateWhere(sqlSentence); if (count != 1) { throw new TipsException("修改失败!"); } // 添加用户日志处理 JSONObject jsonObjectData = new JSONObject(); jsonObjectData.put("key", "用户到访"); logArray.add(jsonObjectData); // 记录编号 String recordNo = UserInfoTool.createUSLGNo(commonService, user.getId(), user.getCIQ()); // 用户日志 UserInfoTool.addUserUpdateLog(commonService, userDto.getAppIdCode(), user, userDto.getOpShopId(), userDto.getOpId(), null, user.getId(), "用户到访", logArray, null, recordNo); // 添加调整用户状态日志 调整了用户等级在写入日志 if (!StringUtils.isEmpty(status)) { // 记录编号 recordNo = UserInfoTool.createUSLGNo(commonService, user.getId(), user.getCIQ()); // 添加用户日志 UserStatusTool.addUserStatusLog(commonService, userDto.getAppIdCode(), user, UserStatusLog.CHANGE_STATUS_TYPE_VISIT, userDto.getVisitRecordId(), UserStatusConstants.USER_STATUS_ACTIVE_MEMBER, recordNo); } //处理唤醒记录 if(userDto.getUserWakeUpLog() != null && StringUtils.noNull(userDto.getUserWakeUpLog().getAppointmentId())) { UserWakeUpLog userWakeUpLog = userDto.getUserWakeUpLog(); sqlValue.clear(); sqlValue.put("appointmentId", userWakeUpLog.getAppointmentId()); sqlSentence.setSqlSentence(" select id, createTime from user_wake_up_log where isDel = 0 and appointmentId = #{m.appointmentId} "); UserWakeUpLog oldLog = userWakeUpLogMapper.selectOne(sqlSentence); userWakeUpLog.setAppId(userDto.getAppId()); userWakeUpLog.setOriginChannel(userDto.getAppIdCode()); if (oldLog == null) { //先取消用户其他有效唤醒记录 sqlValue.put("userId", userDto.getUserId()); sqlValue.put("status", UserWakeUpLog.STATUS_INVALID); sqlValue.put("oldStatus", UserWakeUpLog.STATUS_VALID); sqlSentence.setSqlSentence(" status = #{m.status} where userId = #{m.userId} and status = #{m.oldStatus}"); userWakeUpLogMapper.updateWhere(sqlSentence); //再新增 if (userWakeUpLogMapper.insert(userWakeUpLog) != 1) { throw new TipsException("新增唤醒记录失败"); } } else { //更新 userWakeUpLog.setId(oldLog.getId()); userWakeUpLog.setCreateTime(oldLog.getCreateTime()); if (userWakeUpLogMapper.updateAll(userWakeUpLog) != 1) { throw new TipsException("更新唤醒记录失败"); } } } } return data; } /** * 根据员工id查询 用户hisId 用于同步his客户来源 * @param employeeId 员工id * @return 用户对象信息 */ private User getUserByEmployee(String employeeId) { SqlSentence sqlSentence = new SqlSentence(); Map sqlMap = new HashMap<>(); sqlMap.put("isDel", BaseEntity.NO); sqlMap.put("userBelongingType", UserChannelType.CATEGORY_EMPLOYEE); sqlMap.put("id", employeeId); String sql = "SELECT us.* FROM employee AS emp INNER JOIN `user` AS us ON us.userBelongingId=emp.apiId WHERE emp.isDel=#{m.isDel} AND us.isDel=#{m.isDel}" + " AND us.userBelongingType=#{m.userBelongingType} AND emp.id=#{m.id}"; sqlSentence.setSqlSentence(sql); sqlSentence.setM(sqlMap); return userMapper.selectOne(sqlSentence); } /**修改*/ @Override public void updateHeaderImg(String userId, String imgUrl) { SqlSentence sqlSentence = new SqlSentence(); Map sqlMap = new HashMap<>(); sqlMap.put("isDel", BaseEntity.NO); sqlMap.put("userId", userId); sqlMap.put("imgUrl", imgUrl); sqlSentence.setM(sqlMap); sqlSentence.setSqlSentence(" imgUrl=#{m.imgUrl} WHERE isDel=#{m.isDel} AND id=#{m.userId}"); int count = userMapper.updateWhere(sqlSentence); if(count!=1) { throw new TipsException("更新头像失败!"); } } /**修改*/ @Override public void updateUserApiId(String userId, String apiId) { SqlSentence sqlSentence = new SqlSentence(); Map sql = new HashMap<>(); sql.put("isDel",BaseEntity.NO); sql.put("userId",userId); sql.put("apiId",apiId); sqlSentence.setSqlSentence(" apiId=#{m.apiId} WHERE isDel=#{m.isDel} AND id=#{m.userId}"); sqlSentence.setM(sql); int count = userMapper.updateWhere(sqlSentence); if(count!=1) { throw new TipsException("保存失败!"); } } /** * 修改用户商汤id */ @Override public void updateUserShangTangId(String userId, String shangTangId) { SqlSentence sqlSentence = new SqlSentence(); Map sql = new HashMap<>(); sql.put("isDel", BaseEntity.NO); sql.put("userId", userId); sql.put("shangTangId", shangTangId); sql.put("bindSTTime", new Date()); sql.put("editTime", new Date()); sqlSentence.setSqlSentence(" shangTangId=#{m.shangTangId},bindSTTime=#{m.bindSTTime},editTime=#{m.editTime} WHERE id=#{m.userId}"); sqlSentence.setM(sql); int count = userMapper.updateWhere(sqlSentence); if (count != 1) { throw new TipsException("保存失败!"); } } /** * 修改用户KOAP(康柏嘉)id */ @Override public void updateUserKOAPId(String userId, String koapId) { SqlSentence sqlSentence = new SqlSentence(); Map sql = new HashMap<>(); sql.put("isDel",BaseEntity.NO); sql.put("userId",userId); sql.put("koapId",koapId); sql.put("bindKOAPTime", new Date()); sql.put("editTime", new Date()); sqlSentence.setSqlSentence(" koapId=#{m.koapId},bindKOAPTime=#{m.bindKOAPTime},editTime=#{m.editTime} WHERE id=#{m.userId}"); sqlSentence.setM(sql); int count = userMapper.updateWhere(sqlSentence); if(count!=1) { throw new TipsException("保存失败!"); } } /** * 修改用户phimedId */ @Override public void updateUserPhiMedId(String userId, String phiMedId) { SqlSentence sqlSentence = new SqlSentence(); Map sql = new HashMap<>(); sql.put("isDel",BaseEntity.NO); sql.put("userId",userId); sql.put("phimedId",phiMedId); sql.put("bindPhimedTime", new Date()); sql.put("editTime", new Date()); sqlSentence.setSqlSentence(" phimedId=#{m.phimedId},bindPhimedTime=#{m.bindPhimedTime},editTime=#{m.editTime} WHERE id=#{m.userId}"); sqlSentence.setM(sql); int count = userMapper.updateWhere(sqlSentence); if(count!=1) { throw new TipsException("保存失败!"); } } /**删除一个*/ @Override public void deleteUser(String delId) { // 删除用户信息 SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); map.put("id", delId); map.put("isDel", BaseEntity.YES); sqlSentence.setSqlSentence(" isDel = #{m.isDel} where id = #{m.id}"); sqlSentence.setM(map); int count = userMapper.updateWhere(sqlSentence); if(count!=1) { throw new TipsException("删除失败!"); }else { // 删除用户后处理 sqlSentence.setSqlSentence(" isDel = #{m.isDel} where userId = #{m.id}"); // 删除用户详细信息 userInfoMapper.updateWhere(sqlSentence); // 删除用户联系信息 userContactInformationMapper.updateWhere(sqlSentence); // 删除用户兴趣爱好数据 userInterestsMapper.updateWhere(sqlSentence); // 删除用户电话簿 userPhoneBookMapper.updateWhere(sqlSentence); // 删除用户地址薄 userAddressBookMapper.updateWhere(sqlSentence); } } /** * 构建同步 his系统 json 请求数据 到访修改用户信息 * @param user 用户对象 * @param consultantId 顾问id * @param doctorId 医生id * @return 返回JSON对象 */ private JSONObject buildSyncUserHisData(User user,String consultantId,String doctorId) { // 重新刷新下数据 user = userMapper.selectOneByKey(user.getId()); if (user == null) { throw new TipsException("用户信息不存在!"); } //同步his用户json参数 JSONObject userJson = new JSONObject(); userJson.put("id", user.getId()); userJson.put("type", BaseEntity.YES); userJson.put("hisId", user.getApiId()); // 性别 if (User.SEX_WUMAN.equals(user.getGender())) { userJson.put("gender", "F"); } else if (User.SEX_MAN.equals(user.getGender())) { userJson.put("gender", "M"); } else { userJson.put("gender", "M"); } // 用户名称处理 userJson.put("name", user.getName()); if (!StringUtils.isEmpty(consultantId)) { //更改所属咨询 userJson.put("consultantId", consultantId); } if (!StringUtils.isEmpty(doctorId)) { //更改所属医生 userJson.put("doctorId", doctorId); } return userJson; } /** * 构建同步 his系统 json 请求数据 * @param user 用户对象 * @param type 操作类型 0新增 1修改 * @param note 客户备注(请求参数如果没有更改备注则不修改HIS的客户备注) * @return 返回JSON对象 */ private JSONObject buildSyncUserHisData(User user,String hisShopId,String consultantId,String doctorId,String beauticianId, String customerServiceId,String serviceConsultantId,String note,Integer type) { // 重新刷新下数据 user = userMapper.selectOneByKey(user.getId()); if (user == null) { throw new TipsException("用户信息不存在!"); } //同步his用户json参数 JSONObject userJson = new JSONObject(); userJson.put("id", user.getId()); userJson.put("type", type); if (BaseEntity.YES == type) { userJson.put("hisId", user.getApiId()); } //是否共享客户(默认否) // userJson.put("isShared",true); int gender = user.getGender(); if (gender == User.SEX_WUMAN) { userJson.put("gender", "F"); } else if (gender == User.SEX_MAN) { userJson.put("gender", "M"); } else { userJson.put("gender", "M"); } // 屏蔽传ciq 荣爷说 20220629 /*if(!StringUtils.isEmpty(user.getCIQ())){ userJson.put("number",user.getCIQ()); }*/ // 多号码同步领建处理 // userJson.put("mobile", user.getTel()); // 用户名称处理 userJson.put("name", user.getName()); // 渠道来源类型不能为空 if (!StringUtils.isEmpty(user.getChannelCategory())) { // 来源类型为渠道 if (UserChannelType.CATEGORY_CHANNEL.equals(user.getChannelCategory())) { String channel2Id = user.getChannel2Id(); if (!StringUtils.isEmpty(channel2Id)) { Channels channels = commonService.selectOneByKey(ChannelsMapper.class, channel2Id); if (channels != null) { // 判断hisId是否为空 if (!StringUtils.isEmpty(channels.getHisId())) { JSONObject referrer = new JSONObject(); referrer.put("internal", false); referrer.put("referrerId", channels.getHisId()); userJson.put("referrer", referrer); } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "渠道的hisId为空!"); } } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "客户来源渠道信息不存在!"); } } } // 来源类型为会员 if (UserChannelType.CATEGORY_MEMBERS.equals(user.getChannelCategory())) { String inviteeId = user.getInviteeId(); if (!StringUtils.isEmpty(inviteeId)) { User inviteeUser = commonService.selectOneByKey(UserMapper.class, inviteeId); if (inviteeUser != null) { // 判断hisId是否为空 if (!StringUtils.isEmpty(inviteeUser.getApiId())) { JSONObject referrer = new JSONObject(); referrer.put("internal", true); referrer.put("referrerId", inviteeUser.getApiId()); userJson.put("referrer", referrer); } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "用户的hisId为空!"); } } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "客户来源员工信息不存在!"); } } } // 来源类型为员工 if (UserChannelType.CATEGORY_EMPLOYEE.equals(user.getChannelCategory())) { String inviteeId = user.getInviteeId(); if (!StringUtils.isEmpty(inviteeId)) { User employeeUser = getUserByEmployee(inviteeId); if (employeeUser != null) { // 判断hisId是否为空 if (!StringUtils.isEmpty(employeeUser.getApiId())) { JSONObject referrer = new JSONObject(); referrer.put("internal", true); referrer.put("referrerId", employeeUser.getApiId()); userJson.put("referrer", referrer); } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "员工用户的hisId为空!"); } } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "客户来源员工的用户信息不存在!"); } } } } String birthDay = user.getBirthDay(); if (!StringUtils.isEmpty(birthDay)) { String[] birthDays = birthDay.split("-"); if (birthDays.length >= 3) { JSONObject birthdayJson = new JSONObject(); birthdayJson.put("year", birthDays[0]); birthdayJson.put("month", birthDays[1]); birthdayJson.put("day", birthDays[2]); userJson.put("birthday", birthdayJson); } } // 修改所属信息 if (!StringUtils.isEmpty(hisShopId)) { //更改所属门店 userJson.put("organizationId", hisShopId); } if (!StringUtils.isEmpty(consultantId)) { //更改所属咨询 userJson.put("consultantId", consultantId); } if (!StringUtils.isEmpty(doctorId)) { //更改所属医生 userJson.put("doctorId", doctorId); } if (!StringUtils.isEmpty(beauticianId)) { //更改所属美容师 userJson.put("beauticianId", beauticianId); } if (!StringUtils.isEmpty(customerServiceId)) { //更改所属客服 userJson.put("customerServiceId", customerServiceId); } if (!StringUtils.isEmpty(serviceConsultantId)) { //更改所属电网咨询师 userJson.put("serviceConsultantId", serviceConsultantId); } if (!StringUtils.isEmpty(note)) { //修改备注 userJson.put("note", note); } /*else{ userJson.put("note",""); }*/ SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); sqlSentence.setSqlSentence("SELECT * FROM user_address_book WHERE isDel = 0 and userId = #{m.userId} and addressType = #{m.addressType} "); map.put("userId", user.getId()); map.put("addressType", UserAddressBook.TYPE_ADDRESS); List userAddressBooks = userAddressBookMapper.selectList(sqlSentence); JSONObject address = new JSONObject(); if (userAddressBooks != null && userAddressBooks.size() > 0) { if (!StringUtils.isEmpty(userAddressBooks.get(0).getCity())) { address.put("country", userAddressBooks.get(0).getCountry()); address.put("province", userAddressBooks.get(0).getProvince()); address.put("city", userAddressBooks.get(0).getCity()); address.put("district", userAddressBooks.get(0).getArea()); address.put("street", userAddressBooks.get(0).getDetail()); userJson.put("address", address); } } // 电话簿同步处理 if (!StringUtils.isEmpty(user.getTel())) { JSONArray phoneArray = new JSONArray(); // 主号码同步领建处理 JSONObject primaryObject = new JSONObject(); primaryObject.put("countryCode", "+86"); primaryObject.put("number", user.getTel()); primaryObject.put("isPrimary", false); // 默认本人 primaryObject.put("ownerTypeCode", "self"); // 添加到集合 phoneArray.add(primaryObject); // 查询其他号码 String sql = "SELECT * FROM user_phone_book WHERE isDel = #{m.isDel} AND userId = #{m.userId}"; map.put("isDel", BaseEntity.NO); map.put("userId", user.getId()); sqlSentence.sqlSentence(sql, map); List userPhoneBookList = userPhoneBookMapper.selectList(sqlSentence); if (userPhoneBookList != null && userPhoneBookList.size() > 0) { for (UserPhoneBook userPhoneBook : userPhoneBookList) { if (!user.getTel().equals(userPhoneBook.getTel())) { // 排除电话号码为空 if (StringUtils.isEmpty(userPhoneBook.getTel())) { continue; } JSONObject phoneObject = new JSONObject(); phoneObject.put("countryCode", String.format("+%s", userPhoneBook.getAreaCode())); if (Objects.equals(userPhoneBook.getIsPrimary(), BaseEntity.YES)) { phoneObject.put("isPrimary", true); } else { phoneObject.put("isPrimary", false); } phoneObject.put("number", userPhoneBook.getTel()); // 默认本人 phoneObject.put("ownerTypeCode", "self"); // 添加到集合 phoneArray.add(phoneObject); } } } userJson.put("phones", phoneArray); } return userJson; } /** * 构建康柏嘉用户请求参数 * @param user 用户对象 * @return json请求数据 */ public JSONObject buildKOAPUserData(User user){ JSONObject jsonObject = new JSONObject(); // 填写患者编号 if(!StringUtils.isEmpty(user.getKoapId())){ jsonObject.put("patientNo",user.getKoapId()); } // 姓名 jsonObject.put("patientName",user.getName()); // 性别 M:男 if(Objects.equals(user.getGender(), User.SEX_MAN)){ jsonObject.put("sex","M"); } // 性别 F:女 if(Objects.equals(user.getGender(), User.SEX_WUMAN)){ jsonObject.put("sex","F"); } // U:不明 if(Objects.equals(user.getGender(), User.SEX_UNKNOWN)){ jsonObject.put("sex","U"); } // 手机号 jsonObject.put("phoneNo",user.getTel()); // 出生日期 YYYY-MM-DD jsonObject.put("birthday",user.getBirthDay()); // 证件类型 身份证 if(!SimpleTool.checkNotNull(user.getCertificateNo()) && !SimpleTool.checkNotNull(user.getCertificateType())) { if (user.getCertificateType() == User.CERTIFICATE_TYPE_ID) { jsonObject.put("idTypeCode", "1"); jsonObject.put("idNo", user.getCertificateNo()); } // 证件类型 护照 if (user.getCertificateType() == User.CERTIFICATE_TYPE_PASSPORT) { jsonObject.put("idTypeCode", "5"); jsonObject.put("idNo", user.getCertificateNo()); } // 证件类型 台胞证 if (user.getCertificateType() == User.CERTIFICATE_TYPE_TAIWAN) { jsonObject.put("idTypeCode", "7"); jsonObject.put("idNo", user.getCertificateNo()); } } // 备注 jsonObject.put("remarks",user.getRemark()); // 地址获取 SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); sqlSentence.setSqlSentence("SELECT * FROM user_address_book WHERE isDel = 0 and userId = #{m.userId} and addressType = #{m.addressType} "); map.put("userId",user.getId()); map.put("addressType",UserAddressBook.TYPE_ADDRESS); List userAddressBooks= commonService.selectList(UserAddressBookMapper.class,sqlSentence); if(userAddressBooks !=null && userAddressBooks.size()>0) { // 省 String stateDesc = userAddressBooks.get(0).getProvince(); if(!StringUtils.isEmpty(stateDesc)) { if (stateDesc.contains("市")) { stateDesc = stateDesc.replace("市", ""); } jsonObject.put("stateDesc", stateDesc); } // 市 String cityDesc = userAddressBooks.get(0).getCity(); if(!StringUtils.isEmpty(cityDesc)) { if (!StringUtils.isEmpty(userAddressBooks.get(0).getProvince()) && userAddressBooks.get(0).getProvince().contains("市")) { cityDesc = stateDesc; } jsonObject.put("cityDesc", cityDesc); } // 详细地址 String address; if (!StringUtils.isEmpty(userAddressBooks.get(0).getArea())) { address = userAddressBooks.get(0).getArea(); if (!StringUtils.isEmpty(userAddressBooks.get(0).getDetail())) { address = userAddressBooks.get(0).getDetail(); } // 详细地址 jsonObject.put("address", address); } } return jsonObject; } /** * 根据用户id同步修改领建用户等级 * @param userDto 参数 * @param user 参数 */ @Override public void syncUpdateHisUserLevel(UserDto userDto, User user) { // 添加日志 JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "用户等级"); jsonObject.put("before", user.getUserLevel()); jsonObject.put("after", userDto.getUserLevel()); jsonArray.add(jsonObject); // 获取等级配置信息 UserLevelRule userLevelRule = UserLevelTool.getUserLevelRuleByName(commonService, userDto.getUserLevel()); // 修改数据 SqlSentence sqlSentence = new SqlSentence(); Map sqlValues = new HashMap<>(); sqlValues.put("id", user.getId()); sqlValues.put("userLevel", userDto.getUserLevel()); sqlValues.put("memberLevelId", userLevelRule.getMemberLevelId()); sqlSentence.sqlSentence(" userLevel=#{m.userLevel},memberLevelId=#{m.memberLevelId} WHERE id = #{m.id}", sqlValues); int count = userMapper.updateWhere(sqlSentence); if (count != 1) { throw new TipsException("修改用户等级失败"); } else { // 有日志才去添加日志 if (jsonArray.size() > 0) { // 处理用户日志 UserUpdateLog userUpdateLog = new UserUpdateLog(); userUpdateLog.setUserId(userDto.getUserId()); // 来源渠道 userUpdateLog.setSourceAppCode(userDto.getAppIdCode()); if (!StringUtils.isEmpty(userDto.getAppIdCode())){ String name = PlatformConstants.getName(userDto.getAppIdCode()); userUpdateLog.setSourceAppName(name); } // 门店信息处理 if (!StringUtils.isEmpty(userDto.getShopId())) { Shop shop = commonService.selectOneByKey(ShopMapper.class, userDto.getShopId()); if (shop != null) { userUpdateLog.setShopId(shop.getId()); userUpdateLog.setShopName(shop.getName()); } } // 管理员处理 if (!StringUtils.isEmpty(userDto.getOpId())) { Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userDto.getOpId()); if (employee != null) { userUpdateLog.setOperatorType(UserUpdateLog.OPERATOR_TYPE_EMPLOYEE); userUpdateLog.setOperatorId(employee.getId()); userUpdateLog.setOperatorName(employee.getCnName()); } } else { userUpdateLog.setOperatorType(UserUpdateLog.OPERATOR_TYPE_SYSTEM); } userUpdateLog.setContent(jsonArray.toJSONString()); // 记录编号 String recordNo = systemParameterService.createUSLGNo(user.getId(), user.getCIQ()); userUpdateLog.setRecordNo(recordNo); int logCount = userUpdateLogMapper.insert(userUpdateLog); if (logCount != 1) { throw new TipsException("记录修改用户日志失败:" + logCount); } } // 用户等级记录添加信息 UserLevelTool.addUserLevelRecord(commonService, user, userLevelRule, null, userDto.getOpId()); // 调用同步接口同步操作领建 UserLevelTool.syncUpdateHisUserLevel(commonService, syncUserService, user.getId(), userDto.getAppIdCode()); } } /** * 获取用户等级 * @param user 用户 * @return 返回 */ private UserLevelRule getUserNowLevelRule(User user) { SqlSentence sqlSentence = new SqlSentence(); Map sqlValue = new HashMap<>(); sqlValue.put("isDel", BaseEntity.NO); StringBuilder sql = new StringBuilder(); sql.append("SELECT * FROM user_level_rule WHERE isDel = #{m.isDel} "); if (!StringUtils.isEmpty(user.getMemberLevelId())) { sql.append(" AND memberLevelId = #{m.memberLevelId} "); sqlValue.put("memberLevelId", user.getMemberLevelId()); } else if (!StringUtils.isEmpty(user.getUserLevel())) { sql.append(" AND levelName = #{m.levelName} "); sqlValue.put("levelName", user.getUserLevel()); } else { return null; } sqlSentence.sqlSentence(sql.toString(), sqlValue); return commonService.selectOne(UserLevelRuleMapper.class, sqlSentence); } /** * 用户等级计算测试方法 * @param user 用户 * @return 返回 */ @Override public JSONObject userLevelProgress(User user) { // 计算当年消费消费总计 BigDecimal nowConsume = UserLevelTool.getAllConsumeOrder(commonService, user.getId(), BaseEntity.YES, BaseEntity.NO); // 等级升级规则 UserLevelRule userLevelRule = null; if (StringUtils.isEmpty(user.getUserLevel())) { // 默认会员等级普卡 userLevelRule = UserLevelTool.getUserLevelRuleByLeveSort(commonService, 2); } else { // 查询当前等级规则数据 UserLevelRule nowUserLevelRule = this.getUserNowLevelRule(user); if (nowUserLevelRule != null) { // 黑钻卡不需要在显示 if ("BlackDiamondsCard".equals(nowUserLevelRule.getLevelNo())) { return null; } else { userLevelRule = UserLevelTool.getUserLevelRuleByLeveSort(commonService, nowUserLevelRule.getLevelSort() + 1); } } } // 获取下一个等级的消费金额 if (userLevelRule != null) { // 获取规则 JSONObject rule = JSONObject.parseObject(userLevelRule.getUpgradeYearConsumeRule()); if (rule != null && rule.containsKey("value") && rule.get("value") != null) { BigDecimal upgradeConsume = rule.getBigDecimal("value"); // 返回数据 JSONObject returnData = new JSONObject(); returnData.put("nowConsume", nowConsume); // 准会员大于0就会升级 if (BigDecimal.ZERO.compareTo(upgradeConsume) == 0){ upgradeConsume = BigDecimal.ONE; } returnData.put("upgradeConsume", upgradeConsume); returnData.put("difference", upgradeConsume.subtract(nowConsume)); return returnData; } } return null; } /** * 构建日志信息 * @return 返回 */ private String getUserFamiliesRoomInfo(UserFamiliesRoom userFamiliesRoom) { // 参数数据 JSONObject jsonObject = null; if (userFamiliesRoom != null) { // 数据处理 jsonObject = new JSONObject(); // 所属科室 if (!StringUtils.isEmpty(userFamiliesRoom.getFamiliesRoomName())) { jsonObject.put("所属科室", userFamiliesRoom.getFamiliesRoomName()); } // 所属顾问 if (!StringUtils.isEmpty(userFamiliesRoom.getAdviserName())) { jsonObject.put("所属顾问", userFamiliesRoom.getAdviserName()); } // 所属医生 if (!StringUtils.isEmpty(userFamiliesRoom.getDoctorName())) { jsonObject.put("所属医生", userFamiliesRoom.getDoctorName()); } // 所属护士 if (!StringUtils.isEmpty(userFamiliesRoom.getNurseName())) { jsonObject.put("所属护士", userFamiliesRoom.getNurseName()); } } // 返回数据 if (jsonObject != null) { return jsonObject.toJSONString(); } return null; } /** * 修改用户科室关系信息 * @param userParamDto 参数 * @param user 用户信息 * @param opEmployee 操作人 */ @Override public void updateFamiliesRoom(UserParamDto userParamDto, User user, Employee opEmployee) { // 科室数据 List userFamiliesRoomList; try { userFamiliesRoomList = JSONArray.parseArray(userParamDto.getDepartmentJson(), UserFamiliesRoom.class); } catch (Exception ex) { throw new TipsException("科室关系参数解析失败请确认参数!"); } // 操作数据处理 if (userFamiliesRoomList != null && userFamiliesRoomList.size() > 0) { // 日志数据 JSONArray logArray = new JSONArray(); // 处理数据 for (UserFamiliesRoom userFamiliesRoom : userFamiliesRoomList) { // 科室id FamiliesRoom familiesRoom; if (StringUtils.isEmpty(userFamiliesRoom.getFamiliesRoomId())) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "数据中的科室id不能为空!"); } else { familiesRoom = familiesRoomMapper.selectOneByKey(userFamiliesRoom.getFamiliesRoomId()); if (familiesRoom == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "数据中的科室信息不存在!"); } } // 之前用户科室Json信息 String checkUserFamiliesRoomBefore = null; // 校验数据是否存在存在数据就修改 每个科室只有一条 UserFamiliesRoom checkUserFamiliesRoom = UserInfoTool.getUserFamiliesRoom(commonService, user.getId(), familiesRoom.getId()); if (checkUserFamiliesRoom != null) { checkUserFamiliesRoomBefore = this.getUserFamiliesRoomInfo(checkUserFamiliesRoom); } // 科室信息 if (checkUserFamiliesRoom != null) { checkUserFamiliesRoom.setFamiliesRoomId(familiesRoom.getId()); checkUserFamiliesRoom.setFamiliesRoomName(familiesRoom.getFamiliesRoomName()); } else { userFamiliesRoom.setFamiliesRoomId(familiesRoom.getId()); userFamiliesRoom.setFamiliesRoomName(familiesRoom.getFamiliesRoomName()); } // 用户信息 userFamiliesRoom.setUserId(user.getId()); // 顾问 if (!StringUtils.isEmpty(userFamiliesRoom.getAdviserId())) { Employee employee = employeeMapper.selectOneByKey(userFamiliesRoom.getAdviserId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "数据中的顾问信息不存在!"); } else { if (checkUserFamiliesRoom != null) { checkUserFamiliesRoom.setAdviserId(employee.getId()); checkUserFamiliesRoom.setAdviserName(employee.getCnName()); } else { userFamiliesRoom.setAdviserId(employee.getId()); userFamiliesRoom.setAdviserName(employee.getCnName()); } } } // 医生 if (!StringUtils.isEmpty(userFamiliesRoom.getDoctorId())) { Employee employee = employeeMapper.selectOneByKey(userFamiliesRoom.getDoctorId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "数据中的医生信息不存在!"); } else { if (checkUserFamiliesRoom != null) { checkUserFamiliesRoom.setDoctorId(employee.getId()); checkUserFamiliesRoom.setDoctorName(employee.getCnName()); } else { userFamiliesRoom.setDoctorId(employee.getId()); userFamiliesRoom.setDoctorName(employee.getCnName()); } } } // 护士 if (!StringUtils.isEmpty(userFamiliesRoom.getNurseId())) { Employee employee = employeeMapper.selectOneByKey(userFamiliesRoom.getNurseId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "数据中的护士信息不存在!"); } else { if (checkUserFamiliesRoom != null) { checkUserFamiliesRoom.setNurseId(employee.getId()); checkUserFamiliesRoom.setNurseName(employee.getCnName()); } else { userFamiliesRoom.setNurseId(employee.getId()); userFamiliesRoom.setNurseName(employee.getCnName()); } } } // 判断是添加还是修改 if (checkUserFamiliesRoom == null) { // 添加用户科室数据 userFamiliesRoomMapper.insert(userFamiliesRoom); // 处理用户日志 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "添加用户科室关系"); jsonObject.put("before", ""); // 之后信息 String userFamiliesRoomAfter = this.getUserFamiliesRoomInfo(userFamiliesRoom); jsonObject.put("after", userFamiliesRoomAfter); logArray.add(jsonObject); } else { // 修改用户科室数据 checkUserFamiliesRoom.setEditTime(new Date()); userFamiliesRoomMapper.updateAll(checkUserFamiliesRoom); // 处理用户日志 JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改用户科室关系"); jsonObject.put("before", checkUserFamiliesRoomBefore); // 之后信息 String checkUserFamiliesRoomAfter = this.getUserFamiliesRoomInfo(checkUserFamiliesRoom); jsonObject.put("after", checkUserFamiliesRoomAfter); logArray.add(jsonObject); } } // 记录编号 String recordNo = systemParameterService.createUSLGNo(user.getId(), user.getCIQ()); // 添加用户日志 UserInfoTool.addUserUpdateLog(commonService, userParamDto.getApiId(), user, user.getShopId(), opEmployee.getId(), null, null, "调整用户科室关系数据", logArray, null, recordNo); } } /** * 重新计算用户等级 * @param userParamDto 参数 * @param user 用户信息 * @param employee 操作人信息 */ @Override public void userLevelCalc(UserParamDto userParamDto, User user, Employee employee) { // 获取最后一条等级改变记录 SqlSentence sqlSentence = new SqlSentence(); Map sqlValue = new HashMap<>(); sqlValue.put("userId", userParamDto.getUserId()); sqlValue.put("isDel", BaseEntity.NO); sqlValue.put("isNowLevel", BaseEntity.YES); String sql = "SELECT * FROM user_level_record WHERE userId = #{m.userId} AND isNowLevel = #{m.isNowLevel} AND isDel = #{m.isDel} ORDER BY createTime DESC LIMIT 1"; sqlSentence.sqlSentence(sql, sqlValue); UserLevelRecord lastUserLevelRecord = commonService.selectOne(com.hx.phiappt.dao.mapper.UserLevelRecordMapper.class, sqlSentence); if (lastUserLevelRecord != null) { // 备注填写下 lastUserLevelRecord.setRemarks("重新计算用户等级-" + userParamDto.getRemark()); // 填写下操作人信息 lastUserLevelRecord.setOperatorType(UserLevelRecord.OPERATOR_TYPE_EMPLOYEE); lastUserLevelRecord.setOperatorId(employee.getId()); lastUserLevelRecord.setOperatorName(employee.getCnName()); // 处理重新计算用户等级 UserLevelTool.reCalcUserLevel(commonService, lastUserLevelRecord, user); // 添加用户日志 User checkUser = commonService.selectOneByKey(UserMapper.class, user.getId()); if (checkUser != null && !StringUtils.isEmpty(checkUser.getUserLevel()) && !checkUser.getUserLevel().equals(user.getUserLevel())) { JSONArray logArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "重新计算用户等级"); jsonObject.put("before", user.getUserLevel()); jsonObject.put("after", checkUser.getUserLevel()); logArray.add(jsonObject); // 记录编号 String recordNo = UserInfoTool.createUSLGNo(commonService, user.getId(), user.getCIQ()); // 添加日志 UserInfoTool.addUserUpdateLog(commonService, PlatformConstants.TYPE_PLATFORM_PHIS, user, user.getShopId(), employee.getId(), null, null, "重新计算用户等级", logArray, userParamDto.getRemark(), recordNo); } } else { throw new TipsException("当前用户没有等级记录不需要重新计算!"); } } @Override public void userCompleteInfoById(UserInfoCompleteDto userInfoCompleteDto, User user) { JSONArray logArray = new JSONArray(); SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); String userId = user.getId(); values.put("userId", userId); // 处理日志 if (!StringUtils.isEmpty(userInfoCompleteDto.getName())) { if (!userInfoCompleteDto.getName().equals(user.getName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改姓名"); jsonObject.put("before", user.getName()); jsonObject.put("after", userInfoCompleteDto.getName()); logArray.add(jsonObject); } } if (userInfoCompleteDto.getGender() != null) { if (!userInfoCompleteDto.getGender().equals(user.getGender())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改性别"); jsonObject.put("before", user.getGender()); jsonObject.put("after", userInfoCompleteDto.getGender()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getTel())) { if (!userInfoCompleteDto.getTel().equals(user.getTel())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改手机号"); jsonObject.put("before", user.getTel()); jsonObject.put("after", userInfoCompleteDto.getTel()); logArray.add(jsonObject); } } if (userInfoCompleteDto.getCertificateType() != null && !StringUtils.isEmpty(userInfoCompleteDto.getCertificateNo())) { if (!userInfoCompleteDto.getCertificateType().equals(user.getCertificateType())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改证件类型"); jsonObject.put("before", user.getCertificateType()); jsonObject.put("after", userInfoCompleteDto.getCertificateType()); logArray.add(jsonObject); } if (!userInfoCompleteDto.getCertificateNo().equals(user.getCertificateNo())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改身份证号码"); jsonObject.put("before", user.getCertificateNo()); jsonObject.put("after", userInfoCompleteDto.getCertificateNo()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getBirthDay())) { if (!userInfoCompleteDto.getBirthDay().equals(user.getBirthDay())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改生日"); jsonObject.put("before", user.getBirthDay()); jsonObject.put("after", userInfoCompleteDto.getBirthDay()); logArray.add(jsonObject); } } //user表更新字段 values.put("name", userInfoCompleteDto.getName()); values.put("gender", userInfoCompleteDto.getGender()); values.put("tel", userInfoCompleteDto.getTel()); values.put("certificateType", userInfoCompleteDto.getCertificateType()); values.put("certificateNo", userInfoCompleteDto.getCertificateNo()); values.put("birthday", userInfoCompleteDto.getBirthDay()); sqlSentence.setSqlSentence(" name = #{m.name},gender = #{m.gender}, tel = #{m.tel}, certificateType = #{m.certificateType}, certificateNo = #{m.certificateNo},birthday = #{m.birthday} where id = #{m.userId} "); if (userMapper.updateWhere(sqlSentence) != 1) throw new TipsException("更新用户信息失败!"); //user_info 更新字段 UserInfo userInfo = userInfoMapper.selectOneByUserId(userInfoCompleteDto.getUserId()); if (userInfo != null) { if (!StringUtils.isEmpty(userInfoCompleteDto.getProfessionTypeName())) { if (!userInfoCompleteDto.getProfessionTypeName().equals(userInfo.getProfessionTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改工作"); jsonObject.put("before", userInfo.getProfessionTypeName()); jsonObject.put("after", userInfoCompleteDto.getProfessionTypeName()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getMarriageTypeName())) { if (!userInfoCompleteDto.getMarriageTypeName().equals(userInfo.getMarriageTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改婚否"); jsonObject.put("before", userInfo.getMarriageTypeName()); jsonObject.put("after", userInfoCompleteDto.getMarriageTypeName()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getGrowthTypeName())) { if (!userInfoCompleteDto.getGrowthTypeName().equals(userInfo.getGrowthTypeName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改生育"); jsonObject.put("before", userInfo.getGrowthTypeName()); jsonObject.put("after", userInfoCompleteDto.getGrowthTypeName()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getSourceName())) { if (!userInfoCompleteDto.getSourceName().equals(userInfo.getSourceName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改冗余来源名称"); jsonObject.put("before", userInfo.getSourceName()); jsonObject.put("after", userInfoCompleteDto.getSourceName()); logArray.add(jsonObject); } } if (userInfoCompleteDto.getIsFriendReferrer() != null && !StringUtils.isEmpty(userInfoCompleteDto.getFriendName())) { if (!userInfoCompleteDto.getIsFriendReferrer().equals(userInfo.getIsFriendReferrer())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改是否好友推荐"); jsonObject.put("before", userInfo.getIsFriendReferrer()); jsonObject.put("after", userInfoCompleteDto.getIsFriendReferrer()); logArray.add(jsonObject); } if (!userInfoCompleteDto.getFriendName().equals(userInfo.getFriendName())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改推荐人名称"); jsonObject.put("before", userInfo.getFriendName()); jsonObject.put("after", userInfoCompleteDto.getFriendName()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getMainAppeal())) { if (!userInfoCompleteDto.getMainAppeal().equals(userInfo.getMainAppeal())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改主要诉求"); jsonObject.put("before", userInfo.getMainAppeal()); jsonObject.put("after", userInfoCompleteDto.getMainAppeal()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getMinorAppeal())) { if (!userInfoCompleteDto.getMinorAppeal().equals(userInfo.getMinorAppeal())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改次要诉求"); jsonObject.put("before", userInfo.getMinorAppeal()); jsonObject.put("after", userInfoCompleteDto.getMinorAppeal()); logArray.add(jsonObject); } } values.put("userInfoId", userInfo.getId()); values.put("professionTypeName", userInfoCompleteDto.getProfessionTypeName()); values.put("marriageTypeName", userInfoCompleteDto.getMarriageTypeName()); values.put("growthTypeName", userInfoCompleteDto.getGrowthTypeName()); values.put("sourceName", userInfoCompleteDto.getSourceName()); values.put("isFriendReferrer", userInfoCompleteDto.getIsFriendReferrer()); values.put("friendName", userInfoCompleteDto.getFriendName()); values.put("mainAppeal", userInfoCompleteDto.getMainAppeal()); values.put("minorAppeal", userInfoCompleteDto.getMinorAppeal()); sqlSentence.setSqlSentence(" professionTypeName = #{m.professionTypeName},marriageTypeName = #{m.marriageTypeName}, growthTypeName = #{m.growthTypeName}, sourceName = #{m.sourceName}, isFriendReferrer = #{m.isFriendReferrer}, friendName = #{m.friendName}, mainAppeal = #{m.mainAppeal}, minorAppeal = #{m.minorAppeal} where id = #{m.userInfoId}"); if (userInfoMapper.updateWhere(sqlSentence) != 1) throw new TipsException("更新用户详情信息失败!"); } else { userInfo = new UserInfo(); userInfo.setProfessionTypeName(userInfoCompleteDto.getProfessionTypeName()); userInfo.setMarriageTypeName(userInfoCompleteDto.getMarriageTypeName()); userInfo.setGrowthTypeName(userInfoCompleteDto.getGrowthTypeName()); userInfo.setSourceName(userInfoCompleteDto.getSourceName()); userInfo.setIsFriendReferrer(userInfoCompleteDto.getIsFriendReferrer()); userInfo.setFriendName(userInfoCompleteDto.getFriendName()); userInfo.setMainAppeal(userInfoCompleteDto.getMainAppeal()); userInfo.setMinorAppeal(userInfoCompleteDto.getMinorAppeal()); userInfo.setUserId(userId); if (userInfoMapper.insert(userInfo) != 1) throw new TipsException("新增用户详情信息失败!"); } //user_contact_information 更新字段 UserContactInformation contactInformation = userContactInformationMapper.selectOneByUserId(userId); if (contactInformation != null) { if (!StringUtils.isEmpty(userInfoCompleteDto.getEmail())) { if (!userInfoCompleteDto.getEmail().equals(contactInformation.getEmail())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改邮箱"); jsonObject.put("before", contactInformation.getEmail()); jsonObject.put("after", userInfoCompleteDto.getEmail()); logArray.add(jsonObject); } } values.put("email", userInfoCompleteDto.getEmail()); values.put("contactInformationId", contactInformation.getId()); sqlSentence.setSqlSentence(" email = #{m.email} where id = #{m.contactInformationId}"); if (userContactInformationMapper.updateWhere(sqlSentence) != 1) throw new TipsException("更新用户联系信息失败!"); } else { contactInformation = new UserContactInformation(); contactInformation.setEmail(userInfoCompleteDto.getEmail()); contactInformation.setUserId(userId); if (userContactInformationMapper.insert(contactInformation) != 1) throw new TipsException("新增用户联系信息失败!"); } // user_address_book 更新字段 sqlSentence.setSqlSentence("select * from user_address_book where userId = #{m.userId} and addressType = 1 and isDel = 0 order by createTime desc limit 1"); UserAddressBook userAddressBook = userAddressBookMapper.selectOne(sqlSentence); if (userAddressBook != null) { if (!StringUtils.isEmpty(userInfoCompleteDto.getCountry())) { if (!userInfoCompleteDto.getCountry().equals(userAddressBook.getCountry())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改地址-国家"); jsonObject.put("before", userAddressBook.getCountry()); jsonObject.put("after", userInfoCompleteDto.getCountry()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getCountry())) { if (!userInfoCompleteDto.getProvince().equals(userAddressBook.getProvince())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改地址-省份"); jsonObject.put("before", userAddressBook.getProvince()); jsonObject.put("after", userInfoCompleteDto.getProvince()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getCity())) { if (!userInfoCompleteDto.getCity().equals(userAddressBook.getCity())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改地址-城市"); jsonObject.put("before", userAddressBook.getCity()); jsonObject.put("after", userInfoCompleteDto.getCity()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getArea())) { if (!userInfoCompleteDto.getArea().equals(userAddressBook.getArea())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改地址-区域"); jsonObject.put("before", userAddressBook.getArea()); jsonObject.put("after", userInfoCompleteDto.getArea()); logArray.add(jsonObject); } } if (!StringUtils.isEmpty(userInfoCompleteDto.getDetail())) { if (!userInfoCompleteDto.getDetail().equals(userAddressBook.getDetail())) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", "修改地址-详细"); jsonObject.put("before", userAddressBook.getDetail()); jsonObject.put("after", userInfoCompleteDto.getDetail()); logArray.add(jsonObject); } } values.put("country", userInfoCompleteDto.getCountry()); values.put("province", userInfoCompleteDto.getProvince()); values.put("city", userInfoCompleteDto.getCity()); values.put("area", userInfoCompleteDto.getArea()); values.put("detail", userInfoCompleteDto.getDetail()); values.put("userAddressBookId", userAddressBook.getId()); sqlSentence.setSqlSentence(" country = #{m.country},province = #{m.province}, city = #{m.city}, area = #{m.area}, detail = #{m.detail} where id = #{m.userAddressBookId}"); if (userAddressBookMapper.updateWhere(sqlSentence) != 1) throw new TipsException("更新用户地址信息失败!"); } else { userAddressBook = new UserAddressBook(); userAddressBook.setUserId(userId); userAddressBook.setCountry(userInfoCompleteDto.getCountry()); userAddressBook.setProvince(userInfoCompleteDto.getProvince()); userAddressBook.setCity(userInfoCompleteDto.getCity()); userAddressBook.setArea(userInfoCompleteDto.getArea()); userAddressBook.setDetail(userInfoCompleteDto.getDetail()); if (userAddressBookMapper.insert(userAddressBook) != 1) throw new TipsException("新增用户地址信息失败!"); } //------- 处理用户标签数据 handleUserTag(userInfoCompleteDto); //--------处理关注公众号 try { handleGzhFocusRecord(userId); }catch (Exception e){ logger.info("完善资料页更新关注公众号记录异常:{}", GlobalExceptionHandler.getExceptionInformation(e)); } //----------------添加日志 // 记录编号 String recordNo = UserInfoTool.createUSLGNo(commonService, user.getId(), user.getCIQ()); UserInfoTool.addUserUpdateLog(commonService, PlatformConstants.TYPE_PLATFORM_CRM, user, user.getShopId(), user.getId(), null, null, "crm用户扫码编辑自己信息页", logArray, null, recordNo); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** 用户信息完善 处理标签信息**/ public void handleUserTag(UserInfoCompleteDto userInfoCompleteDto) { //------- 处理用户标签数据 //标签 -职位 UserLabelDcpDto professionType= new UserLabelDcpDto(); professionType.setIsCustom(1); // 标签 - 婚否 UserLabelDcpDto marriageTyp = new UserLabelDcpDto(); marriageTyp.setIsCustom(0); // 标签- 生育 UserLabelDcpDto growthType = new UserLabelDcpDto(); growthType.setIsCustom(0); //区分环境处理 职业 生育 婚否 if ("prod".equals(customParameter.getPlatformPattern())){ //职业 professionType.setTypeNo("LT20230406mRbkLG"); //婚否 marriageTyp.setTypeNo("LT202208162cHDcz"); if(userInfoCompleteDto.getMarriageTypeName().equals("已婚")){ marriageTyp.setTagNo("LA20220816MsuHuP"); }else { marriageTyp.setTagNo("LA20220816Gl0vLL"); } //生育 growthType.setTypeNo("LT20230921QnaLns"); if(userInfoCompleteDto.getGrowthTypeName().equals("已育")){ growthType.setTagNo("LA20230921TgcoAc"); }else { growthType.setTagNo("LA20230921HWZNLS"); } }else{ //职业 professionType.setTypeNo("profession"); //婚否 marriageTyp.setTypeNo("LT20230921zyrMZC"); if(userInfoCompleteDto.getMarriageTypeName().trim().equals("已婚")){ marriageTyp.setTagNo("LA20230921hkVYme"); }else { marriageTyp.setTagNo("LA20230921s87r0q"); } //生育 growthType.setTypeNo("LT20230921Mg7yoF"); if(userInfoCompleteDto.getGrowthTypeName().trim().equals("已育")){ growthType.setTagNo("LA202309218d5OFD"); }else { growthType.setTagNo("LA20230921KtufiX"); } } List list = new ArrayList<>(); UserLabelDcpAddDto userLabelAddDto = new UserLabelDcpAddDto(); userLabelAddDto.setUserId(userInfoCompleteDto.getUserId()); professionType.setTagName(userInfoCompleteDto.getProfessionTypeName().trim()); list.add(professionType); marriageTyp.setTagName(userInfoCompleteDto.getMarriageTypeName().trim()); list.add(marriageTyp); growthType.setTagName(userInfoCompleteDto.getGrowthTypeName().trim()); list.add(growthType); userLabelAddDto.setUserLabelDtoList(list); List userLabelDtoLists = userLabelAddDto.getUserLabelDtoList(); if (userLabelDtoLists == null) { userLabelDtoLists = new ArrayList<>(); } for (UserLabelDcpDto userLabelDcpDto : userLabelDtoLists) { if (StringUtils.isEmpty(userLabelDcpDto.getTagName())) { throw new TipsException("标签名称为空!"); } if (userLabelDcpDto.getIsCustom() == null) { throw new TipsException("请选择标签是否自定义!"); } } JSONObject data = new JSONObject(); data.put("userId", userLabelAddDto.getUserId()); data.put("sourceType", "phis"); List tagList = new ArrayList<>(); List userLabelDtoList = userLabelAddDto.getUserLabelDtoList(); if (userLabelDtoList != null && userLabelDtoList.size() > 0) { List> editUserTagInfoList = new ArrayList<>(); Map editUserTagInfo; for (UserLabelDcpDto userLabelDcpDto : userLabelDtoList) { editUserTagInfo = new HashMap<>(); editUserTagInfo.put("typeNo", userLabelDcpDto.getTypeNo()); editUserTagInfo.put("tagName", userLabelDcpDto.getTagName().trim()); if (userLabelDcpDto.getIsCustom() == 1) { editUserTagInfo.put("isCustom", userLabelDcpDto.getIsCustom()); } else if (userLabelDcpDto.getIsCustom() == 0) { editUserTagInfo.put("isCustom", userLabelDcpDto.getIsCustom()); editUserTagInfo.put("tagNo", userLabelDcpDto.getTagNo()); } tagList.add(userLabelDcpDto.getTagName().trim()); editUserTagInfoList.add(editUserTagInfo); } data.put("editUserTagInfoList", editUserTagInfoList); } //要删除的标签 固定 - 职位 生育 婚否 SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("userId",userLabelAddDto.getUserId()); sqlSentence.setSqlSentence(" select * from user_general_label where isDel = 0 and userId = #{m.userId} and labelTypeNo IN ('LT20230921zyrMZC','LT20230921Mg7yoF','LT202208162cHDcz','LT20230921QnaLns','LT202208162cHDcz','LT20230921QnaLns','profession','LT20230406mRbkLG') "); List userGeneralLabelList = commonService.selectList(UserGeneralLabelMapper.class,sqlSentence); List deleteList = new ArrayList<>(); if (userGeneralLabelList != null && userGeneralLabelList.size() > 0) { List oldList = userGeneralLabelList.stream().filter(oldInfo -> !tagList.stream().collect(Collectors.toList()) .contains(oldInfo.getName())).collect(Collectors.toList()); if (oldList != null && oldList.size() > 0) { for (UserGeneralLabel tagInfoDt : oldList) { deleteList.add(tagInfoDt.getSourceId()); } data.put("deleteUserTagInfoIdList", deleteList); } } logger.info("dcp更新用户基本信息标签(工作/生育/婚否):{}", JSONObject.toJSONString(data)); sUserTagInfoService.edit(data); } /**处理用户关注公众号 */ public void handleGzhFocusRecord(String userId) { User user = userMapper.selectOneByKey(userId); if(user == null){ return; } SqlSentence sqlSentence = new SqlSentence(); StringBuffer sql = new StringBuffer(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("isDel", BaseEntity.NO); values.put("userId", userId); //查询用户登录数据 获取unionId sql.append(" select * from user_union_his where userId = #{m.userId} AND isDel = #{m.isDel} order by createTime desc limit 1"); sqlSentence.setSqlSentence(sql.toString()); UserUnionHis userUnionHis = commonService.selectOne(UserUnionHisMapper.class, sqlSentence); if (userUnionHis != null && !StringUtils.isEmpty(userUnionHis.getUnionId())) { //查询公众号关注记录 sql.delete(0, sql.length()); values.put("unionId", userUnionHis.getUnionId()); sql.append(" select * from gzh_focus_record where unionId = #{m.unionId} and isDel = #{m.isDel} order by createTime desc limit 1"); sqlSentence.setSqlSentence(sql.toString()); GzhFocusRecord gzhFocusRecord = commonService.selectOne(GzhFocusRecordMapper.class, sqlSentence); //用户Id为空时更新 if (gzhFocusRecord != null && StringUtils.isEmpty(gzhFocusRecord.getUserId())) { sql.delete(0, sql.length()); values.put("id", gzhFocusRecord.getId()); values.put("userName", user.getName()); values.put("hisId", user.getApiId()); sql.append(" userId = #{m.userId}, userName = #{m.userName}, hisId = #{m.hisId} where id = #{m.id} "); sqlSentence.setSqlSentence(sql.toString()); if(commonService.updateWhere(GzhFocusRecordMapper.class, sqlSentence) != 1){ throw new TipsException("更新绑定公众号失败!"); }; } } } }