ApiAppDeviceLogController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. package cn.fastfun.controller.api;
  2. import cn.fastfun.controller.param.*;
  3. import cn.fastfun.service.AppDeviceLogService;
  4. import cn.fastfun.service.AppDeviceService;
  5. import cn.fastfun.service.entity.AppDevice;
  6. import cn.fastfun.service.entity.AppDeviceLog;
  7. import cn.fastfun.util.DateUtils;
  8. import cn.fastfun.util.ObjectUtil;
  9. import com.bridge.dto.*;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import io.swagger.annotations.ApiParam;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.data.domain.Page;
  15. import org.springframework.util.CollectionUtils;
  16. import org.springframework.util.StringUtils;
  17. import org.springframework.web.bind.annotation.RequestBody;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RequestMethod;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import javax.annotation.Resource;
  22. import java.math.BigInteger;
  23. import java.util.ArrayList;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;
  27. /**
  28. * @author Bridge AutoGen
  29. */
  30. @Slf4j
  31. @Api(tags = {"2.1 设备操作信息"})
  32. @RestController
  33. @RequestMapping("/api/v1/app/device/log")
  34. public class ApiAppDeviceLogController {
  35. //业务类
  36. @Resource(name = "appDeviceService")
  37. AppDeviceService appDeviceService;
  38. @Resource
  39. AppDeviceLogService deviceLogService;
  40. @ApiOperation(value = "新增入库 单个 or 批次")
  41. @RequestMapping(value = "instorage", method = RequestMethod.POST)
  42. public ApiDTO inStorage(@RequestBody @ApiParam(name = "入库参数", value = "指定sn", required = true) LibraryInFormParam param) {
  43. deviceLogService.putInStorage(param);
  44. return ApiDTO.ok();
  45. }
  46. @ApiOperation(value = "设备自检")
  47. @RequestMapping(value = "selfcheck", method = RequestMethod.POST)
  48. public ApiDTO selfCheck(@RequestBody @ApiParam(name = "入库参数", value = "指定sn", required = true) LibraryInFormParam param) {
  49. AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn", param.getSn()));
  50. device.setCheckStatus(1);
  51. appDeviceService.save(device);
  52. return ApiDTO.ok();
  53. }
  54. @ApiOperation(value = "批次入库 搜索 & 重置")
  55. @RequestMapping(value = "instorage/batch/Query", method = RequestMethod.POST)
  56. public ApiPageDTO inStorageBatchQuery(@RequestBody DeviceBatchQueryParam param) {
  57. StringBuffer sql = new StringBuffer();
  58. sql.append("select t1.batch_num,t1.operate_id,t1.operator,t1.sn,t1.check_status,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,");
  59. sql.append("count(if(status = 3,true,null)) as out_storage,count(if(status = 4,true,null)) as handle,");
  60. sql.append("t1.add_time,t1.received_place from app_device t1");
  61. if (!StringUtils.isEmpty(param.getBatchNum())) {
  62. sql.append(" where t1.batch_num like '%").append(param.getBatchNum()).append("%'");
  63. }
  64. sql.append(" group by t1.operate_id");
  65. if (!StringUtils.isEmpty(param.getOrderBy())) {
  66. sql.append(param.getOrderBy());
  67. }
  68. log.info("SQL: {}", sql.toString());
  69. ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param);
  70. if (null != page.getData()) {
  71. // 组装数据
  72. List<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
  73. for (Map<String, Object> p : list) {
  74. AppDevice device = new AppDevice();
  75. device.setImei(ObjectUtil.obj2String(p.get("imei")));
  76. appDeviceService.addImeiTitle(device);
  77. p.put("type_title", device.getTypeTitle());
  78. p.put("pack_title", device.getPackTitle());
  79. p.put("deliver_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("deliver_time")), DateUtils.YMD));
  80. p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS));
  81. }
  82. page.setData(list);
  83. }
  84. return page;
  85. }
  86. @ApiOperation(value = "批次入库 --> 入库 搜索 & 重置")
  87. @RequestMapping(value = "instorage/batch/inStorageQuery", method = RequestMethod.POST)
  88. public ApiPageDTO inStorageBatchInStorageQuery(@RequestBody DeviceBatchQueryParam param) {
  89. if (!StringUtils.isEmpty(param)) {
  90. param.addParam(QueryParamExp.eq("batchNum", param.getBatchNum()));
  91. }
  92. Page<AppDevice> devicePage = appDeviceService.findByParam(param);
  93. devicePage.getContent().forEach(p -> {
  94. appDeviceService.addImeiTitle(p);
  95. });
  96. return new ApiPageDTO(null, devicePage);
  97. }
  98. @ApiOperation(value = "设备入库 搜索 & 重置")
  99. @RequestMapping(value = "instorage/pageQuery", method = RequestMethod.POST)
  100. public ApiPageDTO inStoragePageQuery(@RequestBody LibraryInQueryParam param) {
  101. StringBuffer sql = new StringBuffer();
  102. if (StringUtils.isEmpty(param.getCheckStatus())) {
  103. sql.append("SELECT * FROM app_device_log WHERE type=1");
  104. } else {
  105. sql.append("SELECT * FROM app_device_log WHERE type=1 AND sn IN(SELECT sn FROM app_device WHERE check_status=" +
  106. param.getCheckStatus().toString() + ")");
  107. }
  108. if (!StringUtils.isEmpty(param.getSn())) {
  109. sql.append(" AND sn like '%" + param.getSn() + "%'");
  110. }
  111. log.info("SQL: {}", sql.toString());
  112. ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param);
  113. if (null != page.getData()) {
  114. // 组装数据
  115. List<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
  116. List<Map<String, Object>> listRes = new ArrayList<>();
  117. for (Map<String, Object> p : list) {
  118. Map<String, Object> pTemp = new HashMap<>();
  119. AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn", p.get("sn")));
  120. appDeviceService.addImeiTitle(device);
  121. pTemp.put("sn", p.get("sn"));
  122. pTemp.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS));
  123. pTemp.put("type_title", device.getTypeTitle());
  124. pTemp.put("pack_title", device.getPackTitle());
  125. pTemp.put("batch_num", device.getBatchNum());
  126. pTemp.put("check_status", device.getCheckStatus());
  127. pTemp.put("status", device.getStatus());
  128. pTemp.put("received_place", device.getReceivedPlace());
  129. pTemp.put("operate_time", DateUtils.toString(ObjectUtil.obj2Date(device.getUpdateTime()), DateUtils.YMD));
  130. listRes.add(pTemp);
  131. }
  132. page.setData(listRes);
  133. }
  134. return page;
  135. }
  136. @ApiOperation(value = "根据sn或batch调拨 ")
  137. @RequestMapping(value = "transfer", method = RequestMethod.POST)
  138. public ApiDTO transfer(@RequestBody @ApiParam(name = "划拨参数", value = "传入json格式", required = true) TransferFormParam param) {
  139. if (CollectionUtils.isEmpty(param.getBatchNum()) && CollectionUtils.isEmpty(param.getSn()))
  140. return ApiDTO.error("未设定设备号或sn");
  141. deviceLogService.transfer(param);
  142. return ApiDTO.ok();
  143. }
  144. @ApiOperation(value = "调回平台 ")
  145. @RequestMapping(value = "transferBack", method = RequestMethod.POST)
  146. public ApiDTO transferBack(@RequestBody @ApiParam(name = "回调参数", value = "输入sn", required = true) TransferFormParam param) {
  147. deviceLogService.transferBack(param);
  148. return ApiDTO.ok();
  149. }
  150. @ApiOperation(value = "设备调拨 查看详情")
  151. @RequestMapping(value = "transfer/detialQuery", method = RequestMethod.POST)
  152. public ApiPageDTO transferDetialQuery(@RequestBody detialQueryParam param) {
  153. param.addParam(QueryParamExp.eq("operateID", param.getOperateID()));
  154. param.addParam(QueryParamExp.eq("type", 2));
  155. Page<AppDeviceLog> deviceLogPage = deviceLogService.findByParam(param);
  156. deviceLogPage.getContent().forEach(p -> {
  157. AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn", p.getSn()));
  158. appDeviceService.addImeiTitle(device);
  159. p.appendFormDevice(device);
  160. p.appendInTime(device);
  161. });
  162. return new ApiPageDTO(null, deviceLogPage);
  163. }
  164. @ApiOperation(value = "设备调拨 搜索 & 重置")
  165. @RequestMapping(value = "transfer/pageQuery", method = RequestMethod.POST)
  166. public ApiPageDTO transferPageQuery(@RequestBody LogTransferQueryParam param) {
  167. StringBuffer sql = new StringBuffer("select t.batch_num,t.operate_id, t.add_time,count(0) as total,t.tf_event,t.tf_device_type,t.tf_used,t.tf_describe,t.out_custom_id,t.operator,t.remarks from app_device_log t where t.type = 2 ");
  168. // sn搜索
  169. if (!StringUtils.isEmpty(param.getSn())) {
  170. sql.append(" and t.sn like '%").append(param.getSn()).append("%'");
  171. }
  172. // 类型搜索
  173. if (!StringUtils.isEmpty(param.getType())) {
  174. sql.append(" and t.tf_device_type = ").append(param.getType());
  175. }
  176. sql.append(" group by t.operate_id");
  177. if (!StringUtils.isEmpty(param.getOrderBy())) {
  178. sql.append(param.getOrderBy());
  179. }
  180. log.info("SQL: {}", sql.toString());
  181. ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param);
  182. // 组装数据
  183. if (null != page.getData()) {
  184. List<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
  185. for (Map<String, Object> p : list) {
  186. p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS));
  187. p.put("customTitle", "骑享科技");
  188. }
  189. page.setData(list);
  190. }
  191. return page;
  192. }
  193. @ApiOperation(value = "新增调拨 --> 选择设备 查询 & 重置")
  194. @RequestMapping(value = "transfer/bySn/pageQuery", method = RequestMethod.POST)
  195. public ApiPageDTO transferBySnPageQuery(@RequestBody TransferBySnQueryParam param) {
  196. param.addParam(QueryParamExp.eq("status", 1));
  197. Page<AppDevice> devicePage = appDeviceService.findByParam(param);
  198. devicePage.getContent().forEach(p -> {
  199. QueryParam finalQuery = new QueryParam();
  200. finalQuery.addParam(QueryParamExp.desc("addTime"));
  201. finalQuery.addParam(QueryParamExp.eq("sn", p.getSn()));
  202. finalQuery.addParam(QueryParamExp.eq("type", 2));
  203. Page<AppDeviceLog> deviceLogPage = deviceLogService.findByParam(finalQuery);
  204. AppDeviceLog lastDeviceLogPage = new AppDeviceLog();
  205. if (!deviceLogPage.isEmpty()) {
  206. lastDeviceLogPage = deviceLogPage.getContent().get(0);
  207. }
  208. appDeviceService.addImeiTitle(p);
  209. p.appendInfo(lastDeviceLogPage);
  210. });
  211. return new ApiPageDTO(null, devicePage);
  212. }
  213. @ApiOperation(value = "新增调拨 --> 选择批次 查询 & 重置")
  214. @RequestMapping(value = "transfer/byBatch/pageQuery", method = RequestMethod.POST)
  215. public ApiPageDTO transferByBatchPageQuery(@RequestBody DeviceBatchQueryParam param) {
  216. StringBuffer sql = new StringBuffer();
  217. sql.append("select t1.batch_num,t1.operator,t1.operate_id,t1.sn,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,");
  218. sql.append("count(if(status = 3,true,null)) as out_storage,count(if(status = 4,true,null)) as handle,");
  219. sql.append("t1.add_time,t1.received_place from app_device t1");
  220. if (!StringUtils.isEmpty(param.getBatchNum())) {
  221. sql.append(" where t1.batch_num like '%").append(param.getBatchNum()).append("%'");
  222. }
  223. sql.append(" group by t1.operate_id");
  224. if (!StringUtils.isEmpty(param.getOrderBy())) {
  225. sql.append(param.getOrderBy());
  226. }
  227. log.info("SQL: {}", sql.toString());
  228. ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param);
  229. if (null != page.getData()) {
  230. // 组装数据
  231. List<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
  232. for (Map<String, Object> p : list) {
  233. AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn",p.get("sn")));
  234. device.setImei(ObjectUtil.obj2String(p.get("imei")));
  235. appDeviceService.addImeiTitle(device);
  236. p.put("type_title", device.getTypeTitle());
  237. p.put("pack_title", device.getPackTitle());
  238. p.put("deliver_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("deliver_time")), DateUtils.YMD));
  239. p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS));
  240. p.put("instorageTime", device.getInstorageTime());
  241. }
  242. page.setData(list);
  243. }
  244. return page;
  245. }
  246. @ApiOperation(value = "新增调拨 --> 选择批次 查看")
  247. @RequestMapping(value = "transfer/batch/detailQuery", method = RequestMethod.POST)
  248. public ApiPageDTO transferByBatchDetailQuery(@RequestBody DeviceBatchQueryParam param) {
  249. if (!StringUtils.isEmpty(param)) {
  250. param.addParam(QueryParamExp.like("batchNum", "%".concat(param.getBatchNum()).concat("%")));
  251. }
  252. Page<AppDevice> devicePage = appDeviceService.findByParam(param);
  253. devicePage.getContent().forEach(p -> {
  254. appDeviceService.addImeiTitle(p);
  255. });
  256. return new ApiPageDTO(null, devicePage);
  257. }
  258. @ApiOperation(value = "调回平台 搜索 & 重置")
  259. @RequestMapping(value = "transferBack/pageQuery", method = RequestMethod.POST)
  260. public ApiPageDTO transferBackPageQuery(@RequestBody TransferBySnQueryParam param) {
  261. param.addParam(QueryParamExp.eq("status", 3));
  262. Page<AppDevice> devicePage = appDeviceService.findByParam(param);
  263. return new ApiPageDTO(null, devicePage);
  264. }
  265. @ApiOperation(value = "根据sn或batch出库")
  266. @RequestMapping(value = "outstorage", method = RequestMethod.POST)
  267. public ApiDTO outStorage(@RequestBody @ApiParam(name = "出库参数", value = "传入json格式", required = true) LibraryOutFormParam param) {
  268. deviceLogService.outStorage(param);
  269. return ApiDTO.ok();
  270. }
  271. @ApiOperation(value = "设备出库 查看详情")
  272. @RequestMapping(value = "outstorage/detialQuery", method = RequestMethod.POST)
  273. public ApiPageDTO outDetialQuery(@RequestBody detialQueryParam param) {
  274. param.addParam(QueryParamExp.eq("operateID", param.getOperateID()));
  275. param.addParam(QueryParamExp.eq("type", 3));
  276. Page<AppDeviceLog> deviceLogPage = deviceLogService.findByParam(param);
  277. deviceLogPage.getContent().forEach(p -> {
  278. AppDevice device = new AppDevice();
  279. device.setImei(p.getImei());
  280. appDeviceService.addImeiTitle(device);
  281. device.setImei(p.getImei());
  282. appDeviceService.addImeiTitle(device);
  283. p.appendFormDevice(device);
  284. p.appendInTime(device);
  285. });
  286. return new ApiPageDTO(null, deviceLogPage);
  287. }
  288. @ApiOperation(value = "设备出库 搜索 & 重置")
  289. @RequestMapping(value = "outstorage/pageQuery", method = RequestMethod.POST)
  290. public ApiPageDTO outPageQuery(@RequestBody OutQueryParam param) {
  291. StringBuffer sql = new StringBuffer("select t.batch_num,t.operate_id,t.add_time,count(0) as total,t.out_type,t.receiver_name,t.receiver_phone,t.remarks,t.out_custom_id,t.operator,t.update_time from app_device_log t where t.type = 3");
  292. // sn搜索
  293. if (!StringUtils.isEmpty(param.getSn())) {
  294. sql.append(" and t.sn like '%").append(param.getSn()).append("%'");
  295. }
  296. // 类型搜索
  297. if (!StringUtils.isEmpty(param.getOutType())) {
  298. sql.append(" and t.out_type = ").append(param.getOutType());
  299. }
  300. sql.append(" group by t.operate_id");
  301. if (!StringUtils.isEmpty(param.getOrderBy())) {
  302. sql.append(param.getOrderBy());
  303. }
  304. log.info("SQL: {}", sql.toString());
  305. ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param);
  306. if (null != page.getData()) {
  307. // 组装数据
  308. List<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
  309. for (Map<String, Object> p : list) {
  310. p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS));
  311. p.put("update_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("update_time")), DateUtils.YMDHMS));
  312. p.put("out_type", String.valueOf(p.get("out_type")));
  313. }
  314. page.setData(list);
  315. }
  316. return page;
  317. }
  318. @ApiOperation(value = "批次出库 --> 查看")
  319. @RequestMapping(value = "outstorage/batch/detailQuery", method = RequestMethod.POST)
  320. public ApiPageDTO outByBatchDetailQuery(@RequestBody detialQueryParam param) {
  321. param.addParam(QueryParamExp.eq("operateID", param.getOperateID()));
  322. Page<AppDevice> devicePage = appDeviceService.findByParam(param);
  323. devicePage.getContent().forEach(p -> {
  324. appDeviceService.addImeiTitle(p);
  325. });
  326. return new ApiPageDTO(null, devicePage);
  327. }
  328. @ApiOperation(value = "批次出库 搜索 & 重置")
  329. @RequestMapping(value = "outstorage/byBatch/pageQuery", method = RequestMethod.POST)
  330. public ApiPageDTO outByBatchPageQuery(@RequestBody DeviceBatchQueryParam param) {
  331. StringBuffer sql = new StringBuffer();
  332. sql.append("select t1.batch_num,t1.operate_id,t1.operator,t1.sn,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,");
  333. sql.append("count(if(status = 3,true,null)) as out_storage,count(if(status = 4,true,null)) as handle,");
  334. sql.append("t1.add_time,t1.received_place from app_device t1 where t1.status = 2");
  335. if (!StringUtils.isEmpty(param.getBatchNum())) {
  336. sql.append(" and t1.batch_num like '%").append(param.getBatchNum()).append("%'");
  337. }
  338. sql.append(" group by t1.operate_id");
  339. if (!StringUtils.isEmpty(param.getOrderBy())) {
  340. sql.append(param.getOrderBy());
  341. }
  342. log.info("SQL: {}", sql.toString());
  343. ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param);
  344. if (null != page.getData()) {
  345. // 组装数据
  346. List<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
  347. for (Map<String, Object> p : list) {
  348. AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn",p.get("sn")));
  349. device.setImei(ObjectUtil.obj2String(p.get("imei")));
  350. appDeviceService.addImeiTitle(device);
  351. p.put("type_title", device.getTypeTitle());
  352. p.put("pack_title", device.getPackTitle());
  353. p.put("deliver_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("deliver_time")), DateUtils.YMD));
  354. p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS));
  355. p.put("instorageTime", DateUtils.toString(ObjectUtil.obj2Date(device.getInstorageTime()), DateUtils.YMDHMS));
  356. }
  357. page.setData(list);
  358. }
  359. return page;
  360. }
  361. @ApiOperation(value = "新增处置")
  362. @RequestMapping(value = "handle", method = RequestMethod.POST)
  363. public ApiDTO handle(@RequestBody @ApiParam(name = "出库参数", value = "传入json格式", required = true) HandelFormParam param) {
  364. deviceLogService.handle(param);
  365. return ApiDTO.ok();
  366. }
  367. @ApiOperation(value = "处置 搜索 & 重置")
  368. @RequestMapping(value = "handle/pageQuery", method = RequestMethod.POST)
  369. public ApiPageDTO deviceLogPageQuery(@RequestBody HandelQueryParam param) {
  370. param.addParam(QueryParamExp.eq("type", 4));
  371. Page<AppDeviceLog> devicePage = deviceLogService.findByParam(param);
  372. devicePage.getContent().forEach(p -> {
  373. AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn", p.getSn()));
  374. p.appendInTime(device);
  375. });
  376. return new ApiPageDTO(null,devicePage);
  377. }
  378. }