Browse Source

朝阳 养老驿站填报系统 更新养老机构信息接口代码优化

master
唐周平 1 month ago
parent
commit
fb3f5753d3
3 changed files with 167 additions and 181 deletions
  1. +7
    -2
      mztb/src/main/java/cc/smtweb/biz/mztb/web/base/partyDataFill/PartyDataFillHandler.java
  2. +7
    -1
      mztb/src/main/java/cc/smtweb/biz/mztb/web/base/partyInfo/PartyInfoHandler.java
  3. +153
    -178
      mztb/src/main/java/cc/smtweb/biz/mztb/web/controller/MztbController.java

+ 7
- 2
mztb/src/main/java/cc/smtweb/biz/mztb/web/base/partyDataFill/PartyDataFillHandler.java View File

@@ -1,11 +1,13 @@
package cc.smtweb.biz.mztb.web.base.partyDataFill;

import cc.smtweb.biz.mztb.web.base.*;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.db.EntityHelper;
import cc.smtweb.framework.core.db.cache.DictsCache;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.util.DateUtil;
import cc.smtweb.framework.core.util.StringUtil;
import cc.smtweb.system.bpm.web.engine.dynPage.DynRetBean;
@@ -22,7 +24,6 @@ public class PartyDataFillHandler {
protected static FinanceInfo financeInfo;
protected static YearEndPersons yearEndPersons;
protected static BusinessInfo businessInfo;
// protected static PartyInfo partyInfo;

protected static final String YEAR_END_PERSONS_DS_NAME = "yearEndPersonsForm";
protected static final String FINANCE_DS_NAME = "financeForm";
@@ -95,7 +96,11 @@ public class PartyDataFillHandler {
bean.setUser(UserCache.getInstance().getNameById(us.getUserId()));
DbEngine instance = DbEngine.getInstance();
// 将机构表数据同步到填报主表机构信息中
PartyInfo partyInfo = instance.queryEntity(PartyInfo.class, params.readLong("CUR_PARTY_ID"));
final List<PartyInfo> partyInfos = instance.queryWhere(PartyInfo.class, " pi_sys_party_id = ? ", us.getPartyId());
if(partyInfos == null || partyInfos.size() == 0){
throw new BizException("未找到机构信息");
}
PartyInfo partyInfo = partyInfos.get(0);
SwMap partyInfoData = partyInfo.getData();
partyInfoData.remove("pi_update_at");
partyInfoData.remove("pi_sys_party_id");


+ 7
- 1
mztb/src/main/java/cc/smtweb/biz/mztb/web/base/partyInfo/PartyInfoHandler.java View File

@@ -6,6 +6,7 @@ import cc.smtweb.biz.mztb.web.tool.DbUtil;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.framework.core.util.DateUtil;
@@ -16,6 +17,7 @@ import org.slf4j.LoggerFactory;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;

@@ -60,7 +62,11 @@ public class PartyInfoHandler extends AbstractHandler {
}catch (SQLException sqlException) {
logger.debug("创建 Connection Exception:",sqlException);
}
PartyInfo partyInfo = instance.queryEntity(PartyInfo.class, us.getPartyId());
final List<PartyInfo> partyInfos = instance.queryWhere(PartyInfo.class, " pi_sys_party_id = ? ", us.getPartyId());
if(partyInfos == null || partyInfos.size() == 0){
throw new BizException("未找到机构信息");
}
PartyInfo partyInfo = partyInfos.get(0);
DbUtil dbUtil = new DbUtil(connection);
SwMap swmap = partyInfo.getData();
// 处理前置库和本系统 机构表不同的字段


+ 153
- 178
mztb/src/main/java/cc/smtweb/biz/mztb/web/controller/MztbController.java View File

@@ -20,10 +20,7 @@ import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -38,14 +35,23 @@ public class MztbController {

private static final String PWD_SALT = "goodpj";

/**
* 民政端推送机构数据
* @param swMap
* @return
*/
@PostMapping("/push")
@ResponseBody
public R pushWork(@RequestBody SwMap swMap) {
log.info("收到民政端推送机构数据,请求参数:"+swMap);
// addNewPartyAccount();
DbEngine instance = DbEngine.getInstance();
log.info("传入isRet参数,视为删除机构数据");
if (swMap.containsKey("isRet")){
//删除养老机构
String codes = swMap.readString("code");
if (codes.isEmpty()){
log.info("未传入需要删除的统一社会信用代码!");
return R.error(2,"未获取到需要删除的统一社会信用代码!");
}
//先将所有需要删除的用户查出 然后根据id去删除其他相关表数据
@@ -70,194 +76,162 @@ public class MztbController {
num.set(instance.findDao(User.class).batchDelete(userList));
});

if (num.get() == codeList.size()){
log.info("删除成功!");
return R.success();
}else {
if (num.get() != codeList.size()){
log.info("删除失败!");
List<User> users = instance.queryWhere(User.class, " sur_nicky in (" + codes + ")");
String retCodes = users.stream().map(User::getNicky).collect(Collectors.joining(","));
return R.error(3,retCodes);
}
log.info("删除成功!");
return R.success();
}

}else {
List<Map<String, Object>> updatePartyList = swMap.readListMap("data");

if (updatePartyList == null || updatePartyList.size() < 1) {
log.info("请求携带需要更新的机构数据为空!");
return R.success();
/*****************非删除机构,而是同步机构数据************************/
List<Map<String, Object>> paramData = swMap.readListMap("data");
if (paramData == null || paramData.size() < 1) {
log.info("请求携带需要更新的机构数据为空!");
return R.success();
}
log.debug("获取到数据:"+paramData.size()+"条,准备处理机构数据");
//已有的机构数据则更新、不存在的则新增,同时检测并添加不存在的账号,
Map<String, PartyInfo> tbPartyInfoMapByCode = instance.query(PartyInfo.class).stream().collect(Collectors.toMap(PartyInfo::getCreditCode, Function.identity()));
List<PartyInfo> updPartyInfoList = new ArrayList<>();
List<PartyInfo> addPartyInfoList = new ArrayList<>();
List<Party> addPartyList = new ArrayList<>();
Set<String> addPartyIdSet = new HashSet<>();
List<User> addUserList = new ArrayList<>();
List<Dept> addDeptList = new ArrayList<>();
List<UserParty> addUserPartyList = new ArrayList<>();
List<UserRole> addUserRoleList = new ArrayList<>();
List<UserStatu> addUserStatuList = new ArrayList<>();
Set<String> orgCodeMap = new HashSet<>();
for (Map<String, Object> orgInfo : paramData) {
SwMap data = new SwMap();
data.putAll(orgInfo);
String orgCode = data.readString("pi_credit_code");
if(StringUtil.isEmpty(orgCode) || orgCodeMap.contains(orgCode)){
//一次机构 同一个信用代码的只接受一次
log.info("信用代码为空或者重复,跳过处理!数据为:"+orgInfo);
continue;
}else{
orgCodeMap.add(orgCode);
}
//新增或同步机构数据
PartyInfo partyInfo = new PartyInfo();
partyInfo.init();
partyInfo.getData().putAll(orgInfo);
if(tbPartyInfoMapByCode.containsKey(orgCode)){
//机构已存在,只更新数据
partyInfo.setId(tbPartyInfoMapByCode.get(orgCode).getId());
partyInfo.setSysPartyId(tbPartyInfoMapByCode.get(orgCode).getSysPartyId());
updPartyInfoList.add(partyInfo);
}else{
partyInfo.setId(DbEngine.getInstance().nextId());
addPartyInfoList.add(partyInfo);
}
log.debug("获取到数据:"+updatePartyList.size()+"条,准备处理机构数据。。。。。");

// 批量处理的数据
List<PartyInfo> partysUpdateList = new ArrayList<>();
List<PartyInfo> partysInsertList = new ArrayList<>();
List<Party> sysPartyList = new ArrayList<>();
List<User> userList = new ArrayList<>();
List<UserParty> userPartyList = new ArrayList<>();
List<Dept> deptList = new ArrayList<>();
List<UserRole> userRoleList = new ArrayList<>();
List<UserStatu> userStatuList = new ArrayList<>();

List<String> ptIdList = new ArrayList<>();

// 记录重复数据
List<PartyInfo> partysInsertListExist = new ArrayList<>();
List<Party> sysPartyListExist = new ArrayList<>();
List<User> userListExist = new ArrayList<>();
List<UserParty> userPartyListExist = new ArrayList<>();
List<Dept> deptListExist = new ArrayList<>();
List<String> ptIdListExist = new ArrayList<>();
List<UserRole> userRoleListExist = new ArrayList<>();
List<UserStatu> userStatuListExist = new ArrayList<>();

SwMap existPartyMap = new SwMap();
int insertIndex = 0;
// 使用社会信用代码 当做key 查询当前机构信息
Map<String, PartyInfo> partyInfoMap = instance.query(PartyInfo.class).stream().collect(Collectors.toMap(PartyInfo::getCreditCode, Function.identity()));
for (Map<String, Object> map : updatePartyList) {
PartyInfo partyInfo = new PartyInfo();
SwMap updatePartySwMap = new SwMap();
for (String key : map.keySet()) { // 注意民政端推送数据的字段和填报系统字段要一致
updatePartySwMap.put(key, map.get(key));
}
// 将查询到的数据转为 填报系统机构表数据
partyInfo.getData().putAll(updatePartySwMap);
if (partyInfoMap.containsKey(map.get("pi_credit_code") + "")) { // 判断该机构是否存在
long piIdOld = partyInfoMap.get(map.get("pi_credit_code") + "").getId();
long sysPartyId = partyInfoMap.get(map.get("pi_credit_code") + "").getSysPartyId();
partyInfo.setId(piIdOld);
partyInfo.setSysPartyId(sysPartyId);
partysUpdateList.add(partyInfo);
} else { // 新增(包括 底层的party 填报系统的 partyInfo 默认的用户)
boolean existParty = existPartyMap.containsKey(map.get("pi_credit_code") + "");
if (existParty) {
// 包含就更新机构信息 ,系统机构信息没有可更改的内容故不处理
int index = existPartyMap.readInt(map.get("pi_credit_code") + "");
partysInsertListExist.add(partysInsertList.get(index));
userListExist.add(userList.get(index));
userPartyListExist.add(userPartyList.get(index));
sysPartyListExist.add(sysPartyList.get(index));
deptListExist.add(deptList.get(index));
userRoleListExist.add(userRoleList.get(index));
userStatuListExist.add(userStatuList.get(index));
ptIdListExist.add(ptIdList.get(index));
}
partyInfo.setId(instance.nextId());
existPartyMap.put(map.get("pi_credit_code") + "", insertIndex);
insertIndex++;

Party party = new Party(); // 底层机构表
party.init();
// long ptId = Long.parseLong(map.get("pi_id") + "");
// party.setId(ptId);
// party.setCode(ptId + "");
party.setId(partyInfo.getId());
party.setCode(partyInfo.getId() + "");
party.setName(partyInfo.getPartyName());
party.setType(101);
party.setAreaId(Long.parseLong(partyInfo.getAreaCode()));
// partyInfo.setSysPartyId(ptId);
sysPartyList.add(party);
partysInsertList.add(partyInfo);
// 添加机构id
ptIdList.add(partyInfo.getId() + "");

User user = new User(); // 底层用户表
user.init();
long userId = instance.nextId();
user.setId(userId);
user.setCode(partyInfo.getCreditCode());
user.setName(partyInfo.getPartyName() + "-填报人员");
user.setNicky(partyInfo.getCreditCode());
user.setLevel(100);
user.setStatu(1);
//判断系统机构是否存在 ,不存在 则新增
Party party = PartyCache.getInstance().getByCode(orgCode);
if (party == null) {
party = new Party(); // 底层机构表
party.init();
party.setId(partyInfo.getId());
party.setCode(partyInfo.getCreditCode());
party.setName(partyInfo.getPartyName());
party.setType(101);
party.setAreaId(Long.parseLong(partyInfo.getAreaCode()));
partyInfo.setSysPartyId(party.getId());
addPartyList.add(party);
addPartyIdSet.add(String.valueOf(party.getId()));
}
//添加系统用户
User user = UserCache.getInstance().getByCode(partyInfo.getCreditCode());
if(user == null){
user = new User();
user.init();
long userId = instance.nextId();
user.setId(userId);
user.setCode(partyInfo.getCreditCode());
user.setName(partyInfo.getPartyName() + "-填报人员");
user.setNicky(partyInfo.getCreditCode());
user.setLevel(100);
user.setStatu(1);
// user.setPwd("13217b04835b4cbceb55edb54a72deb4"); //默认密码 abc@123456
user.setPwd(DigestUtils.md5Hex(PWD_SALT + user.getId() + "abc@123456")); //默认密码 abc@123456
user.setPwdLevel(0);
userList.add(user);

Dept dept = new Dept();// 添加部门
dept.init();
long deptId = instance.nextId();
dept.setId(deptId);
dept.setCode(RandomUtil.randomString(8));
dept.setName("填报部门");
dept.setType("100");
dept.setPtId(partyInfo.getId());
dept.setStatu(0);
deptList.add(dept);

UserParty userParty = new UserParty(); //用户机构关联表
long userPartyId = instance.nextId();
userParty.setId(userPartyId);
userParty.setPartyId(partyInfo.getId());
userParty.setUserId(userId);
userParty.setDeptId(deptId); // 关联部门表
userPartyList.add(userParty);

UserRole userRole = new UserRole(); // 用户角色
userRole.setId(instance.nextId());
userRole.setSupId(userPartyId);
userRole.setRoleGroupId(927515588790587392L); // 角色组id todo 先写死 一般不会变
userRoleList.add(userRole);

UserStatu userStatu = new UserStatu(); // 用户登录状态
userStatu.init();
userStatu.setId(userId);
userStatuList.add(userStatu);
}
user.setPwd(DigestUtils.md5Hex(PWD_SALT + user.getId() + "abc@123456")); //默认密码 abc@123456
user.setPwdLevel(0);
addUserList.add(user);

Dept dept = new Dept();// 添加部门
dept.init();
long deptId = instance.nextId();
dept.setId(deptId);
dept.setCode(RandomUtil.randomString(8));
dept.setName("填报部门");
dept.setType("100");
dept.setPtId(party.getId());
dept.setStatu(0);
addDeptList.add(dept);

UserParty userParty = new UserParty(); //用户机构关联表
long userPartyId = instance.nextId();
userParty.setId(userPartyId);
userParty.setPartyId(party.getId());
userParty.setUserId(userId);
userParty.setDeptId(deptId); // 关联部门表
addUserPartyList.add(userParty);

UserRole userRole = new UserRole(); // 用户角色
userRole.setId(instance.nextId());
userRole.setSupId(userPartyId);
userRole.setRoleGroupId(927515588790587392L); // 角色组id todo 先写死 一般不会变
addUserRoleList.add(userRole);

UserStatu userStatu = new UserStatu(); // 用户登录状态
userStatu.init();
userStatu.setId(userId);
addUserStatuList.add(userStatu);
}

// 删除重复新增的元素
partysInsertList.removeAll(partysInsertListExist);
sysPartyList.removeAll(sysPartyListExist);
userList.removeAll(userListExist);
userPartyList.removeAll(userPartyListExist);
deptList.removeAll(deptListExist);
userRoleList.removeAll(userRoleListExist);
userStatuList.removeAll(userStatuListExist);
ptIdList.removeAll(ptIdListExist);

log.debug("数据构建完成,向数据库写入数据");
instance.doTrans(() -> {
// 处理新增或者修改的数据
instance.findDao(PartyInfo.class).batchInsertEntity(partysInsertList);
instance.findDao(PartyInfo.class).batchUpdateEntity(partysUpdateList);
instance.findDao(Party.class).batchInsertEntity(sysPartyList);
instance.findDao(User.class).batchInsertEntity(userList);
instance.findDao(UserParty.class).batchInsertEntity(userPartyList);
instance.findDao(Dept.class).batchInsertEntity(deptList);
instance.findDao(UserRole.class).batchInsertEntity(userRoleList);
instance.findDao(UserStatu.class).batchInsertEntity(userStatuList);
log.debug("数据写入完成-----");

// 将新增的机构 加入角色组的 机构字段
if (ptIdList.size() > 0) {
instance.update("UPDATE " + EntityHelper.getSchemaTableName(RoleGroup.ENTITY_NAME)
+ " SET srg_party_id = CONCAT(srg_party_id,',' ,'" + String.join(",", ptIdList) + "') where srg_id = ? ", 927515588790587392L); // 角色组填报员
}
// 将机构、用户信息放入缓存,或者刷新缓存
// PartyCache.getInstance().putList(sysPartyList);
PartyCache.getInstance().refresh();
// UserCache.getInstance().putList(userList);
UserCache.getInstance().refresh();
// UserPartyCache.getInstance().putList(userPartyList);
UserPartyCache.getInstance().refresh();
// DeptCache.getInstance().putList(deptList);
DeptCache.getInstance().refresh();
// UserRoleCache.getInstance().putList(userRoleList);
UserRoleCache.getInstance().refresh();
// UserStatuCache.getInstance().putList(userStatuList);
UserStatuCache.getInstance().refresh();
RoleGroupCache.getInstance().refresh();
log.debug("机构缓存刷新完成!");
});
return R.success();
}
instance.doTrans(() -> {
// 处理新增或者修改的数据
instance.findDao(PartyInfo.class).batchInsertEntity(addPartyInfoList);
instance.findDao(PartyInfo.class).batchUpdateEntity(updPartyInfoList);
instance.findDao(Party.class).batchInsertEntity(addPartyList);
instance.findDao(User.class).batchInsertEntity(addUserList);
instance.findDao(UserParty.class).batchInsertEntity(addUserPartyList);
instance.findDao(Dept.class).batchInsertEntity(addDeptList);
instance.findDao(UserRole.class).batchInsertEntity(addUserRoleList);
instance.findDao(UserStatu.class).batchInsertEntity(addUserStatuList);
log.debug("数据写入完成-----");

// 将新增的机构 加入角色组的 机构字段
if (addPartyIdSet.size() > 0) {
instance.update("UPDATE " + EntityHelper.getSchemaTableName(RoleGroup.ENTITY_NAME)
+ " SET srg_party_id = CONCAT(srg_party_id,',' ,'" + String.join(",", addPartyIdSet) + "') where srg_id = ? ", 927515588790587392L); // 角色组填报员
}
// 将机构、用户信息放入缓存,或者刷新缓存
PartyCache.getInstance().refresh();
UserCache.getInstance().refresh();
UserPartyCache.getInstance().refresh();
DeptCache.getInstance().refresh();
UserRoleCache.getInstance().refresh();
UserStatuCache.getInstance().refresh();
RoleGroupCache.getInstance().refresh();
log.debug("机构缓存刷新完成!");
});
log.debug("数据写入完成-----,updPartyInfoList:"+updPartyInfoList.size()
+",addPartyInfoList:"+addPartyInfoList.size()
+",addPartyList:"+addPartyList.size()
+",addUserList:"+addUserList.size()
+",addUserPartyList:"+addUserPartyList.size()
+",addDeptList:"+addDeptList.size()
+",addUserRoleList:"+addUserRoleList.size()
+",addUserStatuList:"+addUserStatuList.size());
return R.success();
}


//民政端拉取填报数据
@PostMapping("/pull")
@ResponseBody
public R pullWork(@RequestBody SwMap swMap) {
@@ -298,6 +272,7 @@ public class MztbController {
return R.success(query);
}

//数据驳回
@PostMapping("/dataReject")
@ResponseBody
public R dataRejectWorker(@RequestBody SwMap swMap) {


Loading…
Cancel
Save