package com.changhong.epc.form.service.budget.impl; import com.changhong.autoform.entity.BudgetData; import com.changhong.autoform.entity.BudgetTitle; import com.changhong.autoform.mapper.associate.Associate; import com.changhong.epc.constter.form.extend.FunctionConst; import com.changhong.epc.form.filter.data.FormDataFilterUtil; import com.changhong.epc.form.service.budget.IBudgetMoney; import com.changhong.epc.form.service.budget.tool.entity.SelectFormResult; import com.changhong.epc.form.service.budget.tool.impl.SuperBudgetSelectForm; import com.changhong.epc.form.service.field.FormFieldService; import com.github.pagehelper.Page; import com.iemsoft.framework.cloud.core.tools.MsgTool; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.ui.ModelMap; import javax.annotation.Resource; import java.util.*; @Service("associate") @Slf4j public class AssociateImpl implements Associate, FunctionConst { @Resource private IBudgetMoney budgetMoney; @Resource private FormFieldService formFieldService; @Resource private SuperBudgetSelectForm superBudgetSelectForm; /** * 查询会写预算函数 */ @Override public List> getAssociateDataSourse() { return Arrays.asList( // 部门预算 new ModelMap("key", ORG_BUDGET_KEY) .addAttribute("val", MsgTool.get(ORG_BUDGET_KEY)) // 归口预算 , new ModelMap("key",OCCUPATION_BUDGET_KEY) .addAttribute("val", MsgTool.get(OCCUPATION_BUDGET_KEY)) // 上级部门预算 , new ModelMap("key", SUPER_ORG_BUDGET_KEY) .addAttribute("val", MsgTool.get(SUPER_ORG_BUDGET_KEY)) // 申请使用预算 , new ModelMap("key", APPLY_BUDGET_KEY) .addAttribute("val", MsgTool.get(APPLY_BUDGET_KEY)) // 报销使用申请 , new ModelMap("key",EXPEND_BUDGET_KEY) .addAttribute("val", MsgTool.get(EXPEND_BUDGET_KEY)) ); } /** * 查询显示标题 */ @Override public List getAssociateTitle(String key) { if(Objects.equals(superBudgetSelectForm.getName(), key)){ return superBudgetSelectForm.getTitles(key); } return budgetMoney.getTitles(key); } /** * 查询数据列表 */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Map getAssociateData(BudgetData budgetData) { if(Objects.equals(superBudgetSelectForm.getName(), budgetData.getKey())){ SelectFormResult selectFormResult = superBudgetSelectForm.getData(budgetData); return new ModelMap("count" , selectFormResult.getCount()) .addAttribute("list" , FormDataFilterUtil.accept(selectFormResult.getList())); } // 数据列表 Map selectBudgetList = budgetMoney.selectBudgetList(budgetData); if(ObjectUtil.notEmpty(selectBudgetList)){ // code 转 name List> budgetList = (List)selectBudgetList.get("list"); // List> budgetList = formFieldService.getAssociateData((List)selectBudgetList.get("list"), budgetData.getFormID(), // budgetData.getTenantID()); Page page = new Page<>(budgetData.getPageNum(), budgetData.getPageSize()); page.setTotal(budgetList.size()); return new ModelMap ("count" , page.getTotal()) // .addAttribute("list" , getPageData(page, budgetList)); .addAttribute("list" , FormDataFilterUtil.accept(getPageData(page, budgetList))); }else{ return new ModelMap ("count" , 0) .addAttribute("list" , Collections.EMPTY_LIST); } } protected List> getPageData(Page page, List> datas){ return datas.subList(page.getStartRow(), Math.min(page.getEndRow(), new Long(page.getTotal()).intValue())); } }