CameraServiceImpl.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. package com.fdkankan.manage.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import com.fdkankan.common.constant.Constant;
  9. import com.fdkankan.common.util.MD5;
  10. import com.fdkankan.manage.common.*;
  11. import com.fdkankan.manage.entity.*;
  12. import com.fdkankan.manage.exception.BusinessException;
  13. import com.fdkankan.common.util.DateUtil;
  14. import com.fdkankan.manage.constant.CameraConstant;
  15. import com.fdkankan.manage.mapper.ICameraMapper;
  16. import com.fdkankan.manage.mq.param.ScenePayStatusVo;
  17. import com.fdkankan.manage.service.*;
  18. import com.fdkankan.manage.util.Dateutils;
  19. import com.fdkankan.manage.vo.request.CameraInOutParam;
  20. import com.fdkankan.manage.vo.request.CameraParam;
  21. import com.fdkankan.manage.vo.response.CameraDataVo;
  22. import com.fdkankan.manage.vo.response.CameraDetailVo;
  23. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  24. import lombok.extern.slf4j.Slf4j;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.beans.factory.annotation.Value;
  28. import org.springframework.stereotype.Service;
  29. import java.util.*;
  30. import java.util.stream.Collectors;
  31. /**
  32. * <p>
  33. * 相机主表 服务实现类
  34. * </p>
  35. *
  36. * @author
  37. * @since 2022-06-16
  38. */
  39. @Service
  40. @Slf4j
  41. public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implements ICameraService {
  42. @Autowired
  43. ICameraDetailService cameraDetailService;
  44. @Autowired
  45. ISceneService sceneService;
  46. @Autowired
  47. ISceneProService sceneProService;
  48. @Autowired
  49. IUserIncrementService userIncrementService;
  50. @Autowired
  51. ISceneResourceCameraService sceneResourceCameraService;
  52. @Autowired
  53. IScenePlusService scenePlusService;
  54. @Autowired
  55. ICompanyService companyService;
  56. @Autowired
  57. IExcelService excelService;
  58. @Autowired
  59. IOrderService orderService;
  60. @Autowired
  61. ICameraWifiPrefixService cameraWifiPrefixService;
  62. @Autowired
  63. ICameraTypeService cameraTypeService;
  64. @Override
  65. public List<Camera> getListByCameraIdList(List<Long> cameraIdList) {
  66. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  67. wrapper.in(Camera::getId,cameraIdList);
  68. return this.list(wrapper);
  69. }
  70. @Override
  71. public Camera getBySnCode(String snCode) {
  72. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  73. wrapper.eq(Camera::getSnCode,snCode);
  74. List<Camera> list = this.list(wrapper);
  75. if(list == null || list.size() <=0 ){
  76. return null;
  77. }
  78. return list.get(0);
  79. }
  80. private List<Camera> getBySnCodes(List<String> snCodeList) {
  81. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  82. wrapper.in(Camera::getSnCode,snCodeList);
  83. return this.list(wrapper);
  84. }
  85. private List<Camera> getByOutSnCodes(List<String> snCodeList) {
  86. return this.getBaseMapper().getByOutSnCodes(snCodeList);
  87. }
  88. @Override
  89. public void unbindCamera(Long cameraId) {
  90. userIncrementService.unbindCamera(cameraId); //取消关联用户权益
  91. cameraDetailService.unbindCamera(cameraId); //取消相机用户关联
  92. sceneService.unbindCamera(cameraId); //取消关联场景
  93. sceneProService.unbindCamera(cameraId); //取消关联场景
  94. scenePlusService.unbindCamera(cameraId); //取消关联场景
  95. sceneResourceCameraService.unbindCamera(cameraId); //删除协作相机
  96. }
  97. @Override
  98. public PageInfo pageList(CameraParam param) {
  99. Page<CameraDetailVo> voPage = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
  100. List<CameraType> list = cameraTypeService.list();
  101. HashMap<String,CameraType> typeHashMap = new HashMap<>();
  102. for (CameraType cameraType : list) {
  103. typeHashMap.put(cameraType.getCameraType().toString(),cameraType);
  104. }
  105. for (CameraDetailVo record : voPage.getRecords()) {
  106. record.setTypeStr(typeHashMap.get(record.getType()).getName());
  107. }
  108. return PageInfo.PageInfo(voPage);
  109. }
  110. @Override
  111. public void in(String wifiName) {
  112. if(StringUtils.isEmpty(wifiName) ){
  113. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  114. }
  115. List<CameraWifiPrefix> list = cameraWifiPrefixService.list();
  116. Set<String> wifiNamePrefixList = list.stream().map(CameraWifiPrefix::getWifiNamePrefix).collect(Collectors.toSet());
  117. if(!wifiName.contains("_")){
  118. throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
  119. }
  120. String[] split = wifiName.split("_");
  121. String cameraPrefix = split[0] +"_";
  122. String snCode = split[1];
  123. if(!wifiNamePrefixList.contains(cameraPrefix)){
  124. throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
  125. }
  126. HashMap<String,CameraWifiPrefix> cameraTypeMap = new HashMap<>();
  127. list.forEach(entity->cameraTypeMap.put(entity.getWifiNamePrefix(),entity));
  128. if(cameraTypeMap.get(cameraPrefix) == null){
  129. throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
  130. }
  131. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  132. wrapper.eq(Camera::getSnCode,snCode);
  133. long count = this.count(wrapper);
  134. if(count > 0){
  135. throw new BusinessException(ResultCode.WIFI_NAME_REPEAT);
  136. }
  137. saveBatchCamera(Collections.singletonList(wifiName),cameraTypeMap);
  138. }
  139. private Integer saveBatchCamera(List<String> wifiNameList,HashMap<String,CameraWifiPrefix> cameraTypeMap){
  140. HashSet<String> wifiNameSet = new HashSet<>(wifiNameList);
  141. List<Camera> cameraList = new ArrayList<>();
  142. for (String wifiName : wifiNameSet) {
  143. String[] res = wifiName.split("_");
  144. if(res.length !=2 || StringUtils.isBlank(res[1])){
  145. throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
  146. }
  147. if(cameraTypeMap.get(res[0] +"_") == null){
  148. throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
  149. }
  150. Camera camera = new Camera();
  151. camera.setWifiName(wifiName);
  152. camera.setSnCode(res[1]);
  153. camera.setChildName(res[1]);
  154. camera.setWifiPassword(CameraConstant.WIFI_PASSWORD_VALUE);
  155. camera.setChildPassword(CameraConstant.CHILD_PASSWORD_VALUE);
  156. camera.setActivatedTime(DateUtil.date2String(new Date(),DateUtil.DEFAULT_DATE_FORMAT));
  157. cameraList.add(camera);
  158. }
  159. this.saveBatch(cameraList);
  160. List<CameraDetail> cameraDetailList = new ArrayList<>();
  161. for (Camera camera : cameraList) {
  162. CameraDetail cameraDetail = new CameraDetail();
  163. cameraDetail.setAgency(CameraConstant.DEFAULT_AGENT);
  164. cameraDetail.setCameraId(camera.getId());
  165. cameraDetail.setCountry(0);//默认中国
  166. String wifiNamePrix = camera.getWifiName().split("_")[0]+"_";
  167. CameraWifiPrefix cameraType = cameraTypeMap.get(wifiNamePrix);
  168. cameraDetail.setType(cameraType.getCameraType());
  169. cameraDetail.setTotalSpace(Long.valueOf(Constant.CAMERA_BASE_SPACE_VALUE));
  170. cameraDetail.setUsedSpace(0L);
  171. cameraDetail.setUnit(CacheUtil.cameraUnit);
  172. if(cameraDetail.getUnit().equals("SP")){
  173. cameraDetail.setTotalSpace(Long.valueOf(CacheUtil.cameraSpaceNum));
  174. }
  175. if("aws".equals(CacheUtil.uploadType)){
  176. cameraDetail.setCountry(1);//1-国外
  177. }
  178. Long goodId = null;
  179. if(cameraDetail.getType() == 1 || cameraDetail.getType() == 4){
  180. goodId = 4L;
  181. }
  182. if(cameraDetail.getType() == 9){
  183. goodId = 9L;
  184. }
  185. if(cameraDetail.getType() == 10){
  186. goodId = 10L;
  187. }
  188. cameraDetail.setGoodsId(goodId);
  189. if("local".equals(CacheUtil.uploadType)) { //本地版本 ,入库即出库,并且添加无限期会员权限
  190. cameraDetail.setCountry(2);
  191. cameraDetail.setOwn(2);
  192. cameraDetail.setOutTime(Dateutils.getDate(new Date()));
  193. }
  194. cameraDetailList.add(cameraDetail);
  195. }
  196. return cameraDetailService.saveBatch(cameraDetailList) ? cameraList.size() : 0;
  197. }
  198. @Override
  199. public Integer ins(List<String> wifiNameList){
  200. List<CameraWifiPrefix> cameraTypeList = cameraWifiPrefixService.list();
  201. Set<String> wifiNamePrefixList = cameraTypeList.stream().map(CameraWifiPrefix::getWifiNamePrefix).collect(Collectors.toSet());
  202. List<Integer> errorRow = getErrorRow(wifiNameList,wifiNamePrefixList);
  203. HashMap<String,CameraWifiPrefix> cameraTypeMap = new HashMap<>();
  204. cameraTypeList.forEach(entity->cameraTypeMap.put(entity.getWifiNamePrefix(),entity));
  205. excelService.toExcelError(errorRow);
  206. List<String> snCodeList = new ArrayList<>();
  207. for (String wifiName : wifiNameList) {
  208. snCodeList.add(wifiName.split("_")[1]);
  209. }
  210. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  211. wrapper.in(Camera::getSnCode,snCodeList);
  212. List<Camera> list = this.list(wrapper);
  213. if(list.size() >0){
  214. List<String> newList = list.parallelStream().map(Camera::getSnCode).collect(Collectors.toList());
  215. List<Integer> errorRow2 = getErrorRow(snCodeList, newList);
  216. excelService.toExcelError(errorRow2);
  217. }
  218. return saveBatchCamera(wifiNameList,cameraTypeMap);
  219. }
  220. private List<Integer> getErrorRow(List<String> wifiNameList,Set<String> wifiNamePrefixList){
  221. List<Integer> errorIndexList = new ArrayList<>();
  222. Set<String> wifiNameSet = new HashSet<>();
  223. Integer index = 0;
  224. List<String> snCodes = new ArrayList<>();
  225. for (String wifiName : wifiNameList) {
  226. index ++;
  227. if(StringUtils.isBlank(wifiName)){
  228. errorIndexList.add(index);
  229. continue;
  230. }
  231. if(wifiNameSet.contains(wifiName)){
  232. errorIndexList.add(index);
  233. continue;
  234. }
  235. if(!wifiName.contains("_")){
  236. errorIndexList.add(index);
  237. continue;
  238. }
  239. String[] split = wifiName.split("_");
  240. String cameraPrefix = split[0] +"_";
  241. String snCode = split[1];
  242. if(!wifiNamePrefixList.contains(cameraPrefix)){
  243. errorIndexList.add(index);
  244. continue;
  245. }
  246. if(snCodes.contains(snCode)){
  247. errorIndexList.add(index);
  248. continue;
  249. }
  250. snCodes.add(snCode);
  251. wifiNameSet.add(wifiName);
  252. }
  253. return errorIndexList;
  254. }
  255. private List<Integer> getErrorRow(List<String> wifiNameList,List<String> dbList){
  256. List<Integer> errorIndexList = new ArrayList<>();
  257. if(dbList.size() <=0){
  258. return errorIndexList;
  259. }
  260. Integer index = 0;
  261. for (String wifiName : wifiNameList) {
  262. index ++;
  263. if(dbList.contains(wifiName)){
  264. errorIndexList.add(index);
  265. }
  266. }
  267. return errorIndexList;
  268. }
  269. @Override
  270. public void out(CameraInOutParam param) {
  271. if(param.getOutType() == null || param.getId() == null){
  272. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  273. }
  274. if(StringUtils.isNotBlank(param.getCompanyName())){
  275. Company company = companyService.getCompanyByName(param.getCompanyName());
  276. if(company == null){
  277. throw new BusinessException(ResultCode.COMPANY_NAME_NOT_EXIST);
  278. }
  279. param.setCompanyId(company.getId());
  280. }
  281. Camera camera = this.getById(param.getId());
  282. if(camera == null){
  283. throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
  284. }
  285. CameraDetail detail = cameraDetailService.getByCameraId(camera.getId());
  286. if(detail ==null){
  287. throw new BusinessException(ResultCode.CAMERA_NOT_IN);
  288. }
  289. HashMap<Long,CameraDetail> detailMap = new HashMap<>();
  290. detailMap.put(detail.getCameraId(),detail);
  291. this.saveBatchDetail(detailMap, Collections.singletonList(param));
  292. }
  293. @Override
  294. public Integer outs(List<CameraInOutParam> params){
  295. setCompanyIdByDb(params);
  296. checkOrderSn(params);
  297. HashMap<String, Object> resultMap = getResultMap(params,1);
  298. HashMap<Long,CameraDetail> detailMap = (HashMap<Long, CameraDetail>) resultMap.get("detailMap");
  299. HashMap<String, Camera> snCodeMap = (HashMap<String, Camera>) resultMap.get("snCodeMap");
  300. for (CameraInOutParam param : params) {
  301. if(param.getId() == null){
  302. param.setId(snCodeMap.get(param.getSnCode()).getId());
  303. }
  304. }
  305. return this.saveBatchDetail(detailMap,params);
  306. }
  307. private void checkOrderSn(List<CameraInOutParam> params) {
  308. List<String> orderSnList = params.stream().map(CameraInOutParam::getOrderSn).collect(Collectors.toList());
  309. if(orderSnList.size() >0){
  310. List<Order> orders = orderService.getByOrderSnList(orderSnList);
  311. List<String> dbOrderSn = orders.stream().map(Order::getOrderSn).collect(Collectors.toList());
  312. List<Integer> errorList = new ArrayList<>();
  313. Integer index = 0;
  314. for (String sn : orderSnList) {
  315. index ++;
  316. if(StringUtils.isBlank(sn)){
  317. continue;
  318. }
  319. if(!dbOrderSn.contains(sn)){
  320. log.error("excel-export-error-->:订单号不存在不存在:index:{},orderSn:{}",index+3,sn);
  321. errorList.add(index);
  322. }
  323. }
  324. excelService.toExcelError(errorList);
  325. }
  326. }
  327. private Integer saveBatchDetail(HashMap<Long, CameraDetail> detailMap, List<CameraInOutParam> params){
  328. List<CameraDetail> cameraDetails = new ArrayList<>();
  329. for (CameraInOutParam param : params) {
  330. CameraDetail cameraDetail = detailMap.get(param.getId());
  331. if(cameraDetail == null){
  332. throw new BusinessException(ResultCode.CAMERA_NOT_IN);
  333. }
  334. cameraDetail.setAgentId(param.getAgentId());
  335. cameraDetail.setBuyDate(Dateutils.getDayDate(param.getBuyDate()));
  336. cameraDetail.setOrderSn(param.getOrderSn());
  337. cameraDetail.setOwn(param.getOutType());
  338. cameraDetail.setCompanyId(param.getCompanyId());
  339. cameraDetail.setOutTime(Dateutils.getDate(new Date()));
  340. cameraDetail.setUnit(CacheUtil.cameraUnit);
  341. if(cameraDetail.getUnit().equals("SP")){
  342. cameraDetail.setTotalSpace(Long.valueOf(CacheUtil.cameraSpaceNum));
  343. }
  344. cameraDetails.add(cameraDetail);
  345. }
  346. return cameraDetailService.saveOrUpdateBatch(cameraDetails) ? cameraDetails.size() : 0;
  347. }
  348. private void checkSnCode(List<String> snCodeList,List<String> dbSnCode) {
  349. HashMap<String,Integer> map = new HashMap<>();
  350. List<Integer> errorList = new ArrayList<>();
  351. Integer index = 0;
  352. for (String snCode : snCodeList) {
  353. index ++;
  354. if(StringUtils.isBlank(snCode)){
  355. log.error("excel-export-error-->:index:{},snCode不存在:snCode:{}",index+3,snCode);
  356. errorList.add(index);
  357. }
  358. if(map.get(snCode) == null){
  359. map.put(snCode,1);
  360. }else {
  361. map.put(snCode,2);
  362. log.error("excel-export-error-->:index:{},snCode已存在:snCode:{}",index+3,snCode);
  363. errorList.add(index);
  364. }
  365. }
  366. excelService.toExcelError(errorList);
  367. Integer index2 = 0;
  368. for (String snCode : snCodeList) {
  369. index2 ++;
  370. if(!dbSnCode.contains(snCode)){
  371. log.error("excel-export-error-->:index:{},snCode未入库:snCode:{}",index2+3,snCode);
  372. errorList.add(index2);
  373. }
  374. }
  375. excelService.toExcelError(errorList);
  376. }
  377. @Override
  378. public void updateCamera(CameraInOutParam param) {
  379. if(param.getId() == null|| param.getOutType() == null){
  380. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  381. }
  382. CameraDetail cameraDetail = cameraDetailService.getByCameraId(param.getId());
  383. if(cameraDetail == null){
  384. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  385. }
  386. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  387. wrapper.eq(CameraDetail::getId,cameraDetail.getId());
  388. if(StringUtils.isNotBlank(param.getCompanyName())){
  389. Company company = companyService.getCompanyByName(param.getCompanyName());
  390. if(company == null){
  391. throw new BusinessException(ResultCode.COMPANY_NAME_NOT_EXIST);
  392. }
  393. wrapper.set(CameraDetail::getCompanyId,company.getId());
  394. }else {
  395. wrapper.set(CameraDetail::getCompanyId,null);
  396. }
  397. if(StringUtils.isNotBlank(param.getOrderSn())){
  398. Order orderSn = orderService.getByOrderSn(param.getOrderSn());
  399. if(orderSn == null ){
  400. throw new BusinessException(ResultCode.ORDER_SN_ERROR);
  401. }
  402. wrapper.set(CameraDetail::getOrderSn,orderSn.getOrderSn());
  403. }else {
  404. wrapper.set(CameraDetail::getOrderSn,null);
  405. }
  406. if(param.getAgentId() != null){
  407. wrapper.set(CameraDetail::getAgentId,param.getAgentId());
  408. }else {
  409. wrapper.set(CameraDetail::getAgentId,null);
  410. }
  411. wrapper.set(CameraDetail::getOwn,param.getOutType());
  412. cameraDetailService.update(wrapper);
  413. }
  414. @Override
  415. public void deleteCamera(Long id) {
  416. if(id == null){
  417. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  418. }
  419. CameraDetail cameraDetail = cameraDetailService.getByCameraId(id);
  420. if(cameraDetail !=null && cameraDetail.getUserId()!=null){
  421. this.unbindCamera(cameraDetail.getCameraId());
  422. }
  423. this.removeById(id);
  424. cameraDetailService.deleteByCameraId(id);
  425. }
  426. @Override
  427. public Integer updateCompany(List<CameraInOutParam> companyParams) {
  428. setCompanyIdByDb(companyParams);
  429. HashMap<String, Object> resultMap = getResultMap(companyParams,2);
  430. HashMap<Long, CameraDetail> detailMap = (HashMap<Long, CameraDetail>) resultMap.get("detailMap");
  431. HashMap<String, Camera> snCodeMap = (HashMap<String, Camera>) resultMap.get("snCodeMap");
  432. List<CameraDetail> updateDetailList = new ArrayList<>();
  433. for (CameraInOutParam companyParam : companyParams) {
  434. Camera camera = snCodeMap.get(companyParam.getSnCode());
  435. CameraDetail cameraDetail = detailMap.get(camera.getId());
  436. cameraDetail.setCompanyId(companyParam.getCompanyId());
  437. updateDetailList.add(cameraDetail);
  438. }
  439. return cameraDetailService.updateBatchById(updateDetailList) ? updateDetailList.size() : 0;
  440. }
  441. private void setCompanyIdByDb(List<CameraInOutParam> companyParams){
  442. List<String> companyNames = companyParams.parallelStream().map(CameraInOutParam::getCompanyName).collect(Collectors.toList());
  443. List<Company> companyList = companyService.getCompanyByNames(companyNames);
  444. HashMap<String,Long> companyNameMap = new HashMap<>();
  445. for (Company company : companyList) {
  446. companyNameMap.put(company.getCompanyName(),company.getId());
  447. }
  448. List<Integer> errorList = new ArrayList<>();
  449. Integer index = 0;
  450. for (CameraInOutParam companyParam : companyParams) {
  451. index ++;
  452. if(StringUtils.isNotBlank(companyParam.getCompanyName())){
  453. if(companyNameMap.get(companyParam.getCompanyName()) == null){
  454. log.error("outError-->出库错误:客户名称不存在:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
  455. ,companyParam.getSnCode(),companyParam.getOutType(),companyParam.getCompanyName(),companyParam.getOrderSn(),companyParam.getAgentId());
  456. errorList.add(index);
  457. }
  458. companyParam.setCompanyId(companyNameMap.get(companyParam.getCompanyName()));
  459. }
  460. }
  461. excelService.toExcelError(errorList);
  462. }
  463. private HashMap<String, Object> getResultMap(List<CameraInOutParam> params,Integer type){
  464. HashMap<String,Object> resultMap = new HashMap<>();
  465. List<String> snCodeList = params.parallelStream().map(CameraInOutParam::getSnCode).collect(Collectors.toList());
  466. List<Camera> cameraList = new ArrayList<>();
  467. if(type == 1){
  468. cameraList = this.getBySnCodes(snCodeList);
  469. }
  470. if(type == 2){
  471. cameraList = this.getByOutSnCodes(snCodeList);
  472. }
  473. checkSnCode(snCodeList,cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList()));
  474. List<Long> cameraIds = cameraList.parallelStream().map(Camera::getId).collect(Collectors.toList());
  475. List<CameraDetail> cameraDetails = cameraDetailService.getByCameraIds(cameraIds);
  476. HashMap<Long,CameraDetail> detailMap = new HashMap<>();
  477. for (CameraDetail cameraDetail : cameraDetails) {
  478. detailMap.put(cameraDetail.getCameraId(),cameraDetail);
  479. }
  480. HashMap<String,Camera> snCodeMap = new HashMap<>();
  481. for (Camera camera : cameraList) {
  482. snCodeMap.put(camera.getSnCode(),camera);
  483. }
  484. List<Integer> errorList = new ArrayList<>();
  485. for (String snCode : snCodeList) {
  486. Camera camera = snCodeMap.get(snCode);
  487. if(camera == null || detailMap.get(camera.getId()) ==null){
  488. log.error("excel-export-error-->:相机未入库:snCode:{}",snCode);
  489. errorList.add(snCodeList.indexOf(snCode) );
  490. }
  491. }
  492. excelService.toExcelError(errorList);
  493. resultMap.put("detailMap",detailMap);
  494. resultMap.put("snCodeMap",snCodeMap);
  495. return resultMap;
  496. }
  497. @Autowired
  498. RabbitMqProducer rabbitMqProducer;
  499. @Override
  500. public void initAllCameraSpace(Long userId) {
  501. List<Long> cameraIds ;
  502. List<CameraDetail> cameraDetails;
  503. if(userId != null){
  504. cameraDetails = cameraDetailService.getByUserId(userId);
  505. }else {
  506. List<Camera> list = this.list();
  507. cameraIds = list.stream().map(Camera::getId).collect(Collectors.toList());
  508. cameraDetails = cameraDetailService.getByCameraIds(cameraIds);
  509. }
  510. if(cameraDetails == null || cameraDetails.size() <=0){
  511. return;
  512. }
  513. // for (CameraDetail cameraDetail : cameraDetails) {
  514. // ScenePayStatusVo scenePayStatusVo = new ScenePayStatusVo(cameraDetail.getCameraId());
  515. // rabbitMqProducer.sendByWorkQueue("scene-pay-status", JSONObject.toJSONString(scenePayStatusVo));
  516. // }
  517. HashMap<Long, Long> map = sceneProService.getSpaceGroupByCameraId();
  518. for (CameraDetail cameraDetail : cameraDetails) {
  519. Long space = map.get(cameraDetail.getCameraId());
  520. if(space != null){
  521. space = space > 0 ? space : 0;
  522. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  523. wrapper.eq(CameraDetail::getId,cameraDetail.getId());
  524. wrapper.set(CameraDetail::getUsedSpace,space);
  525. cameraDetailService.update(wrapper);
  526. }
  527. }
  528. }
  529. @Override
  530. public void updateCameraType(CameraInOutParam param) {
  531. if(param.getId() == null || param.getCameraType() == null){
  532. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  533. }
  534. Camera camera = this.getById(param.getId());
  535. if(camera == null){
  536. throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
  537. }
  538. String wifiNamePrefix = null;
  539. if(StringUtils.isNotBlank(param.getWifiNamePrefix())){
  540. wifiNamePrefix = param.getWifiNamePrefix();
  541. }else {
  542. CameraType cameraType = cameraTypeService.getByType(param.getCameraType());
  543. if(cameraType == null){
  544. throw new BusinessException(ResultCode.CAMERA_TYPE_ERROR);
  545. }
  546. wifiNamePrefix = cameraType.getWifiNamePrefix();
  547. }
  548. LambdaUpdateWrapper<Camera> cameraLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
  549. cameraLambdaUpdateWrapper.eq(Camera::getId,param.getId());
  550. cameraLambdaUpdateWrapper.set(Camera::getWifiName,wifiNamePrefix+ camera.getSnCode());
  551. this.update(cameraLambdaUpdateWrapper);
  552. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  553. wrapper.eq(CameraDetail::getCameraId,param.getId());
  554. wrapper.set(CameraDetail::getType,param.getCameraType());
  555. wrapper.set(CameraDetail::getGoodsId,param.getCameraType() == 1? 4: param.getCameraType());
  556. cameraDetailService.update(wrapper);
  557. }
  558. @Override
  559. public List<Camera> getLikeBySnCode(String snCode) {
  560. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  561. wrapper.like(Camera::getSnCode,snCode);
  562. return this.list(wrapper);
  563. }
  564. @Override
  565. public HashMap<Long, Camera> getByIds(List<Long> cameraIds) {
  566. HashMap<Long, Camera> map = new HashMap<>();
  567. if(cameraIds != null && !cameraIds.isEmpty()){
  568. List<Camera> cameraList = this.listByIds(cameraIds);
  569. cameraList.forEach(entity -> map.put(entity.getId(),entity));
  570. }
  571. return map;
  572. }
  573. }