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 61358a0c6b..a9a79cb949 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 @@ -272,9 +272,6 @@ public class GovLoginServiceImpl implements GovLoginService { throw new RenException(customerStaffDTOResult.getCode()); } CustomerStaffDTO customerStaff = customerStaffDTOResult.getData(); - /*if(null==customerStaff.getPassword()||"".equals(customerStaff.getPassword().trim())){ - throw new RenException(EpmetErrorCode.PLEASE_ACTIVATE_CURRENT_CUSTOMER_ACCOUNT.getCode()); - }*/ //2、解析微信用户 WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(LoginConstant.APP_GOV, formDTO.getWxCode()); //3、记录staff_wechat,并记录用户激活状态,激活时间 @@ -346,19 +343,20 @@ public class GovLoginServiceImpl implements GovLoginService { havePasswordFlag=true; }else{ logger.warn(String.format("当前用户:手机号%s,客户Id%s下未设置密码.",formDTO.getMobile(),customerStaffDTO.getCustomerId())); + continue; } if (!PasswordUtils.matches(formDTO.getPassword(), customerStaffDTO.getPassword())) { - logger.warn(String.format("当前用户:手机号%s,客户Id%s密码输入错误.",formDTO.getMobile(),customerStaffDTO.getCustomerId())); + logger.warn(String.format("当前用户:手机号%s,客户Id%s密码匹配错误.",formDTO.getMobile(),customerStaffDTO.getCustomerId())); }else{ logger.warn(String.format("当前用户:手机号%s,客户Id%s密码匹配正确.",formDTO.getMobile(),customerStaffDTO.getCustomerId())); passwordRightFlag=true; + customerIdList.add(customerStaffDTO.getCustomerId()); } - customerIdList.add(customerStaffDTO.getCustomerId()); } //根据手机号查出来所有用户,密码都为空,表明用户未激活账户,未设置密码 if(!havePasswordFlag){ - throw new RenException(EpmetErrorCode.PLEASE_ACTIVATE_ACCOUNT.getCode()); + logger.error(String.format("当前手机号(%s)下所有账户都未设置密码,请先使用验证码登录激活账户",formDTO.getMobile())); } //密码错误 if(!passwordRightFlag){ 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 0d17ca70b9..e11006dcaa 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 @@ -31,9 +31,10 @@ public enum EpmetErrorCode { LOSE_EFFICACY(8006,"此邀请链接已过期"), ERROR_PHONE(8007,"请输入正确的手机号"), PLEASE_LOGIN(8008,"请重新登录"), - PASSWORD_ERROR(8009,"密码错误,请重新输入"), - PLEASE_ACTIVATE_ACCOUNT(8010,"请先使用验证码登录激活账户"), - PLEASE_ACTIVATE_CURRENT_CUSTOMER_ACCOUNT(8011,"当前组织下,账号未激活,请先使用验证码登录"), + PASSWORD_ERROR(8009,"手机号密码不符"), + PASSWORD_NOT_FIT(8010,"两次填写的密码不一致"), + PASSWORD_OUT_OF_ORDER(8011,"密码必须8-20个字符,而且同时包含大小写字母和数字"), + PASSWORD_UPDATE_FAILED(8012,"密码修改失败"), MOBILE_HAS_BEEN_USED(8101, "该手机号已注册,请更换手机号或使用原绑定的微信账号登录"), MOBILE_CODE_ERROR(8102, "验证码错误"), AUTO_CONFIRM_FAILED(8103, "党员注册失败"), diff --git a/epmet-module/gov-mine/gov-mine-client/src/main/java/com/epmet/dto/form/StaffResetPassWordFormDTO.java b/epmet-module/gov-mine/gov-mine-client/src/main/java/com/epmet/dto/form/StaffResetPassWordFormDTO.java new file mode 100644 index 0000000000..7fe2d7bf6c --- /dev/null +++ b/epmet-module/gov-mine/gov-mine-client/src/main/java/com/epmet/dto/form/StaffResetPassWordFormDTO.java @@ -0,0 +1,31 @@ +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; + +/** + * 描述一下 + * + * @author yinzuomei@elink-cn.com + * @date 2020/7/1 9:52 + */ +@Data +public class StaffResetPassWordFormDTO implements Serializable { + private static final long serialVersionUID = 7457641974958356125L; + + public interface AddUserInternalGroup { + } + + public interface AddUserShowGroup extends CustomerClientShowGroup { + } + + @NotBlank(message = "新密码不能为空", groups = {AddUserShowGroup.class}) + private String newPassword; + @NotBlank(message = "确认新密码不能为空", groups = {AddUserShowGroup.class}) + private String confirmNewPassword; + @NotBlank(message = "staffId不能为空", groups = {AddUserInternalGroup.class}) + private String staffId; +} diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/controller/MineController.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/controller/MineController.java index 39130b6857..cc9a8c9e94 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/controller/MineController.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/controller/MineController.java @@ -3,10 +3,13 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.form.StaffResetPassWordFormDTO; import com.epmet.dto.result.MineResultDTO; import com.epmet.service.MineService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -32,4 +35,19 @@ public class MineController { public Result profile(@LoginUser TokenDto tokenDto) { return new Result().ok(mineService.profile(tokenDto)); } + + /** + * @param tokenDto + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @author yinzuomei + * @description 修改密码 + * @Date 2020/7/1 9:59 + **/ + @PostMapping("resetpassword") + public Result resetPassword(@LoginUser TokenDto tokenDto, @RequestBody StaffResetPassWordFormDTO formDTO) { + formDTO.setStaffId(tokenDto.getUserId()); + ValidatorUtils.validateEntity(formDTO, StaffResetPassWordFormDTO.AddUserShowGroup.class, StaffResetPassWordFormDTO.AddUserInternalGroup.class); + return mineService.resetPassword(formDTO); + } } diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/MineService.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/MineService.java index 8ec08f7905..61d3830dbe 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/MineService.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/MineService.java @@ -1,6 +1,8 @@ package com.epmet.service; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.form.StaffResetPassWordFormDTO; import com.epmet.dto.result.MineResultDTO; /** @@ -17,4 +19,13 @@ public interface MineService { * @return com.epmet.dto.result.MineResultDTO */ MineResultDTO profile(TokenDto tokenDto); + + /** + * @return com.epmet.commons.tools.utils.Result + * @param formDTO + * @author yinzuomei + * @description 修改密码 + * @Date 2020/7/1 10:00 + **/ + Result resetPassword(StaffResetPassWordFormDTO formDTO); } diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/MineServiceImpl.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/MineServiceImpl.java index 66b152df9f..4d9c0e30c8 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/MineServiceImpl.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/MineServiceImpl.java @@ -1,15 +1,20 @@ package com.epmet.service.impl; +import com.alibaba.fastjson.JSON; +import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; -import com.epmet.commons.tools.exception.ErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.StaffInfoFromDTO; +import com.epmet.dto.form.StaffResetPassWordFormDTO; +import com.epmet.dto.form.StaffResetPwFormDTO; import com.epmet.dto.result.MineResultDTO; +import com.epmet.feign.EpmetUserOpenFeignClient; import com.epmet.feign.GovOrgFeignClient; import com.epmet.service.MineService; -import org.apache.poi.ss.formula.constant.ErrorConstant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +25,12 @@ import org.springframework.stereotype.Service; */ @Service public class MineServiceImpl implements MineService { + private static final Logger logger = LoggerFactory.getLogger(MineServiceImpl.class); @Autowired GovOrgFeignClient govOrgFeignClient; + @Autowired + private EpmetUserOpenFeignClient epmetUserOpenFeignClient; + @Override public MineResultDTO profile(TokenDto tokenDto) { StaffInfoFromDTO fromDTO = new StaffInfoFromDTO(); @@ -32,4 +41,68 @@ public class MineServiceImpl implements MineService { } return result.getData(); } + + @Override + public Result resetPassword(StaffResetPassWordFormDTO formDTO) { + //1、两次填写的密码需要保持一致 + if(!formDTO.getNewPassword().equals(formDTO.getConfirmNewPassword())){ + logger.error(String.format("两次填写的新密码不一致,新密码%s,确认新密码%s",formDTO.getNewPassword(),formDTO.getConfirmNewPassword())); + throw new RenException(EpmetErrorCode.PASSWORD_NOT_FIT.getCode()); + } + //2、校验密码规则:密码必须8-20个字符,而且同时包含大小写字母和数字 + boolean flag=this.checkPassWord(formDTO.getNewPassword()); + if(!flag){ + throw new RenException(EpmetErrorCode.PASSWORD_OUT_OF_ORDER.getCode()); + } + //3、调用user服务修改密码 + StaffResetPwFormDTO staffResetPwFormDTO=new StaffResetPwFormDTO(); + staffResetPwFormDTO.setNewPassword(formDTO.getNewPassword()); + staffResetPwFormDTO.setConfirmNewPassword(formDTO.getConfirmNewPassword()); + staffResetPwFormDTO.setStaffId(formDTO.getStaffId()); + Result updatePassWordResult=epmetUserOpenFeignClient.resetStaffPassword(staffResetPwFormDTO); + if(updatePassWordResult.success()){ + logger.info(String.format("调用%s服务,修改密码成功", ServiceConstant.EPMET_USER_SERVER)); + }else{ + logger.error(String.format("调用%s服务,修改密码失败,返参:%s", ServiceConstant.EPMET_USER_SERVER, + JSON.toJSONString(updatePassWordResult))); + return new Result().error(EpmetErrorCode.PASSWORD_UPDATE_FAILED.getCode()); + } + return new Result(); + } + + private boolean checkPassWord(String password) { + boolean flag=false; + if(password.length()<8||password.length()>20){ + logger.error(String.format("密码长度应为8-20位,当前输入密码%s,长度为%s",password,password.length())); + return flag; + } + boolean numFlag=false; + boolean bigLetter=false; + boolean smallLetter=false; + char[] passwordArray = password.toCharArray(); + for(int i=0;i < passwordArray.length;i++) { + char currentStr=passwordArray[i]; + logger.info(String.format("当前字符%s",currentStr)); + // 判断ch是否是数字字符,如'1','2‘,是返回true。否则返回false + if(Character.isDigit(currentStr)){ + numFlag=true; + continue; + } + // 判断ch是否是字母字符,如'a','b‘,是返回true。否则返回false + if(Character.isUpperCase(currentStr)){ + bigLetter=true; + continue; + } + if(Character.isLowerCase(currentStr)){ + smallLetter=true; + continue; + } + } + if(numFlag&&bigLetter&&smallLetter){ + flag=true; + }else{ + logger.error(String.format("当前密码%s,是否包含数字%s,是否包含大写字母%s,是否包含小写字母%s",password,numFlag,bigLetter,smallLetter)); + } + return flag; + } } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffResetPwFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffResetPwFormDTO.java new file mode 100644 index 0000000000..9d21502254 --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffResetPwFormDTO.java @@ -0,0 +1,32 @@ +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; + +/** + * 工作端,修改工作人员密码 + * + * @author yinzuomei@elink-cn.com + * @date 2020/7/1 10:34 + */ +@Data +public class StaffResetPwFormDTO implements Serializable { + + private static final long serialVersionUID = 6230552511846731272L; + + public interface AddUserInternalGroup { + } + + public interface AddUserShowGroup extends CustomerClientShowGroup { + } + + @NotBlank(message = "新密码不能为空", groups = {AddUserShowGroup.class}) + private String newPassword; + @NotBlank(message = "确认新密码不能为空", groups = {AddUserShowGroup.class}) + private String confirmNewPassword; + @NotBlank(message = "staffId不能为空", groups = {AddUserInternalGroup.class}) + private String staffId; +} 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 d4a09e63cc..0faea1fb73 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 @@ -3,13 +3,11 @@ package com.epmet.feign; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerStaffDTO; -import com.epmet.dto.form.CustomerStaffRoleListFormDTO; -import com.epmet.dto.form.GovStaffRoleFormDTO; -import com.epmet.dto.form.LoginUserDetailsFormDTO; -import com.epmet.dto.form.TagCustomerFormDTO; +import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.feign.fallback.EpmetUserOpenFeignClientFallback; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -31,7 +29,7 @@ public interface EpmetUserOpenFeignClient { * * @return */ - @PostMapping("/epmetuser/user/loginuserdetails") + @PostMapping(value = "/epmetuser/user/loginuserdetails", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) Result getLoginUserDetails(@RequestBody LoginUserDetailsFormDTO dto); /** @@ -40,7 +38,7 @@ public interface EpmetUserOpenFeignClient { * @Author sun * @Description 根据客户Id和staffId查询一个员工在指定客户下的角色列表 **/ - @PostMapping("/epmetuser/staffrole/getcustomerstaffrolelist") + @PostMapping(value = "/epmetuser/staffrole/getcustomerstaffrolelist", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) Result> getCustomerStaffRoleList(@RequestBody CustomerStaffRoleListFormDTO formDTO); /** @@ -68,7 +66,7 @@ public interface EpmetUserOpenFeignClient { * @Description 根据userId获取customerId * @author zxc */ - @PostMapping("/epmetuser/user/getcustomeridbyuserid") + @PostMapping(value = "/epmetuser/user/getcustomeridbyuserid", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) Result getCustomerIdByUserId(@RequestBody TagCustomerFormDTO formDTO); /** @@ -76,6 +74,16 @@ public interface EpmetUserOpenFeignClient { * @param form * @return */ - @PostMapping("/epmetuser/govstaffrole/getbyids") + @PostMapping(value = "/epmetuser/govstaffrole/getbyids", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) Result> getByIds(@RequestBody GovStaffRoleFormDTO form); + + /** + * @return com.epmet.commons.tools.utils.Result + * @param staffResetPwFormDTO + * @author yinzuomei + * @description 工作端,修改工作人员密码 + * @Date 2020/7/1 10:37 + **/ + @PostMapping(value = "/epmetuser/customerstaff/resetstaffpassword", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) + Result resetStaffPassword(@RequestBody StaffResetPwFormDTO staffResetPwFormDTO); } 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 9f87d6f530..ec9cac1b00 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 @@ -4,10 +4,7 @@ import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerStaffDTO; -import com.epmet.dto.form.CustomerStaffRoleListFormDTO; -import com.epmet.dto.form.GovStaffRoleFormDTO; -import com.epmet.dto.form.LoginUserDetailsFormDTO; -import com.epmet.dto.form.TagCustomerFormDTO; +import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.feign.EpmetUserOpenFeignClient; import org.springframework.stereotype.Component; @@ -53,4 +50,9 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getById", form); } + @Override + public Result resetStaffPassword(StaffResetPwFormDTO staffResetPwFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "resetStaffPassword", staffResetPwFormDTO); + } + } 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 ca315b6c68..06a0ff2282 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 @@ -284,4 +284,17 @@ public class CustomerStaffController { return new Result().ok(customerStaffService.getCustomerStaff(staffId)); } + /** + * @return com.epmet.commons.tools.utils.Result + * @param staffResetPwFormDTO + * @author yinzuomei + * @description 工作端,修改工作人员密码 + * @Date 2020/7/1 10:39 + **/ + @PostMapping("resetStaffPassword") + public Result resetStaffPassword(@RequestBody StaffResetPwFormDTO staffResetPwFormDTO){ + ValidatorUtils.validateEntity(staffResetPwFormDTO,StaffResetPwFormDTO.AddUserShowGroup.class,StaffResetPwFormDTO.AddUserInternalGroup.class); + customerStaffService.resetStaffPassword(staffResetPwFormDTO); + return new Result(); + } } \ No newline at end of file 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 c166c3093f..4129e37c8c 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 @@ -232,4 +232,13 @@ public interface CustomerStaffService extends BaseService { * @Description 根据staffId查询工作人员基本信息 **/ CustomerStaffDTO getCustomerStaff(String staffId); + + /** + * @return void + * @param staffResetPwFormDTO + * @author yinzuomei + * @description 工作端,修改工作人员密码 + * @Date 2020/7/1 10:41 + **/ + void resetStaffPassword(StaffResetPwFormDTO staffResetPwFormDTO); } \ No newline at end of file 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 48b2f5a45f..a0f3aab8e2 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 @@ -26,6 +26,7 @@ import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.security.password.PasswordUtils; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.CpUserDetailRedis; import com.epmet.commons.tools.utils.Result; @@ -55,7 +56,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -456,4 +460,24 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl