package com.changhong.epc.form.service.budget.tool.impl;
|
|
import com.changhong.epc.bean.admin.Account;
|
import com.changhong.epc.bean.form.FormBaseEntity;
|
import com.changhong.epc.bean.form.FormDataEntity;
|
import com.changhong.epc.bean.form.FormKey;
|
import com.changhong.epc.bean.tenant.cost.CostFromMapping;
|
import com.changhong.epc.bean.tenant.system.SystemConfig;
|
import com.changhong.epc.bean.tenant.system.SystemForm;
|
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.businesscode.BudgetBusinessMeaningCode;
|
import com.changhong.epc.constter.system.run.EpcRestInterface;
|
import com.changhong.epc.form.mapper.tenant.FormDataMapper;
|
import com.changhong.epc.form.service.budget.impl.GetConstant;
|
import com.changhong.epc.form.service.budget.tool.entity.UpdateBudgetEntity;
|
import com.changhong.epc.form.service.data.FormDataService;
|
import com.changhong.epc.form.service.field.FormFieldService;
|
import com.changhong.epc.form.tool.FormNameTool;
|
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.*;
|
import com.iemsoft.framework.cloud.ribbon.RestInterface;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.collections4.map.HashedMap;
|
|
import javax.annotation.Resource;
|
|
|
|
import java.text.DecimalFormat;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
|
/**
|
* 回写预算抽象类
|
*/
|
@Slf4j
|
public abstract class AbstractUpdateBudget extends AbstractBudgetLog implements SystemClients,BaseConst,BudgetBusinessMeaningCode {
|
|
protected List<CostFromMapping> costFromMappings;
|
|
protected Map<SystemForm, String> systemConfigs;
|
|
@Resource
|
protected FormDataService formDataService;
|
|
@Resource
|
private FormDataMapper formDataMapper;
|
|
@Resource(name="formFieldService")
|
private FormFieldService formFieldService;
|
|
|
@Override
|
public void setCostFromMappings(List<CostFromMapping> costFromMappings) {
|
this.costFromMappings = costFromMappings;
|
}
|
|
/**
|
* 获得主表数据
|
* @param updateBudgetEntity
|
* @return
|
*/
|
protected Map<String, Object> getFormInfo(UpdateBudgetEntity updateBudgetEntity){
|
return getFormInfo(updateBudgetEntity.getFormId(), null, updateBudgetEntity.getDataRowNum());
|
}
|
protected Map<String, Object> getFormInfo(String formId, String childAlias, Integer dataRowNum){
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormId(formId);
|
formDataEntity.setTenantId(StringUtil.toString(Context.getTenantId(), ""));
|
formDataEntity.setDataRowNum(dataRowNum);
|
String formName;
|
if(childAlias != null)
|
formName = FormNameTool.getSubFormTableName(formDataEntity.getTenantId(), formDataEntity.getFormId(), childAlias);
|
else
|
formName = FormNameTool.getFormTableName(formDataEntity.getTenantId(), formDataEntity.getFormId());
|
formDataEntity.setFormName(formName);
|
return formDataMapper.searchFormData(formDataEntity);
|
}
|
|
/**
|
* 获得子表单数据
|
* @param formId
|
* @param childAlias
|
* @param dataRowNum
|
* @return
|
*/
|
protected List<Map<String, Object>> getFormChildInfos(String formId, String childAlias, Integer dataRowNum){
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormId(formId);
|
formDataEntity.setTenantId(StringUtil.toString(Context.getTenantId(), ""));
|
formDataEntity.setDataRowNum(dataRowNum);
|
formDataEntity.setChildAlias(childAlias);
|
String formName;
|
if(formDataEntity.getChildAlias() != null)
|
formName = FormNameTool.getSubFormTableName(formDataEntity.getTenantId(), formDataEntity.getFormId(), formDataEntity.getChildAlias());
|
else
|
formName = FormNameTool.getFormTableName(formDataEntity.getTenantId(), formDataEntity.getFormId());
|
formDataEntity.setFormName(formName);
|
return formDataMapper.searchFormDataList(formDataEntity);
|
}
|
|
|
/**
|
* 修改数据
|
* @param formId
|
* @param childAlias
|
* @param dataRowNum
|
* @param data
|
*/
|
protected void updateData(String formId, String childAlias, Integer dataRowNum, Map<String, Object> data){
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormId(formId);
|
if(ObjectUtil.notEmpty(childAlias)) {
|
formDataEntity.setChildAlias(childAlias);
|
}
|
formDataEntity.setTenantId(Objects.toString(Context.getTenantId(), ""));
|
formDataEntity.setDataRowNum(dataRowNum);
|
formDataEntity.setMap(data);
|
formDataService.updateForm(formDataEntity);
|
}
|
|
@Override
|
public void setSystemFormInfo(List<SystemConfig> systemFormInfo) {
|
Map<SystemForm, String> map = new HashMap<>();
|
systemFormInfo.stream().forEach(systemConfig -> {
|
map.put(SystemForm.valueOf(systemConfig.getCkey()), systemConfig.getCvalue());
|
});
|
this.systemConfigs = map;
|
}
|
|
protected Map<SystemForm, String> getSystemFormInfo(){
|
return this.systemConfigs;
|
}
|
|
protected String getFormId(SystemForm systemForm){
|
return getSystemFormInfo().get(systemForm);
|
}
|
|
protected void checkMoney(double money){
|
Assert.condition(money < 0, BUDGET_MONEY_NOT_ENOUGH);
|
}
|
|
private Map<String,FormBaseEntity> formMap=new HashedMap<>();
|
|
public FormBaseEntity getFormBase(String formId){
|
// if(formMap.get(formId)!=null){
|
// log.debug("回写预算返回表单缓存数据{}", formMap.size());
|
// return formMap.get(formId);
|
// }
|
FormKey fk = new FormKey();
|
fk.setFormId(formId);
|
fk.setTenantId(ThreadData.get(Keys.TENANT_ID));
|
FormBaseEntity fb= formFieldService.selectFormFieldProperty(fk);
|
// log.debug("回写预算返回表单实时数据:{}", JSONTool.toJson(fb));
|
// formMap.put(formId,fb);
|
return fb;
|
|
}
|
|
protected String format(double money,FormBaseEntity fieldSet,String field){
|
String doubleStr =formatDouble(fieldSet.getFieldset(),field);
|
DecimalFormat df = new DecimalFormat(doubleStr);
|
String result = df.format(money);
|
// result = result.replaceAll("0*$", "");
|
result = result.replaceAll("[.]$", "");
|
log.debug("小数格式化信息{}, 格式前数据:{}, 格式后数据:{}", doubleStr, money, result);
|
return result;
|
}
|
|
protected String formatDouble(String str,String field){
|
// String str=fieldSet;
|
Map<String,Object> map=JSONTool.toObj(str,Map.class);
|
final StringBuffer sb =new StringBuffer("#0.");
|
map.keySet()
|
.stream().forEach(o->{
|
Map<String,Object> item = JSONTool.toObj(JSONTool.toJson(map.get(o)),Map.class);
|
Map<String,Object> tagAttribute = JSONTool.toObj(JSONTool.toJson(item.get(TAG_ATTRIBUTE)),Map.class);
|
if(Objects.equals(tagAttribute.get(ALIAS),field)){
|
String decimalplace = Objects.toString(tagAttribute.get(DECIMALPLACE),"0");
|
if(decimalplace!=null && !Objects.equals("",decimalplace )){
|
Integer s = Integer.parseInt(decimalplace);
|
if(s != 0) {
|
for (int i = 0; i < s; i++) {
|
sb.append("0");
|
}
|
}else{
|
sb.deleteCharAt(sb.length()-1);
|
}
|
}else{
|
sb.deleteCharAt(sb.length()-1);
|
}
|
}
|
});
|
return sb.toString();
|
}
|
|
public void account(String formId,String tenantId,String dataRowNum){
|
//请求表单数据判断是否需要记账
|
Map<String,Object> formInfo = getFormInfo(formId,null,Integer.parseInt(dataRowNum));
|
String flag = Objects.toString(formInfo.get(ACCOUNT_FLAG),"");
|
log.debug("{}-{}表单数据记账标示是:{}", formId, dataRowNum, flag);
|
if(Objects.equals(GetConstant.getConstant(ACCOUNT_FLAG),flag) || ObjectUtil.empty(flag)){
|
//请求表单接口
|
FormBaseEntity formBaseEntity = getFormBase(formId);
|
//判断当前表单是否记账
|
log.debug("{}表单记账标示是:{}", formId, ("1".equals(formBaseEntity.getAccountingRule()) ? "记账" : "不记账"));
|
if ("1".equals(formBaseEntity.getAccountingRule())) {
|
Account account = new Account();
|
account.setFormId(formId);
|
account.setTenantId(tenantId);
|
account.setDataRowNum(dataRowNum);
|
account.setCompanyId(ThreadData.get(Keys.COMPANY_ID));
|
account.setOpenId(ThreadData.get(OPEN_ID));
|
account.setFieldSet(formBaseEntity.getFieldset());
|
account.setDataStart(0);
|
account.initParam();
|
RestInterface restInterface = SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class);
|
Object data = restInterface.post(AdminUrlConst.ACCOUNT_ADD, account, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
|
|
}
|
}
|
|
}
|
|
}
|