| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- package com.jeesite.modules.mes.web;
- import com.alibaba.fastjson.JSONValidator;
- import com.jeesite.common.codec.EncodeUtils;
- import com.jeesite.common.collect.ListUtils;
- import com.jeesite.common.config.Global;
- import com.jeesite.common.entity.Page;
- import com.jeesite.common.lang.DateUtils;
- import com.jeesite.common.utils.excel.ExcelExport;
- import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
- import com.jeesite.common.web.BaseController;
- import com.jeesite.modules.mes.entity.MesDeviceConsumable;
- import com.jeesite.modules.mes.entity.MesDeviceConsumableRecord;
- import com.jeesite.modules.mes.resp.CommonResp;
- import com.jeesite.modules.mes.service.MesDeviceConsumableRecordService;
- import com.jeesite.modules.mes.service.MesDeviceConsumableService;
- 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.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.ModelAttribute;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- 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;
- /**
- * 易耗品Controller
- * @author mes
- * @version 2023-06-19
- */
- @Controller
- @RequestMapping(value = "${adminPath}/mes/mesDeviceConsumable")
- public class MesDeviceConsumableController extends BaseController {
- @Autowired
- private MesDeviceConsumableService mesDeviceConsumableService;
-
- /**
- * 获取数据
- */
- @ModelAttribute
- public MesDeviceConsumable get(String id, boolean isNewRecord) {
- return mesDeviceConsumableService.get(id, isNewRecord);
- }
-
- /**
- * 查询列表
- */
- @RequiresPermissions("mes:mesDeviceConsumable:view")
- @RequestMapping(value = {"list", ""})
- public String list(MesDeviceConsumable mesDeviceConsumable, Model model) {
- model.addAttribute("mesDeviceConsumable", mesDeviceConsumable);
- return "modules/mes/mesDeviceConsumableList";
- }
-
- /**
- * 查询列表数据
- */
- @RequiresPermissions("mes:mesDeviceConsumable:view")
- @RequestMapping(value = "listData")
- @ResponseBody
- public Page<MesDeviceConsumable> listData(MesDeviceConsumable mesDeviceConsumable, HttpServletRequest request, HttpServletResponse response) {
- mesDeviceConsumable.setPage(new Page<>(request, response));
- Page<MesDeviceConsumable> page = mesDeviceConsumableService.findPage(mesDeviceConsumable);
- return page;
- }
- /**
- * 查看编辑表单
- */
- @RequiresPermissions("mes:mesDeviceConsumable:view")
- @RequestMapping(value = "form")
- public String form(MesDeviceConsumable mesDeviceConsumable, Model model) {
- model.addAttribute("mesDeviceConsumable", mesDeviceConsumable);
- return "modules/mes/mesDeviceConsumableForm";
- }
- /**
- * 保存数据
- */
- @RequiresPermissions("mes:mesDeviceConsumable:edit")
- @PostMapping(value = "save")
- @ResponseBody
- public String save(@Validated MesDeviceConsumable mesDeviceConsumable) {
- mesDeviceConsumableService.save(mesDeviceConsumable);
- return renderResult(Global.TRUE, text("保存易耗品成功!"));
- }
- /**
- * 导出数据
- */
- @RequiresPermissions("mes:mesDeviceConsumable:view")
- @RequestMapping(value = "exportData")
- public void exportData(MesDeviceConsumable mesDeviceConsumable, HttpServletResponse response) {
- List<MesDeviceConsumable> list = mesDeviceConsumableService.findList(mesDeviceConsumable);
- String fileName = "易耗品" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
- try(ExcelExport ee = new ExcelExport("易耗品", MesDeviceConsumable.class)){
- ee.setDataList(list).write(response, fileName);
- }
- }
- /**
- * 使用记录导出数据
- */
- @Autowired
- private MesDeviceConsumableRecordService mesDeviceConsumableRecordService;
- @RequestMapping(value = "exportDatajilu")
- public void exportData(MesDeviceConsumableRecord mesDeviceConsumableRecord, HttpServletResponse response) {
- List<MesDeviceConsumableRecord> list = mesDeviceConsumableRecordService.findList(mesDeviceConsumableRecord);
- String fileName = "易耗品记录" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
- try(ExcelExport ee = new ExcelExport("易耗品记录", MesDeviceConsumableRecord.class)){
- ee.setDataList(list).write(response, fileName);
- }
- }
- /**
- * 下载模板
- */
- @RequiresPermissions("mes:mesDeviceConsumable:view")
- @RequestMapping(value = "importTemplate")
- public void importTemplate(HttpServletResponse response) {
- MesDeviceConsumable mesDeviceConsumable = new MesDeviceConsumable();
- List<MesDeviceConsumable> list = ListUtils.newArrayList(mesDeviceConsumable);
- String fileName = "易耗品模板.xlsx";
- try(ExcelExport ee = new ExcelExport("易耗品", MesDeviceConsumable.class, Type.IMPORT)){
- ee.setDataList(list).write(response, fileName);
- }
- }
- /**
- * 导入数据
- */
- @ResponseBody
- @RequiresPermissions("mes:mesDeviceConsumable:edit")
- @PostMapping(value = "importData")
- public String importData(MultipartFile file) {
- try {
- String message = mesDeviceConsumableService.importData(file);
- return renderResult(Global.TRUE, "posfull:"+message);
- } catch (Exception ex) {
- return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
- }
- }
-
- /**
- * 删除数据
- */
- @RequiresPermissions("mes:mesDeviceConsumable:edit")
- @RequestMapping(value = "delete")
- @ResponseBody
- public String delete(MesDeviceConsumable mesDeviceConsumable) {
- mesDeviceConsumableService.delete(mesDeviceConsumable);
- return renderResult(Global.TRUE, text("删除易耗品成功!"));
- }
- /**
- * 查询列表数据
- */
- @RequiresPermissions("mes:mesDeviceConsumable:view")
- @RequestMapping(value = "getList")
- @ResponseBody
- public CommonResp getList(MesDeviceConsumable mesDeviceConsumable, HttpServletRequest request, HttpServletResponse response) {
- List<MesDeviceConsumable> list = mesDeviceConsumableService.findList(mesDeviceConsumable);
- CommonResp<List<MesDeviceConsumable>> resp = new CommonResp<>();
- resp.setData(list);
- return resp;
- }
- @RequiresPermissions("mes:mesDeviceConsumable:view")
- @RequestMapping(value = "consumableSelect")
- public String userSelect(MesDeviceConsumable mesWarehouse, String selectData, Model model) {
- String selectDataJson = EncodeUtils.decodeUrl(selectData);
- if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()){
- model.addAttribute("selectData", selectDataJson);
- }
- model.addAttribute("warehouse", mesWarehouse);
- return "modules/mes/mesDeviceConsumableSelect";
- }
- }
|