| | |
| | | import com.product.core.service.support.AbstractBaseService; |
| | | import com.product.project.management.config.Cmnconst; |
| | | import com.product.project.management.config.SystemCode; |
| | | import com.product.project.management.util.ItemizeUtil; |
| | | import com.product.project.management.util.ProjectItemUtil; |
| | | import com.product.util.BaseUtil; |
| | | |
| | |
| | | * @param headerDataList excel标题数据 |
| | | */ |
| | | public DataTableEntity importBudget2(DataTableEntity dtParseData, List<List<String>> headerDataList) { |
| | | try { |
| | | |
| | | |
| | | //判断是否有解析EXCEL数据 |
| | | if (BaseUtil.dataTableIsEmpty(dtParseData)) { |
| | | return null; |
| | |
| | | for (int i = 0; i < dtParseData.getRows(); i++) { |
| | | //获取excel行数据 |
| | | FieldSetEntity fseParseData = dtParseData.getFieldSetEntity(i); |
| | | //生成项目分项 |
| | | String uuid = autoCreateProjectItem(dtNewProjectItem, fseParseData, itemizeFullNameAndUUID, itemizeFullNameAndCode, itemizeFullNameAndMaxCode); |
| | | fseParseData.setValue(Cmnconst.PROJECT_ITEMIZE_UUID, uuid); |
| | | |
| | | //生成材料类型 |
| | | String bugetCode = fseParseData.getString(Cmnconst.BUDGET_CODE); |
| | | String materialType = null; |
| | | if ("声测管".equals(bugetCode)) { |
| | | materialType = "2"; |
| | | }else { |
| | | String materialCode = fseParseData.getString(Cmnconst.MATERIAL_CODE); |
| | | if (materialCode.contains("架立筋")) { |
| | | materialType = "1"; |
| | | fseParseData.setValue(Cmnconst.MATERIAL_CODE, ItemizeUtil.getChineseOrEnglishOrNumber("ENGLISHNUMBER", materialCode)); |
| | | }else if (materialCode.contains("钢筋网")) { |
| | | materialType = "3"; |
| | | fseParseData.setValue(Cmnconst.MATERIAL_CODE, ItemizeUtil.getChineseOrEnglishOrNumber("ENGLISHNUMBER", materialCode)); |
| | | }else{ |
| | | FieldSetEntity fseMaterial = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_BASE_MATERIAL,"material_code=?", new Object[] {materialCode}, false); |
| | | if (fseMaterial != null) { |
| | | materialType = fseMaterial.getString(Cmnconst.MATERIAL_TYPE); |
| | | if (materialType.indexOf("0")>-1) { |
| | | materialType = "0"; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | fseParseData.setValue(Cmnconst.MATERIAL_TYPE, materialType); |
| | | } |
| | | if (!BaseUtil.dataTableIsEmpty(dtNewProjectItem)) { |
| | | try { |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return dtParseData; |
| | | } |
| | |
| | | public String autoCreateProjectItem(DataTableEntity dtNewProjectItem, FieldSetEntity fseParseData, Map<String, String> itemizeFullNameAndUUID, Map<String, String> itemizeFullNameAndCode, Map<String, String> itemizeFullNameAndMaxCode) { |
| | | String itemizFullName = null; |
| | | String finalUUID = null; |
| | | FieldSetEntity fseProject = baseDao.getFieldSetByFilter(Cmnconst.PRODUCT_PROJECT_QXLW, "project_name=?", new Object[] {fseParseData.getString("field0")}, false); |
| | | String projectUUID = fseProject.getUUID(); |
| | | //循环field1~field6字段,逐步生成对应的项目分项数据 |
| | | for (int i = 1; i < 7; i++) { |
| | | for (int i = 1; i < 9; i++) { |
| | | |
| | | //获取分项名称,判断是否为空 |
| | | String itemize = fseParseData.getString("field"+i); |
| | | //判断项目分项名称是否为空(如为空:则该预算对应的项目分项生成完毕,预算关联的UUID为上一个field分项对应的UUID |
| | | if (BaseUtil.strIsNull(itemize)) { |
| | | finalUUID = itemizeFullNameAndUUID.get(itemizFullName); |
| | | break; |
| | | if (i==8) { |
| | | finalUUID = itemizeFullNameAndUUID.get(itemizFullName); |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | //获取上级分项和当前分项全称(如当前分项没有上级:则全称等于名称;如有上级:则全称等于上级全称/名称) |
| | |
| | | //判断项目分项是否存在于集合中 |
| | | if(!itemizeFullNameAndCode.containsKey(itemizFullName)) { |
| | | //查询分项和上级分项是否存在于数据库中 |
| | | FieldSetEntity fseProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, "itemize_full_name=?", new Object[] {itemizFullName}, false); |
| | | FieldSetEntity fseProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, "project_uuid = ? AND itemize_full_name=?", new Object[] {projectUUID,itemizFullName}, false); |
| | | if (fseProjectItem == null) { |
| | | String uuid = UUID.randomUUID().toString(); |
| | | String code; |
| | |
| | | }else { |
| | | FieldSetEntity fseMaxProjectItem; |
| | | if(BaseUtil.strIsNull(itemizeParent)) { |
| | | fseMaxProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, new String[] {"Max(itemize_code)itemize_code"}, "itemize_parent_code IS NULL", new Object[] {}, false, null); |
| | | fseMaxProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, new String[] {"Max(itemize_code)itemize_code"}, "project_uuid = ? AND itemize_parent_code IS NULL", new Object[] {projectUUID}, false, null); |
| | | }else { |
| | | fseMaxProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, new String[] {"Max(itemize_code)itemize_code"}, "itemize_parent_code = ?", new Object[] {itemizeFullNameAndCode.get(itemizeParent)}, false, null); |
| | | fseMaxProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, new String[] {"Max(itemize_code)itemize_code"}, "project_uuid = ? AND itemize_parent_code = ?", new Object[] {projectUUID, itemizeFullNameAndCode.get(itemizeParent)}, false, null); |
| | | } |
| | | if (fseMaxProjectItem==null || BaseUtil.strIsNull(fseMaxProjectItem.getString(Cmnconst.ITEMIZE_CODE))) { |
| | | code = ProjectItemUtil.autoCreateCode(itemizeFullNameAndCode.get(itemizeParent)); |
| | |
| | | FieldSetEntity fseNewProject = new FieldSetEntity(Cmnconst.PRODUCT_PROJECT_ITEM); |
| | | fseNewProject.setValue(Cmnconst.UUID, uuid); |
| | | fseNewProject.setValue("~type~", "add"); |
| | | // fseNewProject.setValue(Cmnconst.PROJECT_UUID, ); |
| | | fseNewProject.setValue(Cmnconst.PROJECT_UUID, projectUUID); |
| | | fseNewProject.setValue(Cmnconst.ITEMIZE, itemize); |
| | | fseNewProject.setValue(Cmnconst.ITEMIZE_CODE, code); |
| | | fseNewProject.setValue(Cmnconst.ITEMIZE_PARENT_CODE, itemizeFullNameAndCode.get(itemizeParent)); |
| | |
| | | String code = fseProjectItem.getString(Cmnconst.ITEMIZE_CODE); |
| | | FieldSetEntity fseMaxProjectItem; |
| | | if (BaseUtil.strIsNull(fseProjectItem.getString(Cmnconst.ITEMIZE_PARENT_CODE))) { |
| | | fseMaxProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, new String[] {"Max(itemize_code)itemize_code"}, "itemize_parent_code IS NULL", new Object[] {}, false, null); |
| | | fseMaxProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, new String[] {"Max(itemize_code)itemize_code"}, "project_uuid = ? AND itemize_parent_code IS NULL", new Object[] {projectUUID}, false, null); |
| | | }else { |
| | | fseMaxProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, new String[] {"Max(itemize_code)itemize_code"}, "itemize_parent_code=?", new Object[] {fseProjectItem.getString(Cmnconst.ITEMIZE_PARENT_CODE)}, false, null); |
| | | fseMaxProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, new String[] {"Max(itemize_code)itemize_code"}, " project_uuid = ? AND itemize_parent_code=?", new Object[] {projectUUID, fseProjectItem.getString(Cmnconst.ITEMIZE_PARENT_CODE)}, false, null); |
| | | } |
| | | itemizeFullNameAndUUID.put(itemizFullName, uuid); |
| | | itemizeFullNameAndCode.put(itemizFullName, code); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 项目预算导入 |
| | | * @param dtParseData 解析数据 |
| | | * @param headerDataList excel标题数据 |
| | | */ |
| | | public DataTableEntity importBudget(DataTableEntity dtParseData, List<List<String>> headerDataList) { |
| | | //判断是否有解析EXCEL数据 |
| | | if (BaseUtil.dataTableIsEmpty(dtParseData)) { |
| | | return null; |
| | | } |
| | | //声明异常集 |
| | | StringBuilder sbError = new StringBuilder(); |
| | | //遍历excel转换数据 |
| | | for (int i = 0; i < dtParseData.getRows(); i++) { |
| | | FieldSetEntity fseParseData = dtParseData.getFieldSetEntity(i); |
| | | |
| | | //根据解析数据获取项目分项信息 |
| | | List<Object> params = new ArrayList<>(); |
| | | String projectItem = autoCreateFilter(params, fseParseData); |
| | | |
| | | //根据模板项目分项查询数据库项目分项 |
| | | FieldSetEntity fseProjectItem = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_ITEM, "project_uuid IN (SELECT uuid FROM product_project_qxlw WHERE project_name=?) AND itemize_full_name=?", params.toArray(), false); |
| | | if(fseProjectItem==null) { |
| | | sbError.append(String.format("第 %s 行项目分项 '%s' 不存在于系统中。", fseParseData.getString("~row~"), projectItem)); |
| | | continue; |
| | | } |
| | | //设置关联项目分项 |
| | | fseParseData.setValue("project_itemize_uuid", fseProjectItem.getUUID()); |
| | | |
| | | //获取编码生成材料类型 |
| | | String budgetCode = fseParseData.getString(Cmnconst.BUDGET_CODE); |
| | | Integer materialType = 0; |
| | | if("架立筋".equals(budgetCode)) { |
| | | materialType = 1; |
| | | }else if("声测管".equals(budgetCode)) { |
| | | materialType = 2; |
| | | }else { |
| | | //网片 |
| | | FieldSetEntity materialInfo = baseDao.getFieldSetEntityByFilter(Cmnconst.PRODUCT_PROJECT_BASE_MATERIAL, "material_type=3 AND material_name like ?", new Object[] {fseParseData.getString(Cmnconst.MATERIAL_CODE)+"%"}, false); |
| | | if (materialInfo!=null) { |
| | | materialType = 3; |
| | | } |
| | | } |
| | | fseParseData.setValue(Cmnconst.MATERIAL_TYPE, materialType); |
| | | } |
| | | //判断是否包含错误信息 |
| | | if (!BaseUtil.strIsNull(sbError.toString())) { |
| | | throw new BaseException(SystemCode.PROJECT_BUDGET_IMPORT_FAIL.getValue(), sbError.toString()); |
| | | } |
| | | return dtParseData; |
| | | } |
| | | |
| | | /** |
| | | * 自动生成查询项目分项filter |
| | | * @param params |
| | | * @param fseParseData |
| | | * 清除所有预算 |
| | | * @param projectUUID |
| | | * @return |
| | | */ |
| | | public String autoCreateFilter(List<Object> params , FieldSetEntity fseParseData) { |
| | | StringBuilder projectItem = new StringBuilder(); |
| | | for (int i = 1; i < 7; i++) { |
| | | String fieldValue = fseParseData.getString("field"+i); |
| | | if(!BaseUtil.strIsNull(fieldValue)) { |
| | | if (i>2) { |
| | | projectItem.append("/"); |
| | | } |
| | | if(i==1) { |
| | | params.add(fieldValue); |
| | | }else{ |
| | | projectItem.append(fieldValue); |
| | | } |
| | | } |
| | | public boolean clearBudget(String projectUUID, String itemizeCode) { |
| | | DataTableEntity dtOutbound; |
| | | if(BaseUtil.strIsNull(itemizeCode)) { |
| | | dtOutbound = baseDao.listTable(Cmnconst.PRODUCT_PROJECT_OUTBOUND, "project_uuid=?", new Object[] {projectUUID}); |
| | | }else { |
| | | dtOutbound = baseDao.listTable(Cmnconst.PRODUCT_PROJECT_OUTBOUND, "project_uuid=? AND project_itemize IN (SELECT uuid FROM product_project_item WHERE project_uuid=? AND itemize_code LIKE ?)", new Object[] {projectUUID,projectUUID,itemizeCode+"%"}); |
| | | } |
| | | params.add(projectItem.toString()); |
| | | return projectItem.toString(); |
| | | if (!BaseUtil.dataTableIsEmpty(dtOutbound)) { |
| | | throw new BaseException(SystemCode.PROJeCT_BUDGET_CLEAR_FAIL_HAS_OUTBOUND.getValue(), SystemCode.PROJeCT_BUDGET_CLEAR_FAIL_HAS_OUTBOUND.getText()); |
| | | } |
| | | return false; |
| | | // if (BaseUtil.strIsNull(itemizeCode)) { |
| | | // return baseDao.executeUpdate("DELETE FROM product_project_budget WHERE project_itemize_uuid IN (SELECT uuid FROM product_project_item WHERE project_uuid=?)", new Object[] {projectUUID}); |
| | | // }else { |
| | | // return baseDao.executeUpdate("DELETE FROM product_project_budget WHERE project_itemize_uuid IN (SELECT uuid FROM product_project_item WHERE project_uuid=? AND itemize_code LIKE ?)", new Object[] {projectUUID,itemizeCode+"%"}); |
| | | // } |
| | | } |
| | | } |