BillSamplingServiceImpl.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. s = uploadImage.getVideoCom(img);
  116. if (s.equals("上传失败")) {
  117. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  118. return new Result(10001, "视频上传失败", false);
  119. }
  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. String[] split2 = allLocationId.split(",");
  268. int a=0;
  269. for (int i = 0; i < split2.length; i++) {
  270. if (locationId.toString().equals(split2[i])) {
  271. a = i + 1;
  272. }
  273. }
  274. int indexOf = 2 * (a - 2);//当前位置在所有流程位置中的下标
  275. String substring = baseProcess.getAllLocationStatus().substring(0, indexOf + 3);//截取已经过的位置状态
  276. String[] split1 = substring.split(",");
  277. String sb2 = "";
  278. for (int i = 0; i < split1.length; i++) {
  279. if (i == split1.length - 1) {
  280. sb2 = sb2 + split1[i].replaceAll(split1[i], "2");
  281. } else {
  282. sb2 = split1[i].replaceAll(split1[i], "2") + "," + sb2;
  283. }
  284. }
  285. sb2 = sb2 + baseProcess.getAllLocationStatus().substring(indexOf + 3);
  286. StringBuilder sb = new StringBuilder(sb2);
  287. sb.replace(indexOf + 4, indexOf + 5, "2");
  288. sb.replace(indexOf + 6, indexOf + 7, "1");
  289. baseProcess.setAllLocationStatus(sb.toString());
  290. }
  291. } else if (nextId == 1) {
  292. //新增采样
  293. BillSampling billSampling = (BillSampling) newObject;
  294. if (sampling.getVistitType() != 0) {
  295. billSampling.setCarNum(sampling.getCarNum());
  296. }
  297. if (sampling.getVistitType() == 5) {
  298. billSampling.setResource(sampling.getResource());
  299. billSampling.setFeedImgUrl(sampling.getFeedImgUrl());
  300. billSampling.setRemark(sampling.getRemark());
  301. }
  302. billSamplingMapper.insert(billSampling);
  303. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  304. }else if (nextId == 2) {
  305. //新增pcr
  306. BillPcr billClean = (BillPcr) newObject;
  307. if (sampling.getVistitType() != 0) {
  308. billClean.setCarNum(sampling.getCarNum());
  309. }
  310. if (sampling.getVistitType() == 5) {
  311. billClean.setResource(sampling.getResource());
  312. billClean.setFeedImgUrl(sampling.getFeedImgUrl());
  313. billClean.setRemark(sampling.getRemark());
  314. }
  315. pcrMapper.insert(billClean);
  316. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  317. }else if (nextId == 3) {
  318. //新增洗澡
  319. BillClean billClean = (BillClean) newObject;
  320. if (sampling.getVistitType() != 0) {
  321. billClean.setCarNum(sampling.getCarNum());
  322. }if (sampling.getVistitType() == 5) {
  323. billClean.setResource(sampling.getResource());
  324. billClean.setFeedImgUrl(sampling.getFeedImgUrl());
  325. billClean.setRemark(sampling.getRemark());
  326. }
  327. cleanMapper.insert(billClean);
  328. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  329. }else if (nextId == 4) {
  330. //新增隔离
  331. BillIsolate pcr = (BillIsolate) newObject;
  332. if (sampling.getVistitType() != 0) {
  333. pcr.setCarNum(sampling.getCarNum());
  334. }
  335. if (sampling.getVistitType() == 5) {
  336. pcr.setResource(sampling.getResource());
  337. pcr.setFeedImgUrl(sampling.getFeedImgUrl());
  338. pcr.setRemark(sampling.getRemark());
  339. }
  340. isolateMapper.insert(pcr);
  341. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  342. }else if (nextId == 5) {
  343. BillDry billClean = (BillDry) newObject;
  344. if (sampling.getVistitType() != 0) {
  345. billClean.setCarNum(sampling.getCarNum());
  346. }
  347. if (sampling.getVistitType() == 5) {
  348. billClean.setResource(sampling.getResource());
  349. billClean.setFeedImgUrl(sampling.getFeedImgUrl());
  350. billClean.setRemark(sampling.getRemark());
  351. }
  352. dryMapper.insert(billClean);
  353. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  354. //新增烘干
  355. }else if (nextId == 6) {
  356. //新增洗澡前拍照
  357. BillCleanBefore before = (BillCleanBefore) newObject;
  358. if (sampling.getVistitType() != 0) {
  359. before.setCarNum(sampling.getCarNum());
  360. }
  361. if (sampling.getVistitType() == 5) {
  362. before.setResource(sampling.getResource());
  363. before.setFeedImgUrl(sampling.getFeedImgUrl());
  364. before.setRemark(sampling.getRemark());
  365. }
  366. billCleanBeforeMapper.insert(before);
  367. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  368. }
  369. else if (nextId == 7) {
  370. //新增洗澡前拍照
  371. BillGoodsInventory before = (BillGoodsInventory) newObject;
  372. if (sampling.getVistitType() != 0) {
  373. before.setCarNum(sampling.getCarNum());
  374. }
  375. if (sampling.getVistitType() == 5) {
  376. before.setResource(sampling.getResource());
  377. before.setFeedImgUrl(sampling.getFeedImgUrl());
  378. before.setRemark(sampling.getRemark());
  379. }
  380. inventoryMapper.insert(before);
  381. baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
  382. }
  383. baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + LocalDateTime.now().format(dateTimeFormatter));
  384. baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + "," + baseLocation.getLocationName());
  385. baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + "," + baseLocation.getId());
  386. String status = baseProcess.getCurrentStatus();
  387. String substring = status.substring(0, status.length() - 1);
  388. baseProcess.setCurrentStatus(substring + "1," + 0);
  389. processMapper.updateById(baseProcess);
  390. billSamplingMapper.updateById(sampling);
  391. return new Result(10000, "修改成功!", true);
  392. }
  393. @Override
  394. public Result listAll(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
  395. String farmId = paramsMap.get("farmId");
  396. String type = paramsMap.get("type");//展示类型
  397. String data = paramsMap.get("data");
  398. String pageNum = paramsMap.get("pageNum");
  399. String pageSize = paramsMap.get("pageSize");
  400. Page<BillSampling> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
  401. QueryWrapper<BillSampling> queryWrapper = new QueryWrapper<>();
  402. queryWrapper.eq("farm_id", farmId).orderByDesc("sub_date").eq("vistit_type",type);
  403. if ("0".equals(data)) {
  404. queryWrapper.in("bill_status", 0, 1, 2, 3);
  405. }
  406. if ("1".equals(data)) {
  407. queryWrapper.in("bill_status", 0,3);
  408. }
  409. if ("2".equals(data)) {
  410. queryWrapper.eq("bill_status", 1);
  411. }
  412. return new Result(ResultCode.SUCCESS,billSamplingMapper.selectPage(page,queryWrapper));
  413. }
  414. public static void main(String[] args) {
  415. String s = "0,35,0,36,0,38,0";
  416. String[] split1 = s.split(",");
  417. int a = 0;
  418. for (int i = 0; i < split1.length; i++) {
  419. if ("36".equals(split1[i])) {
  420. a = i+1;
  421. }
  422. }
  423. int i = 2 *(a - 2);
  424. System.out.println(i);
  425. String s1 = "2,2,2,1,0,0,0";
  426. String s2 = s1.substring(0, i + 3);
  427. System.out.println("s2:"+s2);
  428. String[] split = s2.split(",");
  429. String sb2 = "";
  430. for (int j = 0; j < split.length; j++) {
  431. if (j == split.length - 1) {
  432. sb2 = sb2 + split[j].replaceAll(split[j], "2");
  433. } else {
  434. sb2 = split[j].replaceAll(split[j], "2") + "," + sb2;
  435. }
  436. }
  437. sb2 = sb2 + s1.substring(i + 3);
  438. StringBuilder sb = new StringBuilder(sb2);
  439. sb.replace(i + 4, i + 5, "2");
  440. sb.replace(i + 6, i + 7, "1");
  441. System.out.println(sb.toString());
  442. }
  443. }