diff --git a/epmet-auth/pom.xml b/epmet-auth/pom.xml index 3d6c2500ae..cb03612b3b 100644 --- a/epmet-auth/pom.xml +++ b/epmet-auth/pom.xml @@ -76,7 +76,7 @@ com.epmet - epmet-commons-mybatis + epmet-user-client 2.0.0 compile @@ -115,12 +115,6 @@ 8081 dev - - - - - epmet - elink@833066 0 122.152.200.70 @@ -155,12 +149,6 @@ 8081 test - - - - - epmet - elink@833066 0 122.152.200.70 diff --git a/epmet-auth/src/main/java/com/epmet/controller/LoginController.java b/epmet-auth/src/main/java/com/epmet/controller/LoginController.java index 147206dd0a..849daa1ca5 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/LoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/LoginController.java @@ -1,6 +1,5 @@ package com.epmet.controller; -import com.epmet.common.token.annotation.Login; import com.epmet.common.token.dto.form.LoginByPassWordFormDTO; import com.epmet.common.token.dto.form.LoginByWxCodeFormDTO; import com.epmet.common.token.dto.result.UserTokenResultDTO; @@ -8,7 +7,10 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.service.LoginService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +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; /** * @Description 通用登陆接口 diff --git a/epmet-auth/src/main/java/com/epmet/dao/CustomerUserDao.java b/epmet-auth/src/main/java/com/epmet/dao/CustomerUserDao.java deleted file mode 100644 index 5e2b1956dc..0000000000 --- a/epmet-auth/src/main/java/com/epmet/dao/CustomerUserDao.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2018 人人开源 https://www.renren.io - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.epmet.dao; - -import com.epmet.commons.mybatis.dao.BaseDao; -import com.epmet.entity.CustomerUserEntity; -import org.apache.ibatis.annotations.Mapper; - -/** - * 客户用户信息表 - * - * @author generator generator@elink-cn.com - * @since v1.0.0 2020-03-14 - */ -@Mapper -public interface CustomerUserDao extends BaseDao { - - /** - * @param openId - * @return userId - * @Author yinzuomei - * @Description 根据openId查询居民用户信息 - * @Date 2020/3/14 20:45 - **/ - String selectByWxOpenId(String openId); -} diff --git a/epmet-auth/src/main/java/com/epmet/entity/CustomerUserEntity.java b/epmet-auth/src/main/java/com/epmet/entity/CustomerUserEntity.java deleted file mode 100644 index 99affa17fb..0000000000 --- a/epmet-auth/src/main/java/com/epmet/entity/CustomerUserEntity.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright 2018 人人开源 https://www.renren.io - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.epmet.entity; - -import com.baomidou.mybatisplus.annotation.TableName; - -import com.epmet.commons.mybatis.entity.BaseEpmetEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.Date; - -/** - * 客户用户信息表 - * - * @author generator generator@elink-cn.com - * @since v1.0.0 2020-03-14 - */ -@Data -@EqualsAndHashCode(callSuper=false) -@TableName("customer_user") -public class CustomerUserEntity extends BaseEpmetEntity { - - private static final long serialVersionUID = 1L; - - /** - * 客户Id CUSTOMER.id - */ - private String customerId; - - /** - * 微信openId - */ - private String wxOpenId; - - /** - * 手机号 - */ - private String mobile; - - /** - * 昵称 - */ - private String nickname; - - /** - * 性别:0.男 1.女 字典表(key:sex) - */ - private Integer sex; - - /** - * 头像 - */ - private String headImgUrl; - - /** - * 国家 - */ - private String country; - - /** - * 省份 - */ - private String province; - - /** - * 城市 - */ - private String city; - - /** - * 语言 - */ - private String language; - -} diff --git a/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java new file mode 100644 index 0000000000..b7437c22cb --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -0,0 +1,54 @@ +package com.epmet.feign; + +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerUserDTO; +import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; +import com.epmet.dto.form.WxLoginUserInfoFormDTO; +import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; +import com.epmet.feign.fallback.EpmetUserFeignClientFallback; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * @Description + * @Author yinzuomei + * @Date 2020/3/16 14:48 + */ +@FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallback = EpmetUserFeignClientFallback.class) +public interface EpmetUserFeignClient { + + /** + * 获取用户信息 + * + * @param loginUserInfoFormDTO + * @return java.lang.String + * @author yinzuomei + * @date 2020/3/16 14:48 + */ + @PostMapping(value = "/epmetuser/customeruser/selecLoginUserInfo", consumes = MediaType.APPLICATION_JSON_VALUE) + Result selecWxLoginUserInfo(WxLoginUserInfoFormDTO loginUserInfoFormDTO); + + /** + * 获取居民微信信息,保存到customer_user表,返回主键 + * + * @param customerUserDTO + * @return java.lang.String + * @author yinzuomei + * @date 2020/3/16 14:48 + */ + @PostMapping(value = "/epmetuser/customeruser/saveCustomerUser", consumes = MediaType.APPLICATION_JSON_VALUE) + Result saveCustomerUser(CustomerUserDTO customerUserDTO); + + /** + * @param passwordLoginUserInfoFormDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 根据手机号查询用户信息 + * @Date 2020/3/16 16:14 + **/ + @PostMapping(value = "/epmetuser/customeruser/selectLoginUserInfoByPassword", consumes = MediaType.APPLICATION_JSON_VALUE) + Result selectLoginUserInfoByPassword(PasswordLoginUserInfoFormDTO passwordLoginUserInfoFormDTO); +} diff --git a/epmet-auth/src/main/java/com/epmet/feign/ResourceFeignClient.java b/epmet-auth/src/main/java/com/epmet/feign/ResourceFeignClient.java index 41a0156915..e874d61f06 100644 --- a/epmet-auth/src/main/java/com/epmet/feign/ResourceFeignClient.java +++ b/epmet-auth/src/main/java/com/epmet/feign/ResourceFeignClient.java @@ -22,7 +22,7 @@ import java.util.List; * @author Mark sunlightcs@gmail.com * @since 1.0.0 */ -@FeignClient(name = ServiceConstant.EPMET_ADMIN_SERVER, fallback = ResourceFeignClientFallback.class) +@FeignClient(name = ServiceConstant.EPMET_ADMIN_SERVER, fallback = ResourceFeignClientFallback.class,url = "http://localhost:8082") public interface ResourceFeignClient { /** * 获取所有资源列表 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 new file mode 100644 index 0000000000..214fbbff10 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java @@ -0,0 +1,36 @@ +package com.epmet.feign.fallback; + +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.CustomerUserDTO; +import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; +import com.epmet.dto.form.WxLoginUserInfoFormDTO; +import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; +import com.epmet.feign.EpmetUserFeignClient; +import org.springframework.stereotype.Component; + +/** + * @Description + * @Author yinzuomei + * @Date 2020/3/16 14:53 + */ +@Component +public class EpmetUserFeignClientFallback implements EpmetUserFeignClient { + + @Override + public Result selecWxLoginUserInfo(WxLoginUserInfoFormDTO loginUserInfoFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "selecWxLoginUserInfo", loginUserInfoFormDTO); + } + + @Override + public Result saveCustomerUser(CustomerUserDTO customerUserDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "saveCustomerUser", customerUserDTO); + } + + @Override + public Result selectLoginUserInfoByPassword(PasswordLoginUserInfoFormDTO passwordLoginUserInfoFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "selectLoginUserInfoByPassword", passwordLoginUserInfoFormDTO); + } + +} diff --git a/epmet-auth/src/main/java/com/epmet/jwt/JwtUtils.java b/epmet-auth/src/main/java/com/epmet/jwt/JwtUtils.java index 9ffdef84f4..dbd8743793 100644 --- a/epmet-auth/src/main/java/com/epmet/jwt/JwtUtils.java +++ b/epmet-auth/src/main/java/com/epmet/jwt/JwtUtils.java @@ -29,9 +29,10 @@ import java.util.Date; public class JwtUtils { private static final Logger logger = LoggerFactory.getLogger(JwtUtils.class); + /* @Autowired + private JwtProperties jwtProperties;*/ @Autowired - private JwtProperties jwtProperties; - + private JwtTokenProperties jwtProperties; /** * 生成jwt token */ diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java index 8d5b19864b..4c9e886410 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java @@ -8,12 +8,18 @@ import com.epmet.common.token.dto.form.LoginByPassWordFormDTO; import com.epmet.common.token.dto.form.LoginByWxCodeFormDTO; import com.epmet.common.token.dto.result.UserTokenResultDTO; import com.epmet.common.token.util.CpUserDetailRedis; +import com.epmet.commons.tools.exception.ErrorCode; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.security.password.PasswordUtils; import com.epmet.commons.tools.utils.Result; -import com.epmet.dao.CustomerUserDao; -import com.epmet.entity.CustomerUserEntity; +import com.epmet.dto.CustomerUserDTO; +import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; +import com.epmet.dto.form.WxLoginUserInfoFormDTO; +import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; +import com.epmet.feign.EpmetUserFeignClient; import com.epmet.jwt.JwtTokenProperties; import com.epmet.jwt.JwtTokenUtils; +import com.epmet.service.CaptchaService; import com.epmet.service.LoginService; import com.epmet.utils.WxMaServiceUtils; import lombok.extern.slf4j.Slf4j; @@ -38,7 +44,7 @@ public class LoginServiceImpl implements LoginService { private static final Logger logger = LoggerFactory.getLogger(AuthServiceImpl.class); @Autowired - private CustomerUserDao customerUserDao; + private EpmetUserFeignClient epmetUserFeignClient; @Autowired private WxMaServiceUtils wxMaServiceUtils; @@ -52,6 +58,9 @@ public class LoginServiceImpl implements LoginService { @Autowired private CpUserDetailRedis cpUserDetailRedis; + @Autowired + private CaptchaService captchaService; + /** * 微信小程序登录 * @@ -115,31 +124,39 @@ public class LoginServiceImpl implements LoginService { * @since 2020/3/14 19:34 */ private String getUserId(LoginByWxCodeFormDTO formDTO, WxMaJscode2SessionResult wxMaJscode2SessionResult) { - String userId = ""; - if (LoginConstant.APP_GOV.equals(formDTO.getApp())) { + WxLoginUserInfoFormDTO wxLoginUserInfoFormDTO=new WxLoginUserInfoFormDTO(); + wxLoginUserInfoFormDTO.setApp(formDTO.getApp()); + wxLoginUserInfoFormDTO.setOpenId(wxMaJscode2SessionResult.getOpenid()); + Result userResult=epmetUserFeignClient.selecWxLoginUserInfo(wxLoginUserInfoFormDTO); + String userId=""; + if(!userResult.success()){ + throw new RenException("获取用户信息失败"+userResult.getMsg()); + } + userId= (String) userResult.getData(); + if (StringUtils.isBlank(userId)&&LoginConstant.APP_GOV.equals(formDTO.getApp())) { //查询customer_staff待完善 - } else if (LoginConstant.APP_OPER.equals(formDTO.getApp())) { + } else if (StringUtils.isBlank(userId)&&LoginConstant.APP_OPER.equals(formDTO.getApp())) { //查询oper_staff待完善 - } else if (LoginConstant.APP_RESI.equals(formDTO.getApp())) { + } else if (StringUtils.isBlank(userId)&&LoginConstant.APP_RESI.equals(formDTO.getApp())) { //查询customer_user - userId = customerUserDao.selectByWxOpenId(wxMaJscode2SessionResult.getOpenid()); - if (StringUtils.isBlank(userId)) { - WxMaUserInfo wxMaUserInfo = wxMaServiceUtils.resiWxMaService().getUserService() - .getUserInfo(wxMaJscode2SessionResult.getSessionKey(), - formDTO.getEncryptedData(), - formDTO.getIv()); - CustomerUserEntity customerUserEntity = new CustomerUserEntity(); - customerUserEntity.setCity(wxMaUserInfo.getCity()); - customerUserEntity.setWxOpenId(wxMaUserInfo.getOpenId()); - customerUserEntity.setNickname(wxMaUserInfo.getNickName()); - customerUserEntity.setCountry(wxMaUserInfo.getCountry()); - customerUserEntity.setHeadImgUrl(wxMaUserInfo.getAvatarUrl()); - customerUserEntity.setCountry(wxMaUserInfo.getCountry()); - customerUserEntity.setProvince(wxMaUserInfo.getProvince()); - customerUserEntity.setSex(Integer.valueOf(wxMaUserInfo.getGender())); - customerUserDao.insert(customerUserEntity); - userId = customerUserEntity.getId(); + WxMaUserInfo wxMaUserInfo = wxMaServiceUtils.resiWxMaService().getUserService() + .getUserInfo(wxMaJscode2SessionResult.getSessionKey(), + formDTO.getEncryptedData(), + formDTO.getIv()); + CustomerUserDTO customerUserDTO = new CustomerUserDTO(); + customerUserDTO.setCity(wxMaUserInfo.getCity()); + customerUserDTO.setWxOpenId(wxMaUserInfo.getOpenId()); + customerUserDTO.setNickname(wxMaUserInfo.getNickName()); + customerUserDTO.setCountry(wxMaUserInfo.getCountry()); + customerUserDTO.setHeadImgUrl(wxMaUserInfo.getAvatarUrl()); + customerUserDTO.setCountry(wxMaUserInfo.getCountry()); + customerUserDTO.setProvince(wxMaUserInfo.getProvince()); + customerUserDTO.setSex(Integer.valueOf(wxMaUserInfo.getGender())); + Result saveCustomerUserResult=epmetUserFeignClient.saveCustomerUser(customerUserDTO); + if(!saveCustomerUserResult.success()){ + throw new RenException("创建用户失败"+userResult.getMsg()); } + userId = saveCustomerUserResult.getData(); } return userId; } @@ -163,6 +180,7 @@ public class LoginServiceImpl implements LoginService { map.put("client", formDTO.getClient()); map.put("userId", userId); String token = jwtTokenUtils.createToken(map); + logger.info("日志输出token="+token); int expire = jwtTokenProperties.getExpire(); TokenDto tokenDto = new TokenDto(); tokenDto.setApp(formDTO.getApp()); @@ -185,9 +203,59 @@ public class LoginServiceImpl implements LoginService { */ @Override public Result loginByPassword(LoginByPassWordFormDTO formDTO) { + //验证码是否正确 + boolean flag = captchaService.validate(formDTO.getUuid(), formDTO.getCaptcha()); + if(!flag){ + return new Result().error(ErrorCode.CAPTCHA_ERROR); + } //1、账号是否存在 + //获取用户信息 + PasswordLoginUserInfoFormDTO passwordLoginUserInfoFormDTO=new PasswordLoginUserInfoFormDTO(); + passwordLoginUserInfoFormDTO.setApp(formDTO.getApp()); + passwordLoginUserInfoFormDTO.setPhone(formDTO.getPhone()); + Result userInfoResult=epmetUserFeignClient.selectLoginUserInfoByPassword(passwordLoginUserInfoFormDTO); + logger.info(userInfoResult.getCode()+userInfoResult.getMsg()); + if(!userInfoResult.success()||null==userInfoResult.getData()){ + return new Result().error("账号不存在"); + } //2、密码是否正确 + //密码错误 + if(!PasswordUtils.matches(userInfoResult.getData().getPassword(), formDTO.getPassword())){ + throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR); + } + if(!userInfoResult.getData().getPassword().equals(formDTO.getPassword())){ + throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR); + } //3、生成token返回,且将TokenDto存到redis - return null; + UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); + userTokenResultDTO.setToken(this.packagingUserToken(formDTO, userInfoResult.getData().getUserId())); + return new Result().ok(userTokenResultDTO); + } + + /** + * 封装用户token值 + * + * @param formDTO + * @param userId + * @return java.lang.String + * @author yinzuomei + * @since 2020/3/14 19:34 + */ + private String packagingUserToken(LoginByPassWordFormDTO formDTO, + String userId) { + // 生成token + Map map = new HashMap<>(); + map.put("app", formDTO.getApp()); + map.put("client", formDTO.getClient()); + map.put("userId", userId); + String token = jwtTokenUtils.createToken(map); + logger.info("日志输出token="+token); + int expire = jwtTokenProperties.getExpire(); + TokenDto tokenDto = new TokenDto(); + tokenDto.setApp(formDTO.getApp()); + tokenDto.setClient(formDTO.getClient()); + tokenDto.setUserId(userId); + cpUserDetailRedis.set(tokenDto, expire); + return token; } } diff --git a/epmet-auth/src/main/resources/bootstrap.yml b/epmet-auth/src/main/resources/bootstrap.yml index 525987775e..bc6128b95b 100644 --- a/epmet-auth/src/main/resources/bootstrap.yml +++ b/epmet-auth/src/main/resources/bootstrap.yml @@ -23,34 +23,6 @@ spring: port: @spring.redis.port@ password: @spring.redis.password@ timeout: 30s - datasource: - druid: - #MySQL - driver-class-name: com.mysql.cj.jdbc.Driver - url: @spring.datasource.druid.url@ - username: @spring.datasource.druid.username@ - password: @spring.datasource.druid.password@ - initial-size: 10 - max-active: 100 - min-idle: 10 - max-wait: 60000 - pool-prepared-statements: true - max-pool-prepared-statement-per-connection-size: 20 - time-between-eviction-runs-millis: 60000 - min-evictable-idle-time-millis: 300000 - #Oracle需要打开注释 - #validation-query: SELECT 1 FROM DUAL - test-while-idle: true - test-on-borrow: false - test-on-return: false - filter: - stat: - log-slow-sql: true - slow-sql-millis: 1000 - merge-sql: false - wall: - config: - multi-statement-allow: true cloud: nacos: discovery: diff --git a/epmet-auth/src/main/resources/mapper/CustomerUserDao.xml b/epmet-auth/src/main/resources/mapper/CustomerUserDao.xml deleted file mode 100644 index 43f12f9172..0000000000 --- a/epmet-auth/src/main/resources/mapper/CustomerUserDao.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java index 8dfd2750c6..742a38844e 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java @@ -26,4 +26,15 @@ public class LoginByPassWordFormDTO extends LoginCommonFormDTO implements Serial @NotBlank(message = "密码不能为空") private String password; + /** + * 验证码 + */ + @NotBlank(message="验证码不能为空") + private String captcha; + + /** + * 唯一标识 + */ + @NotBlank(message="唯一标识不能为空") + private String uuid; } diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java index f312ed9b8c..2f9cdd1376 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java @@ -13,11 +13,11 @@ public enum ErrorCode implements IErrorCode { SUCCESS(0, "请求成功"), - ERR10001(10001, "clientToken不合法或者已过期"), - ERR10002(10002, "无法获取当前用户的信息,无法生成clientToken。"), - ERR10003(10003, "clientToken生成失败,请重试。"), + ERR10001(10001, "token解析失败"), + ERR10002(10002, "token失效"), + ERR10003(10003, "token生成失败,请重试。"), ERR10004(10004, "返回的Object类型不是EsuaResponse,无法添加token!"), - ERR10005(10005, "clentToken不能为空"), + ERR10005(10005, "token不能为空"), ERR500(500, "Internal Server Error"), ERR501(501, "参数绑定异常"), diff --git a/epmet-gateway/pom.xml b/epmet-gateway/pom.xml index e63f9f7d69..0a83dd5e66 100644 --- a/epmet-gateway/pom.xml +++ b/epmet-gateway/pom.xml @@ -97,8 +97,8 @@ - lb://epmet-auth-server - + + http://localhost:8081 lb://epmet-admin-server diff --git a/epmet-gateway/src/main/resources/bootstrap.yml b/epmet-gateway/src/main/resources/bootstrap.yml index a6cb5e4252..94a50fd703 100644 --- a/epmet-gateway/src/main/resources/bootstrap.yml +++ b/epmet-gateway/src/main/resources/bootstrap.yml @@ -140,6 +140,7 @@ renren: urls: - /auth/captcha - /auth/login + - /auth/login/* - /*/swagger-resources/** - /*/swagger-ui.html - /*/webjars/** diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/PasswordLoginUserInfoFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/PasswordLoginUserInfoFormDTO.java new file mode 100644 index 0000000000..37c323b12b --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/PasswordLoginUserInfoFormDTO.java @@ -0,0 +1,22 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Description + * @Author yinzuomei + * @Date 2020/3/16 15:52 + */ +@Data +public class PasswordLoginUserInfoFormDTO implements Serializable { + private static final long serialVersionUID = -6653010297552029277L; + + @NotBlank(message = "app不能为空") + private String app; + + @NotBlank(message = "手机号不能为空") + private String phone; +} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/WxLoginUserInfoFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/WxLoginUserInfoFormDTO.java new file mode 100644 index 0000000000..98a9bbcd63 --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/WxLoginUserInfoFormDTO.java @@ -0,0 +1,22 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Description + * @Author yinzuomei + * @Date 2020/3/16 15:05 + */ +@Data +public class WxLoginUserInfoFormDTO implements Serializable { + private static final long serialVersionUID = 6072396335840099793L; + + @NotBlank(message = "app不能为空") + private String app; + + @NotBlank(message = "openId不能为空") + private String openId; +} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/PasswordLoginUserInfoResultDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/PasswordLoginUserInfoResultDTO.java new file mode 100644 index 0000000000..9918dfc8b6 --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/PasswordLoginUserInfoResultDTO.java @@ -0,0 +1,17 @@ +package com.epmet.dto.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Description + * @Author yinzuomei + * @Date 2020/3/16 15:22 + */ +@Data +public class PasswordLoginUserInfoResultDTO implements Serializable { + private static final long serialVersionUID = -5353521601282463394L; + private String userId; + private String password; +} diff --git a/epmet-user/epmet-user-server/pom.xml b/epmet-user/epmet-user-server/pom.xml index 80043ebabe..0201ee72f3 100644 --- a/epmet-user/epmet-user-server/pom.xml +++ b/epmet-user/epmet-user-server/pom.xml @@ -48,6 +48,12 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config + + com.epmet + epmet-common-clienttoken + 2.0.0 + compile + diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerUserController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerUserController.java index ae4187b65d..042c2348f2 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerUserController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerUserController.java @@ -23,9 +23,12 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.AssertUtils; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.group.AddGroup; -import com.epmet.commons.tools.validator.group.UpdateGroup; import com.epmet.commons.tools.validator.group.DefaultGroup; +import com.epmet.commons.tools.validator.group.UpdateGroup; import com.epmet.dto.CustomerUserDTO; +import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; +import com.epmet.dto.form.WxLoginUserInfoFormDTO; +import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; import com.epmet.excel.CustomerUserExcel; import com.epmet.service.CustomerUserService; import org.springframework.beans.factory.annotation.Autowired; @@ -45,7 +48,7 @@ import java.util.Map; @RestController @RequestMapping("customeruser") public class CustomerUserController { - + @Autowired private CustomerUserService customerUserService; @@ -91,4 +94,44 @@ public class CustomerUserController { ExcelUtils.exportExcelToTarget(response, null, list, CustomerUserExcel.class); } -} \ No newline at end of file + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 根据openId、app查询对应终端用户信息 + * @Date 2020/3/16 16:15 + **/ + @PostMapping("selecWxLoginUserInfo") + public Result selecWxLoginUserInfo(@RequestBody WxLoginUserInfoFormDTO formDTO){ + ValidatorUtils.validateEntity(formDTO); + return customerUserService.selecWxLoginUserInfo(formDTO); + } + + /** + * @param customerUserDTO + * @return 将获取到的居民微信信息,保存到customer_user表,返回主键 + * @Author yinzuomei + * @Description + * @Date 2020/3/16 15:49 + **/ + @PostMapping("saveCustomerUser") + public Result saveCustomerUser(@RequestBody CustomerUserDTO customerUserDTO) { + //效验数据 + ValidatorUtils.validateEntity(customerUserDTO, AddGroup.class, DefaultGroup.class); + return customerUserService.saveCustomerUser(customerUserDTO); + } + + /** + * @param passwordLoginUserInfoFormDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 根据手机号、app获取对应终端用户信息 + * @Date 2020/3/16 16:15 + **/ + @PostMapping("selectLoginUserInfoByPassword") + public Result selectLoginUserInfoByPassword(@RequestBody PasswordLoginUserInfoFormDTO passwordLoginUserInfoFormDTO) { + //效验数据 + ValidatorUtils.validateEntity(passwordLoginUserInfoFormDTO); + return customerUserService.selectLoginUserInfoByPassword(passwordLoginUserInfoFormDTO); + } +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerUserDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerUserDao.java index e41ca338d6..d4bdd734b0 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerUserDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerUserDao.java @@ -18,6 +18,7 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; import com.epmet.entity.CustomerUserEntity; import org.apache.ibatis.annotations.Mapper; @@ -29,5 +30,58 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface CustomerUserDao extends BaseDao { - -} \ No newline at end of file + + /** + * @param openId + * @return userId + * @Author yinzuomei + * @Description 根据openId查询居民用户信息 + * @Date 2020/3/14 20:45 + **/ + String selectCustomerIdByOpenId(String openId); + + /** + * @param openId + * @return userId + * @Author yinzuomei + * @Description 根据openId查询政府工作人员信息 + * @Date 2020/3/14 20:45 + **/ + String selectCustomerStaffId(String openId); + + /** + * @param openId + * @return userId + * @Author yinzuomei + * @Description 根据openId查询运营人员信息 + * @Date 2020/3/14 20:45 + **/ + String selectOperUserId(String openId); + + /** + * @param phone + * @return com.epmet.dto.result.PasswordLoginUserInfoResultDTO + * @Author yinzuomei + * @Description 根据手机号查询政府工作人员信息 + * @Date 2020/3/17 11:01 + **/ + PasswordLoginUserInfoResultDTO selectCustomerStaffByPhone(String phone); + + /** + * @param phone + * @return com.epmet.dto.result.PasswordLoginUserInfoResultDTO + * @Author yinzuomei + * @Description 根据手机号查询运营人员信息 + * @Date 2020/3/17 11:01 + **/ + PasswordLoginUserInfoResultDTO selectOperUserByPhone(String phone); + + /** + * @param phone + * @return com.epmet.dto.result.PasswordLoginUserInfoResultDTO + * @Author yinzuomei + * @Description 根据手机号查询居民信息 + * @Date 2020/3/17 11:01 + **/ + PasswordLoginUserInfoResultDTO selectCustomerUserByPhone(String phone); +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerUserService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerUserService.java index 39ebe54c91..a8a4950b2b 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerUserService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerUserService.java @@ -19,7 +19,11 @@ package com.epmet.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerUserDTO; +import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; +import com.epmet.dto.form.WxLoginUserInfoFormDTO; +import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; import com.epmet.entity.CustomerUserEntity; import java.util.List; @@ -92,4 +96,32 @@ public interface CustomerUserService extends BaseService { * @date 2020-03-16 */ void delete(String[] ids); -} \ No newline at end of file + + /** + * 根据openId、app查询对应终端用户信息 + * + * @param formDTO + * @return void + * @author yinzuomei + * @date 2020-03-16 + */ + Result selecWxLoginUserInfo(WxLoginUserInfoFormDTO formDTO); + + /** + * @param customerUserDTO + * @return 获取居民微信信息,保存到customer_user表,返回主键 + * @Author yinzuomei + * @Description + * @Date 2020/3/16 15:49 + **/ + Result saveCustomerUser(CustomerUserDTO customerUserDTO); + + /** + * @param passwordLoginUserInfoFormDTO + * @return 根据手机号获取用户信息 + * @Author yinzuomei + * @Description + * @Date 2020/3/16 15:49 + **/ + Result selectLoginUserInfoByPassword(PasswordLoginUserInfoFormDTO passwordLoginUserInfoFormDTO); +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerUserServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerUserServiceImpl.java index 59e3ccafaa..210ea0b664 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerUserServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerUserServiceImpl.java @@ -19,12 +19,17 @@ package com.epmet.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.epmet.common.token.constant.LoginConstant; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.ConvertUtils; -import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.commons.tools.utils.Result; import com.epmet.dao.CustomerUserDao; import com.epmet.dto.CustomerUserDTO; +import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; +import com.epmet.dto.form.WxLoginUserInfoFormDTO; +import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; import com.epmet.entity.CustomerUserEntity; import com.epmet.redis.CustomerUserRedis; import com.epmet.service.CustomerUserService; @@ -46,59 +51,117 @@ import java.util.Map; @Service public class CustomerUserServiceImpl extends BaseServiceImpl implements CustomerUserService { - @Autowired - private CustomerUserRedis customerUserRedis; - - @Override - public PageData page(Map params) { - IPage page = baseDao.selectPage( - getPage(params, FieldConstant.CREATED_TIME, false), - getWrapper(params) - ); - return getPageData(page, CustomerUserDTO.class); - } - - @Override - public List list(Map params) { - List entityList = baseDao.selectList(getWrapper(params)); - - return ConvertUtils.sourceToTarget(entityList, CustomerUserDTO.class); - } - - private QueryWrapper getWrapper(Map params){ - String id = (String)params.get(FieldConstant.ID_HUMP); - - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); - - return wrapper; - } - - @Override - public CustomerUserDTO get(String id) { - CustomerUserEntity entity = baseDao.selectById(id); - return ConvertUtils.sourceToTarget(entity, CustomerUserDTO.class); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void save(CustomerUserDTO dto) { - CustomerUserEntity entity = ConvertUtils.sourceToTarget(dto, CustomerUserEntity.class); - insert(entity); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(CustomerUserDTO dto) { - CustomerUserEntity entity = ConvertUtils.sourceToTarget(dto, CustomerUserEntity.class); - updateById(entity); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(String[] ids) { - // 逻辑删除(@TableLogic 注解) - baseDao.deleteBatchIds(Arrays.asList(ids)); - } - -} \ No newline at end of file + @Autowired + private CustomerUserRedis customerUserRedis; + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, CustomerUserDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, CustomerUserDTO.class); + } + + private QueryWrapper getWrapper(Map params) { + String id = (String) params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public CustomerUserDTO get(String id) { + CustomerUserEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, CustomerUserDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(CustomerUserDTO dto) { + CustomerUserEntity entity = ConvertUtils.sourceToTarget(dto, CustomerUserEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(CustomerUserDTO dto) { + CustomerUserEntity entity = ConvertUtils.sourceToTarget(dto, CustomerUserEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + /** + * 根据openId、app查询对应终端用户信息 + * + * @return void + * @author yinzuomei + * @date 2020-03-16 + */ + @Override + public Result selecWxLoginUserInfo(WxLoginUserInfoFormDTO formDTO) { + String userId = ""; + if (LoginConstant.APP_GOV.equals(formDTO.getApp())) { + //查询customer_staff待完善 + userId = baseDao.selectCustomerStaffId(formDTO.getOpenId()); + } else if (LoginConstant.APP_OPER.equals(formDTO.getApp())) { + //查询oper_staff待完善 + userId = baseDao.selectOperUserId(formDTO.getOpenId()); + } else if (LoginConstant.APP_RESI.equals(formDTO.getApp())) { + userId = baseDao.selectCustomerIdByOpenId(formDTO.getOpenId()); + } + return new Result().ok(userId); + } + + /** + * @param customerUserDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 将获取到的居民微信信息,保存到customer_user表,返回主键 + * @Date 2020/3/17 11:04 + **/ + @Override + public Result saveCustomerUser(CustomerUserDTO customerUserDTO) { + CustomerUserEntity entity = ConvertUtils.sourceToTarget(customerUserDTO, CustomerUserEntity.class); + insert(entity); + return new Result().ok(entity.getId()); + } + + /** + * @param formDTO + * @return 根据手机号、app获取对应终端用户信息 + * @Author yinzuomei + * @Description + * @Date 2020/3/16 15:49 + **/ + @Override + public Result selectLoginUserInfoByPassword(PasswordLoginUserInfoFormDTO formDTO) { + PasswordLoginUserInfoResultDTO passwordLoginUserInfoResultDTO = null; + if (LoginConstant.APP_GOV.equals(formDTO.getApp())) { + //查询customer_staff待完善 + passwordLoginUserInfoResultDTO = baseDao.selectCustomerStaffByPhone(formDTO.getPhone()); + } else if (LoginConstant.APP_OPER.equals(formDTO.getApp())) { + //查询oper_user待完善 + passwordLoginUserInfoResultDTO = baseDao.selectOperUserByPhone(formDTO.getPhone()); + } else if (LoginConstant.APP_RESI.equals(formDTO.getApp())) { + passwordLoginUserInfoResultDTO = baseDao.selectCustomerUserByPhone(formDTO.getPhone()); + } + return new Result().ok(passwordLoginUserInfoResultDTO); + } + +} diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerUserDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerUserDao.xml index 14a5b36bc6..09dbe55a56 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerUserDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerUserDao.xml @@ -23,5 +23,73 @@ + + - \ No newline at end of file + + + + + + + + + + + + + + +