25 changed files with 613 additions and 13 deletions
@ -0,0 +1,39 @@ |
|||
package com.epmet.controller; |
|||
|
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.dto.form.GovWebLoginFormDTO; |
|||
import com.epmet.dto.result.UserTokenResultDTO; |
|||
import com.epmet.service.GovWebService; |
|||
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; |
|||
|
|||
/** |
|||
* @Description PC工作端-登陆服务 |
|||
* @author sun |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("govweb") |
|||
public class GovWebController { |
|||
|
|||
@Autowired |
|||
private GovWebService govWebService; |
|||
|
|||
|
|||
/** |
|||
* @param formDTO |
|||
* @return |
|||
* @Author sun |
|||
* @Description PC工作端-工作人员登录 |
|||
**/ |
|||
@PostMapping("login") |
|||
public Result<UserTokenResultDTO> workLogin(@RequestBody GovWebLoginFormDTO formDTO) { |
|||
ValidatorUtils.validateEntity(formDTO); |
|||
return new Result<UserTokenResultDTO>().ok(govWebService.login(formDTO)); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,46 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Description PC工作端 手机号+密码登陆-接口入参 |
|||
* @Author sun |
|||
*/ |
|||
@Data |
|||
public class GovWebLoginFormDTO extends LoginCommonFormDTO implements Serializable { |
|||
private static final long serialVersionUID = 7950477424010655108L; |
|||
|
|||
/** |
|||
* 客户Id |
|||
*/ |
|||
@NotBlank(message = "客户Id不能为空",groups = {AddUserShowGroup.class}) |
|||
private String customerId; |
|||
|
|||
/** |
|||
* 手机号 |
|||
*/ |
|||
@NotBlank(message = "手机号不能为空",groups = {AddUserShowGroup.class}) |
|||
private String phone; |
|||
|
|||
/** |
|||
* 密码 |
|||
*/ |
|||
@NotBlank(message = "密码不能为空",groups = {AddUserShowGroup.class}) |
|||
private String password; |
|||
|
|||
/** |
|||
* 验证码 |
|||
*/ |
|||
@NotBlank(message="验证码不能为空",groups = {AddUserShowGroup.class}) |
|||
private String captcha; |
|||
|
|||
/** |
|||
* 唯一标识 |
|||
*/ |
|||
@NotBlank(message="唯一标识不能为空",groups = {AddUserInternalGroup.class}) |
|||
private String uuid; |
|||
|
|||
} |
@ -0,0 +1,19 @@ |
|||
package com.epmet.service; |
|||
|
|||
import com.epmet.dto.form.GovWebLoginFormDTO; |
|||
import com.epmet.dto.result.UserTokenResultDTO; |
|||
|
|||
/** |
|||
* @Description 第三方-居民端、政府端登陆服务 |
|||
* @author sun |
|||
*/ |
|||
public interface GovWebService { |
|||
|
|||
/** |
|||
* @param formDTO |
|||
* @return |
|||
* @Author sun |
|||
* @Description PC工作端-工作人员登录 |
|||
**/ |
|||
UserTokenResultDTO login(GovWebLoginFormDTO formDTO); |
|||
} |
@ -0,0 +1,124 @@ |
|||
package com.epmet.service.impl; |
|||
|
|||
import com.epmet.common.token.constant.LoginConstant; |
|||
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|||
import com.epmet.commons.tools.exception.RenException; |
|||
import com.epmet.commons.tools.security.dto.TokenDto; |
|||
import com.epmet.commons.tools.security.password.PasswordUtils; |
|||
import com.epmet.commons.tools.utils.CpUserDetailRedis; |
|||
import com.epmet.commons.tools.utils.DateUtils; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.dto.form.GovWebLoginFormDTO; |
|||
import com.epmet.dto.form.GovWebOperLoginFormDTO; |
|||
import com.epmet.dto.form.LoginByPassWordFormDTO; |
|||
import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; |
|||
import com.epmet.dto.result.GovWebOperLoginResultDTO; |
|||
import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; |
|||
import com.epmet.dto.result.UserTokenResultDTO; |
|||
import com.epmet.feign.EpmetUserFeignClient; |
|||
import com.epmet.jwt.JwtTokenProperties; |
|||
import com.epmet.jwt.JwtTokenUtils; |
|||
import com.epmet.service.CaptchaService; |
|||
import com.epmet.service.GovWebService; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author sun |
|||
* @Description 第三方-居民端、政府端登陆服务 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
public class GovWebServiceImpl implements GovWebService { |
|||
|
|||
private static final Logger logger = LoggerFactory.getLogger(GovWebServiceImpl.class); |
|||
@Autowired |
|||
private CaptchaService captchaService; |
|||
@Autowired |
|||
private JwtTokenUtils jwtTokenUtils; |
|||
@Autowired |
|||
private JwtTokenProperties jwtTokenProperties; |
|||
@Autowired |
|||
private CpUserDetailRedis cpUserDetailRedis; |
|||
@Autowired |
|||
private EpmetUserFeignClient epmetUserFeignClient; |
|||
|
|||
/** |
|||
* @param formDTO |
|||
* @return |
|||
* @Author sun |
|||
* @Description PC工作端-工作人员登录 |
|||
**/ |
|||
@Override |
|||
public UserTokenResultDTO login(GovWebLoginFormDTO formDTO) { |
|||
//1.参数校验
|
|||
if (!(LoginConstant.APP_GOV.equals(formDTO.getApp()) && LoginConstant.CLIENT_WEB.equals(formDTO.getClient()))) { |
|||
logger.error("当前接口只适用于PC工作端运营管理后台"); |
|||
throw new RenException("当前接口只适用于PC工作端运营管理后台"); |
|||
} |
|||
//2.验证码校验
|
|||
boolean flag = captchaService.validate(formDTO.getUuid(), formDTO.getCaptcha()); |
|||
if (!flag) { |
|||
logger.error(String.format("用户%s登录,验证码输入错误,暂时放行", formDTO.getPhone())); |
|||
//暂时关闭验证码校验 TODO
|
|||
//throw new RenException(EpmetErrorCode.ERR10019.getCode());
|
|||
} |
|||
//3.校验登陆账号是否存在
|
|||
//根据客户Id和手机号查询登陆用户信息(此处不需要判断登陆人是否是有效客户以及是否是客户的根管理员,前一接口获取登陆手机号对应客户列表已经判断了)
|
|||
GovWebOperLoginFormDTO form = new GovWebOperLoginFormDTO(); |
|||
form.setCustomerId(formDTO.getCustomerId()); |
|||
form.setMobile(formDTO.getPhone()); |
|||
Result<GovWebOperLoginResultDTO> result = epmetUserFeignClient.getStaffIdAndPwd(form); |
|||
if (!result.success() || null == result.getData() || null == result.getData().getUserId()) { |
|||
logger.error("根据手机号查询PC工作端登陆人员信息失败,返回10003账号不存在"); |
|||
throw new RenException(EpmetErrorCode.ERR10003.getCode()); |
|||
} |
|||
GovWebOperLoginResultDTO resultDTO = result.getData(); |
|||
|
|||
//4.密码是否正确
|
|||
//密码错误
|
|||
if (!PasswordUtils.matches(formDTO.getPassword(), resultDTO.getPassWord())) { |
|||
logger.error("登陆密码错误"); |
|||
throw new RenException(EpmetErrorCode.ERR10004.getCode()); |
|||
} |
|||
|
|||
//5.生成token存到redis并返回
|
|||
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|||
userTokenResultDTO.setToken(this.packagingUserToken(formDTO, resultDTO.getUserId())); |
|||
return userTokenResultDTO; |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 生成PC工作端token |
|||
* @author sun |
|||
*/ |
|||
private String packagingUserToken(GovWebLoginFormDTO formDTO, String userId) { |
|||
// 生成token
|
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("app", formDTO.getApp()); |
|||
map.put("client", formDTO.getClient()); |
|||
map.put("userId", userId); |
|||
String token = jwtTokenUtils.createToken(map); |
|||
logger.info("app:" + formDTO.getApp() + ";client:" + formDTO.getClient() + ";userId:" + userId + ";生成token[" + token + "]"); |
|||
int expire = jwtTokenProperties.getExpire(); |
|||
TokenDto tokenDto = new TokenDto(); |
|||
tokenDto.setApp(formDTO.getApp()); |
|||
tokenDto.setClient(formDTO.getClient()); |
|||
tokenDto.setUserId(userId); |
|||
tokenDto.setToken(token); |
|||
tokenDto.setUpdateTime(System.currentTimeMillis()); |
|||
tokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); |
|||
cpUserDetailRedis.set(tokenDto, expire); |
|||
logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); |
|||
return token; |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,20 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 运营端-查询已上架功能列表-接口入参 |
|||
* @author sun |
|||
*/ |
|||
@Data |
|||
public class QueryFunctionListFormDTO implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 功能类型:0.默认功能,1.定制功能 |
|||
*/ |
|||
private String functionGroup; |
|||
} |
@ -0,0 +1,26 @@ |
|||
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; |
|||
|
|||
/** |
|||
* 查询登陆用户客户列表(工作端) |
|||
* @CreateTime 2020/8/25 |
|||
*/ |
|||
@Data |
|||
public class CustomerListFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
public interface UserIdGroup extends CustomerClientShowGroup{} |
|||
|
|||
/** |
|||
* 手机号 |
|||
*/ |
|||
@NotBlank(message = "手机号不能为空",groups = UserIdGroup.class) |
|||
private String phone; |
|||
|
|||
} |
@ -0,0 +1,21 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Description PC工作端登陆获取登陆人信息-接口入参 |
|||
* @Author sun |
|||
*/ |
|||
@Data |
|||
public class GovWebOperLoginFormDTO implements Serializable { |
|||
private static final long serialVersionUID = -6653010297552029277L; |
|||
|
|||
@NotBlank(message = "客户Id不能为空") |
|||
private String customerId; |
|||
|
|||
@NotBlank(message = "手机号不能为空") |
|||
private String mobile; |
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.epmet.dto.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 查询登陆用户客户列表(工作端) |
|||
* @CreateTime 2020/8/25 |
|||
*/ |
|||
@Data |
|||
public class CustomerListResultDTO implements Serializable { |
|||
|
|||
/** |
|||
* 客户Id |
|||
*/ |
|||
private String customerId; |
|||
|
|||
/** |
|||
* 客户名称 |
|||
*/ |
|||
private String customerName; |
|||
} |
@ -0,0 +1,16 @@ |
|||
package com.epmet.dto.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Description PC工作端登陆获取登陆人信息-接口返参 |
|||
* @Author sun |
|||
*/ |
|||
@Data |
|||
public class GovWebOperLoginResultDTO implements Serializable { |
|||
private static final long serialVersionUID = -5353521601282463394L; |
|||
private String userId; |
|||
private String passWord; |
|||
} |
@ -0,0 +1,48 @@ |
|||
package com.epmet.dto.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 获取pc工作端登陆用户信息 |
|||
* @CreateTime 2020/8/25 |
|||
*/ |
|||
@Data |
|||
public class StaffBasicInfoResultDTO implements Serializable { |
|||
|
|||
/** |
|||
* 客户Id |
|||
*/ |
|||
private String customerId; |
|||
|
|||
/** |
|||
* 用户Id |
|||
*/ |
|||
private String userId; |
|||
|
|||
/** |
|||
* 真实姓名 |
|||
*/ |
|||
private String realName; |
|||
|
|||
/** |
|||
* 性别0.未知,1男,2.女 |
|||
*/ |
|||
private String gender; |
|||
|
|||
/** |
|||
* 邮箱 |
|||
*/ |
|||
private String email; |
|||
|
|||
/** |
|||
* 手机号 |
|||
*/ |
|||
private String mobile; |
|||
|
|||
/** |
|||
* 地址 |
|||
*/ |
|||
private String address; |
|||
} |
Loading…
Reference in new issue