|
@@ -0,0 +1,221 @@
|
|
|
+/**
|
|
|
+ * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
|
|
|
+ */
|
|
|
+package com.jeeplus.modules.sg.managementcenter.materialInventory.web;
|
|
|
+
|
|
|
+import com.jeeplus.common.json.AjaxJson;
|
|
|
+import com.jeeplus.common.utils.DateUtils;
|
|
|
+import com.jeeplus.common.utils.StringUtils;
|
|
|
+import com.jeeplus.common.utils.excel.ExportExcel;
|
|
|
+import com.jeeplus.core.persistence.Page;
|
|
|
+import com.jeeplus.core.web.BaseController;
|
|
|
+import com.jeeplus.modules.sg.managementcenter.materialInventory.entity.MaterialInventory;
|
|
|
+import com.jeeplus.modules.sg.managementcenter.materialInventory.entity.MaterialRequisition;
|
|
|
+import com.jeeplus.modules.sg.managementcenter.materialInventory.service.MaterialInventoryService;
|
|
|
+import com.jeeplus.modules.sg.managementcenter.materialInventory.util.ImportPro;
|
|
|
+import com.jeeplus.modules.sg.managementcenter.materialInventory.util.ImportUtil;
|
|
|
+import org.apache.shiro.authz.annotation.Logical;
|
|
|
+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.annotation.ModelAttribute;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Controller
|
|
|
+@RequestMapping(value = "${adminPath}/sg/managementcenter/materialInventory")
|
|
|
+public class MaterialInventoryController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MaterialInventoryService materialInventoryService;
|
|
|
+
|
|
|
+ @ModelAttribute
|
|
|
+ public MaterialInventory get(@RequestParam(required=false) String id) {
|
|
|
+ MaterialInventory entity = null;
|
|
|
+ if (StringUtils.isNotBlank(id)){
|
|
|
+ entity = materialInventoryService.get(id);
|
|
|
+ }
|
|
|
+ if (entity == null){
|
|
|
+ entity = new MaterialInventory();
|
|
|
+ }
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表页面
|
|
|
+ */
|
|
|
+ @RequiresPermissions("managementcenter:materialInventory:list")
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
+ public String list(MaterialInventory materialInventory, Model model) {
|
|
|
+ model.addAttribute("materialInventory", materialInventory);
|
|
|
+ return "modules/sg/managementcenter/materialInventory/materialInventory";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表数据
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequiresPermissions("managementcenter:materialInventory:list")
|
|
|
+ @RequestMapping(value = "data")
|
|
|
+ public Map<String, Object> data(MaterialInventory materialInventory, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
+ Page<MaterialInventory> page = materialInventoryService.findPage(new Page<MaterialInventory>(request, response), materialInventory);
|
|
|
+ return getBootstrapData(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看,增加,编辑表单页面
|
|
|
+ */
|
|
|
+ @RequiresPermissions(value={"managementcenter:materialInventory:view","managementcenter:materialInventory:add","managementcenter:materialInventory:edit"},logical=Logical.OR)
|
|
|
+ @RequestMapping(value = "form")
|
|
|
+ public String form(MaterialInventory materialInventory, Model model) {
|
|
|
+ model.addAttribute("marterialInventory",materialInventory);
|
|
|
+ return "modules/sg/managementcenter/materialInventory/materialInventoryForm";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存表单
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequiresPermissions(value={"managementcenter:materialInventory:add","managementcenter:materialInventory:edit"},logical=Logical.OR)
|
|
|
+ @RequestMapping(value = "save")
|
|
|
+ public AjaxJson save(MaterialInventory materialInventory, Model model) throws Exception{
|
|
|
+ AjaxJson j = new AjaxJson();
|
|
|
+ /**
|
|
|
+ * 后台hibernate-validation插件校验
|
|
|
+ */
|
|
|
+ String errMsg = beanValidator(materialInventory);
|
|
|
+ if (StringUtils.isNotBlank(errMsg)){
|
|
|
+ j.setSuccess(false);
|
|
|
+ j.setMsg(errMsg);
|
|
|
+ return j;
|
|
|
+ }
|
|
|
+ //新增或编辑表单保存
|
|
|
+ materialInventoryService.save(materialInventory);//保存
|
|
|
+ j.setSuccess(true);
|
|
|
+ j.setMsg("保存库存成功");
|
|
|
+ return j;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除表单
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequiresPermissions("managementcenter:materialInventory:del")
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
+ public AjaxJson delete(MaterialInventory materialInventory) {
|
|
|
+ AjaxJson j = new AjaxJson();
|
|
|
+ materialInventoryService.delete(materialInventory);
|
|
|
+ j.setMsg("删除库存成功");
|
|
|
+ return j;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量表单
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequiresPermissions("managementcenter:materialInventory:del")
|
|
|
+ @RequestMapping(value = "deleteAll")
|
|
|
+ public AjaxJson deleteAll(String ids) {
|
|
|
+ AjaxJson j = new AjaxJson();
|
|
|
+ String idArray[] =ids.split(",");
|
|
|
+ for(String id : idArray){
|
|
|
+ materialInventoryService.delete(materialInventoryService.get(id));
|
|
|
+ }
|
|
|
+ j.setMsg("删除请假表单成功");
|
|
|
+ return j;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel文件
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequiresPermissions("managementcenter:materialInventory:export")
|
|
|
+ @RequestMapping(value = "export")
|
|
|
+ public AjaxJson exportFile(MaterialInventory materialInventory, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ AjaxJson j = new AjaxJson();
|
|
|
+ try {
|
|
|
+ String fileName = "库存"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
|
|
|
+ Page<MaterialInventory> page = materialInventoryService.findPage(new Page<MaterialInventory>(request, response, -1), materialInventory);
|
|
|
+ new ExportExcel("库存", MaterialInventory.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("managementcenter:materialInventory:import")
|
|
|
+ @RequestMapping(value = "import")
|
|
|
+ public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request){
|
|
|
+ AjaxJson j = new AjaxJson();
|
|
|
+ try {
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ ImportUtil importUtil = new ImportUtil(file,1,0);
|
|
|
+ boolean judgeInventory = ImportPro.getJudgeInventory(importUtil);
|
|
|
+ if (judgeInventory){
|
|
|
+ j.setSuccess(false);
|
|
|
+ j.setMsg("导入失败:表格不符合规范!");
|
|
|
+ return j;
|
|
|
+ }
|
|
|
+ List<MaterialInventory> materialInventoryUtil = ImportPro.getMaterialInventoryUtil(importUtil);
|
|
|
+ List<MaterialInventory> materialInventories = ImportPro.getSetMaterialInvenntory(materialInventoryUtil);//去重
|
|
|
+ materialInventoryService.saveList(materialInventories);
|
|
|
+ j.setMsg( "已成功导入"+materialInventories.size()+"条,"+"库存记录"+failureMsg);
|
|
|
+ } catch (Exception e) {
|
|
|
+ j.setSuccess(false);
|
|
|
+ j.setMsg("导入库存失败!失败信息:"+e.getMessage());
|
|
|
+ }
|
|
|
+ return j;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 导入Excel数据
|
|
|
+ 导入附件五2
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequiresPermissions("managementcenter:materialInventory:import")
|
|
|
+ @RequestMapping(value = "import1")
|
|
|
+ public AjaxJson importFile1(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request){
|
|
|
+ AjaxJson j = new AjaxJson();
|
|
|
+ try {
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ ImportUtil importUtil = new ImportUtil(file,1,0);
|
|
|
+ boolean judgeRequisition = ImportPro.getJudgeRequisition(importUtil);
|
|
|
+ if (judgeRequisition){
|
|
|
+ j.setSuccess(false);
|
|
|
+ j.setMsg("导入失败:表格不符合规范!");
|
|
|
+ return j;
|
|
|
+ }
|
|
|
+ List<MaterialRequisition> materialRequisitionUtil = ImportPro.getMaterialRequisitionUtil(importUtil);//得到数据表格
|
|
|
+ List<MaterialRequisition> materialRequisitionList = ImportPro.getSetMaterialRequisition(materialRequisitionUtil);//去重
|
|
|
+ List<MaterialInventory> byList = materialInventoryService.findByList(materialRequisitionList);//得到数据库中匹配的物料编码
|
|
|
+ if (null==byList||byList.size()<=0){
|
|
|
+ j.setSuccess(false);
|
|
|
+ j.setMsg("导入领料单失败!失败信息:无基础数据");
|
|
|
+ return j;
|
|
|
+ }
|
|
|
+ List<MaterialInventory> materialInventories = ImportPro.getMaterial(byList, materialRequisitionList);//得到可使用库存数量
|
|
|
+ materialInventoryService.saveList(materialInventories);
|
|
|
+ j.setMsg( "已成功导入"+materialInventories.size()+"条,"+"领料单记录"+failureMsg);
|
|
|
+ } catch (Exception e) {
|
|
|
+ j.setSuccess(false);
|
|
|
+ j.setMsg("导入领料单失败!失败信息:"+e.getMessage());
|
|
|
+ }
|
|
|
+ return j;
|
|
|
+ }
|
|
|
+}
|