提交 b447473c 编写于 作者:  Peijun.zhao's avatar Peijun.zhao

Merge branch 'release' into 'master'

Release



See merge request !54
流水线 #31160 已失败 于阶段
in 0 second
......@@ -11,7 +11,7 @@
<groupId>com.pica.cloud.account</groupId>
<artifactId>pica-cloud-account-client</artifactId>
<version>1.0.3.8</version>
<version>1.0.4.0</version>
<name>pica-cloud-account-client</name>
<packaging>jar</packaging>
......
......@@ -6,6 +6,7 @@ import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @author andong
......@@ -25,4 +26,7 @@ public interface AccountInfoClient {
@RequestHeader(value = "sourceType") Integer sourceType,
@RequestParam(value = "seconds", required = false) Integer seconds);
@PostMapping("/account/info/wechat/batch")
PicaResponse<Map<Integer,String>> getWechatInfoBatch(@RequestBody List<Integer> docIds);
}
......@@ -155,7 +155,7 @@
<dependency>
<groupId>com.pica.cloud.foundation</groupId>
<artifactId>pica-cloud-encryption-client</artifactId>
<version>1.0.2</version>
<version>1.0.5</version>
<exclusions>
<exclusion>
<groupId>com.pica.cloud.foundation</groupId>
......@@ -222,6 +222,23 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.73</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.pica.cloud.foundation</groupId>-->
<!-- <artifactId>pica-cloud-redis</artifactId>-->
<!-- <version>1.4.0</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <artifactId>jedis</artifactId>-->
<!-- <groupId>redis.clients</groupId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
</dependencies>
......
package com.pica.cloud.account.account.server.controller;
import com.pica.cloud.account.account.common.req.AccountInfoReq;
import com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity;
import com.pica.cloud.account.account.server.service.AccountInfoService;
import com.pica.cloud.account.account.server.service.WechatService;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.service.starter.interceptor.EnabledLoginValidate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* @author andong
......@@ -18,11 +23,14 @@ import java.util.List;
@Api(description = "账号信息")
@RestController
@RequestMapping("/info")
public class AccountInfoController {
public class AccountInfoController extends AccountBaseController {
@Autowired
private AccountInfoService accountInfoService;
@Autowired
private WechatService wechatService;
@ApiOperation("获取用户数量")
@PostMapping("/count")
public PicaResponse<Integer> getCount(@RequestBody AccountInfoReq req) {
......@@ -43,4 +51,19 @@ public class AccountInfoController {
return PicaResponse.toResponse(accountInfoService.getDoctorIds(req));
}
@ApiOperation("获取医生wechat信息")
@GetMapping("/wechat")
@EnabledLoginValidate
public PicaResponse<AccountWeChatInfoEntity> getWechatInfo(@RequestHeader String token) {
return PicaResponse.toResponse(wechatService.getAccountWechatInfo(fetchPicaUser()));
}
@ApiOperation("批量获取医生wechat信息")
@PostMapping("/wechat/batch")
public PicaResponse<Map<Integer,String>> getWechatInfoBatch(@RequestBody List<Integer> docIds) {
return PicaResponse.toResponse(wechatService.getAccountWechatInfoBatch(docIds));
}
}
......@@ -2,11 +2,15 @@ package com.pica.cloud.account.account.server.controller;
import com.pica.cloud.account.account.server.entity.Account;
import com.pica.cloud.account.account.server.service.AccountService;
import com.pica.cloud.foundation.encryption.common.constants.EncryptConstants;
import com.pica.cloud.foundation.encryption.util.EncryptUtils;
import com.pica.cloud.foundation.entity.PicaResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import sun.swing.StringUIClientPropertyKey;
import java.util.Map;
......@@ -27,6 +31,9 @@ public class AccountStatusController extends AccountBaseController {
public PicaResponse<Account> getStatus() {
long doctorId = super.getDoctorIdByToken();
Account account = accountService.getById(doctorId);
if (!StringUtils.isEmpty(account) && !StringUtils.isEmpty(account.getCard())) {
account.setCard(EncryptUtils.decryptContent(account.getCard(), EncryptConstants.ENCRYPT_TYPE_DOCTOR_IDNO, EncryptConstants.ENCRYPT_DECRYPT_KEY));
}
return PicaResponse.toResponse(account);
}
......
......@@ -13,6 +13,7 @@ import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.service.starter.interceptor.EnabledLoginValidate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -46,6 +47,9 @@ public class DoctorController extends AccountBaseController {
String dencrypt = EncryptUtils.decryptContent(mobilePhone, EncryptConstants.ENCRYPT_TYPE_MOBILE, super.getToken());
mobilePhone = dencrypt.substring(0, 3) + "****" + dencrypt.substring(7, 11);
doctorInfo.setMobilePhone(mobilePhone);
if (StringUtils.isNotBlank(doctorInfo.getCard())) {
doctorInfo.setCard(EncryptUtils.decryptContent(doctorInfo.getCard(), EncryptConstants.ENCRYPT_TYPE_DOCTOR_IDNO, EncryptConstants.ENCRYPT_DECRYPT_KEY));
}
return PicaResponse.toResponse(doctorInfo);
}
......
......@@ -11,6 +11,7 @@ import com.pica.cloud.account.account.server.log.AccountLogEntityUtils;
import com.pica.cloud.account.account.server.log.AccountLogUtils;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.req.OneClickLoginReq;
import com.pica.cloud.account.account.server.service.CaptchaService;
import com.pica.cloud.account.account.server.service.DoctorService;
import com.pica.cloud.account.account.server.service.LoginService;
import com.pica.cloud.account.account.server.service.TokenService;
......@@ -18,11 +19,13 @@ import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.CryptoUtil;
import com.pica.cloud.account.account.server.util.RSAUtil;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.entity.PicaWarnException;
import com.pica.cloud.foundation.redis.CacheClient;
import com.pica.cloud.foundation.redis.ICacheClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -58,8 +61,11 @@ public class LoginController extends AccountBaseController {
private String cache_prifix = "cache-";
@Autowired
private CaptchaService captchaService;
/**
* 密码登录接口(app、H5)
* 密码登录接口(app、H5、web
*
* @param authCodeReq
* @return
......@@ -199,12 +205,14 @@ public class LoginController extends AccountBaseController {
cacheClient.expire(cache_prifix + request.getWeChatCode(), 60);
long doctorId = super.getDoctorIdByToken();
logger.info("bindWeChat doctorId:{}",doctorId);
String nickname = loginService.bindWeChat(doctorId, request);
Map<String, String> map = new HashMap();
map.put("nickname", nickname);
// String nickname = loginService.bindWeChat(doctorId, request);
Map<String,String> rtnMap = loginService.bindWeChatMap(doctorId, request);
// Map<String, String> map = new HashMap();
// map.put("nickname", rtnMap.get("nickname"));
//成功以后释放锁
cacheClient.del(cache_prifix + request.getWeChatCode());
return PicaResponse.toResponse(map);
return PicaResponse.toResponse(rtnMap);
} catch (Exception e) {
cacheClient.del(cache_prifix + request.getWeChatCode());
logger.error("bindWeChat-" + e.getMessage(), e);
......@@ -363,4 +371,35 @@ public class LoginController extends AccountBaseController {
LoginResult oneClickLoginResultVo = loginService.oneClickLogin(req);
return PicaResponse.toResponse(oneClickLoginResultVo);
}
@ApiOperation(value = "web登录-图形码")
@PostMapping("/web/captchaPwd")
public PicaResponse<LoginResult> webCaptchaPwd(@RequestBody EncryptEntity entity,
HttpServletRequest req) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
logger.info("webCaptchaPwd:{}", JSONObject.toJSONString(request));
String captchaToken = request.getCaptchaToken();
String captchaAnswer = request.getCaptchaAnswer();
//校验图形验证码
if (!captchaService.acknowledge(captchaToken, captchaAnswer)) {
return PicaResponse.toResponse(null, PicaResultCode.PARAM_IS_INVALID.code(), "图形验证码错误");
}
//原登录逻辑
request.setProductType(super.getProductType());
Integer sourceType = super.getSourceType();
request.setSourceType(sourceType == null ? 0 : sourceType);
request.setLoginIp(super.getIpAddr());
request.setUserTokenTourist(super.getUserTokenTourist());
AccountUtils.checkMobilePhone(request.getMobile());
AccountUtils.checkPassword(request.getPassword());
LoginResult login = loginService.login(request);
if (SourceTypeEnum.SAAS.getCode().equals(sourceType)) {
login.setDoctorId("");
} else {
login.setUserId(null);
}
return PicaResponse.toResponse(login);
}
}
......@@ -3,6 +3,8 @@ package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public interface AccountWeChatInfoMapper {
......@@ -25,5 +27,7 @@ public interface AccountWeChatInfoMapper {
int updateByPrimaryKey(AccountWeChatInfoEntity record);
List<AccountWeChatInfoEntity> selectBatchByUnionId(List<String> list);
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.Doctor;
import com.pica.cloud.account.account.server.entity.DoctorEntity;
import com.pica.cloud.account.account.server.entity.PICAPDoctor;
import com.pica.cloud.account.account.server.model.WechatInfoDto;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
......@@ -112,5 +113,9 @@ public interface DoctorMapper {
*/
Integer updateDoctorModifyRecord();
String getUnionIdByDoctorId(@Param("doctorId") Integer doctorId);
List<WechatInfoDto> getBatchUnionIdByDoctorId(List<Integer> list);
}
\ No newline at end of file
package com.pica.cloud.account.account.server.model;
public class WechatInfoDto {
private Integer doctorId;
private String unionId;
private String openId;
public Integer getDoctorId() {
return doctorId;
}
public void setDoctorId(Integer doctorId) {
this.doctorId = doctorId;
}
public String getOpenId() {
return openId;
}
public void setOpenId(String openId) {
this.openId = openId;
}
public String getUnionId() {
return unionId;
}
public void setUnionId(String unionId) {
this.unionId = unionId;
}
}
......@@ -59,6 +59,8 @@ public interface LoginService {
*/
String bindWeChat(long doctorId, BaseRequest request);
Map bindWeChatMap(long doctorId, BaseRequest request);
PICAPDoctor queryDoctor(long doctorId);
/**
......
package com.pica.cloud.account.account.server.service;
import com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity;
import com.pica.cloud.foundation.utils.entity.PicaUser;
import java.util.List;
import java.util.Map;
public interface WechatService {
AccountWeChatInfoEntity getAccountWechatInfo(PicaUser user);
Map<Integer,String> getAccountWechatInfoBatch(List<Integer> docIds);
}
......@@ -100,6 +100,9 @@ public class AccountServiceImpl implements AccountService {
}else {
accountInfo.setRegisterSource(AccountTypeEnum.DEVICE_TYPE_H5.getCode());
}
if (StringUtils.isNotBlank(accountInfo.getIdCard())) {
accountInfo.setIdCard(EncryptUtils.encryptContent(accountInfo.getIdCard(), EncryptConstants.ENCRYPT_TYPE_DOCTOR_IDNO));
}
accountInfoDetailMapper.insertSelective(accountInfo);
Integer acctId = accountInfo.getId();
//doctor表,存入用户id
......@@ -118,6 +121,9 @@ public class AccountServiceImpl implements AccountService {
account.setModifyTime(currentTime);
account.setFirstLoginTime(currentTime);
account.setLastLoginTime(currentTime);
if (StringUtils.isNotBlank(account.getCard())) {
account.setCard(EncryptUtils.encryptContent(account.getCard(), EncryptConstants.ENCRYPT_TYPE_DOCTOR_IDNO));
}
accountMapper.insertSelective(account);
}
}
......
......@@ -10,6 +10,8 @@ import com.pica.cloud.account.account.server.mapper.*;
import com.pica.cloud.account.account.server.service.DoctorService;
import com.pica.cloud.account.account.server.util.AESUtil;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.foundation.encryption.common.constants.EncryptConstants;
import com.pica.cloud.foundation.encryption.util.EncryptUtils;
import com.pica.cloud.foundation.utils.entity.PicaDoctor;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -73,6 +75,9 @@ public class DoctorServiceImpl implements DoctorService {
}
doctor.setMobilePhone(AESUtil.encryptV0(mobilePhone));
doctor.setModifyTime(new Date());
if (StringUtils.isNotBlank(doctor.getCard())) {
doctor.setCard(EncryptUtils.encryptContent(doctor.getCard(), EncryptConstants.ENCRYPT_TYPE_DOCTOR_IDNO));
}
doctorMapper.updateByPrimaryKeySelective(doctor);
Integer acctId = entity.getAcctId();
AccountInfoEntity accountInfoEntity = new AccountInfoEntity();
......@@ -139,6 +144,7 @@ public class DoctorServiceImpl implements DoctorService {
entity.setDeleteFlag(1);
entity.setSex(doctor.getSex());
entity.setName(doctor.getName());
doctor.setCard(EncryptUtils.encryptContent(doctor.getCard(), EncryptConstants.ENCRYPT_TYPE_DOCTOR_IDNO));
entity.setIdCard(doctor.getCard());
entity.setAge(doctor.getAge());
entity.setBirthday(doctor.getBirthday());
......
......@@ -27,6 +27,7 @@ import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.entity.PicaWarnException;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.StringUtil;
import com.pica.cloud.foundation.utils.utils.ValidateUtils;
import com.pica.cloud.patient.smartcontract.common.utils.HttpClientCloudUtils;
import io.jsonwebtoken.*;
......@@ -397,6 +398,11 @@ public class LoginServiceImpl implements LoginService {
WeChatUserInfoEntity weChatUserInfoEntity = WeChatUtils.mergeWechatUserInfo(weChatUserInfo, weChatEntity.getOpenid());
logger.info("loginByWeChat: 获取微信用户信息:{}",JSONObject.toJSONString(weChatUserInfoEntity));
String unionId = weChatUserInfoEntity.getUnionid();
if(StringUtil.isEmpty(unionId)){
logger.error("loginByWeChat get unionId:{}",unionId);
intactUtil.sendIntact(batchNo,"loginByWeChat",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"微信登录无法获取unionId:");
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_CODE_ERROR.getCode(), AccountExceptionEnum.PICA_WECHAT_CODE_ERROR.getMessage());
}
AccountUnionEntity accountUnionEntity = accountUnionMapper.selectByUnionId(unionId);
logger.info("loginByWeChat accountUnionEntity:{}",JSONObject.toJSONString(accountUnionEntity));
//是否绑定逻辑的判断
......@@ -485,7 +491,8 @@ public class LoginServiceImpl implements LoginService {
result.setMobile(request.getMobile());
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
Integer acctId = accountInfo.getId();
processAccountUnion(acctId, request.getUnionId(), request.getProductType());
AccountWeChatInfoEntity entity = accountWeChatInfoMapper.selectByUnionId(request.getUnionId());
processAccountUnion(acctId, request.getUnionId(), request.getProductType(), entity);
return result;
}
......@@ -519,17 +526,42 @@ public class LoginServiceImpl implements LoginService {
updateWechatInfoUser(entity, weChatUserInfoEntity);
}
Integer acctId = doctorInfoMapper.getAcctIdByDoctorId(doctorId);
processAccountUnion(acctId, unionId, request.getProductType());
processAccountUnion(acctId, unionId, request.getProductType(), entity);
return weChatUserInfoEntity.getNickname();
}
@Override
@Transactional
public Map bindWeChatMap(long doctorId, BaseRequest request) {
WeChatEntity weChatEntity = WeChatUtils.getAuthorizationInfo(appId, appSecret, request.getWeChatCode());
Map map = new HashMap();
map.put("access_token", weChatEntity.getAccess_token());
map.put("openid", weChatEntity.getOpenid());
Map weChatUserInfo = WeChatUtils.getWeChatUserInfo(map, weChatURL);
WeChatUserInfoEntity weChatUserInfoEntity = WeChatUtils.mergeWechatUserInfo(weChatUserInfo, weChatEntity.getOpenid());
String unionId = weChatUserInfoEntity.getUnionid();
AccountWeChatInfoEntity entity = accountWeChatInfoMapper.selectByUnionId(unionId);
if (entity == null) {
processWeChatInfoUser(weChatUserInfoEntity, request.getWeChatLoginType());
} else {
updateWechatInfoUser(entity, weChatUserInfoEntity);
}
Integer acctId = doctorInfoMapper.getAcctIdByDoctorId(doctorId);
processAccountUnion(acctId, unionId, request.getProductType(), entity);
Map<String,String> rtnMap = new HashMap();
rtnMap.put("openId",weChatEntity.getOpenid());
rtnMap.put("nickname",weChatUserInfoEntity.getNickname());
return rtnMap;
}
/**
* 把unionId存储到联合登录表中
*
* @param acctId
* @param unionId
*/
private void processAccountUnion(Integer acctId, String unionId, Integer productType) {
private void processAccountUnion(Integer acctId, String unionId, Integer productType, AccountWeChatInfoEntity entity) {
//接入新旭事务一致性
String batchNo = IntactUtils.getUUID();
if(null == acctId || 0 == acctId){
......@@ -541,32 +573,40 @@ public class LoginServiceImpl implements LoginService {
AccountUnionEntity accountUnionResult = accountUnionMapper.selectByUnionId(unionId);
if (accountUnionResult != null) {
intactUtil.sendIntact(batchNo,"processAccountUnion",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"该微信号已绑定其他云鹊医账户,你可以使用微信登录云鹊医,在「设置」页解除绑定");
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_UNBIND.getCode(), AccountExceptionEnum.PICA_WECHAT_UNBIND.getMessage());
if (entity != null) {
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_UNBIND.getCode(), AccountExceptionEnum.PICA_WECHAT_UNBIND.getMessage());
}
}
Map<String, Object> map = new HashedMap(2);
map.put("acctId", acctId);
map.put("unionType", AccountTypeEnum.UNION_LOGIN_WE_CHAT.getCode());
AccountUnionEntity accountUnionEntityAccount = accountUnionMapper.selectByAcctId(map);
AccountWeChatInfoEntity entity2 = null;
if (accountUnionEntityAccount != null) {
intactUtil.sendIntact(batchNo,"processAccountUnion",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"该手机号已绑定其他微信号,你可以在「设置」页解除绑定");
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getCode(), AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getMessage());
if (entity != null) {
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getCode(), AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getMessage());
}
}
AccountUnionEntity accountUnionEntity = new AccountUnionEntity();
accountUnionEntity.setAcctId(acctId.longValue());
accountUnionEntity.setDeleteFlag(1);
accountUnionEntity.setUnionId(unionId);
accountUnionEntity.setCreatedTime(new Date());
accountUnionEntity.setModifiedTime(new Date());
accountUnionEntity.setCreatedId(acctId);
accountUnionEntity.setModifiedId(acctId);
accountUnionEntity.setUnionType(AccountTypeEnum.UNION_LOGIN_WE_CHAT.getCode());
accountUnionMapper.insertSelective(accountUnionEntity);
if (doubleWritingMode) { //双写模式
doctorService.bindWeChat(acctId, unionId);
if (accountUnionResult == null || accountUnionEntityAccount == null) {
AccountUnionEntity accountUnionEntity = new AccountUnionEntity();
accountUnionEntity.setAcctId(acctId.longValue());
accountUnionEntity.setDeleteFlag(1);
accountUnionEntity.setUnionId(unionId);
accountUnionEntity.setCreatedTime(new Date());
accountUnionEntity.setModifiedTime(new Date());
accountUnionEntity.setCreatedId(acctId);
accountUnionEntity.setModifiedId(acctId);
accountUnionEntity.setUnionType(AccountTypeEnum.UNION_LOGIN_WE_CHAT.getCode());
accountUnionMapper.insertSelective(accountUnionEntity);
if (doubleWritingMode) { //双写模式
doctorService.bindWeChat(acctId, unionId);
}
intactUtil.sendIntact(batchNo, "processAccountUnion", com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3, "acctId:" + acctId + ",unionId:" + unionId + ",productType:" + productType);
}
intactUtil.sendIntact(batchNo,"processAccountUnion",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"acctId:"+acctId+",unionId:"+unionId+",productType:"+productType);
}
......
package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity;
import com.pica.cloud.account.account.server.mapper.AccountWeChatInfoMapper;
import com.pica.cloud.account.account.server.mapper.DoctorMapper;
import com.pica.cloud.account.account.server.model.WechatInfoDto;
import com.pica.cloud.account.account.server.service.WechatService;
import com.pica.cloud.foundation.utils.entity.PicaUser;
import com.pica.cloud.foundation.utils.utils.StringUtil;
import io.swagger.models.auth.In;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class WechatServiceImpl implements WechatService {
@Autowired
private DoctorMapper doctorMapper;
@Autowired
private AccountWeChatInfoMapper weChatInfoMapper;
@Override
public AccountWeChatInfoEntity getAccountWechatInfo(PicaUser user) {
String unionId = doctorMapper.getUnionIdByDoctorId(user.getId());
if(StringUtil.isEmpty(unionId)){
return new AccountWeChatInfoEntity();
}else {
AccountWeChatInfoEntity entity = weChatInfoMapper.selectByUnionId(unionId);
if(entity == null) {
entity = new AccountWeChatInfoEntity();
}
return entity;
}
}
@Override
public Map<Integer, String> getAccountWechatInfoBatch(List<Integer> docIds) {
if(CollectionUtils.isEmpty(docIds)){
return null;
}
Map<Integer, String> doctorOpenMap = new HashMap<>();
List<WechatInfoDto> wechatInfoDtos = doctorMapper.getBatchUnionIdByDoctorId(docIds);
Map<String, Integer> unionMap = new HashMap<>();
for(WechatInfoDto dto : wechatInfoDtos){
unionMap.put(dto.getUnionId(),dto.getDoctorId());
}
List<String> unionIds = wechatInfoDtos.stream().map(obj -> obj.getUnionId()).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(unionIds)){
List<AccountWeChatInfoEntity> wechatList = weChatInfoMapper.selectBatchByUnionId(unionIds);
for(AccountWeChatInfoEntity entity : wechatList){
if(unionMap.containsKey(entity.getUnionid())){
doctorOpenMap.put(unionMap.get(entity.getUnionid()),entity.getOpenid());
}
}
}
for(Integer docId : docIds){
if(!doctorOpenMap.containsKey(docId)){
doctorOpenMap.put(docId,null);
}
}
return doctorOpenMap;
}
}
......@@ -153,11 +153,11 @@ public class AESUtil {
* @return
*/
public static String encryptV0(String data) {
return EncryptCreateUtil.encrypt(data);
return EncryptUtils.encryptContent(data, EncryptConstants.ENCRYPT_TYPE_MOBILE);
}
public static String decryptV0(String data) {
return EncryptCreateUtil.dencrypt(data);
return EncryptUtils.decryptContent(data, EncryptConstants.ENCRYPT_TYPE_MOBILE, EncryptConstants.ENCRYPT_DECRYPT_KEY);
}
public static String decrypt(String sSrc, String sKey, String siv) throws Exception {
......
......@@ -48,6 +48,18 @@
limit 1
</select>
<select id="selectBatchByUnionId" resultMap="BaseResultMap" parameterType="java.util.List">
select
<include refid="Base_Column_List"/>
from account_wechat_info
where unionid in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
and delete_flag = 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from account_wechat_info
where id = #{id,jdbcType=INTEGER}
......
......@@ -1063,5 +1063,24 @@
</foreach>
</update>
<select id="getUnionIdByDoctorId" resultType="java.lang.String" parameterType="java.lang.Integer">
select u.union_id from p_doctor d
join account_info a on d.acct_id = a.id
join account_union u on a.id = u.acct_id
where d.id = #{doctorId} and u.union_type = 1
and d.delete_flag = 1 and a.delete_flag = 1 and u.delete_flag = 1
</select>
<select id="getBatchUnionIdByDoctorId" resultType="com.pica.cloud.account.account.server.model.WechatInfoDto" parameterType="java.util.List">
select u.union_id as unionId, d.id as doctorId from p_doctor d
join account_info a on d.acct_id = a.id
join account_union u on a.id = u.acct_id
where d.id in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
and u.union_type = 1
and d.delete_flag = 1 and a.delete_flag = 1 and u.delete_flag = 1
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册