diff --git a/src/main/java/cn/palmte/work/controller/backend/ProcurementTypeController.java b/src/main/java/cn/palmte/work/controller/backend/ProcurementTypeController.java index a2c5811..8127fc4 100644 --- a/src/main/java/cn/palmte/work/controller/backend/ProcurementTypeController.java +++ b/src/main/java/cn/palmte/work/controller/backend/ProcurementTypeController.java @@ -12,8 +12,11 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; @Controller @RequestMapping("/procurement/type") @@ -37,7 +40,7 @@ public class ProcurementTypeController extends BaseController{ Map model) { model.put("keywords",keywords); ConcurrentHashMap searchInfo = getSearchInfo(keywords,model); - model.put("pager",procurementTypeService.list(searchInfo,pageNumber,pageSize)); + model.put(PAGER,procurementTypeService.list(searchInfo,pageNumber,pageSize)); return "/admin/procurement_type_list"; } @@ -134,4 +137,20 @@ public class ProcurementTypeController extends BaseController{ ExportUtils.exportToExcel(headers, exportColumns, 1, 10000, httpServletResponse.getOutputStream(), (pN, pS) -> procurementTypeService.list(searchInfo, pN, pS).getList()); } + + /** + * 类型和类别的映射关系 + */ + @RequestMapping("/map") + @ResponseBody + public ResponseMsg map() { + List procurementTypes = procurementTypeService.allProcurementTypeList(); + Map> map = procurementTypes.stream().collect(Collectors.groupingBy(ProcurementType::getType)); + + Map objectMap = new HashMap<>(); + objectMap.put("procurementTypes", procurementTypes); + objectMap.put("map", map); + return ResponseMsg.buildSuccessData(objectMap); + } + } diff --git a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java index eda739d..3b9335a 100644 --- a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java +++ b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java @@ -64,6 +64,8 @@ public class ProjectController extends BaseController { private ActTaskDefService actTaskDefService; @Autowired private ProjectSettleService projectSettleService; + @Autowired + private ProcurementTypeService procurementTypeService; /** * 项目列表 @@ -176,6 +178,8 @@ public class ProjectController extends BaseController { model.put("incomeDetails", projectBudgetService.getBudgetIncomeDetail(project)); //成本明细 model.put("costDetails", projectBudgetService.getBudgetCostDetail(project)); + //采购类型 + model.put("procurementTypes", procurementTypeService.allProcurementTypeList()); //项目管理成本明细 model.put("costProjectManageDetails", projectBudgetService.getBudgetCostProjectManageDetail(project)); List projectBudgetPlanDetails = projectBudgetService.getProjectBudgetPlanDetails(project); diff --git a/src/main/java/cn/palmte/work/model/ProcurementType.java b/src/main/java/cn/palmte/work/model/ProcurementType.java index 026e72c..7605a57 100644 --- a/src/main/java/cn/palmte/work/model/ProcurementType.java +++ b/src/main/java/cn/palmte/work/model/ProcurementType.java @@ -12,6 +12,9 @@ import java.util.Date; @Table(name = "procurement_type") public class ProcurementType { + public static final int ENABLED = 1; + public static final int DISABLED = 0; + /** * id */ @@ -22,7 +25,7 @@ public class ProcurementType { private String name; - private int category; + private int type; private int enabled; @@ -52,12 +55,12 @@ public class ProcurementType { this.name = name; } - public int getCategory() { - return category; + public int getType() { + return type; } - public void setCategory(int category) { - this.category = category; + public void setType(int type) { + this.type = type; } public int getEnabled() { diff --git a/src/main/java/cn/palmte/work/model/ProcurementTypeRepository.java b/src/main/java/cn/palmte/work/model/ProcurementTypeRepository.java index f5ba88e..d02a02e 100644 --- a/src/main/java/cn/palmte/work/model/ProcurementTypeRepository.java +++ b/src/main/java/cn/palmte/work/model/ProcurementTypeRepository.java @@ -2,7 +2,8 @@ package cn.palmte.work.model; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ProcurementTypeRepository extends JpaRepository { - - + List findAllByEnabledEquals(int enable); } diff --git a/src/main/java/cn/palmte/work/service/ProcurementTypeService.java b/src/main/java/cn/palmte/work/service/ProcurementTypeService.java index 20251d7..1ef1cbf 100644 --- a/src/main/java/cn/palmte/work/service/ProcurementTypeService.java +++ b/src/main/java/cn/palmte/work/service/ProcurementTypeService.java @@ -10,6 +10,7 @@ import top.jfunc.common.db.bean.Page; import top.jfunc.common.db.utils.Pagination; import java.util.Date; +import java.util.List; import java.util.Map; @Service @@ -25,8 +26,8 @@ public class ProcurementTypeService { QueryHelper queryHelper = new QueryHelper("SELECT *","procurement_type"); queryHelper.addCondition(searchInfo.containsKey("name"), "name like ?", "%" + searchInfo.get("name") + "%"); - queryHelper.addCondition(searchInfo.containsKey("category") && !"-1".equals(searchInfo.get("category")), - "category=" + searchInfo.get("category")); + queryHelper.addCondition(searchInfo.containsKey("type") && !"-1".equals(searchInfo.get("type")), + "type=" + searchInfo.get("type")); queryHelper.addCondition(searchInfo.containsKey("enabled") && !"-1".equals(searchInfo.get("enabled")), "enabled=" + searchInfo.get("enabled")); queryHelper.addCondition(searchInfo.containsKey("startTime"), "created_time >= ?", searchInfo.get("startTime") + " 00:00:00"); @@ -44,13 +45,13 @@ public class ProcurementTypeService { if(null == obj){ obj = new ProcurementType(); obj.setName(procurementType.getName()); - obj.setCategory(procurementType.getCategory()); + obj.setType(procurementType.getType()); obj.setEnabled(procurementType.getEnabled()); obj.setCreatedBy(InterfaceUtil.getAdmin().getRealName()); obj.setCreatedTime(new Date()); }else { obj.setName(procurementType.getName()); - obj.setCategory(procurementType.getCategory()); + obj.setType(procurementType.getType()); obj.setEnabled(procurementType.getEnabled()); } procurementTypeRepository.saveAndFlush(obj); @@ -75,10 +76,10 @@ public class ProcurementTypeService { one.setEnabled(status); ProcurementType procurementType = procurementTypeRepository.saveAndFlush(one); - if(null != procurementType){ - return true; - } + return null != procurementType; + } - return false; + public List allProcurementTypeList(){ + return procurementTypeRepository.findAllByEnabledEquals(ProcurementType.ENABLED); } } diff --git a/src/main/resources/static/assets/js/project_budget_cost.js b/src/main/resources/static/assets/js/project_budget_cost.js index 23ced21..5dc6be8 100644 --- a/src/main/resources/static/assets/js/project_budget_cost.js +++ b/src/main/resources/static/assets/js/project_budget_cost.js @@ -2,6 +2,68 @@ * 一个采购成本详情的字段 */ COST_DETAIL_ARR=["type","category","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"]; +/* +[ + {"id":"1","name":"xxx1"},{"id":"2","name":"xxx2"} +] + */ +SELECT_TYPE_CATEGORY_DATA=[]; +/*{ + "1":[ + { + "id":"1", + "name":"华智产品" + }, + { + "id":"2", + "name":"紫光其他产品" + }, + { + "id":"3", + "name":"外购产品" + } + ], + "2":[ + { + "id":"4", + "name":"外购工程" + } + ], + "3":[ + { + "id":"5", + "name":"华智服务" + }, + { + "id":"6", + "name":"紫光其他服务" + }, + { + "id":"7", + "name":"外购服务" + } + ], + "4":[ + { + "id":"8", + "name":"其他" + } + ] +};*/ +SELECT_TYPE_CATEGORY_MAP_DATA={}; +/*{ + "1":"1", + "2":"1", + "3":"1", + "4":"2", + "5":"3", + "6":"3", + "7":"3", + "8":"4" +}; +*/ +SELECT_CATEGORY_TYPE_MAP_DATA={}; + $(function () { $("#cost-detail").click(function () { $('#my-prompt-cost-detail').modal({ @@ -24,11 +86,20 @@ $(function () { bindOtherOtherChangeable(); //绑定采购明细中select联动事件 bindTypeSelectChange(); + + //初始化大类和类别的数据 + getAjax(base+"/procurement/type/map", null, initTypeCategory); }); /** * 采购成本增加一行 */ function appendTrCost() { + //console.log(SELECT_TYPE_CATEGORY_DATA); + var options = ''; + SELECT_TYPE_CATEGORY_DATA.forEach(function (e) { + options+='\r\n'; + }); + var template = ''+ - ''+ + + /*''+ ''+ ''+ ''+ ''+ ''+ ''+ - ''+ + ''+*/ + + options+ + ''+ ''+ ''+ @@ -57,6 +132,7 @@ function appendTrCost() { ''+ ''+ ''; + $("#costTable").append(template); //重新绑定删除事件和input修改事件 bindDeleteBtn(); @@ -158,60 +234,6 @@ function bindOtherOtherChangeable() { }); } -SELECT_TYPE_CATEGORY_MAP_DATA={ - "1":[ - { - "value":"1", - "name":"华智产品" - }, - { - "value":"2", - "name":"紫光其他产品" - }, - { - "value":"3", - "name":"外购产品" - } - ], - "2":[ - { - "value":"4", - "name":"外购工程" - } - ], - "3":[ - { - "value":"5", - "name":"华智服务" - }, - { - "value":"6", - "name":"紫光其他服务" - }, - { - "value":"7", - "name":"外购服务" - } - ], - "4":[ - { - "value":"8", - "name":"其他" - } - ] -}; - -SELECT_CATEGORY_TYPE_MAP_DATA={ - "1":"1", - "2":"1", - "3":"1", - "4":"2", - "5":"3", - "6":"3", - "7":"3", - "8":"4" -}; - /** * 大类类别联动效果 */ @@ -222,16 +244,58 @@ function bindTypeSelectChange() { var type = $(this).val(); //删除后重新添加对应的类别 categorySelect.empty(); - SELECT_TYPE_CATEGORY_MAP_DATA[type].forEach(function (d) { - categorySelect.append(""); - }) + + //console.log(SELECT_TYPE_CATEGORY_MAP_DATA); + + if(SELECT_TYPE_CATEGORY_MAP_DATA[type]){ + SELECT_TYPE_CATEGORY_MAP_DATA[type].forEach(function (d) { + categorySelect.append(""); + }); + } + }); //类别变化联动大类 $(".am-modal-prompt-input-cost-category").on('change',function () { var typeSelect = $(this).parent().parent().find(".am-modal-prompt-input-cost-type"); var category = $(this).val(); //设置他选中类别对应的大类 + + //console.log(SELECT_CATEGORY_TYPE_MAP_DATA); + typeSelect.val(SELECT_CATEGORY_TYPE_MAP_DATA[category]); }); } +/** + * 初始化数据 + * SELECT_TYPE_CATEGORY_MAP_DATA + * SELECT_CATEGORY_TYPE_MAP_DATA + * SELECT_TYPE_CATEGORY_DATA + */ +function initTypeCategory(params, data) { + var d = data.data; + var map = d.map; + Object.keys(map).forEach(function (t, number) { + var temp = []; + map[t].forEach(function (g) { + temp.push({ + name:g.name, + id:g.id+"" + }); + }); + SELECT_TYPE_CATEGORY_MAP_DATA[t]= temp; + }); + + var procurementTypes = d.procurementTypes; + procurementTypes.forEach(function (e) { + SELECT_TYPE_CATEGORY_DATA.push({ + id:e.id+"", + name:e.name + }); + SELECT_CATEGORY_TYPE_MAP_DATA[e.id]=e.type; + }); + + // console.log(SELECT_TYPE_CATEGORY_MAP_DATA); + // console.log(SELECT_TYPE_CATEGORY_DATA); + // console.log(SELECT_CATEGORY_TYPE_MAP_DATA); +} diff --git a/src/main/resources/templates/admin/procurement_type_input.ftl b/src/main/resources/templates/admin/procurement_type_input.ftl index 15fd675..274f74c 100644 --- a/src/main/resources/templates/admin/procurement_type_input.ftl +++ b/src/main/resources/templates/admin/procurement_type_input.ftl @@ -37,11 +37,11 @@
*所属大类
- + + + +
diff --git a/src/main/resources/templates/admin/procurement_type_list.ftl b/src/main/resources/templates/admin/procurement_type_list.ftl index 4e08317..621aee7 100644 --- a/src/main/resources/templates/admin/procurement_type_list.ftl +++ b/src/main/resources/templates/admin/procurement_type_list.ftl @@ -26,12 +26,12 @@ 所属大类
- - - - - + + + +
@@ -124,13 +124,13 @@ ${list.name!} - <#if list.category ==1 > + <#if list.type ==1 > 设备 - <#elseif list.category ==2> + <#elseif list.type ==2> 服务 - <#elseif list.category ==3> + <#elseif list.type ==3> 施工 - <#elseif list.category ==4> + <#elseif list.type ==4> 其他 @@ -196,8 +196,8 @@ var keywordsObj = {}; if ($("#name").val()) keywordsObj.name = $("#name").val(); - if ($("#category").val()) - keywordsObj.category = $("#category").val(); + if ($("#type").val()) + keywordsObj.type = $("#type").val(); if ($("#enabled").val()) keywordsObj.enabled = $("#enabled").val(); if ($("#startTime").val()) @@ -259,8 +259,8 @@ $("#submit-btn").on("click", function () { if ($("#name").val()) keywordsObj.name = $("#name").val(); - if ($("#category").val()) - keywordsObj.category = $("#category").val(); + if ($("#type").val()) + keywordsObj.type = $("#type").val(); if ($("#enabled").val()) keywordsObj.enabled = $("#enabled").val(); if ($("#startTime").val()) diff --git a/src/main/resources/templates/admin/project_budget_edit.ftl b/src/main/resources/templates/admin/project_budget_edit.ftl index 0ecdef0..b7c96c1 100644 --- a/src/main/resources/templates/admin/project_budget_edit.ftl +++ b/src/main/resources/templates/admin/project_budget_edit.ftl @@ -495,14 +495,17 @@