EquipmentController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. url.append("&deviceNumber=");
  125. url.append(deviceNumber);
  126. device.setDeviceNumber(deviceNumber);
  127. mv.addObject("deviceNumber", deviceNumber);
  128. }
  129. if (StringUtil.isNotEmpty(deviceName)) {
  130. url.append("&deviceName=");
  131. url.append(deviceName);
  132. device.setDeviceName(deviceName);
  133. mv.addObject("deviceName", deviceName);
  134. }
  135. if (StringUtil.isNotEmpty(deviceStatus)) {
  136. url.append("&deviceStatus=");
  137. url.append(deviceStatus);
  138. device.setDeviceStatus(Integer.parseInt(deviceStatus));
  139. mv.addObject("deviceStatus", device.getDeviceStatus());
  140. }
  141. if (StringUtil.isNotEmpty(deviceRemake)) {
  142. url.append("&deviceRemake=");
  143. url.append(deviceRemake);
  144. device.setDeviceRemake(deviceRemake);
  145. mv.addObject("deviceRemake", deviceRemake);
  146. }
  147. // 封装请求数据
  148. PageRequest<PtsDevice> pageRequest = new PageRequest<PtsDevice>(device, pageNO, pageSize, pageTotal == null);
  149. PagedResult<PtsDevice> result = equipmentService.listDevice(pageRequest);
  150. long total = 0;
  151. if (pageTotal == null) {
  152. total = result.getPages();
  153. } else {
  154. total = pageTotal;
  155. result.setPages(total);
  156. }
  157. url.append("&pageTotal=").append(total).append("&pageNO=");
  158. mv.addObject("page", result);
  159. mv.addObject("url", url.toString());
  160. return mv;
  161. }
  162. /**
  163. * 进入修改设备页面
  164. * @param request
  165. * @param deviceId
  166. * @return
  167. * @throws Exception
  168. */
  169. @RequiresPermissions("equipment:update:device")
  170. @RequestMapping("/_update_device")
  171. public ModelAndView editDevice(HttpServletRequest request,
  172. @RequestParam(value = "deviceId", defaultValue = "", required = false) Integer deviceId
  173. ) throws Exception {
  174. ModelAndView mv = new ModelAndView("pts/device/update_device");
  175. if (deviceId == null) {
  176. return mv;
  177. }
  178. PtsDevice device = new PtsDevice();
  179. device.setDeviceId(deviceId);
  180. //获取机器列表
  181. List<PtsDevice> deviceList = equipmentService.listPtsDevice(device);
  182. if (deviceList == null || deviceList.size() <= 0) {
  183. return mv;
  184. }
  185. device = deviceList.get(0);//通过id获取只可能有一条数据
  186. mv.addObject("device",device);
  187. return mv;
  188. }
  189. /**
  190. * 修改设备信息
  191. * @param request
  192. * @param device
  193. * @return
  194. * @throws Exception
  195. */
  196. @ResponseBody
  197. @RequiresPermissions("equipment:update:device")
  198. @RequestMapping("/update_device")
  199. public ResponseJson updateDevice(HttpServletRequest request,PtsDevice device) throws Exception {
  200. ResponseJson msg = new ResponseJson();
  201. //修改设备信息
  202. int num = equipmentService.updateDevice(device);
  203. if (num > 0) {
  204. msg.setResultCode(200);
  205. msg.setReturnCode(200);
  206. } else {
  207. msg.setResultCode(500);
  208. msg.setReturnCode(500);
  209. }
  210. return msg;
  211. }
  212. /**
  213. * 进入修改生产流程页面
  214. * @param request
  215. * @return
  216. * @throws Exception
  217. */
  218. @RequiresPermissions("equipment:update:process")
  219. @RequestMapping("/_update_process")
  220. public ModelAndView editProcess(HttpServletRequest request) throws Exception {
  221. ModelAndView mv = new ModelAndView("pts/device/update_process");
  222. String deviceId = request.getParameter("deviceId");
  223. mv.addObject("deviceId",deviceId);
  224. return mv;
  225. }
  226. /**
  227. * 查询产品及工序信息
  228. * @param request
  229. * @return
  230. * @throws Exception
  231. */
  232. @ResponseBody
  233. @RequiresPermissions("equipment:select:process")
  234. @RequestMapping("/select_produce_process")
  235. public ResponseJson selectproduceProcess(HttpServletRequest request) throws Exception {
  236. ResponseJson msg = new ResponseJson();
  237. Map<String, Object> objMap = new HashMap<String, Object>();
  238. Produce produce = new Produce();
  239. //查询产品及工序信息
  240. List<Produce> produceList = equipmentService.listProduct(produce);
  241. PtsEmployee employee = new PtsEmployee();
  242. employee.setEmployeeState(1);
  243. //查询员工集合
  244. List<PtsEmployee> employeeList = equipmentService.listEmployee(employee);
  245. PtsDevice device = new PtsDevice();
  246. device.setDeviceStatus(1);
  247. //获取机器列表
  248. List<PtsDevice> deviceList = equipmentService.listPtsDevice(device);
  249. if (produceList != null && produceList.size() > 0) {
  250. objMap.put("employeeList",employeeList);
  251. objMap.put("produceList",produceList);
  252. objMap.put("deviceList",deviceList);
  253. msg.setResultCode(200);
  254. msg.setReturnCode(200);
  255. msg.addResponseKeyValue("objMap",objMap);
  256. } else {
  257. msg.setResultCode(500);
  258. msg.setReturnCode(500);
  259. }
  260. return msg;
  261. }
  262. /**
  263. * 修改产品工序方法
  264. * @param request
  265. * @param process
  266. * @return
  267. * @throws Exception
  268. */
  269. @ResponseBody
  270. @RequiresPermissions("equipment:update:process")
  271. @RequestMapping("/update_process_info")
  272. public ResponseJson updateProcessInfo(HttpServletRequest request,ProduceProcess process) throws Exception {
  273. ResponseJson msg = new ResponseJson();
  274. if (process == null || process.getProcessId() == null || "".equals(process.getProcessId())) {
  275. msg.setResultCode(500);
  276. msg.setReturnCode(500);
  277. return msg;
  278. }
  279. //修改产品工序
  280. boolean flag = equipmentService.updateProcessInfo(process);
  281. if (flag) {
  282. msg.setResultCode(200);
  283. msg.setReturnCode(200);
  284. return msg;
  285. } else {
  286. msg.setResultCode(500);
  287. msg.setReturnCode(500);
  288. return msg;
  289. }
  290. }
  291. /**
  292. *
  293. * @param request
  294. * @return
  295. */
  296. @ResponseBody
  297. @RequestMapping("/is_equipment")
  298. public ResponseJson getEmployee(HttpServletRequest request){
  299. String deviceNumber = request.getParameter("deviceNumber");
  300. if(deviceNumber == null || "".equals(deviceNumber)){
  301. return new ResponseJson(500, "设备编号为空", 501);
  302. }
  303. PtsDevice ptsDevice = new PtsDevice();
  304. ptsDevice.setDeviceNumber(deviceNumber);
  305. List<PtsDevice> ptsDevicelist = equipmentService.listDeviceByNo(ptsDevice);
  306. if (ptsDevicelist != null && ptsDevicelist.size() > 0 ){
  307. return new ResponseJson(200, "SUCCESS", 200);
  308. }else {
  309. return new ResponseJson(500, "设备不存在", 502);
  310. }
  311. }
  312. }