|
@@ -1,17 +1,20 @@
|
|
|
package com.rongwei.zhsw.system.wechat.impl;
|
|
|
|
|
|
-import com.rongwe.zhsw.system.vo.OwnerVo;
|
|
|
-import com.rongwe.zhsw.system.vo.SwUserManagementVo;
|
|
|
-import com.rongwe.zhsw.system.vo.WeChatLoginReturnVo;
|
|
|
-import com.rongwe.zhsw.system.vo.WeChatLoginVo;
|
|
|
+import com.google.common.base.Strings;
|
|
|
+import com.rongwe.zhsw.system.domain.SwBusinesshallDo;
|
|
|
+import com.rongwe.zhsw.system.domain.SwEnterpriseConfigInfoDo;
|
|
|
+import com.rongwe.zhsw.system.vo.*;
|
|
|
import com.rongwei.commonservice.service.RedisService;
|
|
|
import com.rongwei.rwadmincommon.system.vo.JwtAuthenticationRequest;
|
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
import com.rongwei.rwcommonentity.commonservers.domain.TenantDo;
|
|
|
+import com.rongwei.zhsw.system.config.WeChatLoginApiPara;
|
|
|
import com.rongwei.zhsw.system.dao.CommonBusinessDao;
|
|
|
import com.rongwei.zhsw.system.fegin.LoginAuth;
|
|
|
+import com.rongwei.zhsw.system.service.impl.SwBusinesshallServiceImpl;
|
|
|
+import com.rongwei.zhsw.system.service.impl.SwEnterpriseConfigInfoServiceImpl;
|
|
|
import com.rongwei.zhsw.system.service.impl.SwUserManagementServiceImpl;
|
|
|
import com.rongwei.zhsw.system.utils.WeChatUtils;
|
|
|
import com.rongwei.zhsw.system.wechat.WeChatLoginService;
|
|
@@ -21,9 +24,7 @@ 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;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.rongwei.zhsw.system.utils.SaveConstans.DEFAULT_OWNER_CACHE_SECONDS;
|
|
@@ -47,18 +48,32 @@ public class WeChatLoginServiceImpl implements WeChatLoginService {
|
|
|
private CommonBusinessDao commonBusinessDao;
|
|
|
@Autowired
|
|
|
private SwUserManagementServiceImpl swUserManagementService;
|
|
|
+ @Autowired
|
|
|
+ private WeChatLoginApiPara autoWeChatLoginApiPara;
|
|
|
+ @Autowired
|
|
|
+ private SwBusinesshallServiceImpl swBusinesshallService;
|
|
|
+ @Autowired
|
|
|
+ private SwEnterpriseConfigInfoServiceImpl swEnterpriseConfigInfoService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public R wechatLogin(WeChatLoginVo weChatLoginVo) {
|
|
|
log.info("微信用户登录");
|
|
|
WeChatLoginReturnVo login = WeChatUtils.getWeChatOpenId(weChatLoginVo.getWxCode());
|
|
|
- if (login == null) {
|
|
|
+ if (login == null || 0 != login.getErrcode()) {
|
|
|
+ log.error("登录异常:{}", login);
|
|
|
throw new CustomException("微信登录异常!请联系水务公司");
|
|
|
}
|
|
|
+ // 当前用户的数据来源
|
|
|
+ String dsKey = weChatLoginVo.getDsKey();
|
|
|
String openId = login.getOpenid();
|
|
|
- List<SwUserManagementVo> userByDsKey= getAllOwnerByOpenId(openId,null);
|
|
|
+ List dsKeyList=StringUtils.isNotBlank(dsKey)? Collections.singletonList(dsKey) :null;
|
|
|
+ List<SwUserManagementVo> userByDsKey = getAllOwnerByOpenId(openId, dsKeyList);
|
|
|
login.setSwUserManagementVos(userByDsKey);
|
|
|
// 生成token
|
|
|
- JwtAuthenticationRequest jwtAuthenticationRequest = new JwtAuthenticationRequest(openId, login.getUnionid(), "wechat");
|
|
|
+ JwtAuthenticationRequest jwtAuthenticationRequest = new JwtAuthenticationRequest(openId, login.getSession_key(), "wechat");
|
|
|
jwtAuthenticationRequest.setExpire(DEFAULT_OWNER_CACHE_SECONDS);
|
|
|
Map<String, Object> tokenmap = loginAuth.getTokenInfo(jwtAuthenticationRequest);
|
|
|
String token = (String) tokenmap.get("token");
|
|
@@ -66,25 +81,58 @@ public class WeChatLoginServiceImpl implements WeChatLoginService {
|
|
|
SysUserVo sysUserVo = new SysUserVo();
|
|
|
sysUserVo.setId(openId);
|
|
|
sysUserVo.setName(openId);
|
|
|
+
|
|
|
TenantDo tenantDo = new TenantDo();
|
|
|
- if (userByDsKey != null) {
|
|
|
+ if (userByDsKey != null && !userByDsKey.isEmpty()) {
|
|
|
tenantDo.setDskey(userByDsKey.get(0).getDsKey());
|
|
|
}
|
|
|
sysUserVo.setTenantDo(tenantDo);
|
|
|
- redisService.redisCatchInit("token-" + token, sysUserVo, DEFAULT_OWNER_CACHE_SECONDS);
|
|
|
+ if(autoWeChatLoginApiPara.isNeverExpires()){
|
|
|
+ redisService.redisCatchInit("token-" + token, sysUserVo, -1);
|
|
|
+ }else {
|
|
|
+ redisService.redisCatchInit("token-" + token, sysUserVo, DEFAULT_OWNER_CACHE_SECONDS);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置水务公司数据字典
|
|
|
+ List<TenantDo> tenantDos = commonBusinessDao.getByDsKey(dsKey);
|
|
|
+ List<String> dsKeys = tenantDos.stream().filter(data -> !"incontrol".equals(data.getDskey())).map(TenantDo::getDskey).collect(Collectors.toList());
|
|
|
+ // 获取营业厅信息
|
|
|
+ List<SwBusinesshallDo> swBusinesshallDos = swBusinesshallService.getBaseMapper().selectListByDsKey(dsKeys);
|
|
|
+ // 获取水站基本配置
|
|
|
+ List<SwEnterpriseConfigInfoDo> swEnterpriseConfigInfoDos = swEnterpriseConfigInfoService.getBaseMapper().selectListByDsKey(dsKeys);
|
|
|
+ // 缓存当前用户可以读取到的水站信息
|
|
|
+ List<WeChatPickerVo> waterCompanys = tenantDos.stream()
|
|
|
+ .filter(data -> !"incontrol".equals(data.getDskey()))
|
|
|
+ .map(data -> {
|
|
|
+ WeChatPickerVo weChatPickerVo = new WeChatPickerVo();
|
|
|
+ weChatPickerVo.setId(data.getDskey());
|
|
|
+ weChatPickerVo.setName(data.getTenantname());
|
|
|
+ weChatPickerVo.setSwCompanyInfo(swEnterpriseConfigInfoDos.stream()
|
|
|
+ .filter(info->data.getDskey().equals(info.getRoption()))
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null));
|
|
|
+ weChatPickerVo.setBusinessPoint(swBusinesshallDos.stream()
|
|
|
+ .filter(sw->data.getDskey().equals(sw.getRoption()))
|
|
|
+ .sorted(Comparator.comparing(SwBusinesshallDo::getOrdernumber))
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ return weChatPickerVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ login.setWaterCompany(waterCompanys);
|
|
|
return R.ok(login);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取当前用户的所有户号信息
|
|
|
+ *
|
|
|
* @param openId
|
|
|
* @param dsKeyList
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<SwUserManagementVo> getAllOwnerByOpenId(String openId,List<String> dsKeyList) {
|
|
|
- if(dsKeyList==null || dsKeyList.isEmpty()){
|
|
|
+ // 获取系统中的所有户号信息
|
|
|
+ public List<SwUserManagementVo> getAllOwnerByOpenId(String openId, List<String> dsKeyList) {
|
|
|
+ if (dsKeyList == null || dsKeyList.isEmpty()) {
|
|
|
List<TenantDo> tenantDos = commonBusinessDao.getById("");
|
|
|
- dsKeyList =tenantDos.stream().map(TenantDo::getDskey).collect(Collectors.toList());
|
|
|
+ dsKeyList = tenantDos.stream().map(TenantDo::getDskey).collect(Collectors.toList());
|
|
|
}
|
|
|
// 获取当前用户所绑定的所有用户信息
|
|
|
Map<String, List<String>> dsANdOwnerIdMap = new HashMap<String, List<String>>();
|
|
@@ -116,4 +164,12 @@ public class WeChatLoginServiceImpl implements WeChatLoginService {
|
|
|
// redisService.redisCatchInit(openId, sysUserVo, DEFAULT_OWNER_CACHE_SECONDS);
|
|
|
return userByDsKey;
|
|
|
}
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String address = "江苏省苏州市昆山市花桥镇同城浦江大厦4号楼701";
|
|
|
+ if (!Strings.isNullOrEmpty(address)) {
|
|
|
+ address = StringUtils.left(address, address.length() - 11).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(address, address.length() - 11), StringUtils.length(address), "*"), "***"));
|
|
|
+ }
|
|
|
+ System.out.println(address);
|
|
|
+ }
|
|
|
}
|