Commit e09f18ba authored by wujiang's avatar wujiang

修改同步企业账户

parent 21f89e8c
package com.yeejoin.amos.boot.module.tzs.biz.listener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.paho.client.mqttv3.MqttMessage;
......@@ -14,8 +18,11 @@ import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqxListener;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.service.IDataDictionaryService;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.utils.DesUtil;
import com.yeejoin.amos.boot.module.tzs.biz.utils.RedisUtil;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
......@@ -45,6 +52,10 @@ public class BaseEnterpriseMqTtlListener extends EmqxListener {
String appkey;
@Autowired
RedisUtil redisUtil;
@Autowired
DataDictionaryServiceImpl iDataDictionaryService;
@Override
public void processMessage(String topic, MqttMessage message) throws Exception {
......@@ -60,8 +71,8 @@ public class BaseEnterpriseMqTtlListener extends EmqxListener {
RequestContext.setToken(String.valueOf(redisUtil.get("platform_token")));
FeignClientResult<List<ApplicationModel>> aResult = Privilege.applicationClient.queryAgencyApplications();
List<ApplicationModel> aList = aResult.getResult();
List<String> appCodes = aList.stream().filter(i -> "监管端,企业端".indexOf(i.getAppName()) != -1)
.map(i -> i.getAppCode()).collect(Collectors.toList());
// List<String> appCodes = aList.stream().filter(i -> "监管端,企业端".indexOf(i.getAppName()) != -1)
// .map(i -> i.getAppCode()).collect(Collectors.toList());
FeignClientResult<CompanyModel> cResult = Privilege.companyClient.seleteOne(object.getLong("sequence_nbr"));
// FeignClientResult<Collection<CompanyModel>> cResult =
// Privilege.companyClient.queryAgencyTree(null);
......@@ -72,7 +83,8 @@ public class BaseEnterpriseMqTtlListener extends EmqxListener {
companyModel.setCompanyName(object.getString("use_unit"));
companyModel.setParentId(0L);
companyModel.setLevel("company");
companyModel.setCompanyType("使用单位");
String unitTypes = object.getString("unit_type");
companyModel.setCompanyType(unitTypes);
// companyModel.setSequenceNbr(object.getLong("sequence_nbr"));
companyModel.setCompanyCode(useCode);
if (object.getString("supervise_org_code") != null) {
......@@ -85,7 +97,7 @@ public class BaseEnterpriseMqTtlListener extends EmqxListener {
}
}
FeignClientResult<CompanyModel> createResult = Privilege.companyClient.create(companyModel);
Long companySqr = createResult.getResult().getSequenceNbr();
String unitCode = object.getString("use_code");
if (unitCode == null || unitCode.length() < 6) {
log.error("公司统一信用代码长度不够6位");
......@@ -94,6 +106,8 @@ public class BaseEnterpriseMqTtlListener extends EmqxListener {
String userName = unitCode.substring(unitCode.length() - 6, unitCode.length());
FeignClientResult<AgencyUserModel> uResult = Privilege.agencyUserClient.queryByUserName(userName);
if (uResult.getResult() == null) {
FeignClientResult<List<RoleModel>> roleListResult = Privilege.roleClient.queryRoleList(null, null);
List<RoleModel> allRoleList = roleListResult.getResult();
AgencyUserModel userModel = new AgencyUserModel();
userModel.setUserName(userName);
userModel.setRealName(userName);
......@@ -101,18 +115,32 @@ public class BaseEnterpriseMqTtlListener extends EmqxListener {
userModel.setRePassword(DesUtil.encode(userName, secretKey));
// userModel.setMobile(vo.getPhoneNo());
userModel.setLockStatus("UNLOCK");
FeignClientResult<List<RoleModel>> list = Privilege.roleClient.queryRoleList("使用单位", "admin");
Map<Long, List<Long>> orgRoles = new HashMap<>();
// FeignClientResult<List<RoleModel>> list =
// Privilege.roleClient.queryRoleList("使用单位", "admin");
String[] unitTypeArray = unitTypes.split(",");
List<String> unitTypeList = Arrays.asList(unitTypeArray);
Set<String> roleNameSet =new HashSet<>();
Set<String> appCodesSet = new HashSet<>();
List<RoleModel> userRoleList = new ArrayList<>();
List<Long> roleIds = new ArrayList<>();
roleIds.add(list.getResult().get(0).getSequenceNbr());
// orgRoles.put(object.getLong("sequence_nbr"), roleIds);
orgRoles.put(createResult.getResult().getSequenceNbr(), roleIds);
userModel.setAppCodes(appCodes);
userModel.setOrgRoleSeqs(orgRoles);
Map<Long, List<Long>> roleSeqMap = new HashMap<>();
for (String unitTypeStr : unitTypeList) {
DataDictionary unitType = iDataDictionaryService
.getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getName, unitTypeStr));
String appCode = unitType.getTypeDesc() != null ? unitType.getTypeDesc() : "";
String[] appCodes = appCode.split(",");
Collections.addAll(appCodesSet, appCodes);
roleNameSet.add(unitType.getName());
userRoleList = allRoleList.stream().filter(r -> r.getRoleName().equals(unitType.getName()))
.collect(Collectors.toList());
userRoleList.forEach(r -> roleIds.add(r.getSequenceNbr()));
roleSeqMap.put(companySqr, roleIds);
}
userModel.setAppCodes(new ArrayList<>(appCodesSet));
userModel.setOrgRoleSeqs(roleSeqMap);
Privilege.agencyUserClient.create(userModel);
}
}
}
private boolean isUse(String useCode, Collection<CompanyModel> companys) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment