StorageDeviceRepairController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. package com.chinaitop.depot.device.controller;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import javax.annotation.Resource;
  9. import javax.servlet.http.HttpServletRequest;
  10. import com.chinaitop.depot.device.model.*;
  11. import com.chinaitop.depot.device.service.DSblxxjyService;
  12. import org.springframework.http.MediaType;
  13. import org.springframework.web.bind.annotation.RequestBody;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.chinaitop.depot.device.service.StorageDeviceInputService;
  19. import com.chinaitop.depot.device.service.StorageDeviceRepairService;
  20. import com.chinaitop.depot.utils.ParameterUtil;
  21. import com.fasterxml.jackson.databind.ObjectMapper;
  22. import com.github.pagehelper.PageHelper;
  23. import com.github.pagehelper.PageInfo;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiImplicitParam;
  26. import io.swagger.annotations.ApiImplicitParams;
  27. import io.swagger.annotations.ApiOperation;
  28. @RestController
  29. @RequestMapping(value = {"/deviceRepair"})
  30. @Api(value = "StorageDeviceRepairController", description = "器材设备维修")
  31. public class StorageDeviceRepairController {
  32. @Resource
  33. private StorageDeviceRepairService deviceRepairService;
  34. @Resource
  35. private StorageDeviceInputService deviceInputService;
  36. @Resource
  37. private DSblxxjyService sblxxjyService;
  38. /*@Resource
  39. private OrgInfoService orgInfoService;*/
  40. /**
  41. * 分页获取器材信息
  42. *
  43. * @throws Exception
  44. */
  45. @RequestMapping(value = "/getDeviceList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  46. @ApiOperation(value = "查询维修设备信息", notes = "查询维修设备列表,支持分页")
  47. @ApiImplicitParams({
  48. @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
  49. @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"),
  50. })
  51. public PageInfo<StorageDevicerepair> listCheckPage(HttpServletRequest request, Integer pageNum, Integer pageSize, Integer repairStatus,Integer orgId) throws Exception {
  52. StorageDevicerepairExample storageDevicerepairExample = new StorageDevicerepairExample();
  53. StorageDevicerepairExample.Criteria criteria = storageDevicerepairExample.createCriteria();
  54. if (ParameterUtil.isnotnull(repairStatus)) {
  55. criteria.andRepairStatusEqualTo(repairStatus);
  56. }
  57. if (ParameterUtil.isnotnull(orgId)) {
  58. criteria.andOrgIdEqualTo(orgId);
  59. }
  60. //按照id进行降序
  61. storageDevicerepairExample.setOrderByClause("repair_status=1 desc,repair_status=2 desc,repair_status=0 desc,repair_end desc,id desc");
  62. if (pageNum != null && pageSize != null) {
  63. PageHelper.startPage(pageNum, pageSize);
  64. }
  65. List<StorageDevicerepair> list = deviceRepairService.queryByDevice(storageDevicerepairExample);
  66. PageInfo<StorageDevicerepair> pageInfo = new PageInfo<StorageDevicerepair>(list);
  67. return pageInfo;
  68. }
  69. /**
  70. * 新增维修
  71. */
  72. @RequestMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  73. @ApiOperation(value = "保存数据", notes = "保存增加或修改的数据")
  74. public Map<String, Object> save(@RequestBody StorageDevicerepair storageDevicerepair) {
  75. Map<String, Object> modelMap = new HashMap<>();
  76. // JSON字符串转对象
  77. ObjectMapper mapper = new ObjectMapper();
  78. //StorageDevicerepair storageDevicerepair = null;
  79. try {
  80. //storageDevicerepair = (StorageDevicerepair) mapper.readValue(deviceRepairJson, StorageDevicerepair.class);
  81. storageDevicerepair.setRepairStatus(1);//改变维修表中的状态
  82. deviceRepairService.save(storageDevicerepair);
  83. //入库表中的数量增加 状态发生改变
  84. DSbxxsjyExample example = new DSbxxsjyExample();
  85. DSbxxsjyExample.Criteria criteria = example.createCriteria();
  86. criteria.andSbbhEqualTo(storageDevicerepair.getNumber());
  87. DSbxxsjy dSbxxsjy = sblxxjyService.getList(example).get(0);
  88. long lnumber = storageDevicerepair.getRepairNumber().longValue();
  89. dSbxxsjy.setSbsl(dSbxxsjy.getSbsl() - lnumber);
  90. dSbxxsjy.setMqzt("3");
  91. sblxxjyService.update(dSbxxsjy);
  92. modelMap.put("status", "success");
  93. } catch (Exception e) {
  94. modelMap.put("status", "error");
  95. e.printStackTrace();
  96. }
  97. return modelMap;
  98. }
  99. /**
  100. * 查询仓房对应的设备名称
  101. *
  102. * @return
  103. */
  104. @RequestMapping(value = "/getDeviceName", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  105. @ApiOperation(value = "查询数据", notes = "根据depotId查询数据")
  106. @ApiImplicitParams({
  107. @ApiImplicitParam(name = "depotId", value = "depotId", paramType = "query"),
  108. })
  109. public List<StorageDeviceinput> getHouseList(Integer depotId) {
  110. List<StorageDeviceinput> storageDeviceinput = null;
  111. if (depotId != 0) {
  112. storageDeviceinput = deviceInputService.getDeviceInputList(depotId);
  113. }
  114. return storageDeviceinput;
  115. }
  116. /**
  117. * 查询维修的设备名称
  118. */
  119. @RequestMapping(value = "/getDeviceNameList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  120. @ApiOperation(value = "查询数据", notes = "查询数据")
  121. public List<String> getDeviceNameList(String orgId) {
  122. return deviceInputService.getRepairNameList(orgId);
  123. }
  124. /**
  125. * 查询设备名称对应的型号
  126. *
  127. * @return
  128. */
  129. @RequestMapping(value = "/getDeviceModel", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  130. @ApiOperation(value = "查询数据根据名称", notes = "查询数据根据名称")
  131. @ApiImplicitParams({
  132. @ApiImplicitParam(name = "deviceName", value = "deviceName", paramType = "query"),
  133. })
  134. public List<StorageDeviceinput> getModelList(String deviceName) {
  135. List<StorageDeviceinput> storageDeviceinput = deviceInputService.getDeviceModelRepair(deviceName);
  136. return storageDeviceinput;
  137. }
  138. /**
  139. * 查询设备名称对应的型号
  140. *
  141. * @return
  142. */
  143. @RequestMapping(value = "/getDeviceNumber", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  144. @ApiOperation(value = "查询设备名称对应的型号", notes = "查询设备名称对应的型号")
  145. @ApiImplicitParams({
  146. @ApiImplicitParam(name = "deviceModel", value = "deviceModel", paramType = "query")
  147. })
  148. public List<StorageDeviceinput> getDeviceNumber(String deviceModel) {
  149. List<StorageDeviceinput> storageDeviceinput = deviceInputService.getNumberList(deviceModel);
  150. return storageDeviceinput;
  151. }
  152. /**
  153. * 查询型号对应的数量
  154. *
  155. * @return
  156. */
  157. @RequestMapping(value = "/getDeviceCount", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  158. @ApiOperation(value = "查询数量", notes = "查询设备名称对应的型号")
  159. @ApiImplicitParams({
  160. @ApiImplicitParam(name = "deviceModel", value = "deviceModel", paramType = "query")
  161. })
  162. public List<StorageDeviceinput> getDeviceCount(String number, String model) {
  163. List<StorageDeviceinput> storageDeviceinput = deviceInputService.getCountList(number);
  164. return storageDeviceinput;
  165. }
  166. /**
  167. * 结束维修
  168. */
  169. @RequestMapping(value = "/end", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  170. @ApiOperation(value = "结束维修", notes = "结束维修")
  171. public Map<String, Object> end(@RequestBody StorageDevicerepair storageDevicerepair) {
  172. Map<String, Object> modelMap = new HashMap<>();
  173. // JSON字符串转对象
  174. ObjectMapper mapper = new ObjectMapper();
  175. //StorageDevicerepair storageDevicerepair = null;
  176. try {
  177. //storageDevicerepair = (StorageDevicerepair) mapper.readValue(deviceListJson, StorageDevicerepair.class);
  178. //改变维修表中的信息
  179. storageDevicerepair.setRepairEnd(new Date());
  180. storageDevicerepair.setRepairStatus(0);
  181. deviceRepairService.updateByPrimaryKeySelective(storageDevicerepair);
  182. //根据id获取编号和型号
  183. storageDevicerepair = deviceRepairService.loadDataById(storageDevicerepair.getId());
  184. //入库表中的数量增加 状态发生改变
  185. DSbxxsjyExample example = new DSbxxsjyExample();
  186. DSbxxsjyExample.Criteria criteria = example.createCriteria();
  187. criteria.andSbbhEqualTo(storageDevicerepair.getNumber());
  188. DSbxxsjy dSbxxsjy = sblxxjyService.getList(example).get(0);
  189. long lnumber = storageDevicerepair.getRepairNumber().longValue();
  190. dSbxxsjy.setSbsl(dSbxxsjy.getSbsl() + lnumber);
  191. dSbxxsjy.setMqzt("1");
  192. sblxxjyService.update(dSbxxsjy);
  193. modelMap.put("status", "success");
  194. } catch (Exception e) {
  195. modelMap.put("status", "error");
  196. e.printStackTrace();
  197. }
  198. return modelMap;
  199. }
  200. /**
  201. * 批量结束维修
  202. */
  203. @RequestMapping(value = "/endMore", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  204. @ApiOperation(value = "批量结束维修", notes = "批量结束维修")
  205. public Map<String, Object> endMore(String deviceListJson) {
  206. Map<String, Object> modelMap = new HashMap<>();
  207. // JSON字符串转对象
  208. //ObjectMapper mapper = new ObjectMapper();
  209. try {
  210. JSONObject jsonObject = JSONObject.parseObject(deviceListJson);
  211. String idStr = jsonObject.getString("id");
  212. if (idStr != null && !"".equals(idStr)) {
  213. String[] ids = idStr.split(",");
  214. for (int i = 0; i < ids.length; i++) {
  215. StorageDevicerepair storageDevicerepair = new StorageDevicerepair();
  216. storageDevicerepair.setRepairEnd(new Date());
  217. storageDevicerepair.setRepairStatus(0);
  218. storageDevicerepair.setId(Integer.parseInt(ids[i]));
  219. deviceRepairService.updateByPrimaryKeySelective(storageDevicerepair);
  220. }
  221. }
  222. modelMap.put("status", "success");
  223. } catch (Exception e) {
  224. modelMap.put("status", "error");
  225. e.printStackTrace();
  226. }
  227. return modelMap;
  228. }
  229. /**
  230. * 根据id加载对应数据
  231. *
  232. * @param id
  233. * @return
  234. * @throws Exception
  235. */
  236. @RequestMapping(value = "/loadDataById", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  237. @ApiOperation(value = "根据id加载数据", notes = "根据id加载数据")
  238. @ApiImplicitParams({
  239. @ApiImplicitParam(name = "id", value = "id", paramType = "query")
  240. })
  241. public List<StorageDevicerepair> loadDataById(int id) throws Exception {
  242. StorageDevicerepair storageDevicerepair = deviceRepairService.loadDataById(id);
  243. List<StorageDevicerepair> repairMassageList = new ArrayList<StorageDevicerepair>();
  244. repairMassageList.add(storageDevicerepair);
  245. return repairMassageList;
  246. }
  247. }