package com.changhong.epc.tenant.service.sunCloud.impl;
|
|
import com.changhong.epc.bean.admin.Account;
|
import com.changhong.epc.bean.admin.CorresElField;
|
import com.changhong.epc.bean.form.CheckBuget;
|
import com.changhong.epc.bean.form.FormDataEntity;
|
import com.changhong.epc.bean.parsing.BillInfo;
|
import com.changhong.epc.bean.tenant.bill.RuleCheckMsg;
|
import com.changhong.epc.bean.tenant.cost.CostType;
|
import com.changhong.epc.bean.tenant.cost.extend.CostTypeExtend;
|
import com.changhong.epc.bean.tenant.master.MasterDefine;
|
import com.changhong.epc.bean.tenant.master.MasterElement;
|
import com.changhong.epc.bean.tenant.master.MasterValue;
|
import com.changhong.epc.bean.tenant.sunCloud.*;
|
import com.changhong.epc.constter.admin.AdminUrlConst;
|
import com.changhong.epc.constter.base.Context;
|
import com.changhong.epc.constter.cache.master.MasterCache;
|
import com.changhong.epc.constter.form.utf.FormUrlConst;
|
import com.changhong.epc.constter.system.SystemClients;
|
import com.changhong.epc.constter.system.run.EpcRestInterface;
|
import com.changhong.epc.constter.tenant.SunCloudConst;
|
import com.changhong.epc.rely.api.epc.admin.CorresElFieldApi;
|
import com.changhong.epc.rely.api.service.CscApiService;
|
import com.changhong.epc.rely.api.tool.VersionFilterApi;
|
import com.changhong.epc.tenant.controller.sunCloud.ValidateTool;
|
import com.changhong.epc.tenant.mapper.tenant.bill.BillInfoMapper;
|
import com.changhong.epc.tenant.mapper.tenant.bill.RuleCheckMsgMapper;
|
import com.changhong.epc.tenant.mapper.tenant.cost.CostTypeMapper;
|
import com.changhong.epc.tenant.mapper.tenant.norm.MasterDefineMapper;
|
import com.changhong.epc.tenant.mapper.tenant.norm.MasterElementMapper;
|
import com.changhong.epc.tenant.mapper.tenant.norm.MasterValueMapper;
|
import com.changhong.epc.tenant.service.sunCloud.SunCloudService;
|
import com.iemsoft.framework.cloud.core.base.ResMsg;
|
import com.iemsoft.framework.cloud.core.constant.BaseConst;
|
import com.iemsoft.framework.cloud.core.exception.IEMRestException;
|
import com.iemsoft.framework.cloud.core.exception.IEMRuntimeException;
|
import com.iemsoft.framework.cloud.core.thread.Keys;
|
import com.iemsoft.framework.cloud.core.thread.ThreadData;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
|
import com.iemsoft.framework.cloud.redis.annotation.CacheRm;
|
import com.iemsoft.framework.cloud.ribbon.RestInterface;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.map.HashedMap;
|
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.math.NumberUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.ui.ModelMap;
|
|
import javax.annotation.Resource;
|
import java.math.BigInteger;
|
import java.util.*;
|
@Slf4j
|
@Service
|
public class SunCloudServiceImpl implements SunCloudService, SystemClients, SunCloudConst, BaseConst, MasterCache {
|
|
@Resource
|
private MasterValueMapper masterValueMapper;
|
|
@Resource
|
private MasterDefineMapper masterDefineMapper;
|
|
@Resource
|
private MasterElementMapper masterElementMapper;
|
|
@Resource
|
private CscApiService cscApiService;
|
|
@Resource
|
private CostTypeMapper costTypeMapper;
|
|
|
@Resource
|
private BillInfoMapper billInfoMapper;
|
|
@Resource
|
private RuleCheckMsgMapper ruleCheckMsgMapper;
|
|
|
/*
|
* 下标key
|
*/
|
public static final String INDEX_KEY = "index";
|
|
/*
|
* 删除标记
|
*/
|
public static final String DEL_FLAG = "delFlag";
|
|
/*
|
* 行号
|
*/
|
public static final String ROW_NUM = "rowNum";
|
|
public static final String MAS_DATA_DEF_CODE = "masDataDefCode";
|
|
private Integer tenantId;
|
|
private boolean isNotNull;
|
|
public static final String L = "0";
|
|
public static final String DEFINE_CODE = "masDataDefcode";
|
|
public static final String CODE = "code";
|
|
|
public static final String VALUE = "value";
|
|
//业务类型常量key
|
private static final String BUSINESS_TYPE = "businessType";
|
|
@Transactional
|
@Override
|
public int addCheckResult(String data) {
|
|
CheckResult checkMsg =JSONTool.toObj(data, CheckResult.class);
|
//参数
|
RuleCheckMsg ruleCheckMsg = new RuleCheckMsg(checkMsg.getOrderCode(),data);
|
ruleCheckMsg.setDataStart(INVALID_DATA_FLGE.intValue());
|
ruleCheckMsgMapper.updateStrat(ruleCheckMsg.getOrderCode());
|
ruleCheckMsg.initParam();
|
int i = ruleCheckMsgMapper.insert(ruleCheckMsg);
|
// if(i>0){
|
// log.debug("********规则检查成功!!!");
|
// log.debug("********修改票据状态!!!");
|
// int b = billInfoMapper.updateBillState(ruleCheckMsg.getOrderCode());
|
// if(b>0){
|
// log.debug("********修改票据状态成功!!!");
|
// }else{
|
// log.debug("********票据为不可分配状态!!!");
|
// }
|
// }
|
return i;
|
}
|
|
@Transactional
|
@Override
|
public int updateBillStatus(UpdateBillStatus updateBillStatus) {
|
//参数
|
/*OrderStatus orderStatus = new OrderStatus();
|
orderStatus.setOrderCode(updateBillStatus.getOrderCode());
|
orderStatus.setOrderStatus(updateBillStatus.getOrderStatus());
|
orderStatus.setTenantId(Integer.parseInt(updateBillStatus.getTenantId().toString()));*/
|
|
//发请求
|
RestInterface restInterface = SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class);
|
Account acc=new Account();
|
acc.setOrderCode(updateBillStatus.getOrderCode());
|
Object data = restInterface.post(AdminUrlConst.ACCOUNT_SELECTORDERCODE,acc,ResMsg.class,EpcRestInterface.getEpcHeads()).getData();
|
Account account=JSONTool.toObj(JSONTool.toJson(data),Account.class);
|
acc.setVoucherCode(updateBillStatus.getVoucherCode());
|
RestInterface restInterface2 = SpringUtil.getBean(SERVER_FORM.getBeanName(), RestInterface.class);
|
|
if(ObjectUtil.empty(account)){
|
BillInfo billInfo = new BillInfo();
|
billInfo.setOrderCode(updateBillStatus.getOrderCode());
|
billInfo = billInfoMapper.select(billInfo).stream().findFirst().orElse(null);
|
|
if(ObjectUtil.empty(billInfo)){
|
return -1;
|
}
|
|
Map<String, Object> param = new HashMap<>();
|
param.put("formID", billInfo.getFormId());
|
param.put("dataRowNum", billInfo.getFormDataId());
|
param.put("status", updateBillStatus.getOrderStatus());
|
param.put("tenantID", updateBillStatus.getTenantId());
|
|
return Objects.isNull(
|
restInterface2.post(FormUrlConst.FORM_STATUS,param,ResMsg.class,EpcRestInterface.getEpcHeads()).getData())?-1:1;
|
}else{
|
ThreadData.set(com.changhong.epc.constter.base.BaseConst.COMPANY_ID,Integer.parseInt(account.getCompanyId()));
|
ThreadData.set(com.changhong.epc.constter.base.BaseConst.TENANT_ID,account.getTenantId());
|
ThreadData.set(com.changhong.epc.constter.base.BaseConst.OPEN_ID,account.getOpenId());
|
if(Objects.isNull(account.getFormId())){
|
acc.setFlag(false);
|
Map<String,String> map=new HashedMap<>();
|
map.put("status2",updateBillStatus.getOrderStatus());
|
map.put("colId",account.getDataRowNum());
|
map.put("voucherCode",updateBillStatus.getVoucherCode());
|
restInterface.post(AdminUrlConst.ACCOUNT_UPDATEVOUCHERCODE,acc,ResMsg.class,
|
EpcRestInterface.getEpcHeads()).getData();
|
return Objects.isNull(restInterface2.post(FormUrlConst.ASSET_UPDATESTATUS,map,ResMsg.class,EpcRestInterface.getEpcHeads()).getData())?-1:1;
|
}else{
|
acc.setFlag(true);
|
CheckBuget checkBuget=new CheckBuget();
|
checkBuget.setFormID(account.getFormId());
|
checkBuget.setDataRowNum(account.getDataRowNum());
|
checkBuget.setStatus(Integer.parseInt(updateBillStatus.getOrderStatus()));
|
checkBuget.setTenantID(account.getTenantId());
|
checkBuget.setVoucherCode(updateBillStatus.getVoucherCode());
|
Object data2 = restInterface2.post(FormUrlConst.FORM_STATUS,checkBuget,ResMsg.class,
|
EpcRestInterface.getEpcHeads()).getData();
|
restInterface.post(AdminUrlConst.ACCOUNT_UPDATEVOUCHERCODE,acc,ResMsg.class,
|
EpcRestInterface.getEpcHeads()).getData();
|
return Objects.isNull(data2)?-1:1;
|
}
|
}
|
//回写服务表
|
|
|
|
}
|
|
@SuppressWarnings("finally")
|
@Transactional
|
@Override
|
public int pushOrderBill(PushOrderBill pushOrderBill) {
|
//参数
|
BillInfo billInfo = new BillInfo();
|
billInfo.setOrderCode(pushOrderBill.getOrderCode());
|
//暂时不调用规则检查
|
//billInfo.setDataStart(0);
|
billInfo.setDataStart(2);
|
billInfo.setInfo(pushOrderBill.getBillDatas());
|
|
// try{
|
//
|
// log.debug("------------开始发送规则请求-------------");
|
// Object respData = cscApiService.orderRuleCheck(pushOrderBill.getOrderCode());
|
// log.debug(JSONTool.toJson(respData));
|
// }catch(Exception e){
|
// log.debug("------------规则请求出错-------------");
|
// log.debug(e.toString());
|
// }finally{//将票据信息添加到费用云
|
//发请求
|
log.debug("------------将票据信息添加到费用云-------------");
|
//暂时放在tenant下
|
int result = billInfoMapper.updateBill(billInfo);
|
if(result == 0)
|
result = billInfoMapper.addBill(billInfo);
|
return result;
|
// }
|
|
|
|
}
|
|
|
@Transactional
|
@Override
|
@CacheRm(value = MASTER_VALUE, company = false)
|
public void pushMasDataValue(PushMasDataValue pushMasDataValue) {
|
List<Map<String, Object>> errData = new ArrayList<>();
|
String type = pushMasDataValue.getType();
|
this.tenantId = pushMasDataValue.getTenantId();
|
if(StringUtils.isNotBlank(type)){
|
List<Map<String, Object>> dataList = pushMasDataValue.getData();
|
String masDataDefCode = pushMasDataValue.getMasDataDefCode();
|
if(CollectionUtils.isNotEmpty(dataList)){
|
switch (type) {
|
/* 增加 */
|
case TYPE_INSERT:
|
insert(masDataDefCode, dataList, errData);
|
break;
|
/* 修改 */
|
case TYPE_UPDATE:
|
update(masDataDefCode, dataList, errData);
|
break;
|
/* 删除 */
|
case TYPE_DELETE:
|
beginDelete(masDataDefCode, dataList);
|
break;
|
default:
|
throw new IEMRestException("C0018");
|
}
|
}
|
}
|
}
|
|
/**
|
* 添加错误消息
|
* @Title: setMsg
|
|
* @param @param code
|
* @param @param msg 设定文件
|
* @return void 返回类型
|
* @throws
|
*/
|
// protected void setMsg(String code, Map<String, Object> msg) {
|
// msg.put("rspCode", code);
|
// msg.put("rspDesc", "E10000");
|
// }
|
|
private void insert(String mdCode, List<Map<String, Object>> dataList, List<Map<String, Object>> errData){
|
if(ObjectUtil.empty(dataList) || ObjectUtil.empty(errData)){
|
return;
|
}
|
if(dataList.size() == 1){
|
if(beginInsert(mdCode, dataList.get(0)) == Integer.MIN_VALUE){
|
errData.add(dataList.get(0));
|
}
|
}else{
|
for (Map<String, Object> map : dataList) {
|
if(beginInsert(mdCode, map) == Integer.MIN_VALUE){
|
errData.add(map);
|
}
|
}
|
}
|
}
|
|
private void update(String mdCode, List<Map<String, Object>> dataList, List<Map<String, Object>> errData){
|
if(ObjectUtil.empty(dataList) || ObjectUtil.empty(errData)){
|
return;
|
}
|
for (Map<String, Object> map : dataList) {
|
if(beginUpdate(mdCode, map) == Integer.MIN_VALUE){
|
errData.add(map);
|
}
|
}
|
}
|
|
/**
|
* 开始添加
|
* @Title: insert
|
|
* @param @param data
|
* @param @param userInfo
|
* @param @return 设定文件
|
* @return int 返回类型
|
* @throws
|
*/
|
private int beginInsert(String mdCode, Map<String, Object> data){
|
log.error(String.format("主数据同步ing...%s:%s", mdCode, data.toString()));
|
|
Map<String, Object> config = new ModelMap(DEL_FLAG, data.get(DEL_FLAG))
|
.addAttribute(ROW_NUM, data.get(ROW_NUM))
|
.addAttribute(MAS_DATA_DEF_CODE, mdCode);
|
data.remove(DEL_FLAG);
|
data.remove(ROW_NUM);
|
|
/**
|
* 添加主数据
|
*/
|
// Integer mdId = masterDefineMapper.selectIdByCode(mdCode);
|
MasterValue precord = null;
|
for (Map.Entry<String, Object> val : data.entrySet()) {
|
|
/**
|
* 验证是否存在
|
*/
|
ValidateTool.assertException(
|
masterValueMapper.isEmpty(mdCode//define_code --> master_value 表中对应字段
|
,val.getKey()//ele_code
|
,NumberUtils.toInt(Objects.toString(config.get(ROW_NUM), ""), -1)//row_no
|
,this.tenantId.toString()) > 0);//租户id
|
|
// MasterElementExample mee = new MasterElementExample();
|
// MasterElementExample.Criteria c = mee.createCriteria();
|
// c.andMeMasterIdEqualTo(mdId);
|
precord = new MasterValue();
|
precord.setDefineCode(mdCode);
|
precord.setEleCode(val.getKey());
|
//默认递增
|
precord.setEleValue(Objects.toString(val.getValue(), ""));
|
precord.setRowNo(NumberUtils.toInt(Objects.toString(config.get(ROW_NUM), ""), -1));
|
precord.setDelFlag(NumberUtils.toInt(Objects.toString(config.get(DEL_FLAG), ""), 0));
|
precord.setDataStart(0);
|
precord.setInsP("-1");
|
precord.setUpdP("-1");
|
// System.err.println(ThreadData.get(Keys.TENANT_ID));
|
precord.setTenantId(this.tenantId.toString());
|
// precord.setTenantId(ThreadData.get(Keys.TENANT_ID).toString());
|
precord.setInsT(new Date());
|
precord.setUpdT(new Date());
|
masterValueMapper.insert(precord);
|
}
|
return 1;
|
|
};
|
|
/**
|
* 开始修改
|
* @Title: update
|
* @return int
|
* @throws
|
*/
|
private int beginUpdate(String mdCode, Map<String, Object> data){
|
|
//验证
|
ValidateTool.assertException(
|
StringUtils.isBlank(Objects.toString(data.get(ROW_NUM), "")));
|
|
Map<String, Object> config = new ModelMap(DEL_FLAG, data.get(DEL_FLAG))
|
.addAttribute(ROW_NUM, data.get(ROW_NUM))
|
.addAttribute(MAS_DATA_DEF_CODE, mdCode);
|
data.remove(DEL_FLAG);
|
data.remove(ROW_NUM);
|
|
int count = masterValueMapper.deleteValue(config, data);
|
|
/**
|
* 添加主数据
|
*/
|
MasterValue precord = null;
|
for (Map.Entry<String, Object> val : data.entrySet()) {
|
precord = new MasterValue();
|
precord.setDefineCode(mdCode);
|
precord.setEleCode(val.getKey());
|
//默认递增
|
precord.setEleValue(Objects.toString(val.getValue(), ""));
|
precord.setRowNo(NumberUtils.toInt(Objects.toString(config.get(ROW_NUM), ""), -1));
|
precord.setDelFlag(NumberUtils.toInt(Objects.toString(config.get(DEL_FLAG), ""), 0));
|
precord.setDataStart(0);
|
precord.setInsP("-1");
|
precord.setUpdP("-1");
|
precord.setTenantId(this.tenantId.toString());
|
precord.setInsT(new Date());
|
precord.setUpdT(new Date());
|
count += masterValueMapper.insert(precord);
|
}
|
return count;
|
|
|
};
|
|
/**
|
* 开始删除
|
* @Title: delete
|
|
* @param @param data
|
* @param @param userInfo
|
* @param @return 设定文件
|
* @return int 返回类型
|
* @throws
|
*/
|
private int beginDelete(String mdCode, List<Map<String, Object>> dataList){
|
int count =0;
|
if(ObjectUtil.empty(dataList)){
|
return count;
|
}
|
for (Map<String, Object> map : dataList) {
|
|
Map<String, Object> config = new ModelMap(DEL_FLAG, map.get(DEL_FLAG))
|
.addAttribute(ROW_NUM, map.get(ROW_NUM))
|
.addAttribute(MAS_DATA_DEF_CODE, mdCode);
|
//由之前 逻辑删除 --修改为现在 -- 物理删除
|
count += masterValueMapper.deleteValue(config, map);
|
}
|
return count;
|
};
|
|
/**
|
* 业务类型开始修改
|
* @return
|
*/
|
private String updateBusType(UpdataBusType upDataBusType){
|
CostType cost = this.getCost(upDataBusType);
|
CostType result = costTypeMapper.selectParentId(cost);
|
|
//如果修改的数据不存在,打印修改信息不存在
|
if(result == null){
|
log.debug("修改错误:" + EDIT_FAILURE);
|
return EDIT_FAILURE;
|
}
|
|
if(result.getParentId() == 0){
|
log.debug("-----------------开始修改父级数据----------------------");
|
int pid = result.getId();
|
costTypeMapper.updateBus(cost);
|
log.debug("修改父级:" + EDIT_SUCCESS);
|
CostType ct = new CostType();
|
ct.setParentId(pid);
|
ct.setType(cost.getNodeName());
|
log.debug("--------------------开始修改子级数据-------------------------");
|
List<CostType> resultList = costTypeMapper.selectChild(ct);
|
if(resultList != null){
|
costTypeMapper.updateType(ct);
|
log.debug("修改子级:" + EDIT_SUCCESS);
|
}
|
}else {
|
log.debug("--------------------开始修改单条数据-----------------------");
|
costTypeMapper.updateBus(cost);
|
log.debug("单独修改子级:" + EDIT_SUCCESS);
|
}
|
return EDIT_SUCCESS;
|
}
|
|
|
/**
|
* 删除业务类型
|
* @return
|
*/
|
private String deleteBusType(UpdataBusType upDataBusType){
|
CostType cost = this.getCost(upDataBusType);
|
CostType result = costTypeMapper.selectParentId(cost);
|
|
//如果删除的数据不存在,打印删除信息不存在
|
if(result == null){
|
log.error("删除错误:" + DELETE_FAILURE);
|
return DELETE_FAILURE;
|
}
|
|
if(result.getParentId() == 0){
|
log.debug("---------------开始删除父级数据-----------------");
|
int eid = result.getId();
|
int rid = Integer.valueOf(result.getRecourseCode());
|
costTypeMapper.deleteBusType(rid);
|
log.debug("删除父级:" + DELETE_SUCCESS);
|
CostType ct = new CostType();
|
ct.setParentId(eid);
|
log.debug("--------------------开始删除子级数据----------------------");
|
List<CostType> resultList = costTypeMapper.selectChild(ct);
|
if(resultList != null){
|
Integer recourseCode = result.getId();
|
costTypeMapper.deleteType(recourseCode);
|
log.debug("删除子级:" + DELETE_SUCCESS);
|
}
|
}else {
|
log.debug("--------------------开始删除子级数据-----------------------");
|
Integer recourseCode = Integer.valueOf(cost.getRecourseCode());
|
costTypeMapper.deleteBusType(recourseCode);
|
log.debug("删除子级:" + DELETE_SUCCESS);
|
}
|
return DELETE_SUCCESS;
|
}
|
|
/**
|
* 指定公司业务类型增量同步接口
|
* @throws Exception
|
*/
|
@Transactional
|
@Override
|
public int updateBusType(List<UpdataBusType> updataBusType) throws Exception {
|
CostTypeExtend pId = new CostTypeExtend();
|
pId.setId(0);
|
this.getCostType(updataBusType,pId);
|
return isNotNull ? 1 : 0;
|
}
|
|
/**
|
* 递归插入
|
* @param updataBusType
|
* @throws Exception
|
*/
|
public void getCostType(List<UpdataBusType> updataBusType,CostTypeExtend peId) throws Exception{
|
if(updataBusType==null){
|
this.isNotNull = false;
|
return;
|
}
|
for(UpdataBusType up : updataBusType){
|
CostTypeExtend id = operationBusType(up,peId);
|
if(up.getChildren()!=null && up.getChildren().size()>0){
|
this.getCostType(up.getChildren(),id);
|
}
|
}
|
}
|
|
/**
|
* 插入数据
|
* @param up
|
* @throws Exception
|
*/
|
public CostTypeExtend insertCost(UpdataBusType up,CostTypeExtend id){
|
log.debug("-----------------开始插入----------------");
|
CostType cost = this.getCost(up);
|
|
CostTypeExtend costExtend = new CostTypeExtend();
|
cost.setParentId(id.getId());
|
cost.setType(id.getNodeName());
|
costExtend.SetProperties(cost);
|
costExtend.initParam();//插入时间
|
// System.out.println(costExtend.getType());
|
Object obj = null;
|
try {
|
obj = costTypeMapper.insertCost(costExtend);
|
} catch (Exception e) {
|
log.error("插入数据异常:",e);
|
}
|
log.debug("插入数据:" + INSERT_SUCCESS);
|
// System.out.println(obj);
|
costExtend.setType(cost.getNodeName());
|
return costExtend;
|
}
|
|
/**
|
* 转换格式
|
*/
|
public CostType getCost(UpdataBusType up){
|
CostType cost= new CostType();
|
//对象转换
|
cost.setOrderTypeCode(up.getOrderTypeCode());
|
cost.setSortCode(up.getSortCode());
|
cost.setType(up.getType());
|
cost.setNodeName(up.getName());
|
cost.setParentId(up.getParentId());
|
cost.setRecourseCode(up.getId());
|
return cost;
|
}
|
|
/**
|
* 判断业务类型
|
* @throws Exception
|
*/
|
public CostTypeExtend operationBusType(UpdataBusType up,CostTypeExtend id) throws Exception{
|
String type = up.getType();
|
CostType cost = this.getCost(up);
|
CostType result = costTypeMapper.selectParentId(cost);//是否有该条数据
|
|
//判断是否重复插入
|
if(cost.getType().equals("1") && result != null){
|
if((cost.getOrderTypeCode().equals(result.getOrderTypeCode())
|
&& cost.getRecourseCode().equals(result.getRecourseCode()))){
|
type = "3";
|
}
|
}
|
|
if(StringUtils.isNotBlank(type)){
|
switch (type) {
|
/* 增加 */
|
case TYPE_INSERT:
|
CostTypeExtend costExtend = insertCost(up,id);
|
return costExtend;
|
/* 修改 */
|
case TYPE_UPDATE:
|
String resUpdate = updateBusType(up);
|
break;
|
/* 删除 */
|
case TYPE_DELETE:
|
String resDelete = deleteBusType(up);
|
break;
|
default:
|
throw new IEMRuntimeException("云上行返回业务类型状态错误");
|
}
|
}
|
return id;
|
}
|
|
|
/**
|
* 通用,租户主数据初始化接口
|
*/
|
@Transactional
|
@Override
|
public boolean getMaster(Map<String, Object> map) {
|
BigInteger tenantId = new BigInteger(L);
|
//获取主数据定义
|
map.put(PAGENUM, ONE);
|
map.put(PAGESIZE, Integer.MAX_VALUE);
|
String tenantID = Objects.toString(map.get("tenantId"),L);
|
if(!tenantID.equals(L)){
|
tenantId = new BigInteger(tenantID);
|
}
|
//定义主数据三个集合
|
List<Map> define,element,value;
|
define = element = value = Collections.EMPTY_LIST;
|
try{
|
if(!Objects.equals(tenantId.toString(), L)){
|
//获取租户主数据
|
define = cscApiService.getTenantDefine(map);
|
}
|
//获取通用主数据
|
if(define == null){
|
define = Collections.EMPTY_LIST;
|
}
|
// System.out.println("主数据定义:"+JSONTool.toJson(define));
|
//清空主数据定义,元素,value
|
masterDefineMapper.deleteAll();
|
masterElementMapper.deleteAll();
|
masterValueMapper.deleteAll();
|
// -----------添加主数据定义----------------
|
for(Map de : define){
|
GetMasterDefine masterD = JSONTool.toObj(JSONTool.toJson(de),GetMasterDefine.class);
|
MasterDefine master = new MasterDefine(masterD);
|
if(!Objects.equals(tenantId.toString(), L)){
|
master.setTenantId(tenantId);
|
}
|
masterDefineMapper.insert(master);
|
//根据主数据定义添加元素
|
map.put(CODE, master.getCode());
|
if(!Objects.equals(tenantId.toString(), L)){
|
//获取租户主数据
|
element = cscApiService.getTenantEle(map);
|
}
|
//获取通用主数据
|
if(element == null) {
|
element = Collections.EMPTY_LIST;
|
}
|
// -----------根据主数据定义添加主数据元素-----------
|
for(Map ele : element){
|
GetMasterEle getM = JSONTool.toObj(JSONTool.toJson(ele),GetMasterEle.class);
|
MasterElement el = new MasterElement(getM,master.getCode());
|
//区别于通用主数据和租户主数据
|
if(!Objects.equals(tenantId.toString(), L)){
|
el.setTenantId(tenantId);
|
}
|
//通过定义判断元素的code
|
if(masterD.getEleCodeCode().equals(el.getCode())){
|
el.setAlias(CODE);
|
el.setLen(masterD.getEleCodeDataLen());
|
el.setType(masterD.getEleCodeDataType());
|
}
|
//通过定义判断元素的name
|
if(masterD.getEleNameCode().equals(el.getCode())){
|
el.setAlias(VALUE);
|
el.setLen(masterD.getEleNameDataLen());
|
el.setType(masterD.getEleNameDataType());
|
}
|
//添加主数据元素
|
masterElementMapper.insert(el);
|
}
|
/**
|
* ----------根据主数据定义添加主数据value---------
|
* ----------------租户and通用----------------
|
*/
|
//更换查询主数据元素的参数
|
map.remove(CODE);
|
map.put(DEFINE_CODE, master.getCode() );
|
if(!Objects.equals(tenantId.toString(), L)){
|
//获取租户主数据
|
|
value = cscApiService.getTenantValue(map);
|
}
|
//获取通用主数据
|
if(value == null) {
|
value = Collections.EMPTY_LIST;
|
}
|
if(ObjectUtil.empty(value) || value.stream().findFirst().orElse(null) == null){
|
continue;
|
}
|
//添加主数据value
|
for(Map val: value){
|
GetMasterValue Gval = JSONTool.toObj(JSONTool.toJson(val),GetMasterValue.class);
|
for(Rows row:Gval.getRows()){
|
for(Columns col :row.getColumns()){
|
MasterValue mValue = new MasterValue(col,Gval.getMasDataDefCode());
|
if(!Objects.equals(tenantId, L)){
|
mValue.setTenantId(tenantId.toString());
|
}
|
masterValueMapper.insert(mValue);
|
}
|
}
|
}
|
|
}
|
}catch(Exception e){
|
log.error(e.getMessage(), e);
|
return false;
|
}
|
return true;
|
}
|
/**
|
* 同步增量公司业务类型
|
* zz
|
*/
|
@Override
|
public int updateBusTypes(String compId, String tenantId, String type, List<UpdataBusType> updataBusType){
|
|
String mdCode = SpringUtil.getBean(CorresElFieldApi.class).getVal(BUSINESS_TYPE, CorresElField::getMdCode);
|
//修改主数据版本号
|
VersionFilterApi.filter(mdCode, Context.getTenantIdStr(), Context.getCompanyIdStr());
|
|
//通过公司id、租户id选择表
|
List<UpdataBusType> u =new ArrayList<>();
|
//将递归数据改为列表
|
this.getUpdataBusTypeList(updataBusType,u);
|
int i=0;
|
switch(type){
|
case INSERT_BUSTYPE:
|
i = addBusType(u);
|
break;
|
case DELETE_BUSTYPE:
|
i = delBusType(u,updataBusType);
|
break;
|
case UPDATE_BUSTYPE:
|
i = updBusType(u);
|
break;
|
default:break;
|
}
|
return i;
|
}
|
|
@Override
|
public Map<String, Object> backRule(Map<String, Object> billInfo) {
|
Map<String,Object> m = cscApiService.backRule(new ModelMap("orderCode",billInfo.get("orderCode")));
|
//清空现有表单数据
|
BillInfo bi = new BillInfo();
|
bi.setDataStart(2);
|
bi.setInfo("");
|
bi.setOrderCode(Objects.toString(billInfo.get("orderCode"),""));
|
billInfoMapper.updateBill(bi);
|
//修改表单单据状态
|
FormDataEntity formData = new FormDataEntity(Objects.toString(billInfo.get("formId")),
|
Integer.parseInt(Objects.toString(billInfo.get("dataRowNum"),"0")),ThreadData.get(Keys.TENANT_ID));
|
formData.setMap(new ModelMap("orderStatus",10));
|
RestInterface restInterface = SpringUtil.getBean(SERVER_FORM.getBeanName(), RestInterface.class);
|
Object data = restInterface.post(FormUrlConst.FORM_DATA_UPDATFORM, formData, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
|
|
return m;
|
}
|
|
private int addBusType(List<UpdataBusType> updataBusType){
|
// System.out.println("//增加业务类型");
|
int i = 0;
|
if(ObjectUtil.empty(updataBusType)){
|
return i;
|
}
|
for(UpdataBusType up:updataBusType){
|
if(costTypeMapper.selectByName(up.getId()) == 0){
|
// System.out.println("没有-插入");
|
i += costTypeMapper.insertUpdataBusType(up);
|
}
|
}
|
return i;
|
}
|
private int delBusType(List<UpdataBusType> updataBusType,List<UpdataBusType> updata){
|
// System.out.println("//删除业务类型");
|
int i = 0;
|
if(ObjectUtil.notEmpty(updataBusType)) {
|
for (UpdataBusType up : updataBusType) {
|
if (up.getParentId() != 0) {
|
// System.out.println("删除zi");
|
i += costTypeMapper.delteByCodeId(up.getId());
|
}
|
}
|
}
|
if(ObjectUtil.notEmpty(updata)) {
|
for (UpdataBusType up : updata) {
|
if (up.getParentId() == 0) {
|
if (costTypeMapper.selectConstCounts(new Integer(up.getId())) == 0) {
|
// System.out.println("删除fu");
|
i += costTypeMapper.delteByCodeId(up.getId());
|
}
|
}
|
}
|
}
|
return i;
|
}
|
private int updBusType(List<UpdataBusType> updataBusType){
|
// System.out.println("//更改业务类型");
|
int i = 0;
|
if(ObjectUtil.empty(updataBusType)){
|
return i;
|
}
|
for(UpdataBusType up:updataBusType){
|
costTypeMapper.updateByCodeId(up);
|
}
|
return i;
|
}
|
|
//递归变列表后的数据
|
|
//递归变列表
|
private void getUpdataBusTypeList(List<UpdataBusType> updataBusTypes,List<UpdataBusType> u){
|
if(ObjectUtil.empty(updataBusTypes) || null == u){
|
return;
|
}
|
for(UpdataBusType up:updataBusTypes){
|
if(up != null){
|
u.add(up);
|
if(up.getChildren()!=null && up.getChildren().size()!=0){
|
getUpdataBusTypeList(up.getChildren(),u);
|
}
|
}
|
}
|
}
|
|
|
|
}
|