package com.changhong.epc.parsing.service.util.impl;
|
|
import com.changhong.epc.bean.form.CpnVal;
|
import com.changhong.epc.bean.form.Fieldsets;
|
import com.changhong.epc.bean.form.FormBaseEntity;
|
import com.changhong.epc.bean.form.FormDataEntity;
|
import com.changhong.epc.bean.parsing.BillInfo;
|
import com.changhong.epc.bean.tenant.bill.OCRBillEntity;
|
import com.changhong.epc.bean.tenant.cost.CostType;
|
import com.changhong.epc.bean.tenant.cost.extend.CostFromMappingExtend;
|
import com.changhong.epc.bean.tenant.master.MasterEleValue;
|
import com.changhong.epc.bean.tenant.master.MasterValue;
|
import com.changhong.epc.constter.form.utf.FormUrlConst;
|
import com.changhong.epc.constter.system.SystemClients;
|
import com.changhong.epc.constter.system.businesscode.BusinessMeaningCode;
|
import com.changhong.epc.constter.system.run.EpcRestInterface;
|
import com.changhong.epc.constter.tenant.TenantUrlConst;
|
import com.changhong.epc.parsing.mapper.tenant.JourneyFormMapper;
|
import com.changhong.epc.parsing.service.util.IFromOperate;
|
import com.google.common.base.Objects;
|
import com.iemsoft.framework.cloud.core.base.ResMsg;
|
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.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
import java.util.Map.Entry;
|
|
import static com.changhong.epc.constter.form.utf.FormUrlConst.FORM_DATA_SELECT_ONE;
|
import static com.changhong.epc.constter.form.utf.FormUrlConst.FORM_DATA_UPDATFORM;
|
|
//import org.apache.commons.collections.map.HashedMap;
|
|
@Service("fromOperate")
|
public class FromOperateImpl implements BusinessMeaningCode, SystemClients, IFromOperate {
|
|
// private CpnVal subForm;
|
|
@Resource
|
private JourneyFormMapper journeyFormMapper;
|
|
|
public Object getFromRest(String fs, Object parm) {
|
RestInterface restInterface = SpringUtil.getBean(SERVER_FORM.getBeanName(), RestInterface.class);
|
Object data = restInterface.post(fs, parm, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
|
// // System.out.println("分配成功修改状态返回结果"+JSONTool.toJson(data));
|
return data;
|
}
|
|
public Object getTenantRest(String fs, Object parm) {
|
RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class);
|
Object data = restInterface.post(fs, parm, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
|
|
return data;
|
}
|
|
@Override
|
public FormBaseEntity selectFromAll(BillInfo billInfo) {
|
Map<String, Object> parm = new HashMap<>();
|
parm.put("formId", billInfo.getFormId());
|
@SuppressWarnings("unchecked")
|
Map<String, Object> billDatas = JSONTool.toObj(billInfo.getInfo(), Map.class);
|
parm.put("tenantId", billDatas.get("tenantId"));
|
|
Object fromRest = getFromRest(FormUrlConst.FORM_PROPERTY_URL, parm);
|
FormBaseEntity formBase = JSONTool.toObj(JSONTool.toJson(fromRest), FormBaseEntity.class);
|
return formBase;
|
}
|
|
/**
|
* 将分配完的数据添加到子表单中
|
*/
|
@Override
|
public Integer insertCpnVal(BillInfo billInfo, Map<CpnVal, List<List<CpnVal>>> data) {
|
Map<String, Object> parm = new HashMap<>();
|
CpnVal subForm = new CpnVal();
|
//分配完的行程插入到子表单中
|
List<List<CpnVal>> subFormVals = new ArrayList<>();
|
if(ObjectUtil.notEmpty(data)) {
|
for (Entry<CpnVal, List<List<CpnVal>>> serverDefine : data.entrySet()) {
|
subForm = serverDefine.getKey();
|
subFormVals = serverDefine.getValue();
|
}
|
}
|
|
List<Map<String, Object>> cpnVal = new ArrayList<>();
|
for (List<CpnVal> eachJoun : subFormVals) {
|
HashMap<String, Object> eachCpnVal = new HashMap<>();
|
eachCpnVal.put("PARENTDATAROWNUM", billInfo.getFormDataId());
|
for (CpnVal val : eachJoun) {
|
eachCpnVal.put(val.getAlias(), val.getValCode());
|
}
|
cpnVal.add(eachCpnVal);
|
}
|
parm.put("formId", billInfo.getFormId());
|
parm.put("childAlias", subForm.getAlias());
|
parm.put("data", cpnVal);
|
getFromRest(FormUrlConst.FORM_DATA_INSERT, parm);
|
return null;
|
}
|
|
@Override
|
public List<Integer> insertCpnVal(BillInfo billInfo, CpnVal journeySubForm, List<List<CpnVal>> allJourneyCpn) {
|
|
CpnVal subForm = journeySubForm;
|
Map<String, Object> parm = new HashMap<>();
|
|
List<Map<String, Object>> cpnVal = new ArrayList<>();
|
if(ObjectUtil.notEmpty(allJourneyCpn)) {
|
for (List<CpnVal> eachJoun : allJourneyCpn) {
|
HashMap<String, Object> eachCpnVal = new HashMap<>();
|
eachCpnVal.put("PARENTDATAROWNUM", billInfo.getFormDataId());
|
for (CpnVal val : eachJoun) {
|
eachCpnVal.put(val.getAlias(), val.getValCode());
|
}
|
cpnVal.add(eachCpnVal);
|
}
|
}
|
parm.put("formId", billInfo.getFormId());
|
parm.put("tenantId", JSONTool.toObj(billInfo.getInfo(), Map.class).get("tenantId"));
|
parm.put("childAlias", subForm.getAlias());
|
parm.put("data", cpnVal);
|
// JSONTool.toJson(parm);
|
// // System.out.println("保存控件。。。");
|
// // System.out.println(JSONTool.toJson(parm));
|
// System.out.println("最终添加子表单参数:" + JSONTool.toJson(parm));
|
Object fromRest = getFromRest(FormUrlConst.FORM_DATA_INSERT, parm);
|
List<Map> resList = JSONTool.toList(JSONTool.toJson(fromRest), Map.class);
|
List<Integer> jIds = new ArrayList<>();
|
if(ObjectUtil.notEmpty(resList)) {
|
for (Map map : resList) {
|
Object object = map.get("dataRowNum");
|
jIds.add(Integer.valueOf(object.toString()));
|
}
|
}
|
// // System.out.println("子表单新增数据后返回结果:+++++++++++++++++++++++++++++++++++++++++"+JSONTool.toJson(resList));
|
// // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
|
// // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
|
// // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
|
// // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
|
// // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
|
// // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
|
// // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
|
// System.out.println("添加子表单返回:" + JSONTool.toJson(jIds));
|
return jIds;
|
}
|
|
@Override
|
public boolean updateCpnVal(BillInfo billInfo, Map<CpnVal, List<List<CpnVal>>> data) {
|
Integer row = 0;
|
if(ObjectUtil.empty(data)){
|
data = Collections.EMPTY_MAP;
|
}
|
for (Entry<CpnVal, List<List<CpnVal>>> forms : data.entrySet()) {
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormId(billInfo.getFormId());
|
List<Map<String, Object>> cpnValData = new ArrayList<>();
|
// 主控件
|
if (forms.getKey() == null) {
|
formDataEntity.setDataRowNum(billInfo.getFormDataId());
|
}
|
if(ObjectUtil.notEmpty(forms.getValue())) {
|
for (List<CpnVal> eachJoun : forms.getValue()) {
|
Map<String, Object> eachCpnVal = new HashMap<>();
|
formDataEntity.setChildAlias(forms.getKey().getAlias());
|
eachJoun.stream().forEach(val -> setEachCpnVal(eachCpnVal, val));
|
cpnValData.add(eachCpnVal);
|
}
|
}
|
formDataEntity.setData(cpnValData);
|
|
Object fromRest = getFromRest(FormUrlConst.FORM_DATA_UPDATE, formDataEntity);
|
row += (int) fromRest;
|
|
}
|
return row > 0 ? true : false;
|
|
}
|
|
public void setEachCpnVal(Map<String, Object> eachCpnVal, CpnVal val){
|
eachCpnVal.put(val.getAlias(), val.getValCode());
|
if (Objects.equal("dataRowNum", val.getAlias())) {
|
eachCpnVal.put("PARENTDATAROWNUM", val.getValCode());
|
}
|
}
|
|
|
@Override
|
public Boolean deleteFormData(BillInfo billInfo, CpnVal subForm) {
|
Map<String, Object> parm = new HashMap<>();
|
parm.put("formId", billInfo.getFormId());
|
parm.put("childAlias", subForm.getAlias());
|
parm.put("dataRowNum", billInfo.getFormDataId());
|
parm.put("tenantId", JSONTool.toObj(billInfo.getInfo(), Map.class).get("tenantId"));
|
try {
|
getFromRest(FormUrlConst.FORM_DATA_URL, parm);
|
} catch (Exception e) {
|
return false;
|
}
|
|
return true;
|
}
|
|
// @Override
|
// public void setJourneySubForm(CpnVal journeySubForm) {
|
// subForm = journeySubForm;
|
// }
|
|
|
@Override
|
public Map<CpnVal, List<Map>> selectfromDataAll(BillInfo billInfo, Fieldsets fieldsets) {
|
Map<CpnVal, List<Map>> data = new HashMap<>();
|
|
Map<String, Object> dataKeyVal = new HashMap<>();
|
|
|
FormDataEntity parm = new FormDataEntity();
|
parm.setFormId(billInfo.getFormId());
|
// parm.setChildAlias(JOURNEY_SUB);
|
parm.setDataRowNum(billInfo.getFormDataId());
|
@SuppressWarnings("unchecked")
|
Map<String, Object> billDatas = JSONTool.toObj(billInfo.getInfo(), Map.class);
|
parm.setTenantId(billDatas.get("tenantId").toString());
|
|
// System.out.println(JSONTool.toJson(parm));
|
Object fromRest = getFromRest(FormUrlConst.FORM_DATA_SEARCH_LIST, parm);
|
List<Map> res = JSONTool.toList(JSONTool.toJson(fromRest), Map.class);
|
data.put(null, res);
|
for (CpnVal group : fieldsets.getSubform().keySet()) {
|
parm = new FormDataEntity();
|
parm.setFormId(billInfo.getFormId());
|
parm.setChildAlias(group.getAlias());
|
parm.setDataRowNum(billInfo.getFormDataId());
|
parm.setTenantId(billDatas.get("tenantId").toString());
|
fromRest = getFromRest(FormUrlConst.FORM_DATA_SEARCH_LIST, parm);
|
res = JSONTool.toList(JSONTool.toJson(fromRest), Map.class);
|
data.put(group, res);
|
}
|
|
|
return data;
|
}
|
|
@Override
|
public Integer getBillType(String formId) {
|
HashMap<String, Object> hashMap = new HashMap<>();
|
hashMap.put("fId", formId);
|
// Object postRest = getPostRestTen(TenantUrlConst.REST_TENANT_COSTFORM_SELECTONE, hashMap);
|
Object postRest = null;
|
try {
|
RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class);
|
postRest = restInterface.post(TenantUrlConst.REST_TENANT_COSTFORM_SELECTONE, hashMap, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
|
} catch (Exception e) {
|
// System.err.println(e.getMessage());
|
}
|
CostFromMappingExtend obj = JSONTool.toObj(JSONTool.toJson(postRest), CostFromMappingExtend.class);
|
|
return obj.getCtId();
|
|
}
|
|
@Override
|
public void updateForm(Map<String, Object> data) {
|
Object fromRest = getFromRest(FormUrlConst.FORM_DATA_UPDATE2, data);
|
// System.out.println(fromRest);
|
}
|
|
@Override
|
public int updateFormStatus(BillInfo billInfo, Integer status) {
|
Map<String, Object> param = new HashMap<>();
|
param.put("formID", billInfo.getFormId());
|
param.put("dataRowNum", billInfo.getFormDataId());
|
param.put("status", status);
|
param.put("tenantID", billInfo.getFormDataId());
|
getFromRest(FormUrlConst.FORM_STATUS, param);
|
return 0;
|
}
|
|
@Override
|
public FormBaseEntity selectFromAll(OCRBillEntity OCRBillEntity) {
|
Map<String, Object> parm = new HashMap<>();
|
parm.put("formId", OCRBillEntity.getFormId());
|
parm.put("tenantId", OCRBillEntity.getTenantId());
|
|
Object fromRest = getFromRest(FormUrlConst.FORM_PROPERTY_URL, parm);
|
FormBaseEntity formBase = JSONTool.toObj(JSONTool.toJson(fromRest), FormBaseEntity.class);
|
return formBase;
|
}
|
|
@Override
|
public MasterValue billValToCode(MasterEleValue masterEleValue) {
|
Object fromRest = getTenantRest(TenantUrlConst.REST_TENANT_MASTERVALUE_GETCODE, masterEleValue);
|
MasterValue masterValue = JSONTool.toObj(JSONTool.toJson(fromRest), MasterValue.class);
|
return masterValue;
|
}
|
|
@Override
|
public int updateFormStatusTe(BillInfo billInfo, Integer status, Integer tenantId) {
|
Map<String, Object> param = new HashMap<>();
|
param.put("formID", billInfo.getFormId());
|
param.put("dataRowNum", billInfo.getFormDataId());
|
param.put("status", status);
|
param.put("tenantID", tenantId);
|
|
getFromRest(FormUrlConst.FORM_STATUS, param);
|
return 0;
|
}
|
|
@Override
|
public Map<String, Object> selectFromData(BillInfo formData, Fieldsets fieldsets, OCRBillEntity oCRBillEntity) {
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormId(formData.getFormId());
|
formDataEntity.setDataRowNum(formData.getFormDataId());
|
formDataEntity.setChildAliaList(
|
new ArrayList<>(fieldsets.getSubform() == null
|
? Collections.emptyList() :
|
Arrays.asList(fieldsets.getSubform().keySet().stream().map(cpnVal -> cpnVal.getAlias()).toArray(String[]::new))
|
));
|
formDataEntity.setTenantId(java.util.Objects.toString(oCRBillEntity.getTenantId()));
|
return (Map<String, Object>) getFromRest(FORM_DATA_SELECT_ONE, formDataEntity);
|
}
|
|
@Override
|
public int updateFormStatus(String formId, String tenangId, String dataRowNum, Integer status) {
|
Map<String, Object> param = new HashMap<>();
|
param.put("formID", formId);
|
param.put("dataRowNum", dataRowNum);
|
param.put("status", status);
|
param.put("tenantID", tenangId);
|
getFromRest(FormUrlConst.FORM_STATUS, param);
|
return 0;
|
}
|
|
/**
|
* 修改表单数据
|
*
|
* @param formDataEntity
|
*/
|
@Override
|
public void updateFormData(FormDataEntity formDataEntity) {
|
getFromRest(FORM_DATA_UPDATFORM, formDataEntity);
|
}
|
|
@Override
|
public Map<String, Object> selectSign(String formId, String tenangId, Integer dataRowNum) {
|
FormDataEntity formDataEntity = new FormDataEntity(formId,dataRowNum,tenangId);
|
return (Map<String, Object>) getFromRest(FORM_DATA_SELECT_ONE, formDataEntity);
|
}
|
|
@Override
|
public List<Map> selectSubList(String formId, String tenangId, Integer dataRowNum, String alias) {
|
FormDataEntity formDataEntity = new FormDataEntity(formId,dataRowNum,tenangId);
|
formDataEntity.setChildAlias(alias);
|
return JSONTool.toList(JSONTool.toJson(getFromRest(FormUrlConst.FORM_DATA_SEARCH_LIST, formDataEntity)),Map.class);
|
|
}
|
|
@Override
|
public String getCostCode(Integer ctId) {
|
CostType cost = new CostType();
|
cost.setId(ctId);
|
Object res = getTenantRest(TenantUrlConst.REST_TENANT_COSTTYPE_ONE, cost);
|
cost = JSONTool.toObj(JSONTool.toJson(res),CostType.class);
|
return cost.getOrderTypeCode();
|
}
|
}
|