|
@@ -0,0 +1,971 @@
|
|
|
|
|
+package com.jeeplus.modules.projectStatement.web;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
|
+import com.jeeplus.common.config.Global;
|
|
|
|
|
+import com.jeeplus.common.json.AjaxJson;
|
|
|
|
|
+import com.jeeplus.common.persistence.Page;
|
|
|
|
|
+import com.jeeplus.common.utils.*;
|
|
|
|
|
+import com.jeeplus.common.utils.excel.ExportMultipleTabsExcel;
|
|
|
|
|
+import com.jeeplus.common.utils.excel.utils.ExcelImportBySheetName;
|
|
|
|
|
+import com.jeeplus.common.web.BaseController;
|
|
|
|
|
+import com.jeeplus.modules.projectStatement.entity.ProjectFinalAccounts;
|
|
|
|
|
+import com.jeeplus.modules.projectStatement.entity.ProjectFinalAccountsImport;
|
|
|
|
|
+import com.jeeplus.modules.projectStatement.entity.ProjectSubstationImport;
|
|
|
|
|
+import com.jeeplus.modules.projectStatement.service.ProjectFinalAccountsService;
|
|
|
|
|
+import com.jeeplus.modules.projectrecord.entity.ProjectRecords;
|
|
|
|
|
+import com.jeeplus.modules.projectrecord.enums.ProjectStatusEnum;
|
|
|
|
|
+import com.jeeplus.modules.projectrecord.service.ProjectRecordsService;
|
|
|
|
|
+import com.jeeplus.modules.ruralprojectrecords.entity.RuralProjectRecords;
|
|
|
|
|
+import com.jeeplus.modules.ruralprojectrecords.service.RuralProjectRecordsService;
|
|
|
|
|
+import com.jeeplus.modules.sys.entity.MainDictDetail;
|
|
|
|
|
+import com.jeeplus.modules.sys.entity.User;
|
|
|
|
|
+import com.jeeplus.modules.sys.utils.DictUtils;
|
|
|
|
|
+import com.jeeplus.modules.sys.utils.UserUtils;
|
|
|
|
|
+import com.jeeplus.modules.workreceiptsregister.entity.ResponseEntity;
|
|
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
|
+import org.springframework.ui.Model;
|
|
|
|
|
+import org.springframework.web.bind.WebDataBinder;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
|
+import java.net.URLDecoder;
|
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@Controller
|
|
|
|
|
+@RequestMapping(value = "${adminPath}/project/projectFinalAccounts")
|
|
|
|
|
+public class ProjectFinalAccountsController extends BaseController {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ProjectFinalAccountsService projectFinalAccountsService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RuralProjectRecordsService ruralProjectRecordsService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ protected ProjectRecordsService projectRecordsService;
|
|
|
|
|
+
|
|
|
|
|
+ @ModelAttribute
|
|
|
|
|
+ public ProjectFinalAccounts get(@RequestParam(required = false) String id){
|
|
|
|
|
+// 创建一个ProjectMaterialStorage
|
|
|
|
|
+ ProjectFinalAccounts entity = null;
|
|
|
|
|
+// 对于id进行是否为空的判断,如果不会空,就通过get方法获取材料库对象
|
|
|
|
|
+ if(StringUtils.isNotBlank(id)){
|
|
|
|
|
+ entity = projectFinalAccountsService.get(id);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(entity == null){
|
|
|
|
|
+ entity = new ProjectFinalAccounts();
|
|
|
|
|
+ }
|
|
|
|
|
+// 返回ProjectMaterialStorage
|
|
|
|
|
+ return entity;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 材料库列表页面
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("project:projectFinalAccounts:list")
|
|
|
|
|
+ @RequestMapping(value = {"list",""})
|
|
|
|
|
+ public String list(ProjectFinalAccounts projectFinalAccounts, HttpServletRequest request, HttpServletResponse response, Model model){
|
|
|
|
|
+ //进行查询之后进行任何操作,返回还是查询之后的数据页面
|
|
|
|
|
+ if (StringUtils.isNotBlank(projectFinalAccounts.getToflag())){
|
|
|
|
|
+ if (projectFinalAccounts.getToflag().equals("1")){
|
|
|
|
|
+ request.getSession().removeAttribute("projectFinalAccounts");
|
|
|
|
|
+ ProjectFinalAccounts search=projectFinalAccounts;
|
|
|
|
|
+ request.getSession().setAttribute("projectFinalAccounts",search);
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ if (request.getSession().getAttribute("projectFinalAccounts")!=null){
|
|
|
|
|
+ projectFinalAccounts= (ProjectFinalAccounts) request.getSession().getAttribute("projectFinalAccounts");
|
|
|
|
|
+ model.addAttribute("projectFinalAccounts", projectFinalAccounts);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Page<ProjectFinalAccounts> page = projectFinalAccountsService.findPage(new Page<ProjectFinalAccounts>(request,response),projectFinalAccounts);
|
|
|
|
|
+ model.addAttribute("page",page);
|
|
|
|
|
+ model.addAttribute("projectFinalAccounts",projectFinalAccounts);
|
|
|
|
|
+
|
|
|
|
|
+ return "modules/projectStatement/projectAccountsList";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // @RequiresPermissions(value={"project:projectStatement:add","project:projectStatement:edit"},logical = Logical.OR)
|
|
|
|
|
+ @RequestMapping(value = "save")
|
|
|
|
|
+ public String save(ProjectFinalAccounts projectFinalAccounts, Model model, RedirectAttributes redirectAttributes, String pageId) throws Exception {
|
|
|
|
|
+ int i = 1;
|
|
|
|
|
+ List<ProjectFinalAccountsImport> projectMaterialStorageList = new ArrayList<ProjectFinalAccountsImport>();
|
|
|
|
|
+ List<ProjectFinalAccountsImport> projectMaterialStorageList2 = projectFinalAccounts.getProjectFinalAccountsList();
|
|
|
|
|
+
|
|
|
|
|
+ // 对于list的长度进行判断,判断小于0就根据来的位置进行返回
|
|
|
|
|
+ if(projectMaterialStorageList2.size()<=0){
|
|
|
|
|
+ addMessage(redirectAttributes, "项目名称、材料名称、价格等获取失败,请重试");
|
|
|
|
|
+// pageId 1代表这是从工程咨询进来的 2是从造价审核进来的
|
|
|
|
|
+ if("1".equals(pageId)){
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/ruralProject/ruralProjectMessageAll/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+// 此处需要修改为迭代器形式
|
|
|
|
|
+ Iterator<ProjectFinalAccountsImport> iterator = projectMaterialStorageList2.iterator();
|
|
|
|
|
+ while (iterator.hasNext()){
|
|
|
|
|
+ ProjectFinalAccountsImport projectMaterialStorageImport = iterator.next();
|
|
|
|
|
+ if(projectMaterialStorageImport.getNumber() == null || projectMaterialStorageImport.getProjectOrCostName() == null || projectMaterialStorageImport.getSettlementSum()== null || "1".equals(projectMaterialStorageImport.getDelFlag())){
|
|
|
|
|
+ iterator.remove();
|
|
|
|
|
+ }else {
|
|
|
|
|
+ projectMaterialStorageList.add(projectMaterialStorageImport);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for(int k=0;k<projectMaterialStorageList.size();k++){
|
|
|
|
|
+ projectMaterialStorageList.get(k).setIsNewRecord(true);
|
|
|
|
|
+ // 判断项目名称、材料名称、价格是否为空
|
|
|
|
|
+ if(projectMaterialStorageList.get(k).getNumber()==null || projectMaterialStorageList.get(k).getProjectOrCostName() ==null || projectMaterialStorageList.get(k).getSettlementSum() == null){
|
|
|
|
|
+ addMessage(redirectAttributes, "第"+i+"个项目名称、材料名称、规格型号、单位等获取失败,请重试");
|
|
|
|
|
+
|
|
|
|
|
+ if("1".equals(pageId)){
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/ruralProject/ruralProjectMessageAll/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Map map = projectFinalAccountsService.qureyCountAboutProjectMaterialStorage(projectMaterialStorageList);
|
|
|
|
|
+ if((map.containsKey("failure"))){
|
|
|
|
|
+ addMessage(redirectAttributes, map.get("failure").toString());
|
|
|
|
|
+
|
|
|
|
|
+ if("1".equals(pageId)){
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/ruralProject/ruralProjectMessageAll/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ projectFinalAccountsService.batchSave(projectMaterialStorageList);
|
|
|
|
|
+
|
|
|
|
|
+ if("1".equals(pageId)){
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/ruralProject/ruralProjectMessageAll/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @InitBinder
|
|
|
|
|
+ public void initBinder(WebDataBinder binder) {
|
|
|
|
|
+ // 设置集合自动增长的上限为 1000
|
|
|
|
|
+ binder.setAutoGrowCollectionLimit(1000);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 材料库新增保存功能
|
|
|
|
|
+ * @param projectFinalAccounts
|
|
|
|
|
+ * @param model
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "storageSave")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public Map<String, Object> storageSave(@ModelAttribute ProjectFinalAccounts projectFinalAccounts, String dataBodyType, Model model) throws Exception {
|
|
|
|
|
+ // 初始化返回结果Map
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>(4);
|
|
|
|
|
+ Map<String, Object> stringObjectMap = disposeProjectFinalAccountsList(projectFinalAccounts);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //重复数据
|
|
|
|
|
+ List<ProjectFinalAccountsImport> duplicateList = Lists.newArrayList();
|
|
|
|
|
+ //错误数据
|
|
|
|
|
+ List<ProjectFinalAccountsImport> errorList = Lists.newArrayList();
|
|
|
|
|
+ //成功数据
|
|
|
|
|
+ List<ProjectFinalAccountsImport> uniqueList = Lists.newArrayList();
|
|
|
|
|
+ //元数据
|
|
|
|
|
+ List<ProjectFinalAccountsImport> projectMaterialStorageList = Lists.newArrayList();
|
|
|
|
|
+ //redis存储信息
|
|
|
|
|
+ Map<String, String> redisKeys = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ Boolean accountsSuccess = (Boolean) stringObjectMap.get("success");
|
|
|
|
|
+ if(accountsSuccess && dataBodyType.contains("工程项目竣工结算汇总表")){
|
|
|
|
|
+ duplicateList = (List<ProjectFinalAccountsImport>) stringObjectMap.get("duplicateList");
|
|
|
|
|
+ errorList = (List<ProjectFinalAccountsImport>) stringObjectMap.get("errorList");
|
|
|
|
|
+ uniqueList = (List<ProjectFinalAccountsImport>) stringObjectMap.get("uniqueList");
|
|
|
|
|
+ projectMaterialStorageList = (List<ProjectFinalAccountsImport>) stringObjectMap.get("projectMaterialStorageList");
|
|
|
|
|
+ redisKeys = (Map<String, String>) stringObjectMap.get("redisKeys");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> stringSubstationMap = disposeProjectSubstationList(projectFinalAccounts);
|
|
|
|
|
+ //重复数据
|
|
|
|
|
+ List<ProjectSubstationImport> duplicateSubstationList = Lists.newArrayList();
|
|
|
|
|
+ //错误数据
|
|
|
|
|
+ List<ProjectSubstationImport> errorSubstationList = Lists.newArrayList();
|
|
|
|
|
+ //成功数据
|
|
|
|
|
+ List<ProjectSubstationImport> uniqueSubstationList = Lists.newArrayList();
|
|
|
|
|
+ //元数据
|
|
|
|
|
+ List<ProjectSubstationImport> projectSubstationList = Lists.newArrayList();
|
|
|
|
|
+ //redis存储信息
|
|
|
|
|
+ Map<String, String> redisSubstationKeys = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ Boolean substationSuccess = (Boolean) stringSubstationMap.get("success");
|
|
|
|
|
+ if(substationSuccess && dataBodyType.contains("变电站建筑工程费用汇总表")){
|
|
|
|
|
+ duplicateSubstationList = (List<ProjectSubstationImport>) stringSubstationMap.get("duplicateList");
|
|
|
|
|
+
|
|
|
|
|
+ errorSubstationList = (List<ProjectSubstationImport>) stringSubstationMap.get("errorList");
|
|
|
|
|
+
|
|
|
|
|
+ uniqueSubstationList = (List<ProjectSubstationImport>) stringSubstationMap.get("uniqueList");
|
|
|
|
|
+
|
|
|
|
|
+ projectSubstationList = (List<ProjectSubstationImport>) stringSubstationMap.get("projectMaterialStorageList");
|
|
|
|
|
+
|
|
|
|
|
+ redisSubstationKeys = (Map<String, String>) stringSubstationMap.get("redisKeys");
|
|
|
|
|
+ redisKeys.putAll(redisSubstationKeys);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 封装返回结果
|
|
|
|
|
+ result.put("success", true);
|
|
|
|
|
+ result.put("message", "处理完成");
|
|
|
|
|
+ //元数据总数据量
|
|
|
|
|
+ result.put("metadataCount", projectMaterialStorageList.size() + projectSubstationList.size());
|
|
|
|
|
+ //成功数据量
|
|
|
|
|
+ result.put("uniqueCount", uniqueList.size() + uniqueSubstationList.size());
|
|
|
|
|
+ //错误数据量
|
|
|
|
|
+ result.put("errorCount", errorList.size() + errorSubstationList.size());
|
|
|
|
|
+ //重复数据量
|
|
|
|
|
+ result.put("duplicateCount", duplicateList.size() + duplicateSubstationList.size());
|
|
|
|
|
+ result.put("redisKeys", redisKeys);
|
|
|
|
|
+ result.put("projectId", projectFinalAccounts.getProjectId());
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Map<String,Object> disposeProjectFinalAccountsList(ProjectFinalAccounts projectFinalAccounts){
|
|
|
|
|
+ // 初始化返回结果Map
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>(4);
|
|
|
|
|
+
|
|
|
|
|
+ List<ProjectFinalAccountsImport> projectMaterialStorageList = Lists.newArrayList();
|
|
|
|
|
+ List<ProjectFinalAccountsImport> metadataList = projectFinalAccounts.getProjectFinalAccountsList();
|
|
|
|
|
+
|
|
|
|
|
+ if(null == metadataList || metadataList.isEmpty()){
|
|
|
|
|
+ result.put("success", false);
|
|
|
|
|
+ result.put("message", "请填写材料信息");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ result.put("success", true);
|
|
|
|
|
+ }
|
|
|
|
|
+// 此处需要修改为迭代器形式
|
|
|
|
|
+ Iterator<ProjectFinalAccountsImport> iterator = metadataList.iterator();
|
|
|
|
|
+ while (iterator.hasNext()){
|
|
|
|
|
+ ProjectFinalAccountsImport projectMaterialStorageImport = iterator.next();
|
|
|
|
|
+ if("1".equals(projectMaterialStorageImport.getDelFlag())){
|
|
|
|
|
+ iterator.remove();
|
|
|
|
|
+ }else if(StringUtils.isBlank(projectMaterialStorageImport.getProjectOrCostName()) || null == projectMaterialStorageImport.getSettlementSum()){
|
|
|
|
|
+ iterator.remove();
|
|
|
|
|
+ }else{
|
|
|
|
|
+
|
|
|
|
|
+ if(null !=projectMaterialStorageImport.getSettlementSum()){
|
|
|
|
|
+ BigDecimal scaledValue = projectMaterialStorageImport.getSettlementSum().setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ projectMaterialStorageImport.setSettlementSum(scaledValue);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ projectMaterialStorageList.add(projectMaterialStorageImport);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //对相对有效的数据进行处理
|
|
|
|
|
+ //有效的数据
|
|
|
|
|
+ List<ProjectFinalAccountsImport> effectiveList = Lists.newArrayList();
|
|
|
|
|
+ //错误的数据
|
|
|
|
|
+ List<ProjectFinalAccountsImport> errorList = Lists.newArrayList();
|
|
|
|
|
+ Iterator<ProjectFinalAccountsImport> projectMaterialStorageListIterator = projectMaterialStorageList.iterator();
|
|
|
|
|
+ while (projectMaterialStorageListIterator.hasNext()){
|
|
|
|
|
+ ProjectFinalAccountsImport projectMaterialStorageImport = projectMaterialStorageListIterator.next();
|
|
|
|
|
+ if(StringUtils.isNotBlank(projectMaterialStorageImport.getProjectOrCostName()) || null == projectMaterialStorageImport.getNumber()){
|
|
|
|
|
+ effectiveList.add(projectMaterialStorageImport);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ if(StringUtils.isNotBlank(projectMaterialStorageImport.getProjectOrCostName()) && null == projectMaterialStorageImport.getNumber()){
|
|
|
|
|
+ projectMaterialStorageImport.setErrorMessage("数据中缺少编号、项目或费用名称");
|
|
|
|
|
+ }else if(StringUtils.isNotBlank(projectMaterialStorageImport.getProjectOrCostName())){
|
|
|
|
|
+ projectMaterialStorageImport.setErrorMessage("数据中缺少项目或费用名称");
|
|
|
|
|
+ }else if(null == projectMaterialStorageImport.getNumber()){
|
|
|
|
|
+ projectMaterialStorageImport.setErrorMessage("数据中缺少编号");
|
|
|
|
|
+ }
|
|
|
|
|
+ errorList.add(projectMaterialStorageImport);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //对有效的数据进行去重处理
|
|
|
|
|
+ for (ProjectFinalAccountsImport info : effectiveList) {
|
|
|
|
|
+ // 处理可能的null值,转为空字符串
|
|
|
|
|
+ String number = (info.getNumber() != null) ? info.getNumber() : "";
|
|
|
|
|
+ String name = (info.getProjectOrCostName() != null) ? info.getProjectOrCostName() : "";
|
|
|
|
|
+ String spec = (info.getSettlementSum() != null) ? info.getSettlementSum().toString() : "";
|
|
|
|
|
+ String remarks = (info.getRemarks() != null) ? info.getRemarks() : "";
|
|
|
|
|
+ // 以逗号分隔组合
|
|
|
|
|
+ String resultStr =number + "," + name + "," + spec + "," + remarks;
|
|
|
|
|
+ info.setDistinctStr(resultStr);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String,List<ProjectFinalAccountsImport>> map = projectFinalAccountsService.distinctProjectMaterialStorage(effectiveList,projectFinalAccounts.getProjectId());
|
|
|
|
|
+ //有效数据
|
|
|
|
|
+ List<ProjectFinalAccountsImport> uniqueList = map.get("uniqueList");
|
|
|
|
|
+ //重复数据
|
|
|
|
|
+ List<ProjectFinalAccountsImport> duplicateList = map.get("duplicateList");
|
|
|
|
|
+ for (ProjectFinalAccountsImport info : duplicateList) {
|
|
|
|
|
+ info.setErrorMessage("重复数据");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Iterator<ProjectFinalAccountsImport> uniqueIterator = uniqueList.iterator();
|
|
|
|
|
+ while (uniqueIterator.hasNext()){
|
|
|
|
|
+ ProjectFinalAccountsImport info = uniqueIterator.next();
|
|
|
|
|
+ info.setProjectId(projectFinalAccounts.getProjectId());
|
|
|
|
|
+ Map<String, Object> saveResultMap = projectFinalAccountsService.saveUniqueInfo(info);
|
|
|
|
|
+ Boolean success = (Boolean) saveResultMap.get("success");
|
|
|
|
|
+ String message = (String) saveResultMap.get("message");
|
|
|
|
|
+ if(!success){
|
|
|
|
|
+ info.setErrorMessage(message);
|
|
|
|
|
+ errorList.add(info);
|
|
|
|
|
+ uniqueIterator.remove();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //有效数据:uniqueList
|
|
|
|
|
+ //错误数据:errorList
|
|
|
|
|
+ //重复数据:duplicateList
|
|
|
|
|
+ //元数据:metadataList
|
|
|
|
|
+ //判定,如果 错误数据 中存在数据,则表示前端传过来的数据并没有完全保存。需要将数据转存成exce文档并给下载接口
|
|
|
|
|
+ //可先将数据存储到redis中,保存的redis 的key可以按照 项目id + 登陆人id + uniqueList 这种格式
|
|
|
|
|
+ Map<String, String> redisKeys = new HashMap<>();
|
|
|
|
|
+ if(!duplicateList.isEmpty() || !errorList.isEmpty()){
|
|
|
|
|
+ User user = UserUtils.getUser();
|
|
|
|
|
+ String uniqueRedisKey = projectFinalAccounts.getProjectId() + "_" + user.getId() + "_accounts_uniqueList";
|
|
|
|
|
+ String errorRedisKey = projectFinalAccounts.getProjectId() + "_" + user.getId() + "_accounts_errorList";
|
|
|
|
|
+ String duplicateRedisKey = projectFinalAccounts.getProjectId() + "_" + user.getId() + "_accounts_duplicateList";
|
|
|
|
|
+ String metadataRedisKey = projectFinalAccounts.getProjectId() + "_" + user.getId() + "_accounts_metadataList";
|
|
|
|
|
+
|
|
|
|
|
+ // 保存前先删除对应key的原有数据
|
|
|
|
|
+ projectFinalAccountsService.deleteRedisKey(errorRedisKey);
|
|
|
|
|
+ projectFinalAccountsService.deleteRedisKey(uniqueRedisKey);
|
|
|
|
|
+ projectFinalAccountsService.deleteRedisKey(duplicateRedisKey);
|
|
|
|
|
+ projectFinalAccountsService.deleteRedisKey(metadataRedisKey);
|
|
|
|
|
+
|
|
|
|
|
+ // 分别存储各个列表
|
|
|
|
|
+ if (!errorList.isEmpty()) {
|
|
|
|
|
+ projectFinalAccountsService.saveListToZSet(errorRedisKey, errorList);
|
|
|
|
|
+ redisKeys.put("errorRedisKey", errorRedisKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!uniqueList.isEmpty()) {
|
|
|
|
|
+ projectFinalAccountsService.saveListToZSet(uniqueRedisKey, uniqueList);
|
|
|
|
|
+ redisKeys.put("uniqueRedisKey", uniqueRedisKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!duplicateList.isEmpty()) {
|
|
|
|
|
+ projectFinalAccountsService.saveListToZSet(duplicateRedisKey, duplicateList);
|
|
|
|
|
+ redisKeys.put("duplicateRedisKey", duplicateRedisKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!projectMaterialStorageList.isEmpty()) {
|
|
|
|
|
+ projectFinalAccountsService.saveListToZSet(metadataRedisKey, projectMaterialStorageList);
|
|
|
|
|
+ redisKeys.put("metadataRedisKey", metadataRedisKey);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ result.put("duplicateList", duplicateList);
|
|
|
|
|
+ result.put("errorList", errorList);
|
|
|
|
|
+ result.put("uniqueList", uniqueList);
|
|
|
|
|
+ result.put("projectMaterialStorageList", projectMaterialStorageList);
|
|
|
|
|
+ result.put("redisKeys", redisKeys);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Map<String,Object> disposeProjectSubstationList(ProjectFinalAccounts projectFinalAccounts){
|
|
|
|
|
+ // 初始化返回结果Map
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>(4);
|
|
|
|
|
+
|
|
|
|
|
+ List<ProjectSubstationImport> projectMaterialStorageList = Lists.newArrayList();
|
|
|
|
|
+ List<ProjectSubstationImport> metadataList = projectFinalAccounts.getProjectSubstationList();
|
|
|
|
|
+
|
|
|
|
|
+ if(null == metadataList || metadataList.isEmpty()){
|
|
|
|
|
+ result.put("success", false);
|
|
|
|
|
+ result.put("message", "请填写材料信息");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ result.put("success", true);
|
|
|
|
|
+ }
|
|
|
|
|
+// 此处需要修改为迭代器形式
|
|
|
|
|
+ Iterator<ProjectSubstationImport> iterator = metadataList.iterator();
|
|
|
|
|
+ while (iterator.hasNext()){
|
|
|
|
|
+ ProjectSubstationImport projectMaterialStorageImport = iterator.next();
|
|
|
|
|
+ if("1".equals(projectMaterialStorageImport.getDelFlag())){
|
|
|
|
|
+ iterator.remove();
|
|
|
|
|
+ }else if(StringUtils.isBlank(projectMaterialStorageImport.getProjectOrCostName())){
|
|
|
|
|
+ iterator.remove();
|
|
|
|
|
+ }else{
|
|
|
|
|
+ if(null !=projectMaterialStorageImport.getEngineeringCost()){
|
|
|
|
|
+ BigDecimal scaledValue = projectMaterialStorageImport.getEngineeringCost().setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ projectMaterialStorageImport.setEngineeringCost(scaledValue);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(null !=projectMaterialStorageImport.getLaborCost()){
|
|
|
|
|
+ BigDecimal scaledValue = projectMaterialStorageImport.getLaborCost().setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ projectMaterialStorageImport.setLaborCost(scaledValue);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(null !=projectMaterialStorageImport.getEstimatedMaterialCost()){
|
|
|
|
|
+ BigDecimal scaledValue = projectMaterialStorageImport.getEstimatedMaterialCost().setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ projectMaterialStorageImport.setEstimatedMaterialCost(scaledValue);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(null !=projectMaterialStorageImport.getTotalCost()){
|
|
|
|
|
+ BigDecimal scaledValue = projectMaterialStorageImport.getTotalCost().setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ projectMaterialStorageImport.setTotalCost(scaledValue);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ projectMaterialStorageList.add(projectMaterialStorageImport);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //对相对有效的数据进行处理
|
|
|
|
|
+ //有效的数据
|
|
|
|
|
+ List<ProjectSubstationImport> effectiveList = Lists.newArrayList();
|
|
|
|
|
+ //错误的数据
|
|
|
|
|
+ List<ProjectSubstationImport> errorList = Lists.newArrayList();
|
|
|
|
|
+ Iterator<ProjectSubstationImport> projectMaterialStorageListIterator = projectMaterialStorageList.iterator();
|
|
|
|
|
+ while (projectMaterialStorageListIterator.hasNext()){
|
|
|
|
|
+ ProjectSubstationImport projectMaterialStorageImport = projectMaterialStorageListIterator.next();
|
|
|
|
|
+ if(StringUtils.isNotBlank(projectMaterialStorageImport.getProjectOrCostName())){
|
|
|
|
|
+ effectiveList.add(projectMaterialStorageImport);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ if(StringUtils.isNotBlank(projectMaterialStorageImport.getProjectOrCostName())){
|
|
|
|
|
+ projectMaterialStorageImport.setErrorMessage("数据中缺少项目或费用名称");
|
|
|
|
|
+ }
|
|
|
|
|
+ errorList.add(projectMaterialStorageImport);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //对有效的数据进行去重处理
|
|
|
|
|
+ for (ProjectSubstationImport info : effectiveList) {
|
|
|
|
|
+ // 处理可能的null值,转为空字符串
|
|
|
|
|
+ String number = (info.getNumber() != null) ? info.getNumber() : "";
|
|
|
|
|
+ String name = (info.getProjectOrCostName() != null) ? info.getProjectOrCostName() : "";
|
|
|
|
|
+ String remarks = (info.getRemarks() != null) ? info.getRemarks() : "";
|
|
|
|
|
+ // 以逗号分隔组合
|
|
|
|
|
+ String resultStr =number + "," + name + "," + remarks;
|
|
|
|
|
+ info.setDistinctStr(resultStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ //对数据进行去重分类处理
|
|
|
|
|
+ Map<String,List<ProjectSubstationImport>> map = projectFinalAccountsService.distinctProjectSubstation(effectiveList,projectFinalAccounts.getProjectId());
|
|
|
|
|
+ //有效数据
|
|
|
|
|
+ List<ProjectSubstationImport> uniqueList = map.get("uniqueList");
|
|
|
|
|
+ //重复数据
|
|
|
|
|
+ List<ProjectSubstationImport> duplicateList = map.get("duplicateList");
|
|
|
|
|
+ for (ProjectSubstationImport info : duplicateList) {
|
|
|
|
|
+ info.setErrorMessage("重复数据");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Iterator<ProjectSubstationImport> uniqueIterator = uniqueList.iterator();
|
|
|
|
|
+ while (uniqueIterator.hasNext()){
|
|
|
|
|
+ ProjectSubstationImport info = uniqueIterator.next();
|
|
|
|
|
+ info.setProjectId(projectFinalAccounts.getProjectId());
|
|
|
|
|
+ Map<String, Object> saveResultMap = projectFinalAccountsService.saveSubstationUniqueInfo(info);
|
|
|
|
|
+ Boolean success = (Boolean) saveResultMap.get("success");
|
|
|
|
|
+ String message = (String) saveResultMap.get("message");
|
|
|
|
|
+ if(!success){
|
|
|
|
|
+ info.setErrorMessage(message);
|
|
|
|
|
+ errorList.add(info);
|
|
|
|
|
+ uniqueIterator.remove();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //有效数据:uniqueList
|
|
|
|
|
+ //错误数据:errorList
|
|
|
|
|
+ //重复数据:duplicateList
|
|
|
|
|
+ //元数据:metadataList
|
|
|
|
|
+ //判定,如果 错误数据 中存在数据,则表示前端传过来的数据并没有完全保存。需要将数据转存成exce文档并给下载接口
|
|
|
|
|
+ //可先将数据存储到redis中,保存的redis 的key可以按照 项目id + 登陆人id + uniqueList 这种格式
|
|
|
|
|
+ Map<String, String> redisKeys = new HashMap<>();
|
|
|
|
|
+ if(!duplicateList.isEmpty() || !errorList.isEmpty()){
|
|
|
|
|
+ User user = UserUtils.getUser();
|
|
|
|
|
+ String uniqueRedisKey = projectFinalAccounts.getProjectId() + "_" + user.getId() + "_substation_uniqueList";
|
|
|
|
|
+ String errorRedisKey = projectFinalAccounts.getProjectId() + "_" + user.getId() + "_substation_errorList";
|
|
|
|
|
+ String duplicateRedisKey = projectFinalAccounts.getProjectId() + "_" + user.getId() + "_substation_duplicateList";
|
|
|
|
|
+ String metadataRedisKey = projectFinalAccounts.getProjectId() + "_" + user.getId() + "_substation_metadataList";
|
|
|
|
|
+
|
|
|
|
|
+ // 保存前先删除对应key的原有数据
|
|
|
|
|
+ projectFinalAccountsService.deleteRedisKey(errorRedisKey);
|
|
|
|
|
+ projectFinalAccountsService.deleteRedisKey(uniqueRedisKey);
|
|
|
|
|
+ projectFinalAccountsService.deleteRedisKey(duplicateRedisKey);
|
|
|
|
|
+ projectFinalAccountsService.deleteRedisKey(metadataRedisKey);
|
|
|
|
|
+
|
|
|
|
|
+ // 分别存储各个列表
|
|
|
|
|
+ if (!errorList.isEmpty()) {
|
|
|
|
|
+ projectFinalAccountsService.saveSubstationListToZSet(errorRedisKey, errorList);
|
|
|
|
|
+ redisKeys.put("errorRedisKey", errorRedisKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!uniqueList.isEmpty()) {
|
|
|
|
|
+ projectFinalAccountsService.saveSubstationListToZSet(uniqueRedisKey, uniqueList);
|
|
|
|
|
+ redisKeys.put("uniqueRedisKey", uniqueRedisKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!duplicateList.isEmpty()) {
|
|
|
|
|
+ projectFinalAccountsService.saveSubstationListToZSet(duplicateRedisKey, duplicateList);
|
|
|
|
|
+ redisKeys.put("duplicateRedisKey", duplicateRedisKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!projectMaterialStorageList.isEmpty()) {
|
|
|
|
|
+ projectFinalAccountsService.saveSubstationListToZSet(metadataRedisKey, projectMaterialStorageList);
|
|
|
|
|
+ redisKeys.put("metadataRedisKey", metadataRedisKey);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ result.put("duplicateList", duplicateList);
|
|
|
|
|
+ result.put("errorList", errorList);
|
|
|
|
|
+ result.put("uniqueList", uniqueList);
|
|
|
|
|
+ result.put("projectMaterialStorageList", projectMaterialStorageList);
|
|
|
|
|
+ result.put("redisKeys", redisKeys);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改材料库
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "Update")
|
|
|
|
|
+ public String adminUpdate(ProjectFinalAccounts projectFinalAccounts, RedirectAttributes redirectAttributes){
|
|
|
|
|
+ try {
|
|
|
|
|
+ ProjectFinalAccounts t = projectFinalAccountsService.get(projectFinalAccounts.getId());//从数据库取出记录的值
|
|
|
|
|
+ MyBeanUtils.copyBeanNotNull2Bean(projectFinalAccounts, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
|
|
|
|
|
+ projectFinalAccounts.preUpdate();
|
|
|
|
|
+ if(projectFinalAccountsService.update(t) == 1){
|
|
|
|
|
+ addMessage(redirectAttributes, "修改成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ logger.error("修改项目异常:",e);
|
|
|
|
|
+ addMessage(redirectAttributes, "修改项目:"+e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除材料库
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
|
|
+ public String delete(ProjectFinalAccounts projectFinalAccounts, RedirectAttributes redirectAttributes) {
|
|
|
|
|
+
|
|
|
|
|
+ if(projectFinalAccountsService.delectBylogic(projectFinalAccounts) != 1){
|
|
|
|
|
+ addMessage(redirectAttributes, "删除失败,请重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 下载处理后的文档信息
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("project:projectFinalAccounts:export")
|
|
|
|
|
+ @RequestMapping(value = "export", method = RequestMethod.POST)
|
|
|
|
|
+ public void exportFile(ProjectFinalAccounts projectFinalAccounts, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response, RedirectAttributes redirectAttributes) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 创建多页签导出工具实例
|
|
|
|
|
+ ExportMultipleTabsExcel exporter = new ExportMultipleTabsExcel();
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 获取各类数据(从Redis或数据库)
|
|
|
|
|
+ String projectId = projectFinalAccounts.getProjectId();
|
|
|
|
|
+ String userId = UserUtils.getUser().getId();
|
|
|
|
|
+
|
|
|
|
|
+ // 错误数据列表
|
|
|
|
|
+ List<ProjectFinalAccounts> errorList = projectFinalAccountsService.convertFromRedis(
|
|
|
|
|
+ projectId + "_" + userId + "_errorList");
|
|
|
|
|
+
|
|
|
|
|
+ // 重复数据列表
|
|
|
|
|
+ List<ProjectFinalAccounts> duplicateList = projectFinalAccountsService.convertFromRedis(
|
|
|
|
|
+ projectId + "_" + userId + "_duplicateList");
|
|
|
|
|
+
|
|
|
|
|
+ // 有效数据列表
|
|
|
|
|
+ List<ProjectFinalAccounts> uniqueList = projectFinalAccountsService.convertFromRedis(
|
|
|
|
|
+ projectId + "_" + userId + "_uniqueList");
|
|
|
|
|
+
|
|
|
|
|
+ // 原数据列表
|
|
|
|
|
+ List<ProjectFinalAccounts> metadataList = projectFinalAccountsService.convertFromRedis(
|
|
|
|
|
+ projectId + "_" + userId + "_metadataList");
|
|
|
|
|
+
|
|
|
|
|
+ // 处理可能的空列表,避免导出工具报错
|
|
|
|
|
+ errorList = errorList == null ? Collections.emptyList() : errorList;
|
|
|
|
|
+ duplicateList = duplicateList == null ? Collections.emptyList() : duplicateList;
|
|
|
|
|
+ uniqueList = uniqueList == null ? Collections.emptyList() : uniqueList;
|
|
|
|
|
+ metadataList = metadataList == null ? Collections.emptyList() : metadataList;
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 添加Sheet页(页签名称、标题、实体类、数据列表)
|
|
|
|
|
+ if (!errorList.isEmpty()) {
|
|
|
|
|
+ exporter.addSheet("工程项目竣工结算汇总表-错误数据", "工程项目竣工结算汇总表导入-错误数据", ProjectFinalAccounts.class, errorList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!duplicateList.isEmpty()) {
|
|
|
|
|
+ exporter.addSheet("工程项目竣工结算汇总表-重复数据", "工程项目竣工结算汇总表导入-重复数据", ProjectFinalAccounts.class, duplicateList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!uniqueList.isEmpty()) {
|
|
|
|
|
+ exporter.addSheet("工程项目竣工结算汇总表-有效数据", "工程项目竣工结算汇总表导入-有效数据", ProjectFinalAccounts.class, uniqueList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!metadataList.isEmpty()) {
|
|
|
|
|
+ exporter.addSheet("工程项目竣工结算汇总表-原数据", "工程项目竣工结算汇总表导入-原数据", ProjectFinalAccounts.class, metadataList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 错误数据列表
|
|
|
|
|
+ List<ProjectSubstationImport> errorSubstationList = projectFinalAccountsService.convertFromSubstationRedis(
|
|
|
|
|
+ projectId + "_" + userId + "_substation_errorList");
|
|
|
|
|
+
|
|
|
|
|
+ // 重复数据列表
|
|
|
|
|
+ List<ProjectSubstationImport> duplicateSubstationList = projectFinalAccountsService.convertFromSubstationRedis(
|
|
|
|
|
+ projectId + "_" + userId + "_substation_duplicateList");
|
|
|
|
|
+
|
|
|
|
|
+ // 有效数据列表
|
|
|
|
|
+ List<ProjectSubstationImport> uniqueSubstationList = projectFinalAccountsService.convertFromSubstationRedis(
|
|
|
|
|
+ projectId + "_" + userId + "_substation_uniqueList");
|
|
|
|
|
+
|
|
|
|
|
+ // 原数据列表
|
|
|
|
|
+ List<ProjectSubstationImport> metadataSubstationList = projectFinalAccountsService.convertFromSubstationRedis(
|
|
|
|
|
+ projectId + "_" + userId + "_substation_metadataList");
|
|
|
|
|
+
|
|
|
|
|
+ // 处理可能的空列表,避免导出工具报错
|
|
|
|
|
+ errorSubstationList = errorSubstationList == null ? Collections.emptyList() : errorSubstationList;
|
|
|
|
|
+ duplicateSubstationList = duplicateSubstationList == null ? Collections.emptyList() : duplicateSubstationList;
|
|
|
|
|
+ uniqueSubstationList = uniqueSubstationList == null ? Collections.emptyList() : uniqueSubstationList;
|
|
|
|
|
+ metadataSubstationList = metadataSubstationList == null ? Collections.emptyList() : metadataSubstationList;
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 添加Sheet页(页签名称、标题、实体类、数据列表)
|
|
|
|
|
+ if (!errorSubstationList.isEmpty()) {
|
|
|
|
|
+ exporter.addSheet("变电站建筑工程费用汇总表-错误数据", "变电站建筑工程费用汇总表导入-错误数据", ProjectSubstationImport.class, errorSubstationList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!duplicateSubstationList.isEmpty()) {
|
|
|
|
|
+ exporter.addSheet("变电站建筑工程费用汇总表-重复数据", "变电站建筑工程费用汇总表导入-重复数据", ProjectSubstationImport.class, duplicateSubstationList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!uniqueSubstationList.isEmpty()) {
|
|
|
|
|
+ exporter.addSheet("变电站建筑工程费用汇总表-有效数据", "变电站建筑工程费用汇总表导入-有效数据", ProjectSubstationImport.class, uniqueSubstationList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!metadataSubstationList.isEmpty()) {
|
|
|
|
|
+ exporter.addSheet("变电站建筑工程费用汇总表-原数据", "变电站建筑工程费用汇总表导入-原数据", ProjectSubstationImport.class, metadataSubstationList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 导出文件(关键:设置响应头,确保浏览器正确下载)
|
|
|
|
|
+ String fileName = "结算表导入数据汇总_" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
|
|
|
|
+ // 设置响应类型为Excel
|
|
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
|
+ // 设置文件名(解决中文乱码)
|
|
|
|
|
+ String encodedFileName = URLEncoder.encode(fileName, "UTF-8");
|
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName);
|
|
|
|
|
+ // 禁用缓存
|
|
|
|
|
+ response.setHeader("Pragma", "no-cache");
|
|
|
|
|
+ response.setHeader("Cache-Control", "no-cache");
|
|
|
|
|
+ response.setDateHeader("Expires", 0);
|
|
|
|
|
+
|
|
|
|
|
+ // 修正:直接传递response对象给write方法(移除错误的类型转换)
|
|
|
|
|
+ exporter.write(response, fileName);
|
|
|
|
|
+ exporter.dispose(); // 清理资源
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 日志记录错误(文件导出失败时,前端可通过弹窗提示)
|
|
|
|
|
+ logger.error("多页签导出异常", e);
|
|
|
|
|
+ // 若需向前端传递错误信息,可设置响应状态和消息
|
|
|
|
|
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 确保响应未提交时才写入错误信息
|
|
|
|
|
+ if (!response.isCommitted()) {
|
|
|
|
|
+ response.getWriter().write("导出失败:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
|
+ logger.error("响应错误信息失败", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 文件上传页面跳转
|
|
|
|
|
+ * @param projectRecords
|
|
|
|
|
+ * @param model
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "form")
|
|
|
|
|
+ public String form(RuralProjectRecords projectRecords, Model model,String pageId) {
|
|
|
|
|
+ String storageFlag = projectRecords.getStorageFlag();
|
|
|
|
|
+ if (projectRecords != null && StringUtils.isNotBlank(projectRecords.getId())) {
|
|
|
|
|
+ projectRecords = ruralProjectRecordsService.getQueryProjectUsers(projectRecords.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ projectRecords.setStorageFlag(storageFlag);
|
|
|
|
|
+ model.addAttribute("pageId",pageId);
|
|
|
|
|
+ model.addAttribute("projectRecords",projectRecords);
|
|
|
|
|
+ return "modules/projectStatement/projectStatementForm";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导入Excel数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @RequestMapping(value = "import", method=RequestMethod.POST)
|
|
|
|
|
+ public Map<String,Object> importFile(MultipartFile file, String dataBodyType, RedirectAttributes redirectAttributes) {
|
|
|
|
|
+ Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
+ Integer importSuccessCount = 0;
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<String> list = Lists.newArrayList();
|
|
|
|
|
+ // 核心调用:工作表名称为"工程项目竣工结算汇总表",标题行在第2行(Excel行号)
|
|
|
|
|
+ if(StringUtils.isNotBlank(dataBodyType)){
|
|
|
|
|
+ // 1. 按逗号分割为数组(split参数为正则表达式,需注意转义特殊字符)
|
|
|
|
|
+ String[] strArray = dataBodyType.split(",");
|
|
|
|
|
+ // 2. 数组转List(若需增删元素,用new ArrayList<>()包装)
|
|
|
|
|
+ list = Arrays.asList(strArray);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!list.isEmpty()){
|
|
|
|
|
+ for (String string : list) {
|
|
|
|
|
+
|
|
|
|
|
+ if("变电站建筑工程费用汇总表".equals(string)){
|
|
|
|
|
+ ExcelImportBySheetName importer = new ExcelImportBySheetName(file, 3, 4, string);
|
|
|
|
|
+ List<ProjectSubstationImport> dataList = importer.toEntityList(ProjectSubstationImport.class);
|
|
|
|
|
+ map.put(string,dataList);
|
|
|
|
|
+ importSuccessCount = importSuccessCount + dataList.size();
|
|
|
|
|
+ System.out.println(dataList);
|
|
|
|
|
+ }else{
|
|
|
|
|
+
|
|
|
|
|
+ ExcelImportBySheetName importer = new ExcelImportBySheetName(file, 3,3, string);
|
|
|
|
|
+ List<ProjectFinalAccountsImport> dataList = importer.toEntityList(ProjectFinalAccountsImport.class);
|
|
|
|
|
+ map.put(string,dataList);
|
|
|
|
|
+ importSuccessCount = importSuccessCount + dataList.size();
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println(dataList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 业务处理(如保存到数据库)
|
|
|
|
|
+ // projectService.batchSave(dataList);
|
|
|
|
|
+ map.put("code",0);
|
|
|
|
|
+ map.put("message","导入成功,共" + importSuccessCount + "条数据");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("导入失败", e);
|
|
|
|
|
+ map.put("code",400);
|
|
|
|
|
+ map.put("message","导入失败,共" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @RequestMapping(value = "import/template")
|
|
|
|
|
+ public String importFileTemplate(HttpServletResponse response, HttpServletRequest request, RedirectAttributes redirectAttributes) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ ThisLocalityDownloadUtil download = new ThisLocalityDownloadUtil();
|
|
|
|
|
+ download.download("材料库处理表模板.xlsx",request,response);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("材料库处理表模板下载失败!",e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查看,增加,编辑客户管理表单页面
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "formTwoPage")
|
|
|
|
|
+ public String form(ProjectFinalAccounts projectFinalAccounts, Model model,String isAdd) {
|
|
|
|
|
+ ProjectFinalAccounts projectFinalAccounts2 = new ProjectFinalAccounts();
|
|
|
|
|
+ if(StringUtils.isNotBlank(projectFinalAccounts.getId())){
|
|
|
|
|
+ projectFinalAccounts2 = projectFinalAccountsService.get(projectFinalAccounts.getId());
|
|
|
|
|
+ }else{
|
|
|
|
|
+ model.addAttribute("isAdd",isAdd);
|
|
|
|
|
+ return "modules/projectStatement/projectAccountsAddForm";
|
|
|
|
|
+ }
|
|
|
|
|
+ if(StringUtils.isNotBlank(projectFinalAccounts.getProjectNumber())){
|
|
|
|
|
+
|
|
|
|
|
+ model.addAttribute("projectFinalAccounts", projectFinalAccounts2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return "modules/projectStatement/projectAccountsTwoForm";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查看,增加,编辑客户管理表单页面
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "view")
|
|
|
|
|
+ public String view(ProjectFinalAccounts projectFinalAccounts, Model model,String isAdd) {
|
|
|
|
|
+ ProjectFinalAccounts projectMaterialStorage2 = new ProjectFinalAccounts();
|
|
|
|
|
+ if(StringUtils.isNotBlank(projectFinalAccounts.getId())){
|
|
|
|
|
+ projectMaterialStorage2 = projectFinalAccountsService.get(projectFinalAccounts.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if(StringUtils.isNotBlank(projectFinalAccounts.getProjectNumber())){
|
|
|
|
|
+
|
|
|
|
|
+ model.addAttribute("projectFinalAccounts", projectMaterialStorage2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return "modules/projectStatement/projectAccountsView";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 选择材料关联项目
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "selectproject")
|
|
|
|
|
+ public String selectproject(ProjectRecords project, String url, String fieldLabels, String fieldKeys, String searchLabel, String searchKey, String ids, Integer isProject, Integer isProjectFalg, String details, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
|
|
+ project.setCompany(UserUtils.getSelectCompany());
|
|
|
|
|
+ project.setProjectStatus(ProjectStatusEnum.SIGNED.getValue());//已签状态
|
|
|
|
|
+ Page<ProjectRecords> page = projectRecordsService.ruralFindPageByReimbur(new Page<ProjectRecords>(request, response), project,"");
|
|
|
|
|
+ List<ProjectRecords> list = page.getList();
|
|
|
|
|
+ try {
|
|
|
|
|
+ fieldLabels = URLDecoder.decode(fieldLabels, "UTF-8");
|
|
|
|
|
+ fieldKeys = URLDecoder.decode(fieldKeys, "UTF-8");
|
|
|
|
|
+ searchLabel = URLDecoder.decode(searchLabel, "UTF-8");
|
|
|
|
|
+ searchKey = URLDecoder.decode(searchKey, "UTF-8");
|
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ logger.error("Exception e:"+e);
|
|
|
|
|
+ }
|
|
|
|
|
+ model.addAttribute("labelNames", fieldLabels.split("\\|"));
|
|
|
|
|
+ model.addAttribute("labelValues", fieldKeys.split("\\|"));
|
|
|
|
|
+ model.addAttribute("fieldLabels", fieldLabels);
|
|
|
|
|
+ model.addAttribute("fieldKeys", fieldKeys);
|
|
|
|
|
+ model.addAttribute("url", url);
|
|
|
|
|
+ model.addAttribute("searchLabel", searchLabel);
|
|
|
|
|
+ model.addAttribute("searchKey", searchKey);
|
|
|
|
|
+ project.setDetails(details);
|
|
|
|
|
+ model.addAttribute("obj", project);
|
|
|
|
|
+ model.addAttribute("isProject", isProject);
|
|
|
|
|
+ model.addAttribute("isProjectFalg", isProjectFalg);
|
|
|
|
|
+ model.addAttribute("page",page);
|
|
|
|
|
+ return "modules/sys/gridMaterialProject";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 工程咨询文件上传页面跳转
|
|
|
|
|
+ * @param projectRecords
|
|
|
|
|
+ * @param model
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "projectMessageform")
|
|
|
|
|
+ public String ProjectMessageform(RuralProjectRecords projectRecords, Model model) {
|
|
|
|
|
+ if (projectRecords != null && StringUtils.isNotBlank(projectRecords.getId())) {
|
|
|
|
|
+ projectRecords = ruralProjectRecordsService.getQueryProjectUsers(projectRecords.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ model.addAttribute("projectRecords",projectRecords);
|
|
|
|
|
+ return "modules/ruralprojectrecords/ruralporjectmessage/ruralProjectMessageList";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 造价审核文件上传页面跳转
|
|
|
|
|
+ * @param projectRecords
|
|
|
|
|
+ * @param model
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "ruralCostProjectMessageForm")
|
|
|
|
|
+ public String ruralCostProjectMessageForm(RuralProjectRecords projectRecords, Model model) {
|
|
|
|
|
+ if (projectRecords != null && StringUtils.isNotBlank(projectRecords.getId())) {
|
|
|
|
|
+ projectRecords = ruralProjectRecordsService.getQueryProjectUsers(projectRecords.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ model.addAttribute("projectRecords",projectRecords);
|
|
|
|
|
+ return "modules/ruralprojectrecords/cost/ruralCostProjectMessageList";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 单对象保存
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "signleSave")
|
|
|
|
|
+ public String signleSave(ProjectFinalAccounts projectFinalAccounts, Model model, RedirectAttributes redirectAttributes,String pageId,String isAdd) throws Exception {
|
|
|
|
|
+
|
|
|
|
|
+// 非1为添加 type为1时修改;
|
|
|
|
|
+ if( isAdd.equals("0")){
|
|
|
|
|
+ projectFinalAccounts.setIsNewRecord(true);
|
|
|
|
|
+ String projectNumber = projectFinalAccounts.getProjectOrCostName().substring(0,projectFinalAccounts.getProjectOrCostName().indexOf(","));
|
|
|
|
|
+ projectFinalAccounts.setProjectNumber(projectNumber);
|
|
|
|
|
+ }
|
|
|
|
|
+ /*if(StringUtils.isBlank(projectFinalAccounts.getProjectNumber()) && StringUtils.isNotBlank(projectFinalAccounts.getId())){
|
|
|
|
|
+ projectFinalAccounts = projectFinalAccountsService.get(projectFinalAccounts.getId());
|
|
|
|
|
+ }*/
|
|
|
|
|
+// 判断项目名称、材料名称、是否为空
|
|
|
|
|
+ if(StringUtils.isBlank(projectFinalAccounts.getProjectNumber()) && StringUtils.isBlank(projectFinalAccounts.getProjectOrCostName())){
|
|
|
|
|
+ addMessage(redirectAttributes, "项目名称、材料名称等获取失败,请重试");
|
|
|
|
|
+ if("1".equals(pageId)){
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/ruralProject/ruralProjectMessageAll/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts";
|
|
|
|
|
+ }
|
|
|
|
|
+// 进行项目名称、材料名称、价格重复的判断
|
|
|
|
|
+ if(StringUtils.isBlank(projectFinalAccounts.getProjectNumber()) && StringUtils.isBlank(projectFinalAccounts.getProjectOrCostName())){
|
|
|
|
|
+ addMessage(redirectAttributes, "项目名称、材料名称等获取失败,请重试");
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts";
|
|
|
|
|
+ }
|
|
|
|
|
+ //根据项目id查询报告号并重新赋值
|
|
|
|
|
+ RuralProjectRecords ruralProjectRecords = ruralProjectRecordsService.get(projectFinalAccounts.getProjectNumber());
|
|
|
|
|
+
|
|
|
|
|
+ if(null != ruralProjectRecords){
|
|
|
|
|
+ projectFinalAccounts.setProjectName(ruralProjectRecords.getProjectName());
|
|
|
|
|
+ //projectFinalAccounts.setReportNumber(ruralProjectRecords.getProjectReportNumber());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(StringUtils.isNotBlank(projectFinalAccounts.getProjectNumber())){
|
|
|
|
|
+ projectFinalAccounts.setProjectId(projectFinalAccounts.getProjectNumber());
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> returnMap = projectFinalAccountsService.saveInfo(projectFinalAccounts);
|
|
|
|
|
+ Boolean success = (Boolean) returnMap.get("success");
|
|
|
|
|
+ if(!success){
|
|
|
|
|
+ addMessage(redirectAttributes, returnMap.get("message").toString());
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts/?repage";
|
|
|
|
|
+ }
|
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/project/projectFinalAccounts";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 批量删除
|
|
|
|
|
+ * @param listId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "deleteAll")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public Object deleteAll(String listId){
|
|
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
|
|
+ try{
|
|
|
|
|
+ List<String> idList = Arrays.asList(listId.split(","));
|
|
|
|
|
+ List<ProjectFinalAccounts> byIdList = Lists.newArrayList();
|
|
|
|
|
+ //根据id查询自己创建的材料信息数量
|
|
|
|
|
+ if(!UserUtils.getUser().isAdmin()){
|
|
|
|
|
+ byIdList = projectFinalAccountsService.getByIdList(idList);
|
|
|
|
|
+ if(byIdList.size() < idList.size()){
|
|
|
|
|
+ map.put("success",false);
|
|
|
|
|
+ map.put("str","删除的材料信息保存不属于您创建的信息。请确认后重新删除");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ projectFinalAccountsService.deleteListById(idList);
|
|
|
|
|
+ map.put("success",true);
|
|
|
|
|
+ map.put("str","材料信息删除成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ projectFinalAccountsService.deleteListById(idList);
|
|
|
|
|
+ map.put("success",true);
|
|
|
|
|
+ map.put("str","材料信息删除成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ map.put("success",false);
|
|
|
|
|
+ map.put("str","删除失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据工作内容查询成果类型
|
|
|
|
|
+ * @param achievementParentId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping("getDictList")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public AjaxJson getDictList(String achievementParentId){
|
|
|
|
|
+ AjaxJson ajaxJson = new AjaxJson();
|
|
|
|
|
+ try {
|
|
|
|
|
+ //根据字典key获取字典信息
|
|
|
|
|
+ List<MainDictDetail> getAchievementTypeList = DictUtils.getMainDictListOnProjectAdvent("project_statement_type");
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < getAchievementTypeList.size(); i++) {
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("name", getAchievementTypeList.get(i).getLabel());
|
|
|
|
|
+ map.put("value", getAchievementTypeList.get(i).getValue());
|
|
|
|
|
+ mapList.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ ajaxJson.getBody().put("list", mapList);
|
|
|
|
|
+ ajaxJson.setMsg("获取数据成功");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("获取数据异常!", e);
|
|
|
|
|
+ ajaxJson.setSuccess(false);
|
|
|
|
|
+ ajaxJson.setMsg("获取数据异常");
|
|
|
|
|
+ }
|
|
|
|
|
+ return ajaxJson;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|