EquipmentController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. package com.iamberry.rst.controllers.pts;
  2. import com.iamberry.rst.core.page.PageRequest;
  3. import com.iamberry.rst.core.page.PagedResult;
  4. import com.iamberry.rst.core.pts.Produce;
  5. import com.iamberry.rst.core.pts.ProduceProcess;
  6. import com.iamberry.rst.core.pts.PtsDevice;
  7. import com.iamberry.rst.core.pts.PtsEmployee;
  8. import com.iamberry.rst.faces.pts.EquipmentService;
  9. import com.iamberry.rst.faces.pts.ProduceService;
  10. import com.iamberry.wechat.tools.ResponseJson;
  11. import com.iamberry.wechat.tools.payUtil.StringUtil;
  12. import org.apache.shiro.authz.annotation.RequiresPermissions;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Controller;
  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.servlet.ModelAndView;
  19. import javax.servlet.http.HttpServletRequest;
  20. import java.util.HashMap;
  21. import java.util.Iterator;
  22. import java.util.List;
  23. import java.util.Map;
  24. /**
  25. * Created by Administrator on 2017/8/29.
  26. */
  27. @Controller
  28. @RequestMapping("/admin/equipment")
  29. public class EquipmentController {
  30. @Autowired
  31. private ProduceService produceService;
  32. @Autowired
  33. private EquipmentService equipmentService;
  34. /**
  35. * 进入添加设备页面
  36. * @param request
  37. * @return
  38. * @throws Exception
  39. */
  40. @RequiresPermissions("equipment:add:device")
  41. @RequestMapping("/_add_equpment")
  42. public ModelAndView addEqupmentUI(HttpServletRequest request) throws Exception {
  43. ModelAndView mv = new ModelAndView("pts/device/add_device");
  44. return mv;
  45. }
  46. /**
  47. * 查询所有可用产品工序信息
  48. * @param request
  49. * @return
  50. * @throws Exception
  51. */
  52. @RequiresPermissions("equipment:select:produce")
  53. @ResponseBody
  54. @RequestMapping("/select_produce_list")
  55. public ResponseJson selectProduceList(HttpServletRequest request) throws Exception {
  56. ResponseJson msg = new ResponseJson();
  57. //查询所有
  58. List<Produce> produceList = produceService.listSelectProduct(new Produce());
  59. Iterator<Produce> iter = produceList.iterator();
  60. while(iter.hasNext()){
  61. Produce produce = (Produce) iter.next();
  62. if (produce.getProcess().size() <= 0) {
  63. iter.remove();
  64. }
  65. }
  66. msg.setReturnCode(200);
  67. msg.setResultCode(200);
  68. msg.addResponseKeyValue("produceList",produceList);
  69. return msg;
  70. }
  71. /**
  72. * 添加设备信息
  73. * @param request
  74. * @param device
  75. * @return
  76. * @throws Exception
  77. */
  78. @RequiresPermissions("equipment:add:device")
  79. @ResponseBody
  80. @RequestMapping("/add_equpment")
  81. public ResponseJson addEqupment(HttpServletRequest request,PtsDevice device) throws Exception {
  82. ResponseJson msg = new ResponseJson();
  83. String processId = request.getParameter("selProcess");
  84. String[] processIds = null;
  85. /*if (processId != null && !"".equals(processId) && processId.indexOf(",") > 0) {
  86. processId = processId.substring(0,processId.lastIndexOf(","));
  87. processIds = processId.split(",");
  88. }*/
  89. //添加设备信息和修改工序信息
  90. boolean flag = equipmentService.addDevice(device, processIds);
  91. if (flag) {
  92. msg.setResultCode(200);
  93. msg.setReturnCode(200);
  94. } else {
  95. msg.setResultCode(500);
  96. msg.setReturnCode(500);
  97. }
  98. return msg;
  99. }
  100. /**
  101. * 查询设备列表信息
  102. * @param request
  103. * @param pageNO
  104. * @param pageTotal
  105. * @param pageSize
  106. * @return
  107. * @throws Exception
  108. */
  109. @RequiresPermissions("equipment:select:device")
  110. @RequestMapping("/select_device_list")
  111. public ModelAndView selectDeviceList(HttpServletRequest request,
  112. @RequestParam(value = "pageNO", defaultValue = "1", required = false) int pageNO,
  113. @RequestParam(value = "pageTotal", required = false) Integer pageTotal,
  114. @RequestParam(value = "pageSize", defaultValue = "10", required = false) int pageSize
  115. ) throws Exception {
  116. ModelAndView mv = new ModelAndView("pts/device/device_list");
  117. StringBuilder url = new StringBuilder("/admin/equipment/select_device_list?pageSize=" + pageSize);
  118. String deviceNumber = request.getParameter("deviceNumber");
  119. String deviceStatus = request.getParameter("deviceStatus");
  120. String deviceName = request.getParameter("deviceName");
  121. String deviceRemake = request.getParameter("deviceRemake");
  122. PtsDevice device = new PtsDevice();
  123. if (StringUtil.isNotEmpty(deviceNumber)) {
  124. device.setDeviceNumber(deviceNumber);
  125. mv.addObject("deviceNumber", deviceNumber);
  126. }
  127. if (StringUtil.isNotEmpty(deviceName)) {
  128. device.setDeviceName(deviceName);
  129. mv.addObject("deviceName", deviceName);
  130. }
  131. if (StringUtil.isNotEmpty(deviceStatus)) {
  132. device.setDeviceStatus(Integer.parseInt(deviceStatus));
  133. mv.addObject("deviceStatus", device.getDeviceStatus());
  134. }
  135. if (StringUtil.isNotEmpty(deviceRemake)) {
  136. device.setDeviceRemake(deviceRemake);
  137. mv.addObject("deviceRemake", deviceRemake);
  138. }
  139. // 封装请求数据
  140. PageRequest<PtsDevice> pageRequest = new PageRequest<PtsDevice>(device, pageNO, pageSize, pageTotal == null);
  141. PagedResult<PtsDevice> result = equipmentService.listDevice(pageRequest);
  142. long total = 0;
  143. if (pageTotal == null) {
  144. total = result.getPages();
  145. } else {
  146. total = pageTotal;
  147. result.setPages(total);
  148. }
  149. url.append("&pageTotal=").append(total).append("&pageNO=");
  150. mv.addObject("page", result);
  151. mv.addObject("url", url.toString());
  152. return mv;
  153. }
  154. /**
  155. * 进入修改设备页面
  156. * @param request
  157. * @param deviceId
  158. * @return
  159. * @throws Exception
  160. */
  161. @RequiresPermissions("equipment:update:device")
  162. @RequestMapping("/_update_device")
  163. public ModelAndView editDevice(HttpServletRequest request,
  164. @RequestParam(value = "deviceId", defaultValue = "", required = false) Integer deviceId
  165. ) throws Exception {
  166. ModelAndView mv = new ModelAndView("pts/device/update_device");
  167. if (deviceId == null) {
  168. return mv;
  169. }
  170. PtsDevice device = new PtsDevice();
  171. device.setDeviceId(deviceId);
  172. //获取机器列表
  173. List<PtsDevice> deviceList = equipmentService.listPtsDevice(device);
  174. if (deviceList == null || deviceList.size() <= 0) {
  175. return mv;
  176. }
  177. device = deviceList.get(0);//通过id获取只可能有一条数据
  178. mv.addObject("device",device);
  179. return mv;
  180. }
  181. /**
  182. * 修改设备信息
  183. * @param request
  184. * @param device
  185. * @return
  186. * @throws Exception
  187. */
  188. @ResponseBody
  189. @RequiresPermissions("equipment:update:device")
  190. @RequestMapping("/update_device")
  191. public ResponseJson updateDevice(HttpServletRequest request,PtsDevice device) throws Exception {
  192. ResponseJson msg = new ResponseJson();
  193. //修改设备信息
  194. int num = equipmentService.updateDevice(device);
  195. if (num > 0) {
  196. msg.setResultCode(200);
  197. msg.setReturnCode(200);
  198. } else {
  199. msg.setResultCode(500);
  200. msg.setReturnCode(500);
  201. }
  202. return msg;
  203. }
  204. /**
  205. * 进入修改生产流程页面
  206. * @param request
  207. * @return
  208. * @throws Exception
  209. */
  210. @RequiresPermissions("equipment:update:process")
  211. @RequestMapping("/_update_process")
  212. public ModelAndView editProcess(HttpServletRequest request) throws Exception {
  213. ModelAndView mv = new ModelAndView("pts/device/update_process");
  214. String deviceId = request.getParameter("deviceId");
  215. mv.addObject("deviceId",deviceId);
  216. return mv;
  217. }
  218. /**
  219. * 查询产品及工序信息
  220. * @param request
  221. * @return
  222. * @throws Exception
  223. */
  224. @ResponseBody
  225. @RequiresPermissions("equipment:select:process")
  226. @RequestMapping("/select_produce_process")
  227. public ResponseJson selectproduceProcess(HttpServletRequest request) throws Exception {
  228. ResponseJson msg = new ResponseJson();
  229. Map<String, Object> objMap = new HashMap<String, Object>();
  230. Produce produce = new Produce();
  231. //查询产品及工序信息
  232. List<Produce> produceList = equipmentService.listProduct(produce);
  233. PtsEmployee employee = new PtsEmployee();
  234. employee.setEmployeeState(1);
  235. //查询员工集合
  236. List<PtsEmployee> employeeList = equipmentService.listEmployee(employee);
  237. PtsDevice device = new PtsDevice();
  238. device.setDeviceStatus(1);
  239. //获取机器列表
  240. List<PtsDevice> deviceList = equipmentService.listPtsDevice(device);
  241. if (produceList != null && produceList.size() > 0) {
  242. objMap.put("employeeList",employeeList);
  243. objMap.put("produceList",produceList);
  244. objMap.put("deviceList",deviceList);
  245. msg.setResultCode(200);
  246. msg.setReturnCode(200);
  247. msg.addResponseKeyValue("objMap",objMap);
  248. } else {
  249. msg.setResultCode(500);
  250. msg.setReturnCode(500);
  251. }
  252. return msg;
  253. }
  254. /**
  255. * 修改产品工序方法
  256. * @param request
  257. * @param process
  258. * @return
  259. * @throws Exception
  260. */
  261. @ResponseBody
  262. @RequiresPermissions("equipment:update:process")
  263. @RequestMapping("/update_process_info")
  264. public ResponseJson updateProcessInfo(HttpServletRequest request,ProduceProcess process) throws Exception {
  265. ResponseJson msg = new ResponseJson();
  266. if (process == null || process.getProcessId() == null || "".equals(process.getProcessId())) {
  267. msg.setResultCode(500);
  268. msg.setReturnCode(500);
  269. return msg;
  270. }
  271. //修改产品工序
  272. boolean flag = equipmentService.updateProcessInfo(process);
  273. if (flag) {
  274. msg.setResultCode(200);
  275. msg.setReturnCode(200);
  276. return msg;
  277. } else {
  278. msg.setResultCode(500);
  279. msg.setReturnCode(500);
  280. return msg;
  281. }
  282. }
  283. /**
  284. *
  285. * @param request
  286. * @return
  287. */
  288. @ResponseBody
  289. @RequestMapping("/is_equipment")
  290. public ResponseJson getEmployee(HttpServletRequest request){
  291. String deviceNumber = request.getParameter("deviceNumber");
  292. if(deviceNumber == null || "".equals(deviceNumber)){
  293. return new ResponseJson(500, "设备编号为空", 501);
  294. }
  295. PtsDevice ptsDevice = new PtsDevice();
  296. ptsDevice.setDeviceNumber(deviceNumber);
  297. List<PtsDevice> ptsDevicelist = equipmentService.listDeviceByNo(ptsDevice);
  298. if (ptsDevicelist != null && ptsDevicelist.size() > 0 ){
  299. return new ResponseJson(200, "SUCCESS", 200);
  300. }else {
  301. return new ResponseJson(500, "设备不存在", 502);
  302. }
  303. }
  304. }