forked from luyan/epmet-cloud-lingshan
61 changed files with 1705 additions and 349 deletions
@ -0,0 +1,81 @@ |
|||||
|
package com.epmet.controller; |
||||
|
|
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
||||
|
import com.epmet.dto.form.GovWxmpEnteOrgFormDTO; |
||||
|
import com.epmet.dto.form.GovWxmpFormDTO; |
||||
|
import com.epmet.dto.form.GovWxmpGetOrgsFormDTO; |
||||
|
import com.epmet.dto.form.SendSmsCodeFormDTO; |
||||
|
import com.epmet.dto.result.UserTokenResultDTO; |
||||
|
import com.epmet.service.GovLoginService; |
||||
|
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 政府端登录 |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 10:54 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("gov") |
||||
|
public class GovLoginController { |
||||
|
@Autowired |
||||
|
private GovLoginService govLoginService; |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.UserTokenResultDTO> |
||||
|
* @Author yinzuomei |
||||
|
* @Description 1、政府端小程序根据wxCode获取上一次登录信息,返回token |
||||
|
* @Date 2020/4/20 11:22 |
||||
|
**/ |
||||
|
@PostMapping(value = "/loginwxmp/loginbywxcode") |
||||
|
public Result<UserTokenResultDTO> loginByWxCode(GovWxmpFormDTO formDTO) { |
||||
|
ValidatorUtils.validateEntity(formDTO); |
||||
|
return govLoginService.loginByWxCode(formDTO); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO 手机号 |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author yinzuomei |
||||
|
* @Description 2、政府端微信小程序登录-发送验证码 |
||||
|
* @Date 2020/4/18 10:58 |
||||
|
**/ |
||||
|
@PostMapping(value = "/loginwxmp/sendsmscode") |
||||
|
public Result sendSmsCode(@RequestBody SendSmsCodeFormDTO formDTO) { |
||||
|
ValidatorUtils.validateEntity(formDTO); |
||||
|
return govLoginService.sendSmsCode(formDTO); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.common.token.dto.result.UserTokenResultDTO> |
||||
|
* @Author yinzuomei |
||||
|
* @Description 3、手机验证码获取组织 |
||||
|
* @Date 2020/4/18 21:14 |
||||
|
**/ |
||||
|
@PostMapping(value = "/loginwxmp/getorgs") |
||||
|
public Result getorgs(GovWxmpGetOrgsFormDTO formDTO) { |
||||
|
ValidatorUtils.validateEntity(formDTO); |
||||
|
return govLoginService.getorgs(formDTO); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.UserTokenResultDTO> |
||||
|
* @Author yinzuomei |
||||
|
* @Description 4、选择组织,进入首页 |
||||
|
* @Date 2020/4/20 13:07 |
||||
|
**/ |
||||
|
@PostMapping(value = "/loginwxmp/enterorg") |
||||
|
public Result<UserTokenResultDTO> enterOrg(GovWxmpEnteOrgFormDTO formDTO) { |
||||
|
ValidatorUtils.validateEntity(formDTO); |
||||
|
return govLoginService.enterOrg(formDTO); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
@ -0,0 +1,39 @@ |
|||||
|
package com.epmet.dto.form; |
||||
|
|
||||
|
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 GovWxmpEnteOrgFormDTO implements Serializable { |
||||
|
/** |
||||
|
* wxCode |
||||
|
*/ |
||||
|
@NotBlank(message = "wxCode不能为空") |
||||
|
private String wxCode; |
||||
|
|
||||
|
/** |
||||
|
* 手机号 |
||||
|
*/ |
||||
|
@NotBlank(message = "手机号不能为空") |
||||
|
private String mobile; |
||||
|
|
||||
|
/** |
||||
|
* 选择的组织所属的id |
||||
|
*/ |
||||
|
@NotBlank(message = "客户id不能为空") |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* 选择的要进入的组织(根组织id) |
||||
|
*/ |
||||
|
@NotBlank(message = "组织id不能为空") |
||||
|
private String orgId; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,21 @@ |
|||||
|
package com.epmet.dto.form; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
/** |
||||
|
* @Description 政府端小程序根据wxCode获取上一次登录信息,返回token |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 11:20 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class GovWxmpFormDTO extends LoginCommonFormDTO{ |
||||
|
private static final long serialVersionUID = -207861963128774742L; |
||||
|
/** |
||||
|
* wxCode |
||||
|
*/ |
||||
|
@NotBlank(message = "wxCode不能为空") |
||||
|
private String wxCode; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,23 @@ |
|||||
|
package com.epmet.feign; |
||||
|
|
||||
|
import com.epmet.commons.tools.constant.ServiceConstant; |
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import com.epmet.dto.form.StaffGridInfoFormDTO; |
||||
|
import com.epmet.dto.result.StaffGridInfoResultDTO; |
||||
|
import com.epmet.feign.fallback.GovOrgFeignClientFallback; |
||||
|
import org.springframework.cloud.openfeign.FeignClient; |
||||
|
import org.springframework.http.MediaType; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @Description 政府端组织机构模块 |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 15:18 |
||||
|
*/ |
||||
|
@FeignClient(name = ServiceConstant.GOV_ORG_SERVER, fallback = GovOrgFeignClientFallback.class) |
||||
|
public interface GovOrgFeignClient { |
||||
|
@PostMapping(value = "getStaffGridInfo",consumes = MediaType.APPLICATION_JSON_VALUE) |
||||
|
Result<List<StaffGridInfoResultDTO>> getStaffGridInfo(StaffGridInfoFormDTO staffGridInfoFormDTO); |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
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.form.StaffGridInfoFormDTO; |
||||
|
import com.epmet.dto.result.StaffGridInfoResultDTO; |
||||
|
import com.epmet.feign.GovOrgFeignClient; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @Description 政府端组织机构模块 |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 15:19 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class GovOrgFeignClientFallback implements GovOrgFeignClient { |
||||
|
@Override |
||||
|
public Result<List<StaffGridInfoResultDTO>> getStaffGridInfo(StaffGridInfoFormDTO staffGridInfoFormDTO) { |
||||
|
return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getStaffGridInfo", staffGridInfoFormDTO); |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,51 @@ |
|||||
|
package com.epmet.service; |
||||
|
|
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import com.epmet.dto.form.GovWxmpEnteOrgFormDTO; |
||||
|
import com.epmet.dto.form.GovWxmpFormDTO; |
||||
|
import com.epmet.dto.form.GovWxmpGetOrgsFormDTO; |
||||
|
import com.epmet.dto.form.SendSmsCodeFormDTO; |
||||
|
import com.epmet.dto.result.UserTokenResultDTO; |
||||
|
|
||||
|
/** |
||||
|
* @Description 政府端登录服务 |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 10:56 |
||||
|
*/ |
||||
|
public interface GovLoginService { |
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author yinzuomei |
||||
|
* @Description 政府端微信小程序登录-发送验证码 |
||||
|
* @Date 2020/4/18 10:59 |
||||
|
**/ |
||||
|
Result sendSmsCode(SendSmsCodeFormDTO formDTO); |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.common.token.dto.result.UserTokenResultDTO> |
||||
|
* @Author yinzuomei |
||||
|
* @Description 3、手机验证码获取组织 |
||||
|
* @Date 2020/4/18 21:11 |
||||
|
**/ |
||||
|
Result<UserTokenResultDTO> getorgs(GovWxmpGetOrgsFormDTO formDTO); |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.UserTokenResultDTO> |
||||
|
* @Author yinzuomei |
||||
|
* @Description 政府端小程序根据wxCode获取上一次登录信息,返回token |
||||
|
* @Date 2020/4/20 11:23 |
||||
|
**/ |
||||
|
Result<UserTokenResultDTO> loginByWxCode(GovWxmpFormDTO formDTO); |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.UserTokenResultDTO> |
||||
|
* @Author yinzuomei |
||||
|
* @Description 4、选择组织,进入首页 |
||||
|
* @Date 2020/4/20 13:08 |
||||
|
**/ |
||||
|
Result<UserTokenResultDTO> enterOrg(GovWxmpEnteOrgFormDTO formDTO); |
||||
|
} |
||||
@ -0,0 +1,264 @@ |
|||||
|
package com.epmet.service.impl; |
||||
|
|
||||
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
||||
|
import com.epmet.common.token.constant.LoginConstant; |
||||
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
||||
|
import com.epmet.commons.tools.security.dto.GovTokenDto; |
||||
|
import com.epmet.commons.tools.utils.CpUserDetailRedis; |
||||
|
import com.epmet.commons.tools.utils.DateUtils; |
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import com.epmet.commons.tools.validator.PhoneValidatorUtils; |
||||
|
import com.epmet.dto.CustomerStaffDTO; |
||||
|
import com.epmet.dto.form.*; |
||||
|
import com.epmet.dto.result.LatestStaffWechatLoginResultDTO; |
||||
|
import com.epmet.dto.result.StaffGridInfoResultDTO; |
||||
|
import com.epmet.dto.result.UserTokenResultDTO; |
||||
|
import com.epmet.feign.EpmetUserFeignClient; |
||||
|
import com.epmet.feign.GovOrgFeignClient; |
||||
|
import com.epmet.feign.MessageFeignClient; |
||||
|
import com.epmet.jwt.JwtTokenProperties; |
||||
|
import com.epmet.jwt.JwtTokenUtils; |
||||
|
import com.epmet.redis.CaptchaRedis; |
||||
|
import com.epmet.service.GovLoginService; |
||||
|
import com.epmet.service.LoginService; |
||||
|
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.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @Description 政府端登录服务 |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 10:56 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class GovLoginServiceImpl implements GovLoginService { |
||||
|
private static final Logger logger = LoggerFactory.getLogger(GovLoginServiceImpl.class); |
||||
|
private static final String SEND_SMS_CODE_ERROR = "发送短信验证码异常,手机号[%s],code[%s],msg[%s]"; |
||||
|
@Autowired |
||||
|
private LoginService loginService; |
||||
|
@Autowired |
||||
|
private EpmetUserFeignClient epmetUserFeignClient; |
||||
|
@Autowired |
||||
|
private CaptchaRedis captchaRedis; |
||||
|
@Autowired |
||||
|
private MessageFeignClient messageFeignClient; |
||||
|
@Autowired |
||||
|
private JwtTokenUtils jwtTokenUtils; |
||||
|
@Autowired |
||||
|
private JwtTokenProperties jwtTokenProperties; |
||||
|
@Autowired |
||||
|
private CpUserDetailRedis cpUserDetailRedis; |
||||
|
@Autowired |
||||
|
private GovOrgFeignClient govOrgFeignClient; |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author yinzuomei |
||||
|
* @Description 政府端微信小程序登录-发送验证码 |
||||
|
* @Date 2020/4/18 10:59 |
||||
|
**/ |
||||
|
@Override |
||||
|
public Result sendSmsCode(SendSmsCodeFormDTO formDTO) { |
||||
|
//1、校验手机号是否符合规范
|
||||
|
if (!PhoneValidatorUtils.isMobile(formDTO.getMobile())) { |
||||
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getMobile(), EpmetErrorCode.ERROR_PHONE.getCode(), EpmetErrorCode.ERROR_PHONE.getMsg())); |
||||
|
return new Result().error(EpmetErrorCode.ERROR_PHONE.getCode()); |
||||
|
} |
||||
|
//2、根据手机号校验用户是否存在
|
||||
|
Result<List<CustomerStaffDTO>> customerStaffResult = epmetUserFeignClient.checkCustomerStaff(formDTO.getMobile()); |
||||
|
if (!customerStaffResult.success()) { |
||||
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getMobile(), customerStaffResult.getCode(), customerStaffResult.getMsg())); |
||||
|
return new Result().error(customerStaffResult.getCode()); |
||||
|
} |
||||
|
//3、发送短信验证码
|
||||
|
Result<Map<String, String>> smsCodeResult = messageFeignClient.sendSmsCaptcha(formDTO.getMobile()); |
||||
|
if (!smsCodeResult.success()) { |
||||
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getMobile(), smsCodeResult.getCode(), smsCodeResult.getMsg())); |
||||
|
return new Result().error(smsCodeResult.getCode()); |
||||
|
} |
||||
|
//4、保存短信验证码(删除现有短信验证码、将新的短信验证码存入Redis)
|
||||
|
captchaRedis.saveSmsCode(formDTO, smsCodeResult.getData().get("code")); |
||||
|
logger.info(String.format("发送短信验证码成功,手机号[%s]", formDTO.getMobile())); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.common.token.dto.result.UserTokenResultDTO> |
||||
|
* @Author yinzuomei |
||||
|
* @Description 3、手机验证码获取组织 |
||||
|
* @Date 2020/4/18 21:11 |
||||
|
**/ |
||||
|
@Override |
||||
|
public Result<UserTokenResultDTO> getorgs(GovWxmpGetOrgsFormDTO formDTO) { |
||||
|
//1、根据手机号查询到用户信息
|
||||
|
Result<List<CustomerStaffDTO>> customerStaffResult = epmetUserFeignClient.checkCustomerStaff(formDTO.getMobile()); |
||||
|
if (!customerStaffResult.success()) { |
||||
|
logger.error(String.format("手机验证码登录异常,手机号[%s],code[%s],msg[%s]", formDTO.getMobile(), customerStaffResult.getCode(), customerStaffResult.getMsg())); |
||||
|
return new Result().error(customerStaffResult.getCode()); |
||||
|
} |
||||
|
//2、验证码是否正确
|
||||
|
String rightSmsCode = captchaRedis.getSmsCode(formDTO); |
||||
|
if (!formDTO.getSmsCode().equals(rightSmsCode)) { |
||||
|
return new Result<UserTokenResultDTO>().error(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); |
||||
|
} |
||||
|
//3、TODO返回组织树
|
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Result<UserTokenResultDTO> loginByWxCode(GovWxmpFormDTO formDTO) { |
||||
|
//1、解析微信用户
|
||||
|
WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(formDTO.getApp(), formDTO.getWxCode()); |
||||
|
Result<LatestStaffWechatLoginResultDTO> latestStaffWechat = epmetUserFeignClient.getLatestStaffWechatLoginRecord(wxMaJscode2SessionResult.getOpenid()); |
||||
|
if (!latestStaffWechat.success() || null == latestStaffWechat.getData()) { |
||||
|
logger.error(String.format("没有获取到用户最近一次登录账户信息,code[%s],msg[%s]", EpmetErrorCode.PLEASE_LOGIN.getCode(), EpmetErrorCode.PLEASE_LOGIN.getMsg())); |
||||
|
return new Result<UserTokenResultDTO>().error(EpmetErrorCode.PLEASE_LOGIN.getCode()); |
||||
|
} |
||||
|
LatestStaffWechatLoginResultDTO latestStaffWechatLoginDTO = latestStaffWechat.getData(); |
||||
|
//2、记录staff_wechat
|
||||
|
this.savestaffwechat(latestStaffWechatLoginDTO.getStaffId(), wxMaJscode2SessionResult.getOpenid()); |
||||
|
//3、记录登录日志
|
||||
|
this.saveStaffLoginRecord(latestStaffWechatLoginDTO); |
||||
|
//4、获取用户token
|
||||
|
String token = this.generateGovWxmpToken(latestStaffWechatLoginDTO.getStaffId()); |
||||
|
//5、保存到redis
|
||||
|
this.saveGovTokenDto(latestStaffWechatLoginDTO.getOrgId(), latestStaffWechatLoginDTO.getGridId(), latestStaffWechatLoginDTO.getStaffId(), wxMaJscode2SessionResult, token); |
||||
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
||||
|
userTokenResultDTO.setToken(token); |
||||
|
return new Result<UserTokenResultDTO>().ok(userTokenResultDTO); |
||||
|
} |
||||
|
|
||||
|
//保存登录日志
|
||||
|
private Result saveStaffLoginRecord(LatestStaffWechatLoginResultDTO latestStaffWechatLoginDTO) { |
||||
|
StaffLoginHistoryFormDTO staffLoginHistoryFormDTO = new StaffLoginHistoryFormDTO(); |
||||
|
staffLoginHistoryFormDTO.setCustomerId(latestStaffWechatLoginDTO.getCustomerId()); |
||||
|
staffLoginHistoryFormDTO.setStaffId(latestStaffWechatLoginDTO.getStaffId()); |
||||
|
staffLoginHistoryFormDTO.setWxOpenId(latestStaffWechatLoginDTO.getWxOpenId()); |
||||
|
staffLoginHistoryFormDTO.setMobile(latestStaffWechatLoginDTO.getMobile()); |
||||
|
staffLoginHistoryFormDTO.setOrgId(latestStaffWechatLoginDTO.getOrgId()); |
||||
|
staffLoginHistoryFormDTO.setGridId(latestStaffWechatLoginDTO.getGridId()); |
||||
|
Result staffLoginRecordResult = epmetUserFeignClient.saveStaffLoginRecord(staffLoginHistoryFormDTO); |
||||
|
return staffLoginRecordResult; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Result<UserTokenResultDTO> enterOrg(GovWxmpEnteOrgFormDTO formDTO) { |
||||
|
//1、需要校验要登录的客户,是否被禁用
|
||||
|
CustomerStaffFormDTO customerStaffFormDTO = new CustomerStaffFormDTO(); |
||||
|
customerStaffFormDTO.setCustomerId(formDTO.getCustomerId()); |
||||
|
customerStaffFormDTO.setMobile(formDTO.getMobile()); |
||||
|
Result<CustomerStaffDTO> customerStaffDTOResult = epmetUserFeignClient.getCustomerStaffInfo(customerStaffFormDTO); |
||||
|
if (!customerStaffDTOResult.success() || null == customerStaffDTOResult.getData()) { |
||||
|
logger.error(String.format("获取工作人员信息失败,手机号[%s],客户id:[%s],code[%s],msg[%s]", formDTO.getMobile(), formDTO.getCustomerId(), customerStaffDTOResult.getCode(), customerStaffDTOResult.getMsg())); |
||||
|
return new Result().error(customerStaffDTOResult.getCode()); |
||||
|
} |
||||
|
CustomerStaffDTO customerStaff = customerStaffDTOResult.getData(); |
||||
|
//2、解析微信用户
|
||||
|
WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(LoginConstant.APP_GOV, formDTO.getWxCode()); |
||||
|
//3、记录staff_wechat
|
||||
|
this.savestaffwechat(customerStaff.getUserId(), wxMaJscode2SessionResult.getOpenid()); |
||||
|
//4、记录登录日志
|
||||
|
StaffGridInfoFormDTO staffGridInfoFormDTO = new StaffGridInfoFormDTO(); |
||||
|
staffGridInfoFormDTO.setCustomerId(formDTO.getCustomerId()); |
||||
|
staffGridInfoFormDTO.setOrgId(formDTO.getOrgId()); |
||||
|
staffGridInfoFormDTO.setStaffId(customerStaff.getUserId()); |
||||
|
Result<List<StaffGridInfoResultDTO>> staffGridInfoListResult = govOrgFeignClient.getStaffGridInfo(staffGridInfoFormDTO); |
||||
|
String gridId = null; |
||||
|
if (staffGridInfoListResult.success() && null != staffGridInfoListResult.getData() && staffGridInfoListResult.getData().size() > 0) { |
||||
|
gridId = staffGridInfoListResult.getData().get(0).getGridId(); |
||||
|
} |
||||
|
this.saveStaffLoginRecord(formDTO, customerStaff.getUserId(), wxMaJscode2SessionResult.getOpenid(), gridId); |
||||
|
UserTokenResultDTO userTokenResultDTO = this.getAuthorizationInfo(formDTO.getOrgId(), gridId, customerStaff.getUserId(), wxMaJscode2SessionResult); |
||||
|
return new Result<UserTokenResultDTO>().ok(userTokenResultDTO); |
||||
|
} |
||||
|
|
||||
|
//保存登录日志
|
||||
|
private Result saveStaffLoginRecord(GovWxmpEnteOrgFormDTO formDTO, String staffId, String openId, String grid) { |
||||
|
StaffLoginHistoryFormDTO staffLoginHistoryFormDTO = new StaffLoginHistoryFormDTO(); |
||||
|
staffLoginHistoryFormDTO.setCustomerId(formDTO.getCustomerId()); |
||||
|
staffLoginHistoryFormDTO.setStaffId(staffId); |
||||
|
staffLoginHistoryFormDTO.setWxOpenId(openId); |
||||
|
staffLoginHistoryFormDTO.setMobile(formDTO.getMobile()); |
||||
|
staffLoginHistoryFormDTO.setOrgId(formDTO.getOrgId()); |
||||
|
staffLoginHistoryFormDTO.setGridId(grid); |
||||
|
Result staffLoginRecordResult = epmetUserFeignClient.saveStaffLoginRecord(staffLoginHistoryFormDTO); |
||||
|
return staffLoginRecordResult; |
||||
|
} |
||||
|
|
||||
|
private UserTokenResultDTO getAuthorizationInfo(String orgId, |
||||
|
String gridId, |
||||
|
String staffId, |
||||
|
WxMaJscode2SessionResult wxMaJscode2SessionResult) { |
||||
|
//1、获取用户token
|
||||
|
String token = this.generateGovWxmpToken(staffId); |
||||
|
//2、保存到redis
|
||||
|
this.saveGovTokenDto(orgId, gridId, staffId, wxMaJscode2SessionResult, token); |
||||
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
||||
|
userTokenResultDTO.setToken(token); |
||||
|
return userTokenResultDTO; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param userId |
||||
|
* @param openid |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author yinzuomei |
||||
|
* @Description 保存微信和当前登录用户关系 |
||||
|
* @Date 2020/4/18 22:54 |
||||
|
**/ |
||||
|
private Result savestaffwechat(String userId, String openid) { |
||||
|
StaffWechatFormDTO staffWechatFormDTO = new StaffWechatFormDTO(); |
||||
|
staffWechatFormDTO.setUserId(userId); |
||||
|
staffWechatFormDTO.setWxOpenId(openid); |
||||
|
return epmetUserFeignClient.savestaffwechat(staffWechatFormDTO); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @Description 生成token |
||||
|
* @Date 2020/4/18 23:04 |
||||
|
**/ |
||||
|
private String generateGovWxmpToken(String staffId) { |
||||
|
Map<String, Object> map = new HashMap<>(); |
||||
|
map.put("app", LoginConstant.APP_GOV); |
||||
|
map.put("client", LoginConstant.CLIENT_WXMP); |
||||
|
map.put("staffId", staffId); |
||||
|
String token = jwtTokenUtils.createToken(map); |
||||
|
logger.info("app:" + LoginConstant.APP_GOV + ";client:" + LoginConstant.CLIENT_WXMP + ";staffId:" + staffId + ";生成token[" + token + "]"); |
||||
|
return token; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @Description 生成token |
||||
|
* @Date 2020/4/18 23:04 |
||||
|
**/ |
||||
|
private String saveGovTokenDto(String orgId, |
||||
|
String gridId, |
||||
|
String staffId, |
||||
|
WxMaJscode2SessionResult wxMaJscode2SessionResult, |
||||
|
String token) { |
||||
|
int expire = jwtTokenProperties.getExpire(); |
||||
|
GovTokenDto govTokenDto = new GovTokenDto(); |
||||
|
govTokenDto.setApp(LoginConstant.APP_GOV); |
||||
|
govTokenDto.setClient(LoginConstant.CLIENT_WXMP); |
||||
|
govTokenDto.setStaffId(staffId); |
||||
|
govTokenDto.setOpenId(wxMaJscode2SessionResult.getOpenid()); |
||||
|
govTokenDto.setSessionKey(wxMaJscode2SessionResult.getSessionKey()); |
||||
|
govTokenDto.setUnionId(wxMaJscode2SessionResult.getUnionid()); |
||||
|
govTokenDto.setToken(token); |
||||
|
govTokenDto.setUpdateTime(System.currentTimeMillis()); |
||||
|
govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); |
||||
|
govTokenDto.setOrgId(orgId); |
||||
|
govTokenDto.setGridId(gridId); |
||||
|
cpUserDetailRedis.set(govTokenDto, expire); |
||||
|
logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); |
||||
|
return token; |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,80 @@ |
|||||
|
package com.epmet.commons.tools.security.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @Description 政府端登录信息 |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 11:01 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class GovTokenDto implements Serializable { |
||||
|
/** |
||||
|
* 政府端:gov、居民端:resi、运营端:oper |
||||
|
*/ |
||||
|
private String app; |
||||
|
|
||||
|
/** |
||||
|
* PC端:web、微信小程序:wxmp |
||||
|
*/ |
||||
|
private String client; |
||||
|
|
||||
|
/** |
||||
|
* 用户ID |
||||
|
*/ |
||||
|
private String staffId; |
||||
|
|
||||
|
/** |
||||
|
* sessionKey |
||||
|
*/ |
||||
|
private String sessionKey; |
||||
|
|
||||
|
/** |
||||
|
* openId |
||||
|
*/ |
||||
|
private String openId; |
||||
|
|
||||
|
/** |
||||
|
* unionId |
||||
|
*/ |
||||
|
private String unionId; |
||||
|
|
||||
|
/** |
||||
|
* token字符串 |
||||
|
*/ |
||||
|
private String token; |
||||
|
|
||||
|
/** |
||||
|
* 过期时间戳 |
||||
|
*/ |
||||
|
private Long expireTime; |
||||
|
|
||||
|
/** |
||||
|
* 最后一次更新时间 |
||||
|
*/ |
||||
|
private long updateTime; |
||||
|
|
||||
|
/** |
||||
|
* 当前登录的组织id |
||||
|
*/ |
||||
|
private String orgId; |
||||
|
|
||||
|
/** |
||||
|
* 待定 |
||||
|
*/ |
||||
|
private String orgIdPath; |
||||
|
|
||||
|
/** |
||||
|
* 待定 |
||||
|
*/ |
||||
|
private String gridId; |
||||
|
|
||||
|
/** |
||||
|
* 待定 |
||||
|
*/ |
||||
|
private List<String> deptIdList; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,30 @@ |
|||||
|
package com.epmet.dto.form; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @Description 根据用户选择的组织,查询用户与网格的关系列表 |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 15:29 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class StaffGridInfoFormDTO implements Serializable { |
||||
|
/** |
||||
|
* 用户选择的组织所属的id |
||||
|
*/ |
||||
|
@NotBlank(message = "客户id不能为空") |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* 用户选择的要进入的组织(根组织id) |
||||
|
*/ |
||||
|
@NotBlank(message = "组织id不能为空") |
||||
|
private String orgId; |
||||
|
|
||||
|
@NotBlank(message = "staffId不能为空") |
||||
|
private String staffId; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,39 @@ |
|||||
|
package com.epmet.dto.result; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @Description 根据用户选择的组织,查询用户与网格的关系列表 |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 15:22 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class StaffGridInfoResultDTO implements Serializable { |
||||
|
/** |
||||
|
* ID 唯一标识 |
||||
|
*/ |
||||
|
private String gridId; |
||||
|
|
||||
|
/** |
||||
|
* 客户ID |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* 网格名称 |
||||
|
*/ |
||||
|
private String gridName; |
||||
|
|
||||
|
/** |
||||
|
* 所属组织机构ID(customer_organization.id) |
||||
|
*/ |
||||
|
private String pid; |
||||
|
|
||||
|
/** |
||||
|
* 所有上级组织ID |
||||
|
*/ |
||||
|
private String pids; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,102 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 工作人员登录日志表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2020-04-20 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class StaffLoginHistoryDTO implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 唯一标识 |
||||
|
*/ |
||||
|
private String id; |
||||
|
|
||||
|
/** |
||||
|
* 客户ID |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* customer_staff.userId |
||||
|
*/ |
||||
|
private String staffId; |
||||
|
|
||||
|
/** |
||||
|
* 微信openId |
||||
|
*/ |
||||
|
private String wxOpenId; |
||||
|
|
||||
|
/** |
||||
|
* 手机号 |
||||
|
*/ |
||||
|
private String mobile; |
||||
|
|
||||
|
/** |
||||
|
* 组织机构id |
||||
|
*/ |
||||
|
private String orgId; |
||||
|
|
||||
|
/** |
||||
|
* 网格表Id (CUSTOMER_GRID.id) |
||||
|
*/ |
||||
|
private String gridId; |
||||
|
|
||||
|
/** |
||||
|
* 删除标识:0.未删除 1.已删除 |
||||
|
*/ |
||||
|
private Integer delFlag; |
||||
|
|
||||
|
/** |
||||
|
* 乐观锁 |
||||
|
*/ |
||||
|
private Integer revision; |
||||
|
|
||||
|
/** |
||||
|
* 创建人 |
||||
|
*/ |
||||
|
private String createdBy; |
||||
|
|
||||
|
/** |
||||
|
* 创建时间,登录时间 |
||||
|
*/ |
||||
|
private Date createdTime; |
||||
|
|
||||
|
/** |
||||
|
* 更新人 |
||||
|
*/ |
||||
|
private String updatedBy; |
||||
|
|
||||
|
/** |
||||
|
* 更新时间 |
||||
|
*/ |
||||
|
private Date updatedTime; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
package com.epmet.dto.form; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @Description 根据手机号+客户id获取工作人员基本信息 |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 14:02 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class CustomerStaffFormDTO implements Serializable { |
||||
|
private static final long serialVersionUID = 7619815083427853431L; |
||||
|
@NotBlank(message = "手机号不能为空") |
||||
|
private String mobile; |
||||
|
@NotBlank(message = "客户id不能为空") |
||||
|
private String customerId; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,44 @@ |
|||||
|
package com.epmet.dto.form; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @Description 保存工作人员登录日志 |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 14:26 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class StaffLoginHistoryFormDTO implements Serializable { |
||||
|
/** |
||||
|
* 客户ID |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* customer_staff.userId |
||||
|
*/ |
||||
|
private String staffId; |
||||
|
|
||||
|
/** |
||||
|
* 微信openId |
||||
|
*/ |
||||
|
private String wxOpenId; |
||||
|
|
||||
|
/** |
||||
|
* 手机号 |
||||
|
*/ |
||||
|
private String mobile; |
||||
|
|
||||
|
/** |
||||
|
* 组织机构id |
||||
|
*/ |
||||
|
private String orgId; |
||||
|
|
||||
|
/** |
||||
|
* 网格表Id (CUSTOMER_GRID.id) |
||||
|
*/ |
||||
|
private String gridId; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,46 @@ |
|||||
|
package com.epmet.dto.result; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @Description 当前微信上次登录的账号信息返参DTO |
||||
|
* @Author yinzuomei |
||||
|
* @Date 2020/4/20 12:23 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class LatestStaffWechatLoginResultDTO implements Serializable { |
||||
|
private static final long serialVersionUID = -7088774184276785902L; |
||||
|
|
||||
|
/** |
||||
|
* 客户ID |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* customer_staff.userId |
||||
|
*/ |
||||
|
private String staffId; |
||||
|
|
||||
|
/** |
||||
|
* 微信openId |
||||
|
*/ |
||||
|
private String wxOpenId; |
||||
|
|
||||
|
/** |
||||
|
* 手机号 |
||||
|
*/ |
||||
|
private String mobile; |
||||
|
|
||||
|
/** |
||||
|
* 组织机构id |
||||
|
*/ |
||||
|
private String orgId; |
||||
|
|
||||
|
/** |
||||
|
* 网格表Id (CUSTOMER_GRID.id) |
||||
|
*/ |
||||
|
private String gridId; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,64 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.controller; |
||||
|
|
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import com.epmet.dto.form.StaffLoginHistoryFormDTO; |
||||
|
import com.epmet.dto.result.LatestStaffWechatLoginResultDTO; |
||||
|
import com.epmet.service.StaffLoginHistoryService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 工作人员登录日志表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2020-04-20 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("staffloginhistory") |
||||
|
public class StaffLoginHistoryController { |
||||
|
|
||||
|
@Autowired |
||||
|
private StaffLoginHistoryService staffLoginHistoryService; |
||||
|
|
||||
|
/** |
||||
|
* @param openId |
||||
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.LatestStaffWechatLoginDTO> |
||||
|
* @Author yinzuomei |
||||
|
* @Description 获取当前微信上次登录的账号信息 |
||||
|
* @Date 2020/4/20 12:42 |
||||
|
**/ |
||||
|
@GetMapping(value = "getlatest/{openId}") |
||||
|
public Result<LatestStaffWechatLoginResultDTO> getLatestStaffWechatLoginRecord(@PathVariable("openId") String openId) { |
||||
|
return staffLoginHistoryService.getLatestStaffWechatLoginRecord(openId); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author yinzuomei |
||||
|
* @Description 保存登录日志 |
||||
|
* @Date 2020/4/20 14:29 |
||||
|
**/ |
||||
|
@PostMapping(value = "saveStaffLoginRecord") |
||||
|
public Result saveStaffLoginRecord(@RequestBody StaffLoginHistoryFormDTO formDTO) { |
||||
|
return staffLoginHistoryService.saveStaffLoginRecord(formDTO); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.dao; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.dao.BaseDao; |
||||
|
import com.epmet.dto.result.LatestStaffWechatLoginResultDTO; |
||||
|
import com.epmet.entity.StaffLoginHistoryEntity; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
/** |
||||
|
* 工作人员登录日志表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2020-04-20 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface StaffLoginHistoryDao extends BaseDao<StaffLoginHistoryEntity> { |
||||
|
|
||||
|
/** |
||||
|
* @return com.epmet.dto.result.LatestStaffWechatLoginDTO |
||||
|
* @param openId |
||||
|
* @Author yinzuomei |
||||
|
* @Description 获取当前微信上次登录的账号信息 |
||||
|
* @Date 2020/4/20 12:45 |
||||
|
**/ |
||||
|
LatestStaffWechatLoginResultDTO selectLatestStaffWechatLoginRecord(String openId); |
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
/** |
||||
|
* 工作人员登录日志表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2020-04-20 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper=false) |
||||
|
@TableName("staff_login_history") |
||||
|
public class StaffLoginHistoryEntity extends BaseEpmetEntity { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 客户ID |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* customer_staff.userId |
||||
|
*/ |
||||
|
private String staffId; |
||||
|
|
||||
|
/** |
||||
|
* 微信openId |
||||
|
*/ |
||||
|
private String wxOpenId; |
||||
|
|
||||
|
/** |
||||
|
* 手机号 |
||||
|
*/ |
||||
|
private String mobile; |
||||
|
|
||||
|
/** |
||||
|
* 组织机构id |
||||
|
*/ |
||||
|
private String orgId; |
||||
|
|
||||
|
/** |
||||
|
* 网格表Id (CUSTOMER_GRID.id) |
||||
|
*/ |
||||
|
private String gridId; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,116 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
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.StaffLoginHistoryDTO; |
||||
|
import com.epmet.dto.form.StaffLoginHistoryFormDTO; |
||||
|
import com.epmet.dto.result.LatestStaffWechatLoginResultDTO; |
||||
|
import com.epmet.entity.StaffLoginHistoryEntity; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 工作人员登录日志表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2020-04-20 |
||||
|
*/ |
||||
|
public interface StaffLoginHistoryService extends BaseService<StaffLoginHistoryEntity> { |
||||
|
|
||||
|
/** |
||||
|
* 默认分页 |
||||
|
* |
||||
|
* @param params |
||||
|
* @return PageData<StaffLoginHistoryDTO> |
||||
|
* @author generator |
||||
|
* @date 2020-04-20 |
||||
|
*/ |
||||
|
PageData<StaffLoginHistoryDTO> page(Map<String, Object> params); |
||||
|
|
||||
|
/** |
||||
|
* 默认查询 |
||||
|
* |
||||
|
* @param params |
||||
|
* @return java.util.List<StaffLoginHistoryDTO> |
||||
|
* @author generator |
||||
|
* @date 2020-04-20 |
||||
|
*/ |
||||
|
List<StaffLoginHistoryDTO> list(Map<String, Object> params); |
||||
|
|
||||
|
/** |
||||
|
* 单条查询 |
||||
|
* |
||||
|
* @param id |
||||
|
* @return StaffLoginHistoryDTO |
||||
|
* @author generator |
||||
|
* @date 2020-04-20 |
||||
|
*/ |
||||
|
StaffLoginHistoryDTO get(String id); |
||||
|
|
||||
|
/** |
||||
|
* 默认保存 |
||||
|
* |
||||
|
* @param dto |
||||
|
* @return void |
||||
|
* @author generator |
||||
|
* @date 2020-04-20 |
||||
|
*/ |
||||
|
void save(StaffLoginHistoryDTO dto); |
||||
|
|
||||
|
/** |
||||
|
* 默认更新 |
||||
|
* |
||||
|
* @param dto |
||||
|
* @return void |
||||
|
* @author generator |
||||
|
* @date 2020-04-20 |
||||
|
*/ |
||||
|
void update(StaffLoginHistoryDTO dto); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除 |
||||
|
* |
||||
|
* @param ids |
||||
|
* @return void |
||||
|
* @author generator |
||||
|
* @date 2020-04-20 |
||||
|
*/ |
||||
|
void delete(String[] ids); |
||||
|
|
||||
|
/** |
||||
|
* @param openId |
||||
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.LatestStaffWechatLoginDTO> |
||||
|
* @Author yinzuomei |
||||
|
* @Description 获取当前微信上次登录的账号信息 |
||||
|
* @Date 2020/4/20 12:43 |
||||
|
**/ |
||||
|
Result<LatestStaffWechatLoginResultDTO> getLatestStaffWechatLoginRecord(String openId); |
||||
|
|
||||
|
/** |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author yinzuomei |
||||
|
* @Description 保存登录日志 |
||||
|
* @Date 2020/4/20 14:33 |
||||
|
**/ |
||||
|
Result saveStaffLoginRecord(StaffLoginHistoryFormDTO formDTO); |
||||
|
} |
||||
@ -0,0 +1,121 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* 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. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
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.utils.Result; |
||||
|
import com.epmet.dao.StaffLoginHistoryDao; |
||||
|
import com.epmet.dto.StaffLoginHistoryDTO; |
||||
|
import com.epmet.dto.form.StaffLoginHistoryFormDTO; |
||||
|
import com.epmet.dto.result.LatestStaffWechatLoginResultDTO; |
||||
|
import com.epmet.entity.StaffLoginHistoryEntity; |
||||
|
import com.epmet.service.StaffLoginHistoryService; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 工作人员登录日志表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2020-04-20 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class StaffLoginHistoryServiceImpl extends BaseServiceImpl<StaffLoginHistoryDao, StaffLoginHistoryEntity> implements StaffLoginHistoryService { |
||||
|
private static final Logger logger = LoggerFactory.getLogger(StaffLoginHistoryServiceImpl.class); |
||||
|
@Override |
||||
|
public PageData<StaffLoginHistoryDTO> page(Map<String, Object> params) { |
||||
|
IPage<StaffLoginHistoryEntity> page = baseDao.selectPage( |
||||
|
getPage(params, FieldConstant.CREATED_TIME, false), |
||||
|
getWrapper(params) |
||||
|
); |
||||
|
return getPageData(page, StaffLoginHistoryDTO.class); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<StaffLoginHistoryDTO> list(Map<String, Object> params) { |
||||
|
List<StaffLoginHistoryEntity> entityList = baseDao.selectList(getWrapper(params)); |
||||
|
|
||||
|
return ConvertUtils.sourceToTarget(entityList, StaffLoginHistoryDTO.class); |
||||
|
} |
||||
|
|
||||
|
private QueryWrapper<StaffLoginHistoryEntity> getWrapper(Map<String, Object> params){ |
||||
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
||||
|
|
||||
|
QueryWrapper<StaffLoginHistoryEntity> wrapper = new QueryWrapper<>(); |
||||
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
||||
|
|
||||
|
return wrapper; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public StaffLoginHistoryDTO get(String id) { |
||||
|
StaffLoginHistoryEntity entity = baseDao.selectById(id); |
||||
|
return ConvertUtils.sourceToTarget(entity, StaffLoginHistoryDTO.class); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void save(StaffLoginHistoryDTO dto) { |
||||
|
StaffLoginHistoryEntity entity = ConvertUtils.sourceToTarget(dto, StaffLoginHistoryEntity.class); |
||||
|
insert(entity); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void update(StaffLoginHistoryDTO dto) { |
||||
|
StaffLoginHistoryEntity entity = ConvertUtils.sourceToTarget(dto, StaffLoginHistoryEntity.class); |
||||
|
updateById(entity); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void delete(String[] ids) { |
||||
|
// 逻辑删除(@TableLogic 注解)
|
||||
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Result<LatestStaffWechatLoginResultDTO> getLatestStaffWechatLoginRecord(String openId) { |
||||
|
if (StringUtils.isNotBlank(openId)) { |
||||
|
logger.error("openId 不能为空"); |
||||
|
return new Result(); |
||||
|
} |
||||
|
LatestStaffWechatLoginResultDTO latestStaffWechatLoginDTO = baseDao.selectLatestStaffWechatLoginRecord(openId); |
||||
|
return new Result<LatestStaffWechatLoginResultDTO>().ok(latestStaffWechatLoginDTO); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Result saveStaffLoginRecord(StaffLoginHistoryFormDTO formDTO) { |
||||
|
StaffLoginHistoryEntity entity = ConvertUtils.sourceToTarget(formDTO, StaffLoginHistoryEntity.class); |
||||
|
insert(entity); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
|
||||
|
<mapper namespace="com.epmet.dao.StaffLoginHistoryDao"> |
||||
|
|
||||
|
<resultMap type="com.epmet.entity.StaffLoginHistoryEntity" id="staffLoginHistoryMap"> |
||||
|
<result property="id" column="ID"/> |
||||
|
<result property="customerId" column="CUSTOMER_ID"/> |
||||
|
<result property="staffId" column="STAFF_ID"/> |
||||
|
<result property="wxOpenId" column="WX_OPEN_ID"/> |
||||
|
<result property="mobile" column="MOBILE"/> |
||||
|
<result property="orgId" column="ORG_ID"/> |
||||
|
<result property="gridId" column="GRID_ID"/> |
||||
|
<result property="delFlag" column="DEL_FLAG"/> |
||||
|
<result property="revision" column="REVISION"/> |
||||
|
<result property="createdBy" column="CREATED_BY"/> |
||||
|
<result property="createdTime" column="CREATED_TIME"/> |
||||
|
<result property="updatedBy" column="UPDATED_BY"/> |
||||
|
<result property="updatedTime" column="UPDATED_TIME"/> |
||||
|
</resultMap> |
||||
|
<!-- 获取当前微信上次登录的账号信息 --> |
||||
|
<select id="selectLatestStaffWechatLoginRecord" parameterType="java.lang.String" resultType="com.epmet.dto.result.LatestStaffWechatLoginResultDTO"> |
||||
|
SELECT |
||||
|
slh.CUSTOMER_ID, |
||||
|
slh.STAFF_ID, |
||||
|
slh.WX_OPEN_ID, |
||||
|
slh.MOBILE, |
||||
|
slh.ORG_ID, |
||||
|
slh.GRID_ID |
||||
|
FROM |
||||
|
staff_login_history slh |
||||
|
WHERE |
||||
|
slh.DEL_FLAG = '0' |
||||
|
AND slh.WX_OPEN_ID =#{openId} |
||||
|
ORDER BY |
||||
|
slh.CREATED_TIME DESC |
||||
|
LIMIT 1 |
||||
|
</select> |
||||
|
|
||||
|
</mapper> |
||||
Loading…
Reference in new issue