package com.changhong.epc.tenant.service.cost.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.changhong.epc.bean.admin.CorresElField;
|
import com.changhong.epc.bean.tenant.cost.CostFromMapping;
|
import com.changhong.epc.bean.tenant.cost.CostType;
|
import com.changhong.epc.bean.tenant.cost.extend.CostTypeExtend;
|
import com.changhong.epc.bean.tenant.sunCloud.UpdataBusType;
|
import com.changhong.epc.constter.admin.AdminUrlConst;
|
import com.changhong.epc.constter.base.BaseConst;
|
import com.changhong.epc.constter.base.Context;
|
import com.changhong.epc.constter.system.SystemClients;
|
import com.changhong.epc.constter.system.run.EpcRestInterface;
|
import com.changhong.epc.rely.api.epc.admin.CostFromTemplateApi;
|
import com.changhong.epc.rely.api.service.CscApiService;
|
import com.changhong.epc.rely.api.tool.VersionFilterApi;
|
import com.changhong.epc.tenant.mapper.tenant.cost.CostFromMappingMapper;
|
import com.changhong.epc.tenant.mapper.tenant.cost.CostTypeMapper;
|
import com.changhong.epc.tenant.service.cost.CostTypeService;
|
import com.iemsoft.framework.cloud.core.base.ResMsg;
|
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.ribbon.RestInterface;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.ui.ModelMap;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
import java.util.function.Consumer;
|
|
@Service("costTypeService")
|
public class CostTypeServiceImpl implements CostTypeService, BaseConst,SystemClients {
|
|
@Resource
|
private CostFromMappingMapper costFromMappingMapper;
|
|
@Resource
|
private CostTypeMapper costTypeMapper;
|
|
@Resource
|
private CostFromTemplateApi costFromTemplateApi;
|
|
//业务类型常量key
|
private static final String BUSINESS_TYPE = "businessType";
|
|
@Override
|
public List<CostTypeExtend> selectConstByTypeAll(String type) {
|
List<CostTypeExtend> list = costTypeMapper.selectCostTypeAll(type);
|
// CostFromMapping costForm = new CostFromMapping();
|
// if(type != null){
|
// for(CostTypeExtend cost : list){
|
// costForm.setCtId(cost.getId());
|
// costForm.setType(type);
|
// cost.setCostFromMapping(costFromMappingMapper.select(costForm));
|
// for(CostTypeExtend costs :cost.getChildren()){
|
// costForm.setCtId(costs.getId());
|
// costForm.setType(type);
|
// costs.setCostFromMapping(costFromMappingMapper.select(costForm));
|
// }
|
// }
|
// }
|
return list;
|
}
|
|
@Override
|
public int deleteCostType(CostType costType) {
|
return costTypeMapper.deleteCost(costType.getId())==1?1:-1;
|
}
|
|
/**
|
* 添加费用类型
|
*/
|
@Override
|
public CostType insertCostType(CostTypeExtend costType) {
|
costType.initParam();
|
costTypeMapper.insertCost(costType);
|
//添加表单映射
|
if((costType.getCostFromMapping().size())>0){
|
for(CostFromMapping form : costType.getCostFromMapping()){
|
if(form.getFId()!=null && !form.getFId().equals("")){
|
form.setCtId(costType.getId());
|
form.initParam();
|
costFromMappingMapper.insert(form);
|
}
|
}
|
}
|
if(costType.getParentId()==0){
|
CostTypeExtend cte = new CostTypeExtend();
|
cte.SetProperties(costType);
|
//判断是否有关联表单
|
return cte;
|
|
}else if(costType.getParentId()!=0){
|
costFromMappingMapper.deleteForm(costType.getParentId());
|
|
}
|
|
return costType;
|
}
|
|
/**
|
* 修改费用类型
|
*/
|
@Override
|
public int updateCostType(CostTypeExtend costType) {
|
if(costType.getIsBlock()!=null && !Objects.equals("",costType.getIsBlock())) {
|
//如果修改费用类型隐藏,更新主数据缓存
|
|
RestInterface restInterface = SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class);
|
Object data = restInterface.post(AdminUrlConst.GET_CORRESELFIELD,
|
new ModelMap("businessMeaningCode", BUSINESS_TYPE), ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
|
List<CorresElField> list = JSONTool.toList(JSONTool.toJson(data), CorresElField.class);
|
CorresElField corresElField = list.stream()
|
.filter(f -> f.getMdCode() != null && !Objects.equals("", f.getMdCode()))
|
.findFirst().orElse(null);
|
if (corresElField!=null && corresElField.getMdCode()!=null) {
|
System.out.println("当前主数据:"+corresElField.getMdCode());
|
VersionFilterApi.filter(corresElField.getMdCode(), Context.getTenantIdStr(), Context.getCompanyIdStr());
|
}
|
}
|
return costTypeMapper.updateCostType(costType);
|
}
|
|
/**
|
* 分页查询费用类型
|
*/
|
@Override
|
public List<CostTypeExtend> seachePage(CostType costType) {
|
costType.setDataStart(0);
|
ThreadData.set(Keys.PAGE_SIZE, 20);
|
List<CostTypeExtend> list = costTypeMapper.selectCostTypePage(costType);
|
// CostFromMapping costForm = new CostFromMapping();
|
// for(CostTypeExtend cost : list){
|
// costForm.setCtId(cost.getId());
|
// // System.out.println("添加父类");
|
// cost.setCostFromMapping(costFromMappingMapper.select(costForm));
|
// for(CostTypeExtend costs :cost.getChildren()){
|
// // System.out.println("添加子类");
|
// costForm.setCtId(cost.getId());;
|
// costs.setCostFromMapping(costFromMappingMapper.select(costForm));
|
// }
|
// }
|
return list;
|
}
|
|
@Override
|
public int move(CostType data) {
|
return costTypeMapper.move(data);
|
}
|
|
@Override
|
public CostType selectSingle(CostType cost) {
|
return costTypeMapper.selectByPrimaryKey(cost.getId());
|
}
|
|
@Override
|
public List<CostTypeExtend> selectlike(String nodeName) {
|
return costTypeMapper.selectlike(nodeName);
|
}
|
|
@Autowired
|
CscApiService cscApiService;
|
|
//同步公司业务类型
|
public List<UpdataBusType> addCostTypeList(Consumer<UpdataBusType> consumer){
|
// try{
|
Map<String,Object> map =new HashMap<String,Object>();
|
map.put("companyId", ThreadData.get(COMPANY_MASTER_ID));
|
map.put("tenantId",ThreadData.get(TENANT_ID));
|
|
// map.put("companyId","66");
|
// map.put("tenantId","13");
|
|
Map<String, Object> appointData = cscApiService.busTypeByComp(map);
|
Object list = appointData.get("list");
|
List<UpdataBusType> updataBusTypes = JSONTool.toList(JSON.toJSONString(list), UpdataBusType.class);
|
//递归成列表
|
List<UpdataBusType> u =new ArrayList<UpdataBusType>();
|
this.getUpdataBusTypeList(updataBusTypes,u);
|
// int i = 0;
|
// System.out.println(u.size());
|
for(UpdataBusType up:u){
|
if(costTypeMapper.selectByName(up.getId()) == 0){
|
//插入
|
// System.out.println("没有-插入");
|
costTypeMapper.insertUpdataBusType(up);
|
consumer.accept(up);
|
}
|
// else{
|
// //更改
|
// // System.out.println("有-更改");
|
// //i += costTypeMapper.updateByCodeId(up);
|
// }
|
}
|
return u;
|
// }catch (Exception e) {
|
// // System.err.println(e.getMessage());
|
// return Collections.emptyList();
|
// }
|
|
}
|
|
|
public static void getUpdataBusTypeList(List<UpdataBusType> updataBusTypes,List<UpdataBusType> u ){
|
if(ObjectUtil.empty(updataBusTypes) || u == null){
|
return;
|
}
|
for(UpdataBusType up:updataBusTypes){
|
if(up != null){
|
u.add(up);
|
if(up.getChildren()!=null && up.getChildren().size()!=0){
|
getUpdataBusTypeList(up.getChildren(),u);
|
}
|
}
|
}
|
}
|
}
|