MaterialLibraryController.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package com.jeeplus.modules.supply.materialLibrary.web;
  2. import com.jeeplus.common.json.AjaxJson;
  3. import com.jeeplus.common.utils.StringUtils;
  4. import com.jeeplus.common.utils.excel.ImportExcel;
  5. import com.jeeplus.core.persistence.Page;
  6. import com.jeeplus.core.web.BaseController;
  7. import com.jeeplus.modules.supply.materialLibrary.entity.MaterialLibrary;
  8. import com.jeeplus.modules.supply.materialLibrary.service.MaterialLibraryService;
  9. import com.jeeplus.modules.supply.stockOut.entity.SupplyStockOut;
  10. import org.apache.shiro.authz.annotation.RequiresPermissions;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.ui.Model;
  14. import org.springframework.web.bind.annotation.ModelAttribute;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.ResponseBody;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import javax.servlet.http.HttpServletRequest;
  20. import javax.servlet.http.HttpServletResponse;
  21. import java.io.File;
  22. import java.io.IOException;
  23. import java.util.HashMap;
  24. import java.util.LinkedHashMap;
  25. import java.util.List;
  26. import java.util.Map;
  27. @Controller
  28. @RequestMapping(value = "${adminPath}/supply/materialLibrary")
  29. public class MaterialLibraryController extends BaseController {
  30. @Autowired
  31. private MaterialLibraryService materialLibraryService;
  32. @ModelAttribute
  33. public MaterialLibrary get(@RequestParam(required = false) String id) {
  34. MaterialLibrary entity = null;
  35. if (StringUtils.isNotBlank(id)) {
  36. entity = materialLibraryService.get(id);
  37. }
  38. if (entity == null) {
  39. entity = new MaterialLibrary();
  40. }
  41. return entity;
  42. }
  43. /**
  44. * 项目列表页面
  45. */
  46. // @RequiresPermissions("supply:materialLibrary:list")
  47. @RequestMapping(value = {"list", ""})
  48. public String list(MaterialLibrary materialLibrary,Model model) {
  49. model.addAttribute("materialLibrary",materialLibrary);
  50. return "modules/supply/materialLibrary/supplyMaterialLibraryList";
  51. }
  52. /**
  53. * 列表数据
  54. */
  55. @ResponseBody
  56. // @RequiresPermissions("supply:stockOut:list")
  57. @RequestMapping(value = "data")
  58. public Map<String, Object> data(MaterialLibrary materialLibrary, HttpServletRequest request, HttpServletResponse response, Model model) {
  59. Page<MaterialLibrary> page = materialLibraryService.findPage(new Page<MaterialLibrary>(request, response), materialLibrary);
  60. return getBootstrapData(page);
  61. }
  62. /**
  63. * 删除项目
  64. */
  65. @ResponseBody
  66. // @RequiresPermissions("supply:stockOut:del")
  67. @RequestMapping(value = "delete")
  68. public AjaxJson delete(MaterialLibrary materialLibrary) {
  69. AjaxJson j = new AjaxJson();
  70. materialLibraryService.delete(materialLibrary); //要自己写吗? 前端传的是id,
  71. j.setMsg("删除项目成功");
  72. return j;
  73. }
  74. /**
  75. * 批量删除
  76. */
  77. @ResponseBody
  78. // @RequiresPermissions("supply:stockOut:del")
  79. @RequestMapping(value = "deleteAll")
  80. public AjaxJson deleteAll(String ids) {
  81. AjaxJson j = new AjaxJson();
  82. String[] idArray = ids.split(",");
  83. for (String id : idArray) {
  84. materialLibraryService.delete(materialLibraryService.get(id));
  85. }
  86. j.setMsg("删除成功");
  87. return j;
  88. }
  89. /**
  90. * 导入Excel数据-
  91. */
  92. @ResponseBody
  93. // @RequiresPermissions("supply:stockOut:import")
  94. @RequestMapping(value = "import")
  95. public AjaxJson importFile(@RequestParam("file") MultipartFile file) {
  96. AjaxJson j = new AjaxJson();
  97. try {
  98. String repeat = "0"; //repeat:0:第一次交互,1:覆盖,2:不覆盖
  99. ImportExcel ei = new ImportExcel(file, 1, 0);
  100. List<MaterialLibrary> list = ei.getDataList(MaterialLibrary.class); //直接用就好了吗,格式啥的用设置吗?
  101. LinkedHashMap returnMap = materialLibraryService.disposeImportMaterialLibrary(list,file,repeat);
  102. //放要放的值
  103. returnMap.put("repeat","0");
  104. j.setBody(returnMap);
  105. j.setMsg(returnMap.get("msg").toString());
  106. } catch (Exception e) {
  107. j.setSuccess(false);
  108. j.setMsg("导入项目表单失败!失败信息:" + e.getMessage());
  109. }
  110. return j;
  111. }
  112. /**
  113. * 导入Excel数据-覆盖
  114. */
  115. @ResponseBody
  116. // @RequiresPermissions("supply:stockOut:import")
  117. @RequestMapping(value = "importTwo")
  118. public AjaxJson importFileTwo(String filePath,String repeat) {
  119. AjaxJson j = new AjaxJson();
  120. try {
  121. File file = new File(filePath);
  122. MultipartFile file1 = materialLibraryService.transformFile(file);
  123. ImportExcel ei = new ImportExcel(file, 1, 0);
  124. List<MaterialLibrary> list = ei.getDataList(MaterialLibrary.class); //直接用就好了吗,格式啥的用设置吗?
  125. LinkedHashMap returnMap = materialLibraryService.disposeImportMaterialLibrary(list,file1,repeat);
  126. //如果文件已经使用完毕,则删除
  127. materialLibraryService.deleteFileContent(file);
  128. //放要放的值
  129. j.setBody(returnMap);
  130. j.setMsg(returnMap.get("msg").toString());
  131. } catch (Exception e) {
  132. j.setSuccess(false);
  133. j.setMsg("导入项目表单失败!失败信息:" + e.getMessage());
  134. }
  135. return j;
  136. }
  137. }