package com.changhong.epc.form.service.budget.impl; import com.changhong.autoform.entity.BudgetData; import com.changhong.autoform.entity.BudgetTitle; import com.changhong.autoform.entity.ProcessBudget; import com.changhong.epc.bean.form.Fieldsets; import com.changhong.epc.bean.form.FormDataEntity; import com.changhong.epc.bean.form.FormType; import com.changhong.epc.bean.form.ReleData; import com.changhong.epc.bean.form.budget.BudgetUserDefined; import com.changhong.epc.bean.form.budget.BudgetUserDefined.Dimension; import com.changhong.epc.bean.form.budget.filtrate.BudgetclassifyKey; import com.changhong.epc.bean.form.budget.filtrate.BudgetclassifyValue; import com.changhong.epc.bean.tenant.cost.budgetlog.MoneyBudgetLog; import com.changhong.epc.bean.tenant.log.BudgetLog; import com.changhong.epc.bean.tenant.log.BudgetUpdateType; import com.changhong.epc.bean.tenant.system.SystemConfig; import com.changhong.epc.constter.base.BaseConst; import com.changhong.epc.constter.form.budget.BudgetMsg; import com.changhong.epc.constter.system.SystemClients; import com.changhong.epc.constter.system.businesscode.AutoFormTagArrtibute; import com.changhong.epc.constter.system.run.EpcRestInterface; import com.changhong.epc.constter.tenant.TenantUrlConst; import com.changhong.epc.form.execute.IFormOthersOperation; import com.changhong.epc.form.filter.data.impl.FormDataCodeToNameFilter; import com.changhong.epc.form.mapper.tenant.log.BudgetLogMapper; import com.changhong.epc.form.service.budget.IBudgetMoney; import com.changhong.epc.form.service.budget.department.IDepartment; import com.changhong.epc.form.service.budget.department.impl.SuperBudgtDepartments; import com.changhong.epc.form.service.budget.department.model.BudgetExtend; import com.changhong.epc.form.service.budget.department.util.FormCheck; import com.changhong.epc.form.service.budget.tool.impl.AbstractBudgetLog; import com.changhong.epc.form.service.data.FormDataService; import com.changhong.epc.form.tool.FormNameTool; import com.changhong.epc.form.tool.GetReleData; import com.changhong.epc.rely.api.epc.tenant.SystemConfigApi; import com.iemsoft.framework.cloud.core.base.ResMsg; import com.iemsoft.framework.cloud.core.tools.*; import com.iemsoft.framework.cloud.ribbon.RestInterface; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.ModelMap; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; /** * 用户自定义数据源 —— 项目预算 * @author wangZX * */ @Slf4j @SuppressWarnings("unchecked") @Service("budgetMoney") public class BudgetMoneyImpl implements IBudgetMoney,AutoFormTagArrtibute,SystemClients,TenantUrlConst , BaseConst, BudgetMsg { @Resource private FormCheck formCheck; @Resource private SystemConfigApi systemConfigApi; @Resource private FormDataService formDataService; @Resource private IFormOthersOperation formOthersOperation; @Resource private GetReleData getReleData; @Resource private BudgetLogMapper budgetLogMapper; @Resource private FormDataCodeToNameFilter formDataCodeToNameFilter; /** * 调用那个函数 */ private IDepartment department; /** * 什么单~ */ private FormType flag; private Integer pageSize = 5; private Integer pageNum = 1; private String tp = null; /** * 查询预算列表 */ @Override public Map selectBudgetList(BudgetData budgetData) { ProcessBudget processb = new ProcessBudget(); this.pageNum = budgetData.getPageNum(); this.pageSize = budgetData.getPageSize(); processb.setFormId(GetConstant.getFormIdGetConstant(YS_FORMID)); processb.setAlias(BUDGET_SUB_FROM); processb.setTenantID(budgetData.getTenantID()); // System.out.println(JSONTool.toJson(processb)); if (ObjectUtil.notEmpty(budgetData.getDataRowNum())) { String[] arr = budgetData.getDataRowNum().split(","); Map data = new HashMap<>(); // List> data = new ArrayList<>(); for (int i = 0; i < arr.length; i++) { processb.setDataRowNUm(Integer.valueOf(Objects.toString(arr[i]))); FormDataEntity formData = new FormDataEntity(); formData.setChildAlias(processb.getAlias()); formData.setDataRowNum(processb.getDataRowNUm()); formData.setTenantId(budgetData.getTenantID());//租户ID formData.setFormId(processb.getFormId()); Map subForm = formDataService.searchFormData(formData); formData.setChildAlias(null); formData.setDataRowNum(Integer.parseInt(subForm.get("PARENTDATAROWNUM").toString())); Map searchFormInfo = formDataService.searchFormInfo(formData); formDataCodeToNameFilter.accept(searchFormInfo, subForm); subForm.put(NUMBER_BUDGET, searchFormInfo.get(NUMBER_BUDGET)); subForm.put(BUDGET_START_DATE, searchFormInfo.get(BUDGET_START_DATE)); subForm.put(BUDGET_END_DATE, searchFormInfo.get(BUDGET_END_DATE)); subForm.put(BUDGET_STATEMENT, searchFormInfo.get(BUDGET_STATEMENT)); data.put("list",Arrays.asList(subForm)); data.put("count", subForm.size()); log.debug(JSONTool.toJson(subForm)); } budgetData.setFormID(processb.getFormId()); return data; } else { try { department = getIDepartment(budgetData.getKey()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { } // 获取筛选条件 BudgetUserDefined userDefined = gainScreeningCondition(budgetData); Map dataSource = new HashMap<>(); try { dataSource = getDataSource(userDefined.getMainDimension(), processb, budgetData.getKey()); }catch (Exception e){ e.printStackTrace(); log.error(e.getMessage(), e); } budgetData.setFormID(processb.getFormId()); return dataSource; } } public Boolean writeBudget(ProcessBudget processBudget,Map fromInfo,String formId) { log.debug("测试查看参数1"); log.debug(JSONTool.toJson(processBudget)); log.debug(JSONTool.toJson(fromInfo)); log.debug(JSONTool.toJson(formId)); log.debug("测试查看参数2"); processBudget.setAlias(BUDGET_SUB_FROM); List> ids = new ArrayList<>(); if(department instanceof SuperBudgtDepartments){ String formName = FormNameTool.getSubFormTableName(processBudget.getTenantID(), processBudget.getFormId(), BUDGET_SUB_FROM); List selectMainIdBySubIds = formDataService.selectMainIdBySubIds(formName, Objects.toString(fromInfo.get(TO_WRITE_BUDGET))); for (Integer subId : selectMainIdBySubIds) { List subids = new ArrayList<>(); subids.add(subId); ids.add(subids); } }else{ ids = getDataRows(Objects.toString(fromInfo.get(TO_WRITE_BUDGET))); } log.debug(JSONTool.toJson(fromInfo)); if(flag == FormType.YS){ List> subDatas = (List>) fromInfo.get(BUDGET_SUB_FROM); if(ids.size() != subDatas.size()){ log.debug("对应错误"); return false; } for(int i=0; i> supperBudgetRows = new ArrayList<>(); subDatas.get(i).put(ROW_IDS, ids.get(i)); if(ObjectUtil.notEmpty(ids.get(i))) { for (int id : ids.get(i)) { processBudget.setFormId(GetConstant.getFormIdGetConstant(YS_FORMID)); processBudget.setAlias(BUDGET_SUB_FROM); processBudget.setDataRowNUm(id); Map selectFormDataInfo = formOthersOperation.getFromInfo(processBudget); log.debug(JSONTool.toJson(selectFormDataInfo)); supperBudgetRows.add(selectFormDataInfo); } } //封装成咱们想要的结构 subDatas.get(i).put(SUPPER_BUDGET_ROWS, supperBudgetRows); } } log.debug(JSONTool.toJson(fromInfo)); department.executeWriteBack(fromInfo,processBudget,formId); return true; } public static List> getDataRows(String ids) { List> idList = new ArrayList<>(); String[] split = ids.split(","); for(String group : split){ // System.out.println(group); group = group.trim(); List asList = Arrays.asList(group.split("_")); List asInts = new ArrayList<>(); asList.forEach(o->asInts.add(Integer.valueOf(o))); idList.add(asInts); // System.out.println(idList); } return idList; } /** * 获得预算余额是整数.or.小数 * @param processBudget */ public Integer getBudgetItemBalanceType(ProcessBudget processBudget){ Fieldsets formFieldProperty = formOthersOperation.getFormFieldProperty(processBudget); Integer type = -1; if(DECIMAL.equals(formFieldProperty.getAllTagArr() .get(BUDGET_ITEM_BALANCE) .get(NUMBER_TYPE))){ type = Integer.parseInt(formFieldProperty.getAllTagArr().get(DECIMAL).toString()); }else{ type = 0; } return type; } public void initData(ProcessBudget processBudget){ // Fieldsets formFieldProperty = formOthersOperation.getFormFieldProperty(processBudget); // formFieldProperty.getMainCpn().forEach(o->{ // // // if(Objects.equals(o.getTagType(),"mytext")){ // try { // log.debug("函数名:"+o.getFundata()); // department = getIDepartment(o.getFundata()); // } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // throw new IEMRestException("函数实体创建失败。。。"); // } // } // }); } @Override public Boolean executeProcessRefunds(ProcessBudget processBudget) { /**查询表单控件相关信息*/ Fieldsets formFieldProperty =this.getFieldsets(processBudget); /**根据formID确定表单类型*/ flag = GetConstant.getFormType(processBudget.getFormId()); /**获得相关联表单余额是小数还是整数*/ ProcessBudget onlyBudget = new ProcessBudget(); onlyBudget.setTenantID(processBudget.getTenantID()); if(FormType.YS == flag){ processBudget.setAlias(BUDGET_SUB_FROM); onlyBudget.setFormId(processBudget.getFormId()); }else{ onlyBudget.setFormId(GetConstant.getFormIdGetConstant(YS_FORMID)); } Integer type = getBudgetItemBalanceType(onlyBudget); Map fromInfo = formOthersOperation.selectFormDataInfo(processBudget); fromInfo.put(YS_FORMID, onlyBudget.getFormId()); fromInfo.put(BUDGETITEMBALANCETYPE, type); /**确定具体关联类型*/ formFieldProperty.getMainCpn().stream() .filter( cpn-> Objects.equals(cpn.getAlias(),TO_WRITE_BUDGET)) .forEach(o->{ /**是否使用关联函数*/ try { if(StringUtils.isBlank(o.getFundata())){ /**报销使用申请**/ if(FormType.BX == flag){ department = getIDepartment("ExpendUseApplyFun"); }else{ /**预算占用上级预算*/ department = getIDepartment("SuperBudgtDepartments"); } }else{ /**根据表单创建时候 使用 选择的函数*/ department = getIDepartment(o.getFundata()); } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { } }); if(department != null){ return department.excuteRefunds(fromInfo); } return false; } // private void excuteRefunds(){ // // } private Fieldsets getFieldsets(ProcessBudget processBudget){ return formOthersOperation.getFormFieldProperty(processBudget); } @Override public Boolean selectorModel(ProcessBudget processBudget){ String formId = processBudget.getFormId(); List> cq = new ArrayList<>(); Fieldsets formFieldProperty = this.getFieldsets(processBudget); //根据formID确定表单类型 flag = GetConstant.getFormType(processBudget.getFormId()); if(FormType.YS == flag){ processBudget.setAlias(BUDGET_SUB_FROM); } Map fromInfo = formOthersOperation.selectFormDataInfo(processBudget); //获得申请单余额控件是整数.or.小数 ProcessBudget onlyBudget = new ProcessBudget(); onlyBudget.setTenantID(processBudget.getTenantID()); onlyBudget.setFormId(GetConstant.getFormIdGetConstant(YS_FORMID)); Integer type = getBudgetItemBalanceType(onlyBudget); fromInfo.put("budgetItemBalanceType", type); log.debug(JSONTool.toJson(formFieldProperty.getSubform().toString())); formFieldProperty.getMainCpn().stream() .filter( cpn-> Objects.equals(cpn.getAlias(),TO_WRITE_BUDGET)) .forEach(o->{ if(StringUtils.isBlank(o.getFundata())){ try { // 报销使用申请 if(FormType.BX == flag){ department = getIDepartment("ExpendUseApplyFun"); // System.out.println("查询参数为:"+processBudget); Map fromInfoBX = formOthersOperation.selectFormDataInfo(processBudget); // String formID = GetConstant.getFormIdGetConstant(SQ_FORMID); String formID = formFieldProperty.getAssoFormId(); processBudget.setFormId(formID); // System.out.println("错误参数为:"+fromInfoBX); processBudget.setDataRowNUm(Integer.parseInt((Objects.toString(fromInfoBX.get(TO_WRITE_BUDGET),"0")))); Map fromInfoSQ = formOthersOperation.selectFormDataInfo(processBudget); BigDecimal m = new BigDecimal(fromInfoSQ.get(APPLY_USE_MONEY).toString()).subtract(new BigDecimal(fromInfoBX.get(EXPEND_USE_MONEY).toString())); fromInfoSQ.put(APPLY_USE_MONEY, m); cq.add(fromInfoSQ); }else{ // 预算占用上级预算 department = getIDepartment("SuperBudgtDepartments"); } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { } }else{ try { // 根据表单创建时候 使用 选择的函数 department = getIDepartment(o.getFundata()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { } } }); if(department != null){ return writeBudget(processBudget,cq.size()>0?cq.get(0) : fromInfo,formId); } return false; } /** * 获取筛选条件 * @param budgetData * @return */ public BudgetUserDefined gainScreeningCondition(BudgetData budgetData){ log.debug("开始筛选维度条件。。。"); BudgetUserDefined budgetUserDefined; // 获取子表单内的数据 Map data = budgetData.getFormData(); // 获取 函数维度 String type = Objects.toString(data.get(BUDGET_PROJECT),null); // System.out.println(data.get(BUDGET_PROJECT)+"-------------------------"+type); String key = BUDGET_CONFIGURATION; if(type!=null && !"".equals(type)){ key = BUDGET_PROJECT_CONFIGURATION; } // System.out.println("key:"+key); //判断是什么类型的单子 budgetUserDefined = JSONTool.toObj(JSONTool.toJson( department.getBudgetUserDefined(key)),BudgetUserDefined.class); // System.out.println("函数维度:"+JSONTool.toJson(budgetUserDefined)); // } List> subData = (List>)data.get(BUDGET_SUB_FROM); if(subData != null){ budgetUserDefined.initSubDimensions(subData.size()); for(int i=0; i < subData.size(); i++){ Map map = subData.get(i); List sublistRow = budgetUserDefined.getSubDimensions().get(i); sublistRow.forEach(o->o.setData(map)); } // log.debug(budgetUserDefined.toString()); // log.debug("维度筛选完成。。。"); // return budgetUserDefined; } budgetUserDefined.getMainDimension().forEach(o->o.setData(data)); log.debug("dimension:{}", JSONTool.toJson(budgetUserDefined.getMainDimension())); //最终维度 // System.out.println("最终维度结果:"+JSONTool.toJson(budgetUserDefined)); return budgetUserDefined; } @SuppressWarnings("unused") public Map getDataSource(List dimensions, ProcessBudget processb,String fun){ log.debug("获取匹配的数据源头id集"); //不知道为什么下面用了迭代器,只能记录一下下标 int index = -1; String formName = FormNameTool.getSubFormTableName(processb.getTenantID(), processb.getFormId(), null); Map maintj = new HashMap<>(); if(ObjectUtil.empty(dimensions)){ return new ModelMap(); } Iterator dimensionIterable = dimensions.iterator(); while (dimensionIterable.hasNext()){ Dimension di = dimensionIterable.next(); // maintj.put(di.getName(), di.getValue()); maintj.put(di.getColumn(), di.getValue()); if(di.getIsRemove()){ dimensionIterable.remove(); } } log.debug("maintj:{}", JSONTool.toJson(maintj)); log.debug("dimensions:{}", JSONTool.toJson(dimensions)); String curre = maintj.get(CURRENCY); String pro; if(maintj.get(BUDGET_PROJECT)!=null && !"".equals(maintj.get(BUDGET_PROJECT))){ pro = maintj.get(BUDGET_PROJECT); }else{ pro = null; } //预算结束时间 String toD = null; if(maintj.get(BUDGET_END_DATE)!=null && !"".equals(maintj.get(BUDGET_END_DATE))){ toD = maintj.get(BUDGET_END_DATE); } //常量表中取出定死的 预算 使用 String occupy = GetConstant.getConstant(OCCUPY); //取出项目预算的值 String budProject = GetConstant.getConstant(BUDGET_PROJECT); //取出部门预算的值 String budDep = GetConstant.getConstant(BUDGET_ITEM_DEPARTMENT); //取出可用预算单主表datarownum List selectRangeByIds = formDataService.selectRangeByIds( formName, maintj.get(BUDGET_START_DATE), toD, pro, curre, occupy,(this.pageNum-1)*this.pageSize, this.pageSize, budProject,budDep); log.debug(selectRangeByIds.toString()); LinkedList> data = new LinkedList<>(); if(selectRangeByIds.isEmpty()) return null; FormDataEntity formData = new FormDataEntity(); formData.setFormId(processb.getFormId()); formData.setDimensions(dimensions); //取出可使用的部门、 String dep = null; if(maintj.get(APPLY_DEPARTMENT)!=null && !"".equals(maintj.get(APPLY_DEPARTMENT))){ dep = maintj.get(APPLY_DEPARTMENT); }else if(maintj.get(EXPEND_DEPARTMENT)!=null && !"".equals(maintj.get(EXPEND_DEPARTMENT))){ dep = maintj.get(EXPEND_DEPARTMENT); }else{ dep = maintj.get(BUDGET_ITEM_DEPARTMENT); } String crossLevel = systemConfigApi.getVal(SystemConfig.ofKey("crossLevel", "crossLevel"), SystemConfig::getCvalue); boolean isCrossLevel = Objects.equals("C00001", crossLevel); if(isCrossLevel){ Object ob = this.getData(TenantUrlConst.REST_TENANT_SYSTEM_BUDGETCONFIG_GETPARENTORG, new ModelMap() .addAttribute("orgCode", dep).addAttribute("cId",maintj.get(APPLY_COST_TYPE))); formData.setDepartment(JSONTool.toList(JSONTool.toJson(ob), String.class)); }else{ formData.setDepartment(Arrays.asList(dep)); } formData.setTenantId(processb.getTenantID()); int i = 0;//总条数 for(Integer dataRowNumber : selectRangeByIds){ formData.setChildAlias(processb.getAlias()); formData.setDataRowNum(dataRowNumber); //只查询可被使用的预算单 Map searchFormInfo; List> subs = null; searchFormInfo = formDataService.searchFormInfo1(formData); if(!searchFormInfo.get(BUDGET_SUB_FROM).equals(BUDGET_SUB_FROM) && ((List)searchFormInfo.get(BUDGET_SUB_FROM)).size() >0){ subs = (List>) searchFormInfo.get(BUDGET_SUB_FROM); formDataCodeToNameFilter.accept(searchFormInfo, subs); if(subs == null){ return null; } subs.forEach( o ->{ o.put(NUMBER_BUDGET, searchFormInfo.get(NUMBER_BUDGET)); o.put(BUDGET_START_DATE, searchFormInfo.get(BUDGET_START_DATE)); o.put(BUDGET_END_DATE, searchFormInfo.get(BUDGET_END_DATE)); o.put(BUDGET_STATEMENT, searchFormInfo.get(BUDGET_STATEMENT)); }); // log.debug(JSONTool.toJson(searchFormInfo)); for(Map o :subs){ Double money = 0.0; if(ObjectUtil.notEmpty(o.get(BUDGET_ITEM_BALANCE))){ money = Double.parseDouble(Objects.toString(o.get(BUDGET_ITEM_BALANCE),"0")); } log.debug("当前预算余额:"+money); if(money>0) { i++; data.add(o); } } // subs.forEach( // }); } } // int endPage = data.size() < this.pageSize ? data.size() : (this.pageNum-1)*this.pageSize + this.pageSize; // data.subList((this.pageNum-1)*this.pageSize, endPage); Map result = new HashMap<>(); result.put("count", i); result.put("list", data); // log.debug(JSONTool.toJson(result)); return result; } /** * 创建对应的函数 * @param name * @return * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException */ public static IDepartment getIDepartment(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException{ Class forName = Class.forName("com.changhong.epc.form.service.budget.department.impl."+name); IDepartment department = (IDepartment)forName.newInstance(); return department; } /** * 对原始数据进行分组 * @param budgetFroms * @param department * @return */ private Map dataGroup(List> budgetFroms, IDepartment department) { Map data = new HashMap<>(); if(ObjectUtil.empty(budgetFroms)){ return data; } for(Map budgetFrom : budgetFroms){ BudgetclassifyKey budgetclassifyKey = new BudgetclassifyKey(budgetFrom); BudgetclassifyValue group = data.get(budgetclassifyKey); if(group == null){ group = new BudgetclassifyValue(); group.setBudgetFilterMode(department); data.put(budgetclassifyKey, group); } group.add(budgetFrom); } return data; } @Override @Transactional public boolean extendTime(BudgetExtend budgetExtend) { FormDataEntity formData = new FormDataEntity(); formData.setDataRowNum(budgetExtend.getDataId()); formData.setFormId(budgetExtend.getFormId()); formData.setTenantId(budgetExtend.getTenantID()); // 验证 Map searchFormInfo = formDataService.searchFormInfo(formData); Assert.empty(searchFormInfo, EMPTY_BUDGET); Assert.condition( DateTool.stringToDate(Objects.toString(searchFormInfo.get(BUDGET_END_DATE))) .compareTo(DateTool.stringToDate(budgetExtend.getInfo())) >= 0 , BUDGET_EXPEND_DATE_ERROR ); // 添加log BudgetLog budgetLog = new BudgetLog(); budgetLog.setUpdateType(BudgetUpdateType.DATE); budgetLog.setOriginalText(Objects.toString(searchFormInfo.get(BUDGET_END_DATE))); budgetLog.setUpdateText(budgetExtend.getInfo()); budgetLog.setBudgetId(AbstractBudgetLog.getDataRowNum(searchFormInfo)); budgetLog.initParam(); budgetLogMapper.insert(budgetLog); // 修改预算 formData.setData(Arrays.asList(new ModelMap(BUDGET_END_DATE, budgetExtend.getInfo()))); formData.setChildAlias(null); formDataService.updateFormData(formData); return true; } public static void main(String... args) { // System.out.println(DateTool.stringToDate("20180302").compareTo(DateTool.stringToDate("20180402"))); } @Override public boolean extendMoney(BudgetExtend budgetExtend) { MoneyBudgetLog budgetLog = new MoneyBudgetLog(); FormDataEntity formData = new FormDataEntity(); formData.setChildAlias(BUDGET_SUB_FROM); formData.setDataRowNum(budgetExtend.getDataId()); formData.setFormId(budgetExtend.getFormId()); Map searchFormInfo = formDataService.searchFormInfo(formData); List> subData = (List>)searchFormInfo.get(BUDGET_SUB_FROM); List> data = new ArrayList<>(); budgetLog.setFormId(budgetExtend.getFormId()+"_"+budgetExtend.getTenantID()+""+BUDGET_SUB_FROM); Map info = new HashMap<>(); subData.forEach(o->{ if( Objects.equals(o.get(BUDGET_ITEM_COST_TYPE), budgetExtend.getCostType()) && Objects.equals(o.get(BUDGET_ITEM_DEPARTMENT), budgetExtend.getOrganization())){ Double balance = Double.valueOf(Objects.toString(o.get(BUDGET_ITEM_BALANCE),"0")); info.put(BUDGET_ITEM_BALANCE,balance+Double.valueOf(budgetExtend.getInfo())); info.put(BUDGET_SUPER_EXTENDMONEY, budgetExtend.getInfo()); budgetLog.setRowId(Integer.valueOf(o.get(DATAROWNUMBER).toString())); budgetLog.setAlterContentOld(balance.toString()); budgetLog.setAlterContentNew(Objects.toString(balance+Double.valueOf(budgetExtend.getInfo()))); } }); if(info.isEmpty()){ return false; } data.add(info); formData.setData(data); formDataService.updateFormData(formData); recordLog(budgetLog); return true; } /** * ********************************** * * 【费用类型 如手机费】【开发部】 【100】 * * * -------------------------------- * 1 手机费 开发部 200 100 100 * 2 出差费 200 * 3 路由费 300 * * * * ********************************* * * * @param budgetLog */ private void recordLog(MoneyBudgetLog budgetLog) { } @Override public List getTitles(String key) { try { department = getIDepartment(key); } catch (Exception e) { return null; } return department.getTitles(); } @Override public boolean recycleMoney(BudgetExtend budgetExtend) { MoneyBudgetLog budgetLog = new MoneyBudgetLog(); FormDataEntity formData = new FormDataEntity(); formData.setChildAlias(BUDGET_SUB_FROM); formData.setDataRowNum(budgetExtend.getDataId()); formData.setFormId(budgetExtend.getFormId()); Map searchFormInfo = formDataService.searchFormInfo(formData); List> subData = (List>)searchFormInfo.get(BUDGET_SUB_FROM); List> data = new ArrayList<>(); budgetLog.setFormId(budgetExtend.getFormId()+"_"+budgetExtend.getTenantID()+""+BUDGET_SUB_FROM); Map info = new HashMap<>(); subData.forEach(o->{ if(Objects.equals(o.get(BUDGET_ITEM_COST_TYPE), budgetExtend.getCostType()) && Objects.equals(o.get(BUDGET_ITEM_DEPARTMENT), budgetExtend.getOrganization())){ Double balance = Double.valueOf(Objects.toString(o.get(BUDGET_ITEM_BALANCE),"0")); info.put(BUDGET_ITEM_BALANCE,balance-Double.valueOf(budgetExtend.getInfo())); info.put(BUDGET_SUPER_EXTENDMONEY, budgetExtend.getInfo()); budgetLog.setRowId(Integer.valueOf(o.get(DATAROWNUMBER).toString())); budgetLog.setAlterContentOld(balance.toString()); budgetLog.setAlterContentNew(Objects.toString(balance+Double.valueOf(budgetExtend.getInfo()))); } }); if(info.isEmpty()){ return false; } data.add(info); formData.setData(data); formDataService.updateFormData(formData); recordLog(budgetLog); return true; } /** * * @author quldong * @data 2017-11-28 * 追加/回收 */ @Override public int addMoney(ProcessBudget processBudget) { return 1; } @Override public boolean repaymentMoney(BudgetExtend budgetExtend) { ReleData chooseData =getReleData.GetData(budgetExtend.getTenantID(), budgetExtend.getFormId(), budgetExtend.getDatarowNum(), REPAYMENT_SUPER_LOAN); if(chooseData.getChooseData() != null){ //当前数据(还款单)未还金额 if(Integer.parseInt(getReleData.getNowData().get("AmountRepayment").toString())<= Integer.parseInt(chooseData.getChooseData().get("OutstandingAmount").toString())){ // System.err.println(chooseData.getChooseData()); // System.err.println(getReleData.getNowData()); String formName = ("formdata"+"_"+budgetExtend.getTenantID()+"_"+ budgetExtend.getFormId()); Integer dataRowNum = Integer.parseInt(getReleData.getNowData().get("DATAROWNUM").toString()); Integer Outstanding = Integer.parseInt(getReleData.getNowData().get("OutstandingAmount").toString()) -Integer.parseInt(getReleData.getNowData().get("AmountRepayment").toString()); formDataService.updaterepayment(formName, Outstanding, null, dataRowNum); //选择的数据(借款单)未还金额 Integer datarowNum = Integer.parseInt(chooseData.getChooseData().get("DATAROWNUM").toString()); //之前的代码 // String formname = ("formdata"+"_"+budgetExtend.getTenantID()+"_"+ budgetExtend.getNetformid()); String formname = ("formdata"+"_"+budgetExtend.getTenantID()+"_"+chooseData.getReleFormID()); Integer OutstandingAmount = Integer.parseInt(chooseData.getChooseData().get("OutstandingAmount").toString()) - Integer.parseInt(getReleData.getNowData().get("AmountRepayment").toString()); //选择的数据(借款单)已还金额 Integer alreadyRepaid = Integer.parseInt(chooseData.getChooseData().get("alreadyRepaid").toString()) + Integer.parseInt(getReleData.getNowData().get("AmountRepayment").toString()); formDataService.updaterepayment(formname, OutstandingAmount, alreadyRepaid, datarowNum); }else{ return false; } } return true; } /** * 拼接表明 * @param tenantID * @param formID * @return */ public String getTableName(String tenantID,String formID){ return "formdata" + "_" + tenantID + "_" + formID + "_" + "budget_subfrom"; } /** * 转换Int */ public int toInt(Object o){ return Integer.parseInt(Objects.toString(o, "0")); } public boolean eq(int a,int b){ return a>=b; } //访问费用云,取出 public Object getData(String url,Map map){ RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class); Object data = restInterface.post(url, map, ResMsg.class,EpcRestInterface.getEpcHeads()).getData(); // System.out.println("---------------返回结果--------"); // System.out.println("---------------返回结果--------"); // System.out.println("---------------返回结果--------"); // System.out.println(JSONTool.toJson(data)); return data!=null?data:null; } }