MesDeviceConsumableController.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package com.jeesite.modules.mes.web;
  2. import com.alibaba.fastjson.JSONValidator;
  3. import com.jeesite.common.codec.EncodeUtils;
  4. import com.jeesite.common.collect.ListUtils;
  5. import com.jeesite.common.config.Global;
  6. import com.jeesite.common.entity.Page;
  7. import com.jeesite.common.lang.DateUtils;
  8. import com.jeesite.common.utils.excel.ExcelExport;
  9. import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
  10. import com.jeesite.common.web.BaseController;
  11. import com.jeesite.modules.mes.entity.MesDeviceConsumable;
  12. import com.jeesite.modules.mes.entity.MesDeviceConsumableRecord;
  13. import com.jeesite.modules.mes.resp.CommonResp;
  14. import com.jeesite.modules.mes.service.MesDeviceConsumableRecordService;
  15. import com.jeesite.modules.mes.service.MesDeviceConsumableService;
  16. import org.apache.shiro.authz.annotation.RequiresPermissions;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Controller;
  19. import org.springframework.ui.Model;
  20. import org.springframework.validation.annotation.Validated;
  21. import org.springframework.web.bind.annotation.ModelAttribute;
  22. import org.springframework.web.bind.annotation.PostMapping;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.ResponseBody;
  25. import org.springframework.web.multipart.MultipartFile;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;
  28. import java.util.List;
  29. /**
  30. * 易耗品Controller
  31. * @author mes
  32. * @version 2023-06-19
  33. */
  34. @Controller
  35. @RequestMapping(value = "${adminPath}/mes/mesDeviceConsumable")
  36. public class MesDeviceConsumableController extends BaseController {
  37. @Autowired
  38. private MesDeviceConsumableService mesDeviceConsumableService;
  39. /**
  40. * 获取数据
  41. */
  42. @ModelAttribute
  43. public MesDeviceConsumable get(String id, boolean isNewRecord) {
  44. return mesDeviceConsumableService.get(id, isNewRecord);
  45. }
  46. /**
  47. * 查询列表
  48. */
  49. @RequiresPermissions("mes:mesDeviceConsumable:view")
  50. @RequestMapping(value = {"list", ""})
  51. public String list(MesDeviceConsumable mesDeviceConsumable, Model model) {
  52. model.addAttribute("mesDeviceConsumable", mesDeviceConsumable);
  53. return "modules/mes/mesDeviceConsumableList";
  54. }
  55. /**
  56. * 查询列表数据
  57. */
  58. @RequiresPermissions("mes:mesDeviceConsumable:view")
  59. @RequestMapping(value = "listData")
  60. @ResponseBody
  61. public Page<MesDeviceConsumable> listData(MesDeviceConsumable mesDeviceConsumable, HttpServletRequest request, HttpServletResponse response) {
  62. mesDeviceConsumable.setPage(new Page<>(request, response));
  63. Page<MesDeviceConsumable> page = mesDeviceConsumableService.findPage(mesDeviceConsumable);
  64. return page;
  65. }
  66. /**
  67. * 查看编辑表单
  68. */
  69. @RequiresPermissions("mes:mesDeviceConsumable:view")
  70. @RequestMapping(value = "form")
  71. public String form(MesDeviceConsumable mesDeviceConsumable, Model model) {
  72. model.addAttribute("mesDeviceConsumable", mesDeviceConsumable);
  73. return "modules/mes/mesDeviceConsumableForm";
  74. }
  75. /**
  76. * 保存数据
  77. */
  78. @RequiresPermissions("mes:mesDeviceConsumable:edit")
  79. @PostMapping(value = "save")
  80. @ResponseBody
  81. public String save(@Validated MesDeviceConsumable mesDeviceConsumable) {
  82. mesDeviceConsumableService.save(mesDeviceConsumable);
  83. return renderResult(Global.TRUE, text("保存易耗品成功!"));
  84. }
  85. /**
  86. * 导出数据
  87. */
  88. @RequiresPermissions("mes:mesDeviceConsumable:view")
  89. @RequestMapping(value = "exportData")
  90. public void exportData(MesDeviceConsumable mesDeviceConsumable, HttpServletResponse response) {
  91. List<MesDeviceConsumable> list = mesDeviceConsumableService.findList(mesDeviceConsumable);
  92. String fileName = "易耗品" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
  93. try(ExcelExport ee = new ExcelExport("易耗品", MesDeviceConsumable.class)){
  94. ee.setDataList(list).write(response, fileName);
  95. }
  96. }
  97. /**
  98. * 使用记录导出数据
  99. */
  100. @Autowired
  101. private MesDeviceConsumableRecordService mesDeviceConsumableRecordService;
  102. @RequestMapping(value = "exportDatajilu")
  103. public void exportData(MesDeviceConsumableRecord mesDeviceConsumableRecord, HttpServletResponse response) {
  104. List<MesDeviceConsumableRecord> list = mesDeviceConsumableRecordService.findList(mesDeviceConsumableRecord);
  105. String fileName = "易耗品记录" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
  106. try(ExcelExport ee = new ExcelExport("易耗品记录", MesDeviceConsumableRecord.class)){
  107. ee.setDataList(list).write(response, fileName);
  108. }
  109. }
  110. /**
  111. * 下载模板
  112. */
  113. @RequiresPermissions("mes:mesDeviceConsumable:view")
  114. @RequestMapping(value = "importTemplate")
  115. public void importTemplate(HttpServletResponse response) {
  116. MesDeviceConsumable mesDeviceConsumable = new MesDeviceConsumable();
  117. List<MesDeviceConsumable> list = ListUtils.newArrayList(mesDeviceConsumable);
  118. String fileName = "易耗品模板.xlsx";
  119. try(ExcelExport ee = new ExcelExport("易耗品", MesDeviceConsumable.class, Type.IMPORT)){
  120. ee.setDataList(list).write(response, fileName);
  121. }
  122. }
  123. /**
  124. * 导入数据
  125. */
  126. @ResponseBody
  127. @RequiresPermissions("mes:mesDeviceConsumable:edit")
  128. @PostMapping(value = "importData")
  129. public String importData(MultipartFile file) {
  130. try {
  131. String message = mesDeviceConsumableService.importData(file);
  132. return renderResult(Global.TRUE, "posfull:"+message);
  133. } catch (Exception ex) {
  134. return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
  135. }
  136. }
  137. /**
  138. * 删除数据
  139. */
  140. @RequiresPermissions("mes:mesDeviceConsumable:edit")
  141. @RequestMapping(value = "delete")
  142. @ResponseBody
  143. public String delete(MesDeviceConsumable mesDeviceConsumable) {
  144. mesDeviceConsumableService.delete(mesDeviceConsumable);
  145. return renderResult(Global.TRUE, text("删除易耗品成功!"));
  146. }
  147. /**
  148. * 查询列表数据
  149. */
  150. @RequiresPermissions("mes:mesDeviceConsumable:view")
  151. @RequestMapping(value = "getList")
  152. @ResponseBody
  153. public CommonResp getList(MesDeviceConsumable mesDeviceConsumable, HttpServletRequest request, HttpServletResponse response) {
  154. List<MesDeviceConsumable> list = mesDeviceConsumableService.findList(mesDeviceConsumable);
  155. CommonResp<List<MesDeviceConsumable>> resp = new CommonResp<>();
  156. resp.setData(list);
  157. return resp;
  158. }
  159. @RequiresPermissions("mes:mesDeviceConsumable:view")
  160. @RequestMapping(value = "consumableSelect")
  161. public String userSelect(MesDeviceConsumable mesWarehouse, String selectData, Model model) {
  162. String selectDataJson = EncodeUtils.decodeUrl(selectData);
  163. if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()){
  164. model.addAttribute("selectData", selectDataJson);
  165. }
  166. model.addAttribute("warehouse", mesWarehouse);
  167. return "modules/mes/mesDeviceConsumableSelect";
  168. }
  169. }