|
|
@ -170,6 +170,16 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao, |
|
|
|
return new Result<List<CustomerStaffDTO>>().ok(customerStaffDTOList); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<List<CustomerStaffDTO>> getCustsomerStaffByAccount(String userAccount) { |
|
|
|
//判断用户是否存在
|
|
|
|
List<CustomerStaffDTO> customerStaffDTOList = baseDao.listCustomerStaffByAccount(userAccount); |
|
|
|
if (null == customerStaffDTOList || customerStaffDTOList.size() == 0) { |
|
|
|
logger.warn(String.format("根据账户查询用户异常,账户:[%s],code[%s],msg[%s]", userAccount, EpmetErrorCode.GOV_STAFF_ACCOUNT_NOT_EXISTS.getCode(), EpmetErrorCode.GOV_STAFF_ACCOUNT_NOT_EXISTS.getMsg())); |
|
|
|
return new Result().error(EpmetErrorCode.GOV_STAFF_ACCOUNT_NOT_EXISTS.getCode()); |
|
|
|
} |
|
|
|
return new Result<List<CustomerStaffDTO>>().ok(customerStaffDTOList); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<CustomerStaffDTO> getCustomerStaffInfo(CustomerStaffFormDTO formDTO) { |
|
|
@ -186,6 +196,21 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao, |
|
|
|
return new Result<CustomerStaffDTO>().ok(customerStaffDTO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<CustomerStaffDTO> getCustomerStaffInfoByAccount(CustomerStaffByAccountFormDTO formDTO) { |
|
|
|
CustomerStaffDTO customerStaffDTO = baseDao.selectListCustomerStaffInfoByAccount(formDTO); |
|
|
|
if (null == customerStaffDTO) { |
|
|
|
logger.warn(String.format("根据账户查询用户异常,账户:[%s],code[%s],msg[%s]", formDTO.getUserAccount(), EpmetErrorCode.GOV_STAFF_ACCOUNT_NOT_EXISTS.getCode(), EpmetErrorCode.GOV_STAFF_ACCOUNT_NOT_EXISTS.getMsg())); |
|
|
|
return new Result().error(EpmetErrorCode.GOV_STAFF_ACCOUNT_NOT_EXISTS.getCode()); |
|
|
|
} |
|
|
|
//判断用户是否已被禁用
|
|
|
|
if (null != customerStaffDTO && UserConstant.DISABLED.equals(customerStaffDTO.getEnableFlag())) { |
|
|
|
logger.warn(String.format("根据账户查询用户异常,账户:[%s],客户id:[%s],code[%s],msg[%s]", formDTO.getUserAccount(), formDTO.getCustomerId(), EpmetErrorCode.GOV_STAFF_DISABLED.getCode(), EpmetErrorCode.GOV_STAFF_DISABLED.getMsg())); |
|
|
|
return new Result().error(EpmetErrorCode.GOV_STAFF_DISABLED.getCode()); |
|
|
|
} |
|
|
|
return new Result<CustomerStaffDTO>().ok(customerStaffDTO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<CustomerStaffDTO> getCustomerStaffInfoByUserId(CustomerStaffDTO formDTO) { |
|
|
|
CustomerStaffDTO customerStaffDTO = baseDao.selectStaffInfoByUserId(formDTO); |
|
|
@ -265,11 +290,16 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao, |
|
|
|
if (null == customerStaffDTO) { |
|
|
|
log.warn("工作人员不存在"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(customerStaffDTO.getHeadPhoto())) { |
|
|
|
customerStaffDTO.setHeadPhoto(""); |
|
|
|
} |
|
|
|
resultDTO.setStaffId(customerStaffDTO.getUserId()); |
|
|
|
resultDTO.setUserAccount(customerStaffDTO.getUserAccount()); |
|
|
|
resultDTO.setName(customerStaffDTO.getRealName()); |
|
|
|
resultDTO.setGender(customerStaffDTO.getGender()); |
|
|
|
resultDTO.setMobile(customerStaffDTO.getMobile()); |
|
|
|
resultDTO.setWorkType(customerStaffDTO.getWorkType()); |
|
|
|
resultDTO.setIdCard(customerStaffDTO.getIdCard()); |
|
|
|
//获取角色列表
|
|
|
|
GovStaffRoleDTO govStaffRoleDTO = new GovStaffRoleDTO(); |
|
|
|
govStaffRoleDTO.setCustomerId(fromDTO.getCustomerId()); |
|
|
@ -363,6 +393,71 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao, |
|
|
|
return new Result<CustomerStaffDTO>().ok(ConvertUtils.sourceToTarget(staffEntity, CustomerStaffDTO.class)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result<CustomerStaffDTO> addStaffByAccount(StaffSubmitAccountFromDTO fromDTO) { |
|
|
|
CustomerStaffFormDTO customerStaffFormDTO = new CustomerStaffFormDTO(); |
|
|
|
customerStaffFormDTO.setCustomerId(fromDTO.getCustomerId()); |
|
|
|
customerStaffFormDTO.setMobile(fromDTO.getMobile()); |
|
|
|
CustomerStaffDTO customerStaffDTO = baseDao.selectListCustomerStaffInfo(customerStaffFormDTO); |
|
|
|
if (null != customerStaffDTO) { |
|
|
|
return new Result<CustomerStaffDTO>().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); |
|
|
|
} |
|
|
|
CustomerStaffByAccountFormDTO customerStaffAccountFormDTO = new CustomerStaffByAccountFormDTO(); |
|
|
|
customerStaffAccountFormDTO.setCustomerId(fromDTO.getCustomerId()); |
|
|
|
customerStaffAccountFormDTO.setUserAccount(fromDTO.getUserAccount()); |
|
|
|
customerStaffDTO = baseDao.selectListCustomerStaffInfoByAccount(customerStaffAccountFormDTO); |
|
|
|
if (null != customerStaffDTO) { |
|
|
|
return new Result<CustomerStaffDTO>().error(EpmetErrorCode.ACCOUNT_USED.getCode(), EpmetErrorCode.ACCOUNT_USED.getMsg()); |
|
|
|
} |
|
|
|
//USER表插入数据
|
|
|
|
UserEntity userEntity = new UserEntity(); |
|
|
|
userEntity.setFromApp(fromDTO.getApp()); |
|
|
|
userEntity.setFromClient(fromDTO.getClient()); |
|
|
|
userEntity.setCustomerId(fromDTO.getCustomerId()); |
|
|
|
userService.insert(userEntity); |
|
|
|
//Customer_Staff表插入数据
|
|
|
|
CustomerStaffEntity staffEntity = new CustomerStaffEntity(); |
|
|
|
staffEntity.setCustomerId(fromDTO.getCustomerId()); |
|
|
|
staffEntity.setUserId(userEntity.getId()); |
|
|
|
staffEntity.setUserAccount(fromDTO.getUserAccount()); |
|
|
|
staffEntity.setRealName(fromDTO.getName()); |
|
|
|
staffEntity.setMobile(fromDTO.getMobile()); |
|
|
|
staffEntity.setActiveFlag(CustomerStaffConstant.INACTIVE); |
|
|
|
staffEntity.setGender(fromDTO.getGender()); |
|
|
|
staffEntity.setWorkType(fromDTO.getWorkType()); |
|
|
|
staffEntity.setEnableFlag(CustomerStaffConstant.ENABLE); |
|
|
|
staffEntity.setPassword(PasswordUtils.encode(fromDTO.getPwd())); |
|
|
|
staffEntity.setIdCard(fromDTO.getIdCard()); |
|
|
|
baseDao.insert(staffEntity); |
|
|
|
|
|
|
|
//工作人员角色关联表
|
|
|
|
fromDTO.getRoles().forEach(role -> { |
|
|
|
StaffRoleEntity staffRoleEntity = new StaffRoleEntity(); |
|
|
|
staffRoleEntity.setStaffId(userEntity.getId()); |
|
|
|
staffRoleEntity.setRoleId(role); |
|
|
|
staffRoleEntity.setOrgId(fromDTO.getAgencyId()); |
|
|
|
staffRoleEntity.setCustomerId(fromDTO.getCustomerId()); |
|
|
|
staffRoleService.insert(staffRoleEntity); |
|
|
|
}); |
|
|
|
|
|
|
|
// 角色放缓存
|
|
|
|
CustomerAgencyUserRoleDTO dto = new CustomerAgencyUserRoleDTO(); |
|
|
|
List<RoleKeyValueResultDTO> roleKeyValue = govStaffRoleDao.selectRoleKeyName(fromDTO.getRoles()); |
|
|
|
dto.setCustomerId(fromDTO.getCustomerId()); |
|
|
|
dto.setStaffId(userEntity.getId()); |
|
|
|
dto.setAgencyId(fromDTO.getAgencyId()); |
|
|
|
Map m = new HashMap(16); |
|
|
|
roleKeyValue.forEach(r -> { |
|
|
|
m.put(r.getRoleKey(), r.getRoleName()); |
|
|
|
}); |
|
|
|
dto.setRoles(m); |
|
|
|
CustomerStaffRedis.delStaffInfoFormCache(dto.getCustomerId(), dto.getStaffId()); |
|
|
|
|
|
|
|
return new Result<CustomerStaffDTO>().ok(ConvertUtils.sourceToTarget(staffEntity, CustomerStaffDTO.class)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result editStaff(StaffSubmitFromDTO fromDTO) { |
|
|
@ -437,11 +532,99 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao, |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result editStaffByAccount(StaffSubmitAccountFromDTO fromDTO) { |
|
|
|
CustomerStaffFormDTO customerStaffFormDTO = new CustomerStaffFormDTO(); |
|
|
|
customerStaffFormDTO.setCustomerId(fromDTO.getCustomerId()); |
|
|
|
customerStaffFormDTO.setMobile(fromDTO.getMobile()); |
|
|
|
CustomerStaffDTO customerStaffDTO = baseDao.selectListCustomerStaffInfo(customerStaffFormDTO); |
|
|
|
if (null != customerStaffDTO && !fromDTO.getStaffId().equals(customerStaffDTO.getUserId())) { |
|
|
|
return new Result<CustomerStaffDTO>().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); |
|
|
|
} |
|
|
|
CustomerStaffByAccountFormDTO customerStaffAccountFormDTO = new CustomerStaffByAccountFormDTO(); |
|
|
|
customerStaffAccountFormDTO.setCustomerId(fromDTO.getCustomerId()); |
|
|
|
customerStaffAccountFormDTO.setUserAccount(fromDTO.getUserAccount()); |
|
|
|
customerStaffDTO = baseDao.selectListCustomerStaffInfoByAccount(customerStaffAccountFormDTO); |
|
|
|
if (null != customerStaffDTO && !fromDTO.getStaffId().equals(customerStaffDTO.getUserId())) { |
|
|
|
return new Result<CustomerStaffDTO>().error(EpmetErrorCode.ACCOUNT_USED.getCode(), EpmetErrorCode.ACCOUNT_USED.getMsg()); |
|
|
|
} |
|
|
|
CustomerStaffEntity customerStaffEntity = baseDao.selectByUserId(fromDTO.getStaffId()); |
|
|
|
//Customer_Staff表插入数据
|
|
|
|
CustomerStaffEntity staffEntity = new CustomerStaffEntity(); |
|
|
|
staffEntity.setId(customerStaffEntity.getId()); |
|
|
|
staffEntity.setRealName(fromDTO.getName()); |
|
|
|
staffEntity.setMobile(fromDTO.getMobile()); |
|
|
|
staffEntity.setGender(fromDTO.getGender()); |
|
|
|
staffEntity.setUserAccount(fromDTO.getUserAccount()); |
|
|
|
staffEntity.setWorkType(fromDTO.getWorkType()); |
|
|
|
if (StringUtils.isNotBlank(fromDTO.getPwd())){ |
|
|
|
staffEntity.setPassword(PasswordUtils.encode(fromDTO.getPwd())); |
|
|
|
} |
|
|
|
staffEntity.setIdCard(fromDTO.getIdCard()); |
|
|
|
baseDao.updateById(staffEntity); |
|
|
|
|
|
|
|
//清空权限关联
|
|
|
|
StaffRoleDTO staffRoleDTO = new StaffRoleDTO(); |
|
|
|
staffRoleDTO.setStaffId(fromDTO.getStaffId()); |
|
|
|
staffRoleDTO.setOrgId(fromDTO.getAgencyId()); |
|
|
|
staffRoleService.clearStaffRoles(staffRoleDTO); |
|
|
|
//重新添加角色关联
|
|
|
|
fromDTO.getRoles().forEach(role -> { |
|
|
|
StaffRoleEntity staffRoleEntity = new StaffRoleEntity(); |
|
|
|
staffRoleEntity.setStaffId(fromDTO.getStaffId()); |
|
|
|
staffRoleEntity.setRoleId(role); |
|
|
|
staffRoleEntity.setOrgId(fromDTO.getAgencyId()); |
|
|
|
staffRoleService.insert(staffRoleEntity); |
|
|
|
}); |
|
|
|
|
|
|
|
// 重新查询用户的角色列表(可以取到前端没有传过来的角色,例如根管理员)
|
|
|
|
List<StaffRoleEntity> staffRoleEntytiesByStaffIdAndOrgId = staffRoleService.getStaffRoleEntytiesByStaffIdAndOrgId(fromDTO.getAgencyId(), fromDTO.getStaffId()); |
|
|
|
List<String> roleIds = new ArrayList<>(); |
|
|
|
if (!CollectionUtils.isEmpty(staffRoleEntytiesByStaffIdAndOrgId)) { |
|
|
|
roleIds = staffRoleEntytiesByStaffIdAndOrgId.stream().map(sr -> sr.getRoleId()).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
// redis缓存角色修改
|
|
|
|
UpdateCachedRolesFormDTO updateRolesForm = new UpdateCachedRolesFormDTO(); |
|
|
|
updateRolesForm.setOrgId(fromDTO.getAgencyId()); |
|
|
|
updateRolesForm.setStaffId(fromDTO.getStaffId()); |
|
|
|
updateRolesForm.setRoleIds(roleIds); |
|
|
|
try { |
|
|
|
Result result = authFeignClient.updateCachedRoles(updateRolesForm); |
|
|
|
if (!result.success()) { |
|
|
|
logger.error("修改用户信息:修改用户已缓存的角色列表失败:{}", result.getInternalMsg()); |
|
|
|
} |
|
|
|
logger.info("修改用户信息:修改用户已缓存的角色列表成功"); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("method exception", e); |
|
|
|
logger.error("修改用户信息:修改用户已缓存的角色列表异常:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
|
|
} |
|
|
|
|
|
|
|
// 角色放缓存
|
|
|
|
CustomerAgencyUserRoleDTO dto = new CustomerAgencyUserRoleDTO(); |
|
|
|
List<RoleKeyValueResultDTO> roleKeyValue = govStaffRoleDao.selectRoleKeyName(fromDTO.getRoles()); |
|
|
|
dto.setCustomerId(fromDTO.getCustomerId()); |
|
|
|
dto.setStaffId(fromDTO.getStaffId()); |
|
|
|
dto.setAgencyId(fromDTO.getAgencyId()); |
|
|
|
Map m = new HashMap(16); |
|
|
|
roleKeyValue.forEach(r -> { |
|
|
|
m.put(r.getRoleKey(), r.getRoleName()); |
|
|
|
}); |
|
|
|
dto.setRoles(m); |
|
|
|
CustomerStaffRedis.delStaffInfoFormCache(dto.getCustomerId(), dto.getStaffId()); |
|
|
|
|
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<StaffDetailResultDTO> getStaffDetail(StaffInfoFromDTO fromDTO) { |
|
|
|
StaffDetailResultDTO resultDTO = new StaffDetailResultDTO(); |
|
|
|
//获取工作人员信息
|
|
|
|
CustomerStaffDTO customerStaffDTO = baseDao.selectStaffInfo(fromDTO); |
|
|
|
if (StringUtils.isBlank(customerStaffDTO.getHeadPhoto())) { |
|
|
|
customerStaffDTO.setHeadPhoto(""); |
|
|
|
} |
|
|
|
resultDTO.setStaffId(customerStaffDTO.getUserId()); |
|
|
|
resultDTO.setName(customerStaffDTO.getRealName()); |
|
|
|
resultDTO.setMobile(customerStaffDTO.getMobile()); |
|
|
@ -604,6 +787,19 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao, |
|
|
|
return customerStaffDTOList; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<CustomerStaffDTO> getCustsomerStaffByIdAndAccount(ThirdCustomerStaffByAccountFormDTO formDTO) { |
|
|
|
//根据客户Id和手机号查询工作人员信息
|
|
|
|
List<CustomerStaffDTO> customerStaffDTOList = baseDao.selectStaffByAccount(formDTO); |
|
|
|
if (null == customerStaffDTOList || customerStaffDTOList.size() < NumConstant.ONE) { |
|
|
|
logger.warn(String.format("根据客户Id和账户查询用户异常,客户Id:[%s],账户:[%s],code[%s],msg[%s]", |
|
|
|
formDTO.getCustomerId(), formDTO.getUserAccount(), EpmetErrorCode.GOV_STAFF_ACCOUNT_NOT_EXISTS.getCode(), |
|
|
|
EpmetErrorCode.GOV_STAFF_ACCOUNT_NOT_EXISTS.getMsg())); |
|
|
|
throw new RenException(EpmetErrorCode.GOV_STAFF_ACCOUNT_NOT_EXISTS.getCode()); |
|
|
|
} |
|
|
|
return customerStaffDTOList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @Description 查询工作人员的信息 |
|
|
|