DeviceDefendController.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package com.xcgl.device.controller;
  2. import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
  3. import cn.afterturn.easypoi.excel.entity.ExportParams;
  4. import com.daju.common.util.DataPage;
  5. import com.daju.mix.dao.entity.PDeviceDefend;
  6. import com.daju.mix.dao.entity.TBArchivesProvider;
  7. import com.daju.mix.dao.mapper.TBCarMapper;
  8. import com.xcgl.device.dao.DeviceDao;
  9. import com.xcgl.device.service.impl.DeviceDefendServiceImpl;
  10. import com.xcgl.utils.OrderNumTools;
  11. import org.jeecgframework.core.common.exception.BusinessException;
  12. import org.jeecgframework.core.common.model.json.AjaxJson;
  13. import org.jeecgframework.core.common.model.json.DataGrid;
  14. import org.jeecgframework.core.util.ResourceUtil;
  15. import org.jeecgframework.tag.core.easyui.TagUtil;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Controller;
  18. import org.springframework.ui.ModelMap;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.ResponseBody;
  21. import org.springframework.web.servlet.ModelAndView;
  22. import javax.annotation.Resource;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import java.text.SimpleDateFormat;
  26. import java.util.*;
  27. /**
  28. * @author :sahib.kio.m
  29. * @date :Created in 2021/7/30 上午11:39
  30. */
  31. @Controller
  32. @RequestMapping("/deviceDefendController")
  33. public class DeviceDefendController {
  34. @Resource
  35. private DeviceDefendServiceImpl deviceDefendService;
  36. @Autowired
  37. private DeviceDao deviceDao;
  38. @Resource
  39. TBCarMapper tbCarMapper;
  40. @RequestMapping(params = "list")
  41. public ModelAndView carScheduleDoneStat(HttpServletRequest request) {
  42. return new ModelAndView("com/xcgl/device/defendList");
  43. }
  44. @RequestMapping(params = "goAdd")
  45. public ModelAndView goAdd(HttpServletRequest request) {
  46. return new ModelAndView("com/xcgl/device/defendList-add");
  47. }
  48. @RequestMapping(params = "goUpdate")
  49. public ModelAndView goUpdate(HttpServletRequest request) {
  50. String id = request.getParameter("id");
  51. PDeviceDefend common = deviceDefendService.getById(id);
  52. request.setAttribute("common", common);
  53. request.setAttribute("type_id", request.getParameter("type_id"));
  54. return new ModelAndView("com/xcgl/device/defendList-update");
  55. }
  56. @RequestMapping(params = "datagrid")
  57. public void datagrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  58. Map<String, String> param = new HashMap<>();
  59. for (String key : request.getParameterMap().keySet()){
  60. param.put(key, request.getParameter(key));
  61. }
  62. DataPage result = deviceDefendService.DefendList(param);
  63. TagUtil.datagrid(response, dataGrid, result);
  64. }
  65. @RequestMapping(params = "doAdd")
  66. @ResponseBody
  67. public AjaxJson doAdd(PDeviceDefend common, HttpServletRequest request) {
  68. String message = null;
  69. AjaxJson j = new AjaxJson();
  70. message = "档案添加成功";
  71. j.setSuccess(true);
  72. try{
  73. common.setCode(OrderNumTools.generateNextBillCode("LSSBYH" + getNowDate(),14, "p_device_defend", "code", 4));
  74. deviceDefendService.save(common);
  75. }catch(Exception e){
  76. e.printStackTrace();
  77. message = "档案添加失败";
  78. j.setSuccess(false);
  79. throw new BusinessException(e.getMessage());
  80. }
  81. j.setMsg(message);
  82. return j;
  83. }
  84. private static SimpleDateFormat sdfDate = new SimpleDateFormat("yyyyMMdd");
  85. private static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  86. public static String getNowDate(){
  87. Date now = new Date();
  88. String time = sdfDate.format(now);
  89. return time;
  90. }
  91. public static String getNowDateTime(){
  92. Date now = new Date();
  93. String time = sdfTime.format(now);
  94. return time;
  95. }
  96. @RequestMapping(params = "doUpdate")
  97. @ResponseBody
  98. public AjaxJson doUpdate(PDeviceDefend common, HttpServletRequest request) {
  99. String message = null;
  100. AjaxJson j = new AjaxJson();
  101. message = "档案修改成功";
  102. j.setSuccess(true);
  103. try{
  104. deviceDefendService.updateById(common);
  105. }catch(Exception e){
  106. e.printStackTrace();
  107. message = "档案修改失败";
  108. j.setSuccess(false);
  109. throw new BusinessException(e.getMessage());
  110. }
  111. j.setMsg(message);
  112. return j;
  113. }
  114. @RequestMapping(params = "doDel")
  115. @ResponseBody
  116. public AjaxJson doDel(PDeviceDefend common, HttpServletRequest request){
  117. String message = null;
  118. AjaxJson j = new AjaxJson();
  119. message = "档案删除成功";
  120. try{
  121. deviceDefendService.removeById(common);
  122. }catch(Exception e){
  123. e.printStackTrace();
  124. message = "档案删除失败";
  125. throw new BusinessException(e.getMessage());
  126. }
  127. j.setMsg(message);
  128. return j;
  129. }
  130. @RequestMapping(params = "exportXlsByT")
  131. public String exportXlsByT(ModelMap modelMap) {
  132. List<PDeviceDefend> providers = deviceDefendService.list();
  133. modelMap.put(NormalExcelConstants.FILE_NAME,"设备养护记录档案");
  134. modelMap.put(NormalExcelConstants.CLASS, PDeviceDefend.class);
  135. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("设备养护记录档案", "导出人:"+ ResourceUtil.getSessionUser().getRealName(),
  136. "导出信息"));
  137. modelMap.put(NormalExcelConstants.DATA_LIST, providers);
  138. return NormalExcelConstants.EASYPOI_EXCEL_VIEW;
  139. }
  140. /**
  141. * 设备养护记录到期提醒
  142. */
  143. @RequestMapping(params = "remind")
  144. @ResponseBody
  145. public AjaxJson remind(){
  146. List<String> list = tbCarMapper.getRemind();
  147. AjaxJson j = new AjaxJson();
  148. j.setMsg("请求成功");
  149. j.setObj(list);
  150. j.setSuccess(true);
  151. return j;
  152. }
  153. }