Quellcode durchsuchen

利库资源池导入数据丢失

chenyuesheng vor 2 Jahren
Ursprung
Commit
e63c85002e

+ 230 - 231
src/main/java/com/jeeplus/modules/sg/balancedlibrary/liKuResourcePool/web/LiKuResourcePoolController.java

@@ -37,6 +37,7 @@ import java.util.stream.Collectors;
 
 /**
  * 利库资源池Controller
+ *
  * @author lgf
  * @version 2018-06-12
  */
@@ -44,254 +45,252 @@ import java.util.stream.Collectors;
 @RequestMapping(value = "${adminPath}/liKuResourcePool")
 public class LiKuResourcePoolController extends BaseController {
 
-	@Autowired
-	private LiKuResourcePoolService service;
+    @Autowired
+    private LiKuResourcePoolService service;
 
 
+    @ModelAttribute
+    public LiKuResourcePool get(@RequestParam(required = false) String id) {
+        LiKuResourcePool entity = null;
+        if (StringUtils.isNotBlank(id)) {
+            entity = service.get(id);
+        }
+        if (entity == null) {
+            entity = new LiKuResourcePool();
+        }
+        return entity;
+    }
+
+    /**
+     * 利库资源池列表页面
+     */
+    @RequiresPermissions("sg:balancedlibrary:liKuResourcePool:list")
+    @RequestMapping(value = "list")
+    public String list(LiKuResourcePool entity, Model model) {
+        model.addAttribute("entity", entity);
+        return "modules/sg/balancedlibrary/liKuResourcePool/liKuResourcePoolList";
+    }
+
+    /**
+     * 利库资源池列表数据
+     */
+    @ResponseBody
+    @RequiresPermissions("sg:balancedlibrary:liKuResourcePool:list")
+    @RequestMapping(value = "data")
+    public Map<String, Object> data(LiKuResourcePool entity, HttpServletRequest request, HttpServletResponse response, Model model) {
+        Page<LiKuResourcePool> page = service.findPage(new Page<LiKuResourcePool>(request, response), entity);
+        return getBootstrapData(page);
+    }
+
+    /**
+     * 查看,增加,编辑利库资源池表单页面
+     */
+    @RequiresPermissions(value = {"sg:balancedlibrary:liKuResourcePool:view", "sg:balancedlibrary:liKuResourcePool:add", "sg:balancedlibrary:liKuResourcePool:edit"}, logical = Logical.OR)
+    @RequestMapping(value = "form")
+    public String form(LiKuResourcePool entity, Model model) {
+        model.addAttribute("entity", entity);
+        return "modules/test/one/dialog/liKuResourcePoolForm";
+    }
+
+    /**
+     * 保存利库资源池
+     */
+    @ResponseBody
+    @RequiresPermissions(value = {"sg:balancedlibrary:liKuResourcePool:add", "sg:balancedlibrary:liKuResourcePool:edit"}, logical = Logical.OR)
+    @RequestMapping(value = "save")
+    public AjaxJson save(LiKuResourcePool entity, Model model) throws Exception {
+        AjaxJson j = new AjaxJson();
+        /**
+         * 后台hibernate-validation插件校验
+         */
+        String errMsg = beanValidator(entity);
+        if (StringUtils.isNotBlank(errMsg)) {
+            j.setSuccess(false);
+            j.setMsg(errMsg);
+            return j;
+        }
+        //新增或编辑表单保存
+        service.save(entity);
+        j.setSuccess(true);
+        j.setMsg("保存利库资源池成功");
+        return j;
+    }
 
-	@ModelAttribute
-	public LiKuResourcePool get(@RequestParam(required=false) String id) {
-		LiKuResourcePool entity = null;
-		if (StringUtils.isNotBlank(id)){
-			entity = service.get(id);
-		}
-		if (entity == null){
-			entity = new LiKuResourcePool();
-		}
-		return entity;
-	}
-	
-	/**
-	 * 利库资源池列表页面
-	 */
-	@RequiresPermissions("sg:balancedlibrary:liKuResourcePool:list")
-	@RequestMapping(value = "list")
-	public String list(LiKuResourcePool entity, Model model) {
-		model.addAttribute("entity", entity);
-		return "modules/sg/balancedlibrary/liKuResourcePool/liKuResourcePoolList";
-	}
-	
-		/**
-	 * 利库资源池列表数据
-	 */
-	@ResponseBody
-	@RequiresPermissions("sg:balancedlibrary:liKuResourcePool:list")
-	@RequestMapping(value = "data")
-	public Map<String, Object> data(LiKuResourcePool entity, HttpServletRequest request, HttpServletResponse response, Model model) {
-		Page<LiKuResourcePool> page = service.findPage(new Page<LiKuResourcePool>(request, response), entity);
-		return getBootstrapData(page);
-	}
+    /**
+     * 删除利库资源池
+     */
+    @ResponseBody
+    @RequiresPermissions("sg:balancedlibrary:liKuResourcePool:del")
+    @RequestMapping(value = "delete")
+    public AjaxJson delete(LiKuResourcePool entity) {
+        AjaxJson j = new AjaxJson();
+        service.delete(entity);
+        j.setMsg("删除利库资源池成功");
+        return j;
+    }
 
-	/**
-	 * 查看,增加,编辑利库资源池表单页面
-	 */
-	@RequiresPermissions(value={"sg:balancedlibrary:liKuResourcePool:view","sg:balancedlibrary:liKuResourcePool:add","sg:balancedlibrary:liKuResourcePool:edit"},logical=Logical.OR)
-	@RequestMapping(value = "form")
-	public String form(LiKuResourcePool entity, Model model) {
-		model.addAttribute("entity", entity);
-		return "modules/test/one/dialog/liKuResourcePoolForm";
-	}
+    /**
+     * 批量删除利库资源池
+     */
+    @ResponseBody
+    @RequiresPermissions("sg:balancedlibrary:liKuResourcePool:del")
+    @RequestMapping(value = "deleteAll")
+    public AjaxJson deleteAll(String ids) {
+        AjaxJson j = new AjaxJson();
+        String idArray[] = ids.split(",");
+        for (String id : idArray) {
+            service.delete(service.get(id));
+        }
+        j.setMsg("删除利库资源池成功");
+        return j;
+    }
 
-	/**
-	 * 保存利库资源池
-	 */
-	@ResponseBody
-	@RequiresPermissions(value={"sg:balancedlibrary:liKuResourcePool:add","sg:balancedlibrary:liKuResourcePool:edit"},logical=Logical.OR)
-	@RequestMapping(value = "save")
-	public AjaxJson save(LiKuResourcePool entity, Model model) throws Exception{
-		AjaxJson j = new AjaxJson();
-		/**
-		 * 后台hibernate-validation插件校验
-		 */
-		String errMsg = beanValidator(entity);
-		if (StringUtils.isNotBlank(errMsg)){
-			j.setSuccess(false);
-			j.setMsg(errMsg);
-			return j;
-		}
-		//新增或编辑表单保存
-		service.save(entity);
-		j.setSuccess(true);
-		j.setMsg("保存利库资源池成功");
-		return j;
-	}
-	
-	/**
-	 * 删除利库资源池
-	 */
-	@ResponseBody
-	@RequiresPermissions("sg:balancedlibrary:liKuResourcePool:del")
-	@RequestMapping(value = "delete")
-	public AjaxJson delete(LiKuResourcePool entity) {
-		AjaxJson j = new AjaxJson();
-		service.delete(entity);
-		j.setMsg("删除利库资源池成功");
-		return j;
-	}
-	
-	/**
-	 * 批量删除利库资源池
-	 */
-	@ResponseBody
-	@RequiresPermissions("sg:balancedlibrary:liKuResourcePool:del")
-	@RequestMapping(value = "deleteAll")
-	public AjaxJson deleteAll(String ids) {
-		AjaxJson j = new AjaxJson();
-		String idArray[] =ids.split(",");
-		for(String id : idArray){
-			service.delete(service.get(id));
-		}
-		j.setMsg("删除利库资源池成功");
-		return j;
-	}
-	
-	/**
-	 * 导出excel文件
-	 */
-	@ResponseBody
-	@RequiresPermissions("sg:balancedlibrary:liKuResourcePool:export")
+    /**
+     * 导出excel文件
+     */
+    @ResponseBody
+    @RequiresPermissions("sg:balancedlibrary:liKuResourcePool:export")
     @RequestMapping(value = "export")
     public AjaxJson exportFile(LiKuResourcePool entity, HttpServletRequest request, HttpServletResponse response) {
-		AjaxJson j = new AjaxJson();
-		try {
-            String fileName = "资源池利库情况表"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
+        AjaxJson j = new AjaxJson();
+        try {
+            String fileName = "资源池利库情况表" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
             Page<LiKuResourcePool> page = service.findPage(new Page<LiKuResourcePool>(request, response, -1), entity);
-    		new ExportExcel("", LiKuResourcePool.class).setDataList(page.getList()).write(response, fileName).dispose();
-    		j.setSuccess(true);
-    		j.setMsg("导出成功!");
-    		return j;
-		} catch (Exception e) {
-			j.setSuccess(false);
-			j.setMsg("导出资源池利库情况表失败!失败信息:"+e.getMessage());
-		}
-			return j;
+            new ExportExcel("", LiKuResourcePool.class).setDataList(page.getList()).write(response, fileName).dispose();
+            j.setSuccess(true);
+            j.setMsg("导出成功!");
+            return j;
+        } catch (Exception e) {
+            j.setSuccess(false);
+            j.setMsg("导出资源池利库情况表失败!失败信息:" + e.getMessage());
+        }
+        return j;
     }
 
-	/**
-	 * 利库资源池-导入Excel数据
-	 */
-	@ResponseBody
-	@RequiresPermissions("sg:balancedlibrary:liKuResourcePool:import")
+    /**
+     * 利库资源池-导入Excel数据
+     */
+    @ResponseBody
+    @RequiresPermissions("sg:balancedlibrary:liKuResourcePool:import")
     @RequestMapping(value = "import")
-   	public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
-		AjaxJson j = new AjaxJson();
-		String unit = "";
-		String area = "";
-		try {
-			ImportUtil ei = new ImportUtil(file,0,0);
-			//导入数据 如果没有序号则认为是空行直接过滤
-			List<LiKuResourcePool> list = ei.getDataList(LiKuResourcePool.class)
-					.stream()
-					.filter(l->StringUtils.isNotBlank(l.getSerialNumber()))
-					.collect(Collectors.toList());
-			for(LiKuResourcePool pool:list){
-				pool.setIsSectionLength(LiKuUtils.isTheUnitMeter(pool.getUnitOfMeasurement()));
-				//获取库存地描述,标记数据所属区域
-				pool.setWhereFrom(LiKuUtils.judgmentArea(pool.getInvLocation()));
-				pool.setRemaining(pool.getInventoryAmount());
-				pool.setNumberOfNiches("0");
-			}
-			if (list.size() > 0) {
-				List<LiKuResourcePool> insertList = new ArrayList<>();
-				for (LiKuResourcePool pool :list) {
-					Integer isSectionLength = pool.getIsSectionLength();
-					if (isSectionLength.compareTo(LiKuUtils.YES) == 0) {
-						String lengthOfCable = pool.getLengthOfCable();
+    public AjaxJson importFile(@RequestParam("file") MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
+        AjaxJson j = new AjaxJson();
+        String unit = "";
+        String area = "";
+        try {
+            ImportUtil ei = new ImportUtil(file, 0, 0);
+            //导入数据 如果没有序号则认为是空行直接过滤
+            List<LiKuResourcePool> list = ei.getDataList(LiKuResourcePool.class)
+                    .stream()
+                    .filter(l -> StringUtils.isNotBlank(l.getSerialNumber()))
+                    .collect(Collectors.toList());
+            for (LiKuResourcePool pool : list) {
+                pool.setIsSectionLength(LiKuUtils.isTheUnitMeter(pool.getUnitOfMeasurement()));
+                //获取库存地描述,标记数据所属区域
+                pool.setWhereFrom(LiKuUtils.judgmentArea(pool.getInvLocation()));
+                pool.setRemaining(pool.getInventoryAmount());
+                pool.setNumberOfNiches("0");
+            }
+            if (list.size() > 0) {
+                List<LiKuResourcePool> insertList = new ArrayList<>();
+                for (LiKuResourcePool pool : list) {
+                    Integer isSectionLength = pool.getIsSectionLength();
+                    if (isSectionLength.compareTo(LiKuUtils.YES) == 0) {
+                        String lengthOfCable = pool.getLengthOfCable();
 
-						if (null != lengthOfCable && !"".equals(lengthOfCable)) {
-							String[] split = new String[0];
-							if(lengthOfCable.contains(";")){
-								split = lengthOfCable.split(";");
-							}else if(lengthOfCable.contains(",")){
-								split = lengthOfCable.split(",");
-							}else if(lengthOfCable.contains("/")){
-								split = lengthOfCable.split("/");
-							}else if(lengthOfCable.contains(",")){
-								split = lengthOfCable.split(",");
-							}else if(lengthOfCable.contains(";")){
-								split = lengthOfCable.split(";");
-							}
-							Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]+");
-							for (int i = 0; i < split.length; i++) {
-								if(pattern.matcher(split[i]).find()){
-									throw new RuntimeException("段长物资格式不正确,内包含中文!");
-								}else if(StringUtils.isBlank(split[i])){
-									continue;
-								}
-								LiKuResourcePool liKu = new LiKuResourcePool();
-								liKu.setSerialNumber(pool.getSerialNumber());
-								liKu.setPlanner(pool.getPlanner());
-								liKu.setFactory(pool.getFactory());
-								liKu.setBatch(pool.getBatch());
-								liKu.setMaterialCode(pool.getMaterialCode());
-								liKu.setMaterialDescription(pool.getMaterialDescription());
-								liKu.setUnitOfMeasurement(pool.getUnitOfMeasurement());
-								liKu.setInventoryAmount(split[i]);
-								liKu.setInventoryLocation(pool.getInventoryLocation());
-								liKu.setInvLocation(pool.getInvLocation());
-								liKu.setInvLocationDes(pool.getInvLocationDes());
-								liKu.setSpecialStock(pool.getSpecialStock());
-								liKu.setExtendedCoding(pool.getExtendedCoding());
-								liKu.setExtendedDescription(pool.getExtendedDescription());
-								liKu.setLengthOfCable(split[i]);
-								liKu.setRingCage(pool.getRingCage());
-								liKu.setTerminalWarranty(pool.getTerminalWarranty());
-								liKu.setSpecialParameters(pool.getSpecialParameters());
-								liKu.setRemarks(pool.getRemarks());
-								liKu.setDaysStorage(pool.getDaysStorage());
-								liKu.setMonthStorage(pool.getMonthStorage());
-								liKu.setIsExpansion(pool.getIsExpansion());
-								liKu.setNumberOfNiches(pool.getNumberOfNiches());
-								liKu.setRemaining(split[i]);
-								liKu.setIsSectionLength(pool.getIsSectionLength());
-								liKu.setWhereFrom(pool.getWhereFrom());
-								liKu.setSegBelongs(i + 1);
-								insertList.add(liKu);
-							}
-						} else {
-							pool.setSegBelongs(1);
-							pool.setRemaining(pool.getInventoryAmount());
-							pool.setLengthOfCable(pool.getInventoryAmount());
-							insertList.add(pool);
-						}
-					}else {
-						insertList.add(pool);
-					}
-				}
-				//利库资源池每次重新导入数据,将原有数据清空
-				service.clearLiKuResource();
-				service.insertList(insertList);
-				j.setMsg("已成功导入 " + insertList.size() + " 条利库资源池记录");
-			}
-		} catch (Exception e) {
-			j.setSuccess(false);
-			j.setMsg("导入利库资源池失败!失败信息:"+e.getMessage());
-			e.printStackTrace();
-			System.out.println(e.getMessage());
-		}
-		return j;
+                        if (null != lengthOfCable && !"".equals(lengthOfCable)) {
+                            String[] split = {lengthOfCable};
+                            if (lengthOfCable.contains(";")) {
+                                split = lengthOfCable.split(";");
+                            } else if (lengthOfCable.contains(",")) {
+                                split = lengthOfCable.split(",");
+                            } else if (lengthOfCable.contains("/")) {
+                                split = lengthOfCable.split("/");
+                            } else if (lengthOfCable.contains(",")) {
+                                split = lengthOfCable.split(",");
+                            } else if (lengthOfCable.contains(";")) {
+                                split = lengthOfCable.split(";");
+                            }
+                            Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]+");
+                            for (int i = 0; i < split.length; i++) {
+                                if (pattern.matcher(split[i]).find()) {
+                                    throw new RuntimeException("段长物资格式不正确,段长物资内包含中文!");
+                                } else if (StringUtils.isBlank(split[i])) {
+                                    continue;
+                                }
+                                LiKuResourcePool liKu = new LiKuResourcePool();
+                                liKu.setSerialNumber(pool.getSerialNumber());
+                                liKu.setPlanner(pool.getPlanner());
+                                liKu.setFactory(pool.getFactory());
+                                liKu.setBatch(pool.getBatch());
+                                liKu.setMaterialCode(pool.getMaterialCode());
+                                liKu.setMaterialDescription(pool.getMaterialDescription());
+                                liKu.setUnitOfMeasurement(pool.getUnitOfMeasurement());
+                                liKu.setInventoryAmount(split[i]);
+                                liKu.setInventoryLocation(pool.getInventoryLocation());
+                                liKu.setInvLocation(pool.getInvLocation());
+                                liKu.setInvLocationDes(pool.getInvLocationDes());
+                                liKu.setSpecialStock(pool.getSpecialStock());
+                                liKu.setExtendedCoding(pool.getExtendedCoding());
+                                liKu.setExtendedDescription(pool.getExtendedDescription());
+                                liKu.setLengthOfCable(split[i]);
+                                liKu.setRingCage(pool.getRingCage());
+                                liKu.setTerminalWarranty(pool.getTerminalWarranty());
+                                liKu.setSpecialParameters(pool.getSpecialParameters());
+                                liKu.setRemarks(pool.getRemarks());
+                                liKu.setDaysStorage(pool.getDaysStorage());
+                                liKu.setMonthStorage(pool.getMonthStorage());
+                                liKu.setIsExpansion(pool.getIsExpansion());
+                                liKu.setNumberOfNiches(pool.getNumberOfNiches());
+                                liKu.setRemaining(split[i]);
+                                liKu.setIsSectionLength(pool.getIsSectionLength());
+                                liKu.setWhereFrom(pool.getWhereFrom());
+                                liKu.setSegBelongs(i + 1);
+                                insertList.add(liKu);
+                            }
+                        } else {
+                            pool.setSegBelongs(1);
+                            pool.setRemaining(pool.getInventoryAmount());
+                            pool.setLengthOfCable(pool.getInventoryAmount());
+                            insertList.add(pool);
+                        }
+                    } else {
+                        insertList.add(pool);
+                    }
+                }
+                //利库资源池每次重新导入数据,将原有数据清空
+                service.clearLiKuResource();
+                service.insertList(insertList);
+                j.setMsg("已成功导入 " + insertList.size() + " 条利库资源池记录");
+            }
+        } catch (Exception e) {
+            j.setSuccess(false);
+            j.setMsg("导入利库资源池失败!失败信息:" + e.getMessage());
+            e.printStackTrace();
+            System.out.println(e.getMessage());
+        }
+        return j;
     }
 
 
-
-	/**
-	 * 下载导入利库资源池数据模板
-	 */
-	@ResponseBody
-	@RequiresPermissions("sg:balancedlibrary:liKuResourcePool:import")
+    /**
+     * 下载导入利库资源池数据模板
+     */
+    @ResponseBody
+    @RequiresPermissions("sg:balancedlibrary:liKuResourcePool:import")
     @RequestMapping(value = "import/template")
-     public AjaxJson importFileTemplate(HttpServletResponse response) {
-		AjaxJson j = new AjaxJson();
-		try {
+    public AjaxJson importFileTemplate(HttpServletResponse response) {
+        AjaxJson j = new AjaxJson();
+        try {
             String fileName = "利库资源池数据导入模板.xlsx";
-    		List<LiKuResourcePool> list = Lists.newArrayList(); 
-    		new ExportExcel("", LiKuResourcePool.class, 1).setDataList(list).write(response, fileName).dispose();
-    		return null;
-		} catch (Exception e) {
-			j.setSuccess(false);
-			j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
-		}
-		return j;
+            List<LiKuResourcePool> list = Lists.newArrayList();
+            new ExportExcel("", LiKuResourcePool.class, 1).setDataList(list).write(response, fileName).dispose();
+            return null;
+        } catch (Exception e) {
+            j.setSuccess(false);
+            j.setMsg("导入模板下载失败!失败信息:" + e.getMessage());
+        }
+        return j;
     }
 
 }