diff --git a/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java b/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java index 386e162c02..3ed824f33f 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java @@ -83,6 +83,20 @@ public class GovLoginController { return new Result().ok(userTokenResultDTO); } + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author zhy + * @Description 4、选择组织,进入首页 + * @Date 2020/4/20 13:07 + **/ + @PostMapping(value = "/loginwxmp/enterorgbyaccount") + public Result enterOrgByAccount(@RequestBody GovWxmpEnteOrgByAccountFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO,GovWxmpEnteOrgByAccountFormDTO.AddUserShowGroup.class,GovWxmpEnteOrgByAccountFormDTO.AddUserInternalGroup.class); + UserTokenResultDTO userTokenResultDTO=govLoginService.enterOrgByAccount(formDTO); + return new Result().ok(userTokenResultDTO); + } + /** * @param tokenDto * @return com.epmet.commons.tools.utils.Result @@ -121,5 +135,19 @@ public class GovLoginController { List staffOrgs = govLoginService.getMyOrgByPassword(formDTO); return new Result>().ok(staffOrgs); } + + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result> + * @author zhy + * @description 6、账户密码获取组织 + * @Date 2020/6/30 22:43 + **/ + @PostMapping(value = "/getmyorgbyaccount") + public Result> getMyOrgByAccount(@RequestBody StaffOrgByAccountFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, StaffOrgByAccountFormDTO.AddUserShowGroup.class, StaffOrgByAccountFormDTO.GetMyOrgByPassWordGroup.class); + List staffOrgs = govLoginService.getMyOrgByAccount(formDTO); + return new Result>().ok(staffOrgs); + } } diff --git a/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java b/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java index 144e18d024..e8977cd508 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java @@ -63,6 +63,19 @@ public class ThirdLoginController { return new Result().ok(userTokenResultDTO); } + /** + * @param formDTO + * @return + * @Author zhy + * @Description 单客户-选择组织,进入首页 + **/ + @PostMapping(value = "enterorgbyaccount") + public Result enterOrgByAccount(@RequestBody ThirdWxmpEnteOrgByAccountFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO,ThirdWxmpEnteOrgFormDTO.AddUserShowGroup.class,ThirdWxmpEnteOrgFormDTO.AddUserInternalGroup.class); + UserTokenResultDTO userTokenResultDTO=thirdLoginService.enterOrgByAccount(formDTO); + return new Result().ok(userTokenResultDTO); + } + /** * @param formDTO * @return @@ -89,6 +102,19 @@ public class ThirdLoginController { return new Result>().ok(staffOrgs); } + /** + * @param formDTO + * @return + * @author zhy + * @description 单客户-账号密码获取组织 + **/ + @PostMapping(value = "/getmyorgbyaccount") + public Result> getMyOrgByAccount(@RequestBody ThirdStaffOrgByAccountFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, StaffOrgByAccountFormDTO.AddUserShowGroup.class, StaffOrgByAccountFormDTO.GetMyOrgByPassWordGroup.class); + List staffOrgs = thirdLoginService.getMyOrgByAccount(formDTO); + return new Result>().ok(staffOrgs); + } + /** * @param formDTO * @return diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/GovWxmpEnteOrgByAccountFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/GovWxmpEnteOrgByAccountFormDTO.java new file mode 100644 index 0000000000..4996c0cd50 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/dto/form/GovWxmpEnteOrgByAccountFormDTO.java @@ -0,0 +1,48 @@ +package com.epmet.dto.form; + +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Description 选择组织,进入首页入参Dto + * @Author yinzuomei + * @Date 2020/4/20 13:03 + */ +@Data +public class GovWxmpEnteOrgByAccountFormDTO implements Serializable { + public interface AddUserInternalGroup {} + public interface AddUserShowGroup extends CustomerClientShowGroup {} + /** + * wxCode + */ + @NotBlank(message = "wxCode不能为空",groups = {AddUserInternalGroup.class}) + private String wxCode; + + /** + * 手机号 + */ + @NotBlank(message = "账号不能为空",groups = {AddUserShowGroup.class}) + private String userAccount; + + /** + * 选择的组织所属的id + */ + @NotBlank(message = "客户id不能为空",groups = {AddUserInternalGroup.class}) + private String customerId; + + /** + * 选择的要进入的组织(根组织id) + */ + @NotBlank(message = "组织id不能为空",groups = {AddUserInternalGroup.class}) + private String rootAgencyId; + + /** + * desc:小程序appId + */ + private String appId; + +} + diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/StaffOrgByAccountFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/StaffOrgByAccountFormDTO.java new file mode 100644 index 0000000000..669a0e7998 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/dto/form/StaffOrgByAccountFormDTO.java @@ -0,0 +1,43 @@ +package com.epmet.dto.form; + +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Description 手机验证码获取组织接口入参 + * @Author zhy + * @Date 2020/4/18 10:38 + */ +@Data +public class StaffOrgByAccountFormDTO implements Serializable { + private static final long serialVersionUID = 4193133227120225342L; + /** + * 添加用户操作的用户可见异常分组 + * 该分组用于校验需要返回给前端错误信息提示的列,需要继承CustomerClientShowGroup + * 返回错误码为8999,提示信息为DTO中具体的列的校验注解message的内容 + */ + public interface AddUserShowGroup extends CustomerClientShowGroup { + } + + public interface GetMyOrgByPassWordGroup extends CustomerClientShowGroup { + } + public interface GetMyOrgByLoginWxmp extends CustomerClientShowGroup{} + /** + * 手机号 + */ + @NotBlank(message = "手机号不能为空", groups = {AddUserShowGroup.class}) + private String userAccount; + + /** + * 验证码 + */ + @NotBlank(message="验证码不能为空", groups = {GetMyOrgByLoginWxmp.class}) + private String smsCode; + + @NotBlank(message = "密码不能为空",groups ={GetMyOrgByPassWordGroup.class}) + private String password; +} + diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/ThirdStaffOrgByAccountFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/ThirdStaffOrgByAccountFormDTO.java new file mode 100644 index 0000000000..3cad308ab6 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/dto/form/ThirdStaffOrgByAccountFormDTO.java @@ -0,0 +1,48 @@ +package com.epmet.dto.form; + +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Description appId、账号、验证码获取组织-接口入参 + * @Author zhy + */ +@Data +public class ThirdStaffOrgByAccountFormDTO implements Serializable { + private static final long serialVersionUID = 4193133227120225342L; + /** + * 添加用户操作的用户可见异常分组 + * 该分组用于校验需要返回给前端错误信息提示的列,需要继承CustomerClientShowGroup + * 返回错误码为8999,提示信息为DTO中具体的列的校验注解message的内容 + */ + public interface AddUserShowGroup extends CustomerClientShowGroup { + } + + public interface GetMyOrgByPassWordGroup extends CustomerClientShowGroup { + } + public interface GetMyOrgByLoginWxmp extends CustomerClientShowGroup{} + /** + * 小程序appId + */ + @NotBlank(message = "appId不能为空", groups = {AddUserShowGroup.class}) + private String appId; + + /** + * 手机号 + */ + @NotBlank(message = "账号不能为空", groups = {AddUserShowGroup.class}) + private String userAccount; + + /** + * 验证码 + */ + @NotBlank(message="验证码不能为空", groups = {GetMyOrgByLoginWxmp.class}) + private String smsCode; + + @NotBlank(message = "密码不能为空",groups ={GetMyOrgByPassWordGroup.class}) + private String password; +} + diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/ThirdWxmpEnteOrgByAccountFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/ThirdWxmpEnteOrgByAccountFormDTO.java new file mode 100644 index 0000000000..e89028eb4c --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/dto/form/ThirdWxmpEnteOrgByAccountFormDTO.java @@ -0,0 +1,47 @@ +package com.epmet.dto.form; + +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Description 单客户-选择组织,进入首页入参Dto + * @Author sun + */ +@Data +public class ThirdWxmpEnteOrgByAccountFormDTO implements Serializable { + public interface AddUserInternalGroup {} + public interface AddUserShowGroup extends CustomerClientShowGroup {} + /** + * wxCode + */ + @NotBlank(message = "wxCode不能为空",groups = {AddUserInternalGroup.class}) + private String wxCode; + + /** + * 手机号 + */ + @NotBlank(message = "账号不能为空",groups = {AddUserShowGroup.class}) + private String userAccount; + + /** + * 选择的组织所属的id + */ + @NotBlank(message = "客户id不能为空",groups = {AddUserInternalGroup.class}) + private String customerId; + + /** + * 选择的要进入的组织(根组织id) + */ + @NotBlank(message = "组织id不能为空",groups = {AddUserInternalGroup.class}) + private String rootAgencyId; + + /** + * 客户appId(exJson文件中获取) + */ + @NotBlank(message = "appId不能为空",groups = {AddUserInternalGroup.class}) + private String appId; +} + diff --git a/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java index 44c7d9d3ab..af33d8c632 100644 --- a/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java +++ b/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -70,6 +70,17 @@ public interface EpmetUserFeignClient { @GetMapping(value = "epmetuser/customerstaff/getcustsomerstaffbyphone/{mobile}") Result> checkCustomerStaff(@PathVariable("mobile") String mobile); + /** + * @param account + * @return com.epmet.commons.tools.utils.Result + * @Author zhy + * @Description 根据账户查询政府端工作人员基本信息,校验用户是否存在 + * @Date 2020/4/18 14:03 + **/ + @GetMapping(value = "epmetuser/customerstaff/getcustsomerstaffbyaccount/{account}") + Result> checkCustomerStaffByAccount(@PathVariable("account") String account); + + /** * @param staffWechatFormDTO * @return com.epmet.commons.tools.utils.Result @@ -100,6 +111,17 @@ public interface EpmetUserFeignClient { @PostMapping(value = "epmetuser/customerstaff/getcustomerstaffinfo", consumes = MediaType.APPLICATION_JSON_VALUE) Result getCustomerStaffInfo(@RequestBody CustomerStaffFormDTO customerStaffFormDTO); + /** + * @param customerStaffFormDTO + * @return com.epmet.commons.tools.utils.Result + * @Author zhy + * @Description 根据手机号+客户id获取工作人员基本信息 + * @Date 2020/4/20 14:16 + **/ + @PostMapping(value = "epmetuser/customerstaff/getcustomerstaffinfobyaccount", consumes = MediaType.APPLICATION_JSON_VALUE) + Result getCustomerStaffInfoByAccount(@RequestBody CustomerStaffByAccountFormDTO customerStaffFormDTO); + + /** * @param staffLoginHistoryFormDTO * @return com.epmet.commons.tools.utils.Result diff --git a/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java b/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java index 59623a7dc7..d0ce30ab99 100644 --- a/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java +++ b/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java @@ -44,6 +44,10 @@ public class EpmetUserFeignClientFallback implements EpmetUserFeignClient { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustsomerStaffByPhone", phone); } + @Override + public Result> checkCustomerStaffByAccount(String account) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustsomerStaffByAccount", account); + } @Override public Result saveStaffWechat(StaffWechatFormDTO staffWechatFormDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "saveStaffWechat", staffWechatFormDTO); @@ -59,6 +63,11 @@ public class EpmetUserFeignClientFallback implements EpmetUserFeignClient { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustomerStaffInfo", customerStaffFormDTO); } + @Override + public Result getCustomerStaffInfoByAccount(CustomerStaffByAccountFormDTO customerStaffFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustomerStaffInfoByAccount", customerStaffFormDTO); + } + @Override public Result saveStaffLoginRecord(StaffLoginAgencyRecordFormDTO staffLoginHistoryFormDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "saveStaffLoginRecord", staffLoginHistoryFormDTO); diff --git a/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java b/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java index ea6329ceda..8ec5697a60 100644 --- a/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java +++ b/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java @@ -1,10 +1,7 @@ package com.epmet.service; import com.epmet.commons.tools.security.dto.TokenDto; -import com.epmet.dto.form.GovWxmpEnteOrgFormDTO; -import com.epmet.dto.form.GovWxmpFormDTO; -import com.epmet.dto.form.SendSmsCodeFormDTO; -import com.epmet.dto.form.StaffOrgsFormDTO; +import com.epmet.dto.form.*; import com.epmet.dto.result.StaffOrgsResultDTO; import com.epmet.dto.result.UserTokenResultDTO; @@ -52,6 +49,15 @@ public interface GovLoginService { **/ UserTokenResultDTO enterOrg(GovWxmpEnteOrgFormDTO formDTO); + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author zhy + * @Description 4、选择组织,进入首页 + * @Date 2020/4/20 13:08 + **/ + UserTokenResultDTO enterOrgByAccount(GovWxmpEnteOrgByAccountFormDTO formDTO); + /** * @return com.epmet.commons.tools.utils.Result * @param tokenDto @@ -76,4 +82,13 @@ public interface GovLoginService { * @Date 2020/6/30 22:43 **/ List getMyOrgByPassword(StaffOrgsFormDTO formDTO); + + /** + * @return java.util.List + * @param formDTO + * @author zhy + * @description 6、账户密码获取组织 + * @Date 2020/6/30 22:43 + **/ + List getMyOrgByAccount(StaffOrgByAccountFormDTO formDTO); } diff --git a/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java b/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java index c79a67d41c..69d13bf926 100644 --- a/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java +++ b/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java @@ -36,6 +36,15 @@ public interface ThirdLoginService { **/ UserTokenResultDTO enterOrg(ThirdWxmpEnteOrgFormDTO formDTO); + + /** + * @param formDTO + * @return + * @Author zhy + * @Description 单客户-选择组织,进入首页 + **/ + UserTokenResultDTO enterOrgByAccount(ThirdWxmpEnteOrgByAccountFormDTO formDTO); + /** * @param formDTO * @return @@ -52,6 +61,15 @@ public interface ThirdLoginService { **/ List getMyOrgByPassword(ThirdStaffOrgsFormDTO formDTO); + /** + * @param formDTO + * @return + * @author zhy + * @description 单客户-手机号密码获取组织 + **/ + List getMyOrgByAccount(ThirdStaffOrgByAccountFormDTO formDTO); + + /** * @param formDTO * @return diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java index cbc46e33f1..24267debd1 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java @@ -289,6 +289,36 @@ public class GovLoginServiceImpl implements GovLoginService, ResultDataResolver return userTokenResultDTO; } + @Override + public UserTokenResultDTO enterOrgByAccount(GovWxmpEnteOrgByAccountFormDTO formDTO) { + //1、需要校验要登录的客户,是否被禁用 + CustomerStaffByAccountFormDTO customerStaffFormDTO = new CustomerStaffByAccountFormDTO(); + customerStaffFormDTO.setCustomerId(formDTO.getCustomerId()); + customerStaffFormDTO.setUserAccount(formDTO.getUserAccount()); + Result customerStaffDTOResult = epmetUserFeignClient.getCustomerStaffInfoByAccount(customerStaffFormDTO); + if (!customerStaffDTOResult.success() || null == customerStaffDTOResult.getData()) { + logger.warn(String.format("获取工作人员信息失败,账户[%s],客户id:[%s],code[%s],msg[%s]", formDTO.getUserAccount(), formDTO.getCustomerId(), customerStaffDTOResult.getCode(), customerStaffDTOResult.getMsg())); + throw new RenException(customerStaffDTOResult.getCode()); + } + CustomerStaffDTO customerStaff = customerStaffDTOResult.getData(); + //2、解析微信用户 + WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(LoginConstant.APP_GOV, formDTO.getWxCode(), formDTO.getAppId()); + + //3、记录staff_wechat,并记录用户激活状态,激活时间 + this.savestaffwechat(customerStaff.getUserId(), wxMaJscode2SessionResult.getOpenid(), formDTO.getCustomerId()); + //4、记录登录日志 + GovWxmpEnteOrgFormDTO orgDTO = ConvertUtils.sourceToTarget(formDTO, GovWxmpEnteOrgFormDTO.class); + orgDTO.setMobile(customerStaff.getMobile()); + this.saveStaffLoginRecord(orgDTO, customerStaff.getUserId(), wxMaJscode2SessionResult.getOpenid()); + //5.1、获取用户token + String token = this.generateGovWxmpToken(customerStaff.getUserId()); + //5.2、保存到redis + this.saveGovTokenDto(formDTO.getRootAgencyId(), formDTO.getCustomerId(), customerStaff.getUserId(), wxMaJscode2SessionResult, token); + UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); + userTokenResultDTO.setToken(token); + return userTokenResultDTO; + } + @Override public void loginOut(TokenDto tokenDto) { if(null == tokenDto){ @@ -381,6 +411,63 @@ public class GovLoginServiceImpl implements GovLoginService, ResultDataResolver return new ArrayList<>(); } + @Override + public List getMyOrgByAccount(StaffOrgByAccountFormDTO formDTO) { + //1、根据手机号查询到用户信息 + Result> customerStaffResult = epmetUserFeignClient.checkCustomerStaffByAccount(formDTO.getUserAccount()); + if (!customerStaffResult.success()) { + logger.warn(String.format("账户密码登录异常,手机号[%s],code[%s],msg[%s]", formDTO.getUserAccount(), customerStaffResult.getCode(), customerStaffResult.getMsg())); + throw new RenException(customerStaffResult.getCode()); + } + //2、密码是否正确 + List customerStaffList=customerStaffResult.getData(); + //3、查询用户所有的组织信息 + List customerIdList = new ArrayList<>(); + //是否设置过密码 + boolean havePasswordFlag=false; + //密码是否正确 + boolean passwordRightFlag=false; + for (CustomerStaffDTO customerStaffDTO : customerStaffList) { + if(StringUtils.isNotBlank(customerStaffDTO.getPassword())){ + havePasswordFlag=true; + }else{ + logger.warn(String.format("当前用户:账户%s,客户Id%s下未设置密码.",formDTO.getUserAccount(),customerStaffDTO.getCustomerId())); + continue; + } + if (!PasswordUtils.matches(formDTO.getPassword(), customerStaffDTO.getPassword())) { + logger.warn(String.format("当前用户:账户%s,客户Id%s密码匹配错误.",formDTO.getUserAccount(),customerStaffDTO.getCustomerId())); + + }else{ + logger.warn(String.format("当前用户:账户%s,客户Id%s密码匹配正确.",formDTO.getUserAccount(),customerStaffDTO.getCustomerId())); + passwordRightFlag=true; + customerIdList.add(customerStaffDTO.getCustomerId()); + } + } + //根据手机号查出来所有用户,密码都为空,表明用户未激活账户,未设置密码 + if(!havePasswordFlag){ + logger.warn(String.format("当前账户(%s)下所有账户都未设置密码,请先使用验证码登录激活账户",formDTO.getUserAccount())); + throw new RenException(EpmetErrorCode.PASSWORD_ERROR.getCode()); + } + //密码错误 + if(!passwordRightFlag){ + logger.warn(String.format("根据当前账户(%s)密码未找到所属组织,密码错误",formDTO.getUserAccount())); + throw new RenException(EpmetErrorCode.PASSWORD_ERROR.getCode()); + } + StaffOrgFormDTO staffOrgFormDTO = new StaffOrgFormDTO(); + staffOrgFormDTO.setCustomerIdList(customerIdList); + Result> result = govOrgFeignClient.getStaffOrgList(staffOrgFormDTO); + if(result.success()&&null!=result.getData()){ + return result.getData(); + } + logger.warn(String .format("手机验证码获取组织,调用%s服务失败,入参账户%s,密码%s,返回错误码%s,错误提示信息%s", + ServiceConstant.GOV_ORG_SERVER, + formDTO.getUserAccount(), + formDTO.getPassword(), + result.getCode(), + result.getMsg())); + return new ArrayList<>(); + } + //保存登录日志 private Result saveStaffLoginRecord(GovWxmpEnteOrgFormDTO formDTO, String staffId, String openId) { StaffLoginAgencyRecordFormDTO staffLoginAgencyRecordFormDTO = new StaffLoginAgencyRecordFormDTO(); diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java index dd48a5577f..cd1495ddb2 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java @@ -425,6 +425,68 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol return userTokenResultDTO; } + /** + * @param formDTO + * @return + * @Author sun + * @Description 单客户-选择组织,进入首页 + **/ + @Override + public UserTokenResultDTO enterOrgByAccount(ThirdWxmpEnteOrgByAccountFormDTO formDTO) { + //1、需要校验要登录的客户,是否被禁用 + CustomerStaffByAccountFormDTO customerStaffFormDTO = new CustomerStaffByAccountFormDTO(); + customerStaffFormDTO.setCustomerId(formDTO.getCustomerId()); + customerStaffFormDTO.setUserAccount(formDTO.getUserAccount()); + Result customerStaffDTOResult = epmetUserOpenFeignClient.getCustomerStaffInfoByAccount(customerStaffFormDTO); + if (!customerStaffDTOResult.success() || null == customerStaffDTOResult.getData()) { + logger.error(String.format("获取工作人员信息失败,账户[%s],客户id:[%s],code[%s],msg[%s]", formDTO.getUserAccount(), formDTO.getCustomerId(), customerStaffDTOResult.getCode(), customerStaffDTOResult.getMsg())); + throw new RenException(customerStaffDTOResult.getCode()); + } + CustomerStaffDTO customerStaff = customerStaffDTOResult.getData(); + //2020.7.24 获取微信信息接口调整,改调用微信api的方式 sun start + //2.调用epmet_third服务,校验appId是否有效以及是否授权,校验通过的调用微信API获取用户基本信息 + WxLoginFormDTO resiLoginFormDTO = new WxLoginFormDTO(); + resiLoginFormDTO.setAppId(formDTO.getAppId()); + resiLoginFormDTO.setWxCode(formDTO.getWxCode()); + UserWechatDTO userWechatDTO = this.getUserWeChat(resiLoginFormDTO); + WxMaJscode2SessionResult wxMaJscode2SessionResult = new WxMaJscode2SessionResult(); + wxMaJscode2SessionResult.setOpenid(userWechatDTO.getWxOpenId()); + wxMaJscode2SessionResult.setSessionKey(userWechatDTO.getSessionKey()); + wxMaJscode2SessionResult.setUnionid(""); + // end + //3、记录staff_wechat,并记录用户激活状态,激活时间 + this.savestaffwechat(customerStaff.getUserId(), userWechatDTO.getWxOpenId(), formDTO.getCustomerId()); + //4、记录登录日志 + StaffLatestAgencyResultDTO staffLatestAgencyResultDTO = new StaffLatestAgencyResultDTO(); + staffLatestAgencyResultDTO.setCustomerId(formDTO.getCustomerId()); + staffLatestAgencyResultDTO.setStaffId(customerStaff.getUserId()); + staffLatestAgencyResultDTO.setWxOpenId(userWechatDTO.getWxOpenId()); + staffLatestAgencyResultDTO.setMobile(customerStaff.getMobile()); + staffLatestAgencyResultDTO.setAgencyId(formDTO.getRootAgencyId()); + this.saveStaffLoginRecord(staffLatestAgencyResultDTO); + //5.1、获取用户token + String token = this.generateGovWxmpToken(customerStaff.getUserId()); + //5.2、保存到redis + StaffLatestAgencyResultDTO staffLatestAgency = new StaffLatestAgencyResultDTO(); + staffLatestAgency.setAgencyId(formDTO.getRootAgencyId()); + staffLatestAgency.setCustomerId(formDTO.getCustomerId()); + staffLatestAgency.setStaffId(customerStaff.getUserId()); + this.saveLatestGovTokenDto(staffLatestAgency, userWechatDTO, token); + + UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); + userTokenResultDTO.setToken(token); + + //6.发送登录事件 + try { + sendLoginEvent(customerStaff.getUserId(), formDTO.getAppId(), AppClientConstant.APP_GOV, AppClientConstant.CLIENT_WXMP); + } catch (RenException e) { + log.error(e.getInternalMsg()); + } catch (Exception e) { + log.error("【工作端enterOrg登录】发送登录事件失败,程序继续执行。错误信息"); + } + return userTokenResultDTO; + } + /** * @param formDTO * @return @@ -538,6 +600,69 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol return new ArrayList<>(); } + @Override + public List getMyOrgByAccount(ThirdStaffOrgByAccountFormDTO formDTO) { + //0.根据appId查询对应客户Id + PaCustomerDTO customer = this.getCustomerInfo(formDTO.getAppId()); + //7.28 上边根据appId只能锁定一条客户id,后边的批量循环操作暂不做调整,还是使用之前的代码 sun + //1、根据手机号查询到用户信息 + ThirdCustomerStaffByAccountFormDTO dto = new ThirdCustomerStaffByAccountFormDTO(); + dto.setCustomerId(customer.getId()); + dto.setUserAccount(formDTO.getUserAccount()); + Result> customerStaffResult = epmetUserOpenFeignClient.getCustsomerStaffByIdAndAccount(dto); + if (!customerStaffResult.success()) { + logger.warn(String.format("账户密码登录异常,账户[%s],code[%s],msg[%s]", formDTO.getUserAccount(), customerStaffResult.getCode(), customerStaffResult.getMsg())); + throw new RenException(customerStaffResult.getCode()); + } + //2、密码是否正确 + List customerStaffList=customerStaffResult.getData(); + //3、查询用户所有的组织信息 + List customerIdList = new ArrayList<>(); + //是否设置过密码 + boolean havePasswordFlag=false; + //密码是否正确 + boolean passwordRightFlag=false; + for (CustomerStaffDTO customerStaffDTO : customerStaffList) { + if(StringUtils.isNotBlank(customerStaffDTO.getPassword())){ + havePasswordFlag=true; + }else{ + logger.warn(String.format("当前用户:账户%s,客户Id%s下未设置密码.",formDTO.getUserAccount(),customerStaffDTO.getCustomerId())); + continue; + } + if (!PasswordUtils.matches(formDTO.getPassword(), customerStaffDTO.getPassword())) { + logger.warn(String.format("当前用户:账户%s,客户Id%s密码匹配错误.",formDTO.getUserAccount(),customerStaffDTO.getCustomerId())); + + }else{ + logger.warn(String.format("当前用户:账户%s,客户Id%s密码匹配正确.",formDTO.getUserAccount(),customerStaffDTO.getCustomerId())); + passwordRightFlag=true; + customerIdList.add(customerStaffDTO.getCustomerId()); + } + } + //根据手机号查出来所有用户,密码都为空,表明用户未激活账户,未设置密码 + if(!havePasswordFlag){ + logger.warn(String.format("当前账户(%s)下所有账户都未设置密码,请先使用验证码登录激活账户",formDTO.getUserAccount())); + throw new RenException(EpmetErrorCode.PASSWORD_ERROR.getCode()); + } + //密码错误 + if(!passwordRightFlag){ + logger.warn(String.format("根据当前账户(%s)密码未找到所属组织,密码错误",formDTO.getUserAccount())); + throw new RenException(EpmetErrorCode.PASSWORD_ERROR.getCode()); + } + StaffOrgFormDTO staffOrgFormDTO = new StaffOrgFormDTO(); + staffOrgFormDTO.setCustomerIdList(customerIdList); + Result> result = govOrgOpenFeignClient.getStaffOrgList(staffOrgFormDTO); + if(result.success()&&null!=result.getData()){ + return result.getData(); + } + logger.warn(String .format("手机验证码获取组织,调用%s服务失败,入参账户%s,密码%s,返回错误码%s,错误提示信息%s", + ServiceConstant.GOV_ORG_SERVER, + formDTO.getUserAccount(), + formDTO.getPassword(), + result.getCode(), + result.getMsg())); + return new ArrayList<>(); + } + /** * @Description 获取客户信息 * @param appId diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index 405d84d4ae..64688c8990 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -40,6 +40,7 @@ public enum EpmetErrorCode { PASSWORD_NOT_FIT(8010,"两次填写的密码不一致"), PASSWORD_OUT_OF_ORDER(8011,"密码必须8-20个字符,而且同时包含大小写字母和数字"), PASSWORD_UPDATE_FAILED(8012,"密码修改失败"), + GOV_STAFF_ACCOUNT_NOT_EXISTS(8013,"账户未注册,请联系贵单位管理员"), MOBILE_HAS_BEEN_USED(8101, "该手机号已注册,请更换手机号或使用原绑定的微信账号登录"), MOBILE_CODE_ERROR(8102, "验证码错误"), AUTO_CONFIRM_FAILED(8103, "党员注册失败"), @@ -100,6 +101,7 @@ public enum EpmetErrorCode { EXIT_PEND_PROJECT(8408,"该工作人员有项目尚在处理,处理完毕方可操作"), EXIT_PUBLISHED_ACTIVITY(8409,"该工作人员有活动尚在进行,等活动完成方可操作"), CAN_NOT_SELF(8410,"无法对自己进行操作"), + ACCOUNT_USED(8411,"该账号已注册"), PATROL_IS_NOT_OVER(8520,"巡查尚未结束"), ALREADY_EVALUATE(8501,"您已评价"), diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffPyFromDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffPyFromDTO.java new file mode 100644 index 0000000000..9aa774bd31 --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffPyFromDTO.java @@ -0,0 +1,87 @@ +package com.epmet.dto.form; + +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import java.io.Serializable; +import java.util.List; + +/** + * @author sun + * @dscription + */ +@NoArgsConstructor +@Data +public class AddStaffPyFromDTO implements Serializable { + private static final long serialVersionUID = 1L; + /** + * 新增人员所属类型Id + */ + private String orgId; + /** + * 客户ID + */ + private String customerId; + /** + * 新增人员所属类型【组织:agency;部门:dept;网格:grid】】 + */ + private String orgType; + /** + * 姓名 + */ + @NotBlank(message = "姓名不能为空", groups = AddStaffPyFromDTO.AddStaff.class) + @Length(max = 15, message = "姓名仅允许输入15个字符", groups = AddStaffPyFromDTO.AddStaff.class) + private String name; + /** + * 人员ID + */ + private String staffId; + /** + * 手机 + */ + @NotBlank(message = "手机号不能为空", groups = AddStaffPyFromDTO.AddStaff.class) + @Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "请输入正确的手机号", groups = AddStaffPyFromDTO.AddStaff.class) + private String mobile; + /** + * 性别 + */ + @NotNull(message = "性别不能为空", groups = AddStaffPyFromDTO.AddStaff.class) + private Integer gender; + /** + * 专兼职 + */ + @NotBlank(message = "专兼职不能为空", groups = AddStaffPyFromDTO.AddStaff.class) + private String workType; + + /** + * 账户 + */ + @NotBlank(message = "账号不能为空", groups = AddStaffPyFromDTO.AddStaff.class) + private String userAccount; + + /** + * 密码 + */ + @NotBlank(message = "密码不能为空", groups = AddStaffPyFromDTO.AddStaff.class) + private String pwd; + + /** + * 角色id列表 + */ + @NotNull(message = "角色不能为空", groups = AddStaffPyFromDTO.AddStaff.class) + private List roles; + public interface AddStaff extends CustomerClientShowGroup {} + /** + * 来源app(政府端:gov、居民端:resi、运营端:oper) + */ + private String app; + /** + * 来源client(PC端:web、微信小程序:wxmp) + */ + private String client; +} diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitAccountFromDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitAccountFromDTO.java new file mode 100644 index 0000000000..7e0bf7e36c --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitAccountFromDTO.java @@ -0,0 +1,82 @@ +package com.epmet.dto.form; + +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import java.io.Serializable; +import java.util.List; + +/** + * @author zhy + * @dscription + * @date 2020/4/24 10:43 + */ +@NoArgsConstructor +@Data +public class StaffSubmitAccountFromDTO implements Serializable { + private static final long serialVersionUID = 1L; + /** + * 客户ID + */ + private String customerId; + /** + * 机关ID + */ + private String agencyId; + /** + * 人员ID + */ + private String staffId; + /** + * 姓名 + */ + @NotBlank(message = "姓名不能为空") + @Length(max = 15, message = "姓名仅允许输入15个字符") + private String name; + /** + * 手机 + */ + @NotBlank(message = "手机号不能为空") + @Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "请输入正确的手机号") + private String mobile; + /** + * 性别 + */ + @NotNull(message = "性别不能为空") + private Integer gender; + /** + * 性别 + */ + @NotNull(message = "账号不能为空") + private String userAccount; + /** + * 密码 + */ + private String pwd; + /** + * 专兼职 + */ + @NotBlank(message = "专兼职不能为空") + private String workType; + /** + * 角色id列表 + */ + @NotNull(message = "角色不能为空") + private List roles; + /** + * 来源app(政府端:gov、居民端:resi、运营端:oper) + */ + private String app; + /** + * 来源client(PC端:web、微信小程序:wxmp) + */ + private String client; + /** + * 身份证号 + */ + private String idCard; +} diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java index c3d0f85a22..36cc283268 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java @@ -25,6 +25,10 @@ public class StaffInitResultDTO implements Serializable { * 手机号 */ private String mobile; + /** + * 手机号 + */ + private String userAccount; /** * 性别 */ @@ -33,6 +37,10 @@ public class StaffInitResultDTO implements Serializable { * 专兼职 */ private String workType; + /** + * 身份证号 + */ + private String idCard; /** * 职责列表 */ diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java index 6d3b50b408..939f740fc1 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java @@ -101,6 +101,19 @@ public class StaffController { return staffService.editStaff(tokenDto, fromDTO); } + /** + * 人员编辑 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("editstaffpy") + @RequirePermission(requirePermission = RequirePermissionEnum.ORG_STAFF_UPDATE) + public Result editStaffPy(@LoginUser TokenDto tokenDto, @RequestBody StaffSubmitAccountFromDTO fromDTO){ + ValidatorUtils.validateEntity(fromDTO); + return staffService.editStaffByAccount(tokenDto, fromDTO); + } + /** * 人员详情 * @@ -195,6 +208,20 @@ public class StaffController { return staffService.addStaffV2(fromDTO); } + /** + * 【通讯录】人员添加-平阴 + * @author zhy + */ + + @PostMapping("addstaffpy") + @RequirePermission(requirePermission = RequirePermissionEnum.ORG_STAFF_CREATE) + public Result addStaffPy(@RequestBody StaffSubmitAccountFromDTO fromDTO){ + fromDTO.setApp("gov"); + fromDTO.setClient("wxmp"); + ValidatorUtils.validateEntity(fromDTO); + return staffService.addStaffByAccount(fromDTO); + } + /** * @Description 用户所属组织 * @Param tokenDto diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java index 8190c9418d..9f2c94e49c 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -91,6 +91,16 @@ public interface EpmetUserFeignClient { @PostMapping("/epmetuser/customerstaff/addstaff") Result addStaff(@RequestBody StaffSubmitFromDTO fromDTO); + /** + * 人员添加 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("/epmetuser/customerstaff/addstaffaccount") + Result addStaffByAccount(@RequestBody StaffSubmitAccountFromDTO fromDTO); + + /** * 人员编辑 * @@ -100,6 +110,16 @@ public interface EpmetUserFeignClient { @PostMapping("/epmetuser/customerstaff/editstaff") Result editStaff(@RequestBody StaffSubmitFromDTO fromDTO); + /** + * 人员编辑 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("/epmetuser/customerstaff/editstaffaccount") + Result editStaffByAccount(@RequestBody StaffSubmitAccountFromDTO fromDTO); + + /** * 人员详情 * diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java index 4594d36a60..5b5e7fc04e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java @@ -62,11 +62,21 @@ public class EpmetUserFeignClientFallBack implements EpmetUserFeignClient { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "addStaff", fromDTO); } + @Override + public Result addStaffByAccount(StaffSubmitAccountFromDTO fromDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "addStaffByAccount", fromDTO); + } + @Override public Result editStaff(StaffSubmitFromDTO fromDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "editStaff", fromDTO); } + @Override + public Result editStaffByAccount(StaffSubmitAccountFromDTO fromDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "editStaffByAccount", fromDTO); + } + @Override public Result getStaffDetail(StaffInfoFromDTO fromDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getStaffDetail", fromDTO); diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/StaffService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/StaffService.java index 2c11cd6444..fc2f954b02 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/StaffService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/StaffService.java @@ -64,6 +64,14 @@ public interface StaffService { */ Result editStaff(TokenDto tokenDto,StaffSubmitFromDTO fromDTO); + /** + * 人员编辑 + * + * @param fromDTO 参数 + * @return Result + */ + Result editStaffByAccount(TokenDto tokenDto, StaffSubmitAccountFromDTO fromDTO); + /** * 人员详情 * @@ -130,6 +138,13 @@ public interface StaffService { */ Result addStaffV2(AddStaffV2FromDTO fromDTO); + + /** + * 【通讯录】人员添加-平阴 + * @author zhy + */ + Result addStaffByAccount(StaffSubmitAccountFromDTO fromDTO); + /** * @Description 工作人员所属组织 * @Param tokenDto diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java index e62100cf8d..6950cbcc3c 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java @@ -204,6 +204,25 @@ public class StaffServiceImpl implements StaffService { return result; } + @Override + public Result editStaffByAccount(TokenDto tokenDto, StaffSubmitAccountFromDTO fromDTO) { + CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); + fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); + fromDTO.setApp(tokenDto.getApp()); + fromDTO.setClient(tokenDto.getClient()); + + Result result = epmetUserFeignClient.editStaffByAccount(fromDTO); + if (!result.success()) { + if (result.getCode() != EpmetErrorCode.SERVER_ERROR.getCode()) { + return new Result().error(result.getCode(), result.getMsg()); + } + return new Result().error(EpmetErrorCode.STAFF_EDIT_FAILED.getCode(), EpmetErrorCode.STAFF_EDIT_FAILED.getMsg()); + } + //2021.8.24 sun 人员信息编辑时删除工作人员的缓存信息 + CustomerStaffRedis.delStaffInfoFormCache(fromDTO.getCustomerId(), fromDTO.getStaffId()); + return result; + } + @Override public Result getStaffDetail(StaffInfoFromDTO fromDTO) { CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); @@ -597,6 +616,45 @@ public class StaffServiceImpl implements StaffService { return new Result(); } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result addStaffByAccount(StaffSubmitAccountFromDTO fromDTO) { + CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); + //fromDTO.setApp(tokenDto.getApp()); + //fromDTO.setClient(tokenDto.getClient()); + fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); + Result result = epmetUserFeignClient.addStaffByAccount(fromDTO); + + if (!result.success()) { + if (result.getCode() != EpmetErrorCode.SERVER_ERROR.getCode()) { + return new Result().error(result.getCode(), result.getMsg()); + } + return new Result().error(EpmetErrorCode.STAFF_ADD_FAILED.getCode(), EpmetErrorCode.STAFF_ADD_FAILED.getMsg()); + } + //人员机关关系表 + CustomerStaffAgencyEntity customerStaffAgencyEntity = new CustomerStaffAgencyEntity(); + customerStaffAgencyEntity.setCustomerId(customerAgencyEntity.getCustomerId()); + customerStaffAgencyEntity.setUserId(result.getData().getUserId()); + customerStaffAgencyEntity.setAgencyId(customerAgencyEntity.getId()); + customerStaffAgencyService.insert(customerStaffAgencyEntity); + //机关总人数加一 + customerAgencyEntity.setTotalUser(customerAgencyEntity.getTotalUser() + 1); + customerAgencyService.updateById(customerAgencyEntity); + + //2021.8.25 sun 新增一张工作人员注册组织关系表,所以旧接口新增人员时关系表赋值关系数据 + //工作人员注册组织关系表新增数据 + StaffOrgRelationEntity staffOrgRelationEntity = new StaffOrgRelationEntity(); + staffOrgRelationEntity.setCustomerId(fromDTO.getCustomerId()); + staffOrgRelationEntity.setPids(("".equals(customerAgencyEntity.getPids()) ? "" : customerAgencyEntity.getPids())); + staffOrgRelationEntity.setStaffId(result.getData().getUserId()); + staffOrgRelationEntity.setOrgId(customerAgencyEntity.getId()); + staffOrgRelationEntity.setOrgType("agency"); + staffOrgRelationService.insert(staffOrgRelationEntity); + + return new Result(); + } + /** * @param tokenDto * @Description 工作人员所属组织 diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/CustomerStaffDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/CustomerStaffDTO.java index 5f6e2685a3..9f697c584e 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/CustomerStaffDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/CustomerStaffDTO.java @@ -44,6 +44,11 @@ public class CustomerStaffDTO implements Serializable { */ private String userId; + /** + * 账户 + */ + private String userAccount; + /** * 真实姓名 */ diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerStaffByAccountFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerStaffByAccountFormDTO.java new file mode 100644 index 0000000000..75153c3305 --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerStaffByAccountFormDTO.java @@ -0,0 +1,36 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.List; + +/** + * @Description 根据手机号+客户id获取工作人员基本信息 + * @Author yinzuomei + * @Date 2020/4/20 14:02 + */ +@Data +public class CustomerStaffByAccountFormDTO implements Serializable { + private static final long serialVersionUID = 7619815083427853431L; + + // 根据手机号+客户id获取工作人员基本信息 + public interface GetCustomerStaffInfo {} + + @NotBlank(message = "账号不能为空", groups = { GetCustomerStaffInfo.class }) + private String userAccount; + @NotBlank(message = "客户id不能为空", groups = { GetCustomerStaffInfo.class }) + private String customerId; + + /** + * 姓名 + */ + private String realName; + + /** + * 用户id集合 + */ + private List userIds; +} + diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/ThirdCustomerStaffByAccountFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/ThirdCustomerStaffByAccountFormDTO.java new file mode 100644 index 0000000000..72eacbd9a1 --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/ThirdCustomerStaffByAccountFormDTO.java @@ -0,0 +1,24 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Description 根据客户ID、手机号查询政府端工作人员基本信息 + * @Author zhy + */ +@Data +public class ThirdCustomerStaffByAccountFormDTO implements Serializable{ + private static final long serialVersionUID = -7994579456530273809L; + + /** + * 客户Id + * */ + private String customerId; + + /** + * 账号 + * */ + private String userAccount; +} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java index 73d770a411..43af124f9f 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java @@ -153,6 +153,16 @@ public interface EpmetUserOpenFeignClient { @PostMapping(value = "epmetuser/customerstaff/getcustomerstaffinfo", consumes = MediaType.APPLICATION_JSON_VALUE) Result getCustomerStaffInfo(@RequestBody CustomerStaffFormDTO customerStaffFormDTO); + /** + * @param customerStaffFormDTO + * @return + * @Author sun + * @Description 根据账户+客户id获取工作人员基本信息 + **/ + @PostMapping(value = "epmetuser/customerstaff/getcustomerstaffinfobyaccount", consumes = MediaType.APPLICATION_JSON_VALUE) + Result getCustomerStaffInfoByAccount(@RequestBody CustomerStaffByAccountFormDTO customerStaffFormDTO); + + /** * @param userIdList * @return com.epmet.commons.tools.utils.Result> @@ -234,6 +244,16 @@ public interface EpmetUserOpenFeignClient { @GetMapping(value = "epmetuser/customerstaff/getCustsomerStaffByIdAndPhone") Result> getCustsomerStaffByIdAndPhone(@RequestBody ThirdCustomerStaffFormDTO formDTO); + /** + * @param formDTO + * @return + * @Author zhy + * @Description 根据客户ID、手机号查询政府端工作人员基本信息,校验用户是否存在 + **/ + @GetMapping(value = "epmetuser/customerstaff/getCustsomerStaffByIdAndAccount") + Result> getCustsomerStaffByIdAndAccount(@RequestBody ThirdCustomerStaffByAccountFormDTO formDTO); + + /** * 获取用户基础信息 * diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java index 2de7371623..08b4c30061 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java @@ -99,6 +99,11 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustomerStaffInfo", customerStaffFormDTO); } + @Override + public Result getCustomerStaffInfoByAccount(CustomerStaffByAccountFormDTO customerStaffFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustomerStaffInfoByAccount", customerStaffFormDTO); + } + /** * @param userIdList * @return com.epmet.commons.tools.utils.Result> @@ -174,6 +179,10 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustsomerStaffByIdAndPhone", formDTO); } + @Override + public Result> getCustsomerStaffByIdAndAccount(ThirdCustomerStaffByAccountFormDTO formDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustsomerStaffByIdAndAccount", formDTO); + } @Override public Result selectUserBaseInfo(TokenDto tokenDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "selectUserBaseInfo", tokenDTO); diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java index 215af4eab1..293b925353 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java @@ -119,6 +119,18 @@ public class CustomerStaffController { return customerStaffService.getCustsomerStaffByPhone(mobile); } + /** + * @param account 账户 + * @return com.epmet.commons.tools.utils.Result + * @Author zhy + * @Description 根据账户查询政府端工作人员基本信息,校验用户是否存在 + * @Date 2020/4/18 14:07 + **/ + @GetMapping(value = "getcustsomerstaffbyaccount/{account}") + public Result> getCustsomerStaffByAccount(@PathVariable("account") String account) { + return customerStaffService.getCustsomerStaffByAccount(account); + } + /** * @param formDTO * @return com.epmet.commons.tools.utils.Result @@ -132,6 +144,19 @@ public class CustomerStaffController { return customerStaffService.getCustomerStaffInfo(formDTO); } + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author zhy + * @Description 根据账户+客户id获取工作人员基本信息 + * @Date 2020/4/20 14:04 + **/ + @PostMapping(value = "getcustomerstaffinfobyaccount") + public Result getCustomerStaffInfoByAccount(@RequestBody CustomerStaffByAccountFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, CustomerStaffFormDTO.GetCustomerStaffInfo.class); + return customerStaffService.getCustomerStaffInfoByAccount(formDTO); + } + /** * 根据userId查询网格下用户信息 * @param customerStaffGridDTOS @@ -234,6 +259,31 @@ public class CustomerStaffController { return result; } + + /** + * 人员添加 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("addstaffaccount") + public Result addStaffByAccount(@RequestBody StaffSubmitAccountFromDTO fromDTO){ + Result result = customerStaffService.addStaffByAccount(fromDTO); + + //2021-10-18 推送mq,数据同步到中介库 start + if (result.success()) { + OrgOrStaffMQMsg mq = new OrgOrStaffMQMsg(); + mq.setCustomerId(fromDTO.getCustomerId()); + mq.setOrgId(result.getData().getUserId()); + mq.setOrgType("staff"); + mq.setType("staff_create"); + SendMqMsgUtil.build().openFeignClient(epmetMessageOpenFeignClient).sendOrgStaffMqMsg(mq); + } + //2021-10-18 end + + return result; + } + /** * 人员编辑 * @@ -260,6 +310,30 @@ public class CustomerStaffController { return result; } + /** + * 人员编辑 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("editstaffaccount") + public Result editStaffByAccount(@RequestBody StaffSubmitAccountFromDTO fromDTO){ + Result result = customerStaffService.editStaffByAccount(fromDTO); + + //2021-10-18 推送mq,数据同步到中介库 start + if (result.success()) { + OrgOrStaffMQMsg mq = new OrgOrStaffMQMsg(); + mq.setCustomerId(fromDTO.getCustomerId()); + mq.setOrgId(fromDTO.getStaffId()); + mq.setOrgType("staff"); + mq.setType("staff_change"); + SendMqMsgUtil.build().openFeignClient(epmetMessageOpenFeignClient).sendOrgStaffMqMsg(mq); + } + //2021-10-18 end + + return result; + } + /** * 人员详情 * @@ -366,6 +440,17 @@ public class CustomerStaffController { return new Result>().ok(customerStaffService.getCustsomerStaffByIdAndPhone(formDTO)); } + /** + * @param formDTO + * @return + * @Author zhy + * @Description 根据客户ID、账户查询政府端工作人员基本信息,校验用户是否存在 + **/ + @GetMapping(value = "getCustsomerStaffByIdAndAccount") + public Result> getCustsomerStaffByIdAndAccount(@RequestBody ThirdCustomerStaffByAccountFormDTO formDTO) { + return new Result>().ok(customerStaffService.getCustsomerStaffByIdAndAccount(formDTO)); + } + /** * @Description 查询工作人员的信息 * @param formDTO diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java index b34065223f..1c127d7aa5 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java @@ -45,6 +45,8 @@ public interface CustomerStaffDao extends BaseDao { **/ List selectListCustomerStaffDTO(String mobile); + List listCustomerStaffByAccount(@Param("userAccount") String userAccount); + /** * @param formDTO * @return com.epmet.dto.CustomerStaffDTO @@ -54,6 +56,15 @@ public interface CustomerStaffDao extends BaseDao { **/ CustomerStaffDTO selectListCustomerStaffInfo(CustomerStaffFormDTO formDTO); + /** + * @param formDTO + * @return com.epmet.dto.CustomerStaffDTO + * @Author zhy + * @Description 根据账户+客户id获取工作人员基本信息 + * @Date 2020/4/20 14:08 + **/ + CustomerStaffDTO selectListCustomerStaffInfoByAccount(CustomerStaffByAccountFormDTO formDTO); + CustomerStaffDTO selectStaffInfoByUserId(CustomerStaffDTO formDTO); /** @@ -147,6 +158,14 @@ public interface CustomerStaffDao extends BaseDao { **/ List selectStaff(ThirdCustomerStaffFormDTO formDTO); + /** + * @param formDTO + * @return + * @Author zhy + * @Description 根据客户ID、账户查询政府端工作人员基本信息 + **/ + List selectStaffByAccount(ThirdCustomerStaffByAccountFormDTO formDTO); + /** * @Description 查询工作人员的信息 * @param userIds diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/CustomerStaffEntity.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/CustomerStaffEntity.java index 690bf326c2..aa19464f9e 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/CustomerStaffEntity.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/CustomerStaffEntity.java @@ -42,6 +42,11 @@ public class CustomerStaffEntity extends BaseEpmetEntity { */ private String userId; + /** + * 账户 + */ + private String userAccount; + /** * 真实姓名 */ diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java index f6ca859101..b2a3442172 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java @@ -105,6 +105,15 @@ public interface CustomerStaffService extends BaseService { **/ Result> getCustsomerStaffByPhone(String mobile); + /** + * @param account 账户 + * @return com.epmet.commons.tools.utils.Result + * @Author zhy + * @Description 根据账户查询政府端工作人员基本信息,校验用户是否存在 + * @Date 2020/4/18 14:07 + **/ + Result> getCustsomerStaffByAccount(String account); + /** * @param formDTO * @return com.epmet.commons.tools.utils.Result @@ -114,6 +123,15 @@ public interface CustomerStaffService extends BaseService { **/ Result getCustomerStaffInfo(CustomerStaffFormDTO formDTO); + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author zhy + * @Description 根据账户+客户id获取工作人员基本信息 + * @Date 2020/4/20 14:05 + **/ + Result getCustomerStaffInfoByAccount(CustomerStaffByAccountFormDTO formDTO); + /** * 根据用户ID获取工作人员基本信息 * @@ -169,6 +187,15 @@ public interface CustomerStaffService extends BaseService { */ Result addStaff(StaffSubmitFromDTO fromDTO); + /** + * 人员添加 + * + * @param fromDTO 参数 + * @return Result + */ + Result addStaffByAccount(StaffSubmitAccountFromDTO fromDTO); + + /** * 人员编辑 * @@ -177,6 +204,14 @@ public interface CustomerStaffService extends BaseService { */ Result editStaff(StaffSubmitFromDTO fromDTO); + /** + * 人员编辑 + * + * @param fromDTO 参数 + * @return Result + */ + Result editStaffByAccount(StaffSubmitAccountFromDTO fromDTO); + /** * 人员详情 * @@ -259,6 +294,14 @@ public interface CustomerStaffService extends BaseService { **/ List getCustsomerStaffByIdAndPhone(ThirdCustomerStaffFormDTO formDTO); + /** + * @param formDTO + * @return + * @Author zhy + * @Description 根据客户ID、手机号查询政府端工作人员基本信息,校验用户是否存在 + **/ + List getCustsomerStaffByIdAndAccount(ThirdCustomerStaffByAccountFormDTO formDTO); + /** * @Description 查询工作人员的信息 * @param formDTO diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java index ecfcade3fd..a4b00240f9 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java @@ -170,6 +170,16 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl>().ok(customerStaffDTOList); } + @Override + public Result> getCustsomerStaffByAccount(String userAccount) { + //判断用户是否存在 + List 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>().ok(customerStaffDTOList); + } @Override public Result getCustomerStaffInfo(CustomerStaffFormDTO formDTO) { @@ -186,6 +196,21 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl().ok(customerStaffDTO); } + @Override + public Result 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().ok(customerStaffDTO); + } + @Override public Result getCustomerStaffInfoByUserId(CustomerStaffDTO formDTO) { CustomerStaffDTO customerStaffDTO = baseDao.selectStaffInfoByUserId(formDTO); @@ -265,11 +290,16 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl().ok(ConvertUtils.sourceToTarget(staffEntity, CustomerStaffDTO.class)); } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result 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().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().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 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().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().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().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 staffRoleEntytiesByStaffIdAndOrgId = staffRoleService.getStaffRoleEntytiesByStaffIdAndOrgId(fromDTO.getAgencyId(), fromDTO.getStaffId()); + List 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 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 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 getCustsomerStaffByIdAndAccount(ThirdCustomerStaffByAccountFormDTO formDTO) { + //根据客户Id和手机号查询工作人员信息 + List 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 查询工作人员的信息 diff --git a/epmet-user/epmet-user-server/src/main/resources/db/migration/V0.0.62__alter_customer_staff.sql b/epmet-user/epmet-user-server/src/main/resources/db/migration/V0.0.62__alter_customer_staff.sql new file mode 100644 index 0000000000..c8a15854eb --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/resources/db/migration/V0.0.62__alter_customer_staff.sql @@ -0,0 +1,2 @@ +ALTER TABLE epmet_user.customer_staff ADD USER_ACCOUNT varchar(32) NULL COMMENT '登录账户'; +ALTER TABLE epmet_user.customer_staff CHANGE USER_ACCOUNT USER_ACCOUNT varchar(32) NULL COMMENT '登录账户' AFTER USER_ID; diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml index 5250d48a0a..60b32c4d32 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml @@ -11,6 +11,14 @@ order by cs.ACTIVE_TIME desc,cs.CREATED_TIME asc + + + + + + + +