BillSamplingServiceImpl.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. package com.huimv.receive.service.impl;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.huimv.receive.common.token.TokenSign;
  8. import com.huimv.receive.common.utils.FlowUtil;
  9. import com.huimv.receive.common.utils.Result;
  10. import com.huimv.receive.common.utils.ResultCode;
  11. import com.huimv.receive.common.utils.UploadImage;
  12. import com.huimv.receive.entity.*;
  13. import com.huimv.receive.mapper.*;
  14. import com.huimv.receive.service.IBillSamplingService;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import javax.servlet.http.HttpServletRequest;
  20. import java.io.IOException;
  21. import java.text.ParseException;
  22. import java.time.LocalDateTime;
  23. import java.time.format.DateTimeFormatter;
  24. import java.util.Map;
  25. /**
  26. * <p>
  27. * 洗消表 服务实现类
  28. * </p>
  29. *
  30. * @author author
  31. * @since 2024-03-11
  32. */
  33. @Service
  34. public class BillSamplingServiceImpl extends ServiceImpl<BillSamplingMapper, BillSampling> implements IBillSamplingService {
  35. @Autowired
  36. private BillSamplingMapper billSamplingMapper;
  37. @Autowired
  38. private UploadImage uploadImage;
  39. @Autowired
  40. private BaseProcessMapper processMapper;
  41. @Autowired
  42. private BaseLocationMapper locationMapper;
  43. @Autowired
  44. private BillPcrMapper pcrMapper;
  45. @Autowired
  46. private BillCleanMapper cleanMapper;
  47. @Autowired
  48. private BillIsolateMapper isolateMapper;
  49. @Autowired
  50. private BillDryMapper dryMapper;
  51. @Autowired
  52. private BillCleanBeforeMapper billCleanBeforeMapper;
  53. @Autowired
  54. private BillGoodsInventoryMapper inventoryMapper;
  55. @Override
  56. public Result list(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
  57. String farmId = paramsMap.get("farmId");
  58. String type = paramsMap.get("type");//展示类型
  59. String data = paramsMap.get("data");
  60. String pageNum = paramsMap.get("pageNum");
  61. String pageSize = paramsMap.get("pageSize");
  62. if ("".equals(pageNum) || null == pageNum) {
  63. pageNum = "1";
  64. }
  65. if ("".equals(pageSize) || null == pageSize) {
  66. pageSize = "20";
  67. }
  68. Page<BillSampling> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
  69. QueryWrapper<BillSampling> queryWrapper = new QueryWrapper<>();
  70. queryWrapper.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest)).orderByDesc("sub_date").eq("vistit_type",type);
  71. if ("0".equals(data)) {
  72. queryWrapper.in("bill_status", 0, 1, 2, 3);
  73. }
  74. if ("1".equals(data)) {
  75. queryWrapper.eq("bill_status", 0);
  76. }
  77. if ("2".equals(data)) {
  78. queryWrapper.eq("bill_status", 1);
  79. }
  80. if ("3".equals(data)) {
  81. queryWrapper.in("bill_status", 2, 3);
  82. }
  83. QueryWrapper<BillSampling> queryWrapper2 = new QueryWrapper<>();
  84. queryWrapper2.eq("vistit_type", type);
  85. queryWrapper2.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest)).orderByDesc("sub_date");
  86. queryWrapper2.eq("bill_status", 0);
  87. return new Result(ResultCode.SUCCESS, billSamplingMapper.selectPage(page, queryWrapper), billSamplingMapper.selectCount(queryWrapper2));
  88. }
  89. @Override
  90. public Result listById(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
  91. String id = paramsMap.get("id");
  92. BillSampling billPcr = billSamplingMapper.selectById(id);
  93. return new Result(ResultCode.SUCCESS, billPcr);
  94. }
  95. @Override
  96. public Result listPersonalSample(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
  97. String farmId = paramsMap.get("farmId");
  98. String pageNo = paramsMap.get("pageNum");
  99. String pageSize = paramsMap.get("pageSize");
  100. String vistitType = paramsMap.get("vistitType");
  101. Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
  102. Page<BillSampling> page = new Page<>(Integer.parseInt(pageNo),Integer.parseInt(pageSize));
  103. LambdaQueryWrapper<BillSampling> queryWrapper = new QueryWrapper<BillSampling>().lambda()
  104. .eq(BillSampling::getFarmId,farmId)
  105. .eq(BillSampling::getAdmissionUserId, userId)
  106. .eq(ObjectUtil.isNotEmpty(vistitType), BillSampling::getVistitType, vistitType)
  107. .orderByDesc(BillSampling::getSubDate);
  108. Page<BillSampling> billSamplingPage = billSamplingMapper.selectPage(page,queryWrapper);
  109. Integer count = billSamplingMapper.selectCount(queryWrapper);
  110. return new Result(ResultCode.SUCCESS,billSamplingPage,count);
  111. }
  112. @Override
  113. public Result edit(HttpServletRequest httpServletRequest, String farmId, String id, String date, MultipartFile img) throws ParseException, IOException {
  114. String s = "";
  115. if (uploadImage.getVideoCom(img).equals("上传失败")) {
  116. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  117. return new Result(10001, "视频上传失败", false);
  118. }
  119. s = uploadImage.getVideoCom(img);
  120. DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  121. BillSampling sampling = billSamplingMapper.selectById(id);
  122. if (sampling.getBillStatus() != 0) {
  123. return new Result(10001, "此条记录已被他人修改,请退出刷新查看!", false);
  124. }
  125. sampling.setImgUrl(s);
  126. sampling.setImgStatus(1);
  127. QueryWrapper<BaseProcess> processQueryWrapper = new QueryWrapper<>();
  128. processQueryWrapper.eq("farm_id", farmId).eq("id", sampling.getProcessId());
  129. BaseProcess baseProcess = processMapper.selectOne(processQueryWrapper);//进程
  130. QueryWrapper<BaseLocation> locationQueryWrapper = new QueryWrapper<>();
  131. locationQueryWrapper.eq("id", sampling.getTestLocationId());
  132. BaseLocation baseLocation = locationMapper.selectOne(locationQueryWrapper);//当前pcr检测所在的位置
  133. String allLocationId = baseProcess.getAllLocationId();//所有的位置id
  134. String allFlowId = baseProcess.getAllFlowId();//所有的流程id
  135. String currentFlowId = baseProcess.getCurrentFlowId();//当前已经完成的流程id
  136. String substring1 = allFlowId.substring(currentFlowId.length() + 1, allFlowId.length());
  137. String[] split = substring1.split(",");
  138. Integer nextId = Integer.parseInt(split[0]);
  139. sampling.setBillStatus(1);
  140. sampling.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
  141. sampling.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
  142. sampling.setTestLocation(baseLocation.getLocationName());
  143. sampling.setTestLocationId(baseLocation.getId());
  144. sampling.setCheckDate(LocalDateTime.parse(date, dateTimeFormatter));
  145. sampling.setPassDate(LocalDateTime.now());
  146. Object newObject = BillPcrServiceImpl.getNewObject(nextId, sampling.getDestName(), sampling.getDestId(), sampling.getAdmissionUserName(),
  147. sampling.getAdmissionUserId(), sampling.getVistitDate(), sampling.getSubDate(),
  148. sampling.getProcessId(), Integer.parseInt(sampling.getFarmId()), sampling.getTestLocation(), sampling.getTestLocationId(),
  149. sampling.getVistitType(), sampling.getPhone(),sampling.getDepartureName(),sampling.getDepartureId());
  150. if (nextId == 0) {
  151. if (split.length == 1) {
  152. baseProcess.setProcessType(1);
  153. String[] strings = allLocationId.split(",");
  154. String ss2 = "";
  155. for (int i = 0; i < strings.length; i++) {
  156. strings[i].replaceAll(strings[i], "2");
  157. if (i == strings.length - 1) {
  158. ss2 = ss2 + strings[i].replaceAll(strings[i], "2");
  159. } else {
  160. ss2 = strings[i].replaceAll(strings[i], "2") + "," + ss2;
  161. }
  162. }
  163. baseProcess.setAllLocationStatus(ss2);
  164. } else {
  165. String[] strings = allLocationId.split(",");
  166. Integer index = 0;
  167. for (int i = 0; i < strings.length; i++) {
  168. if ((baseLocation.getId().toString()).equals(strings[i])) {
  169. index = i;
  170. }
  171. }
  172. QueryWrapper<BaseLocation> queryWrapper1 = new QueryWrapper();
  173. queryWrapper1.eq("id", strings[index + 2]);
  174. BaseLocation location = locationMapper.selectOne(queryWrapper1);
  175. FlowUtil flowUtil = new FlowUtil();
  176. Object entity = flowUtil.getEntity(Integer.parseInt(split[1]), sampling.getVistitType(), sampling.getDestName()
  177. , sampling.getDestId(), sampling.getAdmissionUserId(), sampling.getAdmissionUserName(), sampling.getPhone(),
  178. sampling.getVistitDate(), location.getId(), location.getLocationName(), Integer.parseInt(farmId)
  179. , baseProcess.getId(), sampling.getDepartureName(), sampling.getDepartureId());
  180. if (Integer.parseInt(split[1]) == 1) {
  181. //新增采样
  182. BillSampling billSampling = (BillSampling) entity;
  183. if (sampling.getVistitType() != 0) {
  184. billSampling.setCarNum(sampling.getCarNum());
  185. }
  186. if (sampling.getVistitType() == 5) {
  187. billSampling.setResource(sampling.getResource());
  188. billSampling.setFeedImgUrl(sampling.getFeedImgUrl());
  189. billSampling.setRemark(sampling.getRemark());
  190. }
  191. billSamplingMapper.insert(billSampling);
  192. } else if (Integer.parseInt(split[1]) == 2) {
  193. //新增pcr
  194. BillPcr billClean = (BillPcr) entity;
  195. if (sampling.getVistitType() != 0) {
  196. billClean.setCarNum(sampling.getCarNum());
  197. }
  198. if (sampling.getVistitType() == 5) {
  199. billClean.setResource(sampling.getResource());
  200. billClean.setFeedImgUrl(sampling.getFeedImgUrl());
  201. billClean.setRemark(sampling.getRemark());
  202. }
  203. pcrMapper.insert(billClean);
  204. } else if (Integer.parseInt(split[1]) == 3) {
  205. //新增洗澡
  206. BillClean billClean = (BillClean) entity;
  207. if (sampling.getVistitType() != 0) {
  208. billClean.setCarNum(sampling.getCarNum());
  209. }
  210. if (sampling.getVistitType() == 5) {
  211. billClean.setResource(sampling.getResource());
  212. billClean.setFeedImgUrl(sampling.getFeedImgUrl());
  213. billClean.setRemark(sampling.getRemark());
  214. }
  215. cleanMapper.insert(billClean);
  216. } else if (Integer.parseInt(split[1]) == 4) {
  217. //新增隔离
  218. BillIsolate pcr = (BillIsolate) entity;
  219. if (sampling.getVistitType() != 0) {
  220. pcr.setCarNum(sampling.getCarNum());
  221. }
  222. if (sampling.getVistitType() == 5) {
  223. pcr.setResource(sampling.getResource());
  224. pcr.setFeedImgUrl(sampling.getFeedImgUrl());
  225. pcr.setRemark(sampling.getRemark());
  226. }
  227. isolateMapper.insert(pcr);
  228. } else if (Integer.parseInt(split[1]) == 5) {
  229. BillDry billClean = (BillDry) entity;
  230. if (sampling.getVistitType() != 0) {
  231. billClean.setCarNum(sampling.getCarNum());
  232. }
  233. if (sampling.getVistitType() == 5) {
  234. billClean.setResource(sampling.getResource());
  235. billClean.setFeedImgUrl(sampling.getFeedImgUrl());
  236. billClean.setRemark(sampling.getRemark());
  237. }
  238. dryMapper.insert(billClean);
  239. //新增烘干
  240. } else if (Integer.parseInt(split[1]) == 6) {
  241. //新增洗澡前拍照
  242. BillCleanBefore before = (BillCleanBefore) entity;
  243. if (sampling.getVistitType() != 0) {
  244. before.setCarNum(sampling.getCarNum());
  245. }
  246. if (sampling.getVistitType() == 5) {
  247. before.setResource(sampling.getResource());
  248. before.setFeedImgUrl(sampling.getFeedImgUrl());
  249. before.setRemark(sampling.getRemark());
  250. }
  251. billCleanBeforeMapper.insert(before);
  252. }else if (Integer.parseInt(split[1]) == 7) {
  253. //新增洗澡前拍照
  254. BillGoodsInventory before = (BillGoodsInventory) entity;
  255. if (sampling.getVistitType() != 0) {
  256. before.setCarNum(sampling.getCarNum());
  257. }
  258. if (sampling.getVistitType() == 5) {
  259. before.setResource(sampling.getResource());
  260. before.setFeedImgUrl(sampling.getFeedImgUrl());
  261. before.setRemark(sampling.getRemark());
  262. }
  263. inventoryMapper.insert(before);
  264. }
  265. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId + "," + split[1]);
  266. Integer locationId = sampling.getTestLocationId();
  267. int indexOf = allLocationId.indexOf(locationId.toString());//当前位置在所有流程位置中的下标
  268. String substring = baseProcess.getAllLocationStatus().substring(0, indexOf + 3);//截取已经过的位置状态
  269. String[] split1 = substring.split(",");
  270. String sb2 = "";
  271. for (int i = 0; i < split1.length; i++) {
  272. if (i == split1.length - 1) {
  273. sb2 = sb2 + split1[i].replaceAll(split1[i], "2");
  274. } else {
  275. sb2 = split1[i].replaceAll(split1[i], "2") + "," + sb2;
  276. }
  277. }
  278. sb2 = sb2 + baseProcess.getAllLocationStatus().substring(indexOf + 3);
  279. StringBuilder sb = new StringBuilder(sb2);
  280. sb.replace(indexOf + 2, indexOf + 3, "2");
  281. sb.replace(indexOf + 4, indexOf + 5, "1");
  282. baseProcess.setAllLocationStatus(sb.toString());
  283. }
  284. } else if (nextId == 1) {
  285. //新增采样
  286. BillSampling billSampling = (BillSampling) newObject;
  287. if (sampling.getVistitType() != 0) {
  288. billSampling.setCarNum(sampling.getCarNum());
  289. }
  290. if (sampling.getVistitType() == 5) {
  291. billSampling.setResource(sampling.getResource());
  292. billSampling.setFeedImgUrl(sampling.getFeedImgUrl());
  293. billSampling.setRemark(sampling.getRemark());
  294. }
  295. billSamplingMapper.insert(billSampling);
  296. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  297. }else if (nextId == 2) {
  298. //新增pcr
  299. BillPcr billClean = (BillPcr) newObject;
  300. if (sampling.getVistitType() != 0) {
  301. billClean.setCarNum(sampling.getCarNum());
  302. }
  303. if (sampling.getVistitType() == 5) {
  304. billClean.setResource(sampling.getResource());
  305. billClean.setFeedImgUrl(sampling.getFeedImgUrl());
  306. billClean.setRemark(sampling.getRemark());
  307. }
  308. pcrMapper.insert(billClean);
  309. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  310. }else if (nextId == 3) {
  311. //新增洗澡
  312. BillClean billClean = (BillClean) newObject;
  313. if (sampling.getVistitType() != 0) {
  314. billClean.setCarNum(sampling.getCarNum());
  315. }if (sampling.getVistitType() == 5) {
  316. billClean.setResource(sampling.getResource());
  317. billClean.setFeedImgUrl(sampling.getFeedImgUrl());
  318. billClean.setRemark(sampling.getRemark());
  319. }
  320. cleanMapper.insert(billClean);
  321. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  322. }else if (nextId == 4) {
  323. //新增隔离
  324. BillIsolate pcr = (BillIsolate) newObject;
  325. if (sampling.getVistitType() != 0) {
  326. pcr.setCarNum(sampling.getCarNum());
  327. }
  328. if (sampling.getVistitType() == 5) {
  329. pcr.setResource(sampling.getResource());
  330. pcr.setFeedImgUrl(sampling.getFeedImgUrl());
  331. pcr.setRemark(sampling.getRemark());
  332. }
  333. isolateMapper.insert(pcr);
  334. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  335. }else if (nextId == 5) {
  336. BillDry billClean = (BillDry) newObject;
  337. if (sampling.getVistitType() != 0) {
  338. billClean.setCarNum(sampling.getCarNum());
  339. }
  340. if (sampling.getVistitType() == 5) {
  341. billClean.setResource(sampling.getResource());
  342. billClean.setFeedImgUrl(sampling.getFeedImgUrl());
  343. billClean.setRemark(sampling.getRemark());
  344. }
  345. dryMapper.insert(billClean);
  346. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  347. //新增烘干
  348. }else if (nextId == 6) {
  349. //新增洗澡前拍照
  350. BillCleanBefore before = (BillCleanBefore) newObject;
  351. if (sampling.getVistitType() != 0) {
  352. before.setCarNum(sampling.getCarNum());
  353. }
  354. if (sampling.getVistitType() == 5) {
  355. before.setResource(sampling.getResource());
  356. before.setFeedImgUrl(sampling.getFeedImgUrl());
  357. before.setRemark(sampling.getRemark());
  358. }
  359. billCleanBeforeMapper.insert(before);
  360. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  361. }
  362. else if (nextId == 7) {
  363. //新增洗澡前拍照
  364. BillGoodsInventory before = (BillGoodsInventory) newObject;
  365. if (sampling.getVistitType() != 0) {
  366. before.setCarNum(sampling.getCarNum());
  367. }
  368. if (sampling.getVistitType() == 5) {
  369. before.setResource(sampling.getResource());
  370. before.setFeedImgUrl(sampling.getFeedImgUrl());
  371. before.setRemark(sampling.getRemark());
  372. }
  373. inventoryMapper.insert(before);
  374. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  375. }
  376. baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + LocalDateTime.now().format(dateTimeFormatter));
  377. baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + "," + baseLocation.getLocationName());
  378. baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + "," + baseLocation.getId());
  379. String status = baseProcess.getCurrentStatus();
  380. String substring = status.substring(0, status.length() - 1);
  381. baseProcess.setCurrentStatus(substring + "1," + 0);
  382. processMapper.updateById(baseProcess);
  383. billSamplingMapper.updateById(sampling);
  384. return new Result(10000, "修改成功!", true);
  385. }
  386. @Override
  387. public Result listAll(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
  388. String farmId = paramsMap.get("farmId");
  389. String type = paramsMap.get("type");//展示类型
  390. String data = paramsMap.get("data");
  391. String pageNum = paramsMap.get("pageNum");
  392. String pageSize = paramsMap.get("pageSize");
  393. Page<BillSampling> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
  394. QueryWrapper<BillSampling> queryWrapper = new QueryWrapper<>();
  395. queryWrapper.eq("farm_id", farmId).orderByDesc("sub_date").eq("vistit_type",type);
  396. if ("0".equals(data)) {
  397. queryWrapper.in("bill_status", 0, 1, 2, 3);
  398. }
  399. if ("1".equals(data)) {
  400. queryWrapper.in("bill_status", 0,3);
  401. }
  402. if ("2".equals(data)) {
  403. queryWrapper.eq("bill_status", 1);
  404. }
  405. return new Result(ResultCode.SUCCESS,billSamplingMapper.selectPage(page,queryWrapper));
  406. }
  407. public static void main(String[] args) {
  408. String s = "0,1,0,2,0,3,0";
  409. int i = s.indexOf("2");
  410. System.out.println(i);
  411. String s1 = "2,2,2,1,0,0,0";
  412. String s2 = s1.substring(0, i + 3);
  413. System.out.println("s2:"+s2);
  414. String[] split = s2.split(",");
  415. String sb2 = "";
  416. for (int j = 0; j < split.length; j++) {
  417. if (j == split.length - 1) {
  418. sb2 = sb2 + split[j].replaceAll(split[j], "2");
  419. } else {
  420. sb2 = split[j].replaceAll(split[j], "2") + "," + sb2;
  421. }
  422. }
  423. sb2 = sb2 + s1.substring(i + 3);
  424. System.out.println(sb2);
  425. }
  426. }