|
@@ -3,16 +3,33 @@ package com.fdkankan.manage.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.fdkankan.common.constant.CameraTypeEnum;
|
|
|
|
|
+import com.fdkankan.common.constant.Constant;
|
|
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.response.PageInfo;
|
|
import com.fdkankan.common.response.PageInfo;
|
|
|
|
|
+import com.fdkankan.common.util.DateUtil;
|
|
|
|
|
+import com.fdkankan.manage.constant.CameraConstant;
|
|
|
|
|
+import com.fdkankan.manage.constant.CameraOutTypeEnum;
|
|
|
import com.fdkankan.manage.entity.Camera;
|
|
import com.fdkankan.manage.entity.Camera;
|
|
|
|
|
+import com.fdkankan.manage.entity.CameraDetail;
|
|
|
|
|
+import com.fdkankan.manage.entity.Company;
|
|
|
import com.fdkankan.manage.entity.User;
|
|
import com.fdkankan.manage.entity.User;
|
|
|
import com.fdkankan.manage.mapper.ICameraMapper;
|
|
import com.fdkankan.manage.mapper.ICameraMapper;
|
|
|
import com.fdkankan.manage.service.*;
|
|
import com.fdkankan.manage.service.*;
|
|
|
|
|
+import com.fdkankan.manage.util.ExcelUtil;
|
|
|
|
|
+import com.fdkankan.manage.vo.request.CameraInOutParam;
|
|
|
|
|
+import com.fdkankan.manage.vo.request.CameraParam;
|
|
|
import com.fdkankan.manage.vo.response.CameraDetailVo;
|
|
import com.fdkankan.manage.vo.response.CameraDetailVo;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* <p>
|
|
* <p>
|
|
@@ -35,6 +52,10 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
IUserIncrementService userIncrementService;
|
|
IUserIncrementService userIncrementService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
ISceneResourceCameraService sceneResourceCameraService;
|
|
ISceneResourceCameraService sceneResourceCameraService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ ICompanyService companyService;
|
|
|
|
|
+ @Value("${upload.type}")
|
|
|
|
|
+ private String ossType;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<Camera> getListByCameraIdList(List<Long> cameraIdList) {
|
|
public List<Camera> getListByCameraIdList(List<Long> cameraIdList) {
|
|
@@ -44,11 +65,21 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public PageInfo getCameraByUserId(Integer pageNum, Integer pageSize,Long userId) {
|
|
|
|
|
- Page<CameraDetailVo> page = this.getBaseMapper().getCameraByUserId(new Page<>(pageNum,pageSize),userId);
|
|
|
|
|
- return PageInfo.PageInfo(page);
|
|
|
|
|
|
|
+ public Camera getBySnCode(String snCode) {
|
|
|
|
|
+ LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(Camera::getSnCode,snCode);
|
|
|
|
|
+ List<Camera> list = this.list(wrapper);
|
|
|
|
|
+ if(list == null || list.size() <=0 ){
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return list.get(0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private List<Camera> getBySnCodes(List<String> snCodeList) {
|
|
|
|
|
+ LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.in(Camera::getSnCode,snCodeList);
|
|
|
|
|
+ return this.list(wrapper);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void unbindCamera(Long cameraId, User user) {
|
|
public void unbindCamera(Long cameraId, User user) {
|
|
@@ -58,4 +89,262 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
sceneProService.unbindCamera(cameraId); //取消关联场景
|
|
sceneProService.unbindCamera(cameraId); //取消关联场景
|
|
|
sceneResourceCameraService.unbindCamera(cameraId); //删除协作相机
|
|
sceneResourceCameraService.unbindCamera(cameraId); //删除协作相机
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public PageInfo pageList(CameraParam param) {
|
|
|
|
|
+ Page<CameraDetailVo> voPage = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
|
|
|
|
|
+ for (CameraDetailVo record : voPage.getRecords()) {
|
|
|
|
|
+ CameraOutTypeEnum cameraOutTypeEnum = CameraOutTypeEnum.getByCode(record.getOutType());
|
|
|
|
|
+ if(cameraOutTypeEnum != null){
|
|
|
|
|
+ record.setOutTypeString(cameraOutTypeEnum.getMsg());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ record.setOutTypeString("未出库");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return PageInfo.PageInfo(voPage);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void in(String wifiName) {
|
|
|
|
|
+ if(StringUtils.isEmpty(wifiName) ){
|
|
|
|
|
+ throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
|
|
+ }
|
|
|
|
|
+ if( !wifiName.contains("_") || !wifiName.contains("4D")){
|
|
|
|
|
+ throw new BusinessException(-1,"wifi名称格式错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(Camera::getWifiName,wifiName);
|
|
|
|
|
+ long count = this.count(wrapper);
|
|
|
|
|
+ if(count > 0){
|
|
|
|
|
+ throw new BusinessException(-1,"设备wifi名称重复");
|
|
|
|
|
+ }
|
|
|
|
|
+ saveBatchCamera(Collections.singletonList(wifiName));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void saveBatchCamera(List<String> wifiNameList){
|
|
|
|
|
+ HashSet<String> wifiNameSet = new HashSet<>(wifiNameList);
|
|
|
|
|
+ List<Camera> cameraList = new ArrayList<>();
|
|
|
|
|
+ for (String wifiName : wifiNameSet) {
|
|
|
|
|
+ String[] res = wifiName.split("_");
|
|
|
|
|
+ Camera camera = new Camera();
|
|
|
|
|
+ camera.setWifiName(wifiName);
|
|
|
|
|
+ camera.setSnCode(res[1]);
|
|
|
|
|
+ camera.setChildName(res[1]);
|
|
|
|
|
+ camera.setWifiPassword(CameraConstant.WIFI_PASSWORD_VALUE);
|
|
|
|
|
+ camera.setChildPassword(CameraConstant.CHILD_PASSWORD_VALUE);
|
|
|
|
|
+ camera.setActivatedTime(DateUtil.date2String(new Date(),DateUtil.DEFAULT_DATE_FORMAT));
|
|
|
|
|
+ cameraList.add(camera);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.saveBatch(cameraList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void ins(List<String> wifiNameList){
|
|
|
|
|
+ List<Integer> errorRow = getErrorRow(wifiNameList, null);
|
|
|
|
|
+ getResultIn(errorRow);
|
|
|
|
|
+ LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.in(Camera::getWifiName,wifiNameList);
|
|
|
|
|
+ List<Camera> list = this.list(wrapper);
|
|
|
|
|
+ if(list.size() >0){
|
|
|
|
|
+ List<String> newList = list.parallelStream().map(Camera::getWifiName).collect(Collectors.toList());
|
|
|
|
|
+ List<Integer> errorRow2 = getErrorRow(wifiNameList, newList);
|
|
|
|
|
+ getResultIn(errorRow2);
|
|
|
|
|
+ }
|
|
|
|
|
+ saveBatchCamera(wifiNameList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void getResultIn(List<Integer> errorList){
|
|
|
|
|
+ if(errorList.size() <=0){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ StringBuilder res = new StringBuilder("第");
|
|
|
|
|
+ for (Integer index : errorList) {
|
|
|
|
|
+ res.append(index).append(",");
|
|
|
|
|
+ }
|
|
|
|
|
+ res.deleteCharAt(res.lastIndexOf(","));
|
|
|
|
|
+ res.append("行存在错误");
|
|
|
|
|
+ throw new BusinessException(-1, res.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<Integer> getErrorRow(List<String> wifiNameList, List<String> newList){
|
|
|
|
|
+ List<Integer> errorIndexList = new ArrayList<>();
|
|
|
|
|
+ boolean bo = false;
|
|
|
|
|
+ if(newList == null){
|
|
|
|
|
+ newList = wifiNameList;
|
|
|
|
|
+ bo = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (String wifiName : newList) {
|
|
|
|
|
+ int index = wifiNameList.indexOf(wifiName) + 3;
|
|
|
|
|
+ if(bo){
|
|
|
|
|
+ if( !wifiName.contains("_") || !wifiName.contains("4D")){
|
|
|
|
|
+ errorIndexList.add(index);
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ errorIndexList.add(index);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return errorIndexList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void out(CameraInOutParam param) {
|
|
|
|
|
+ if(param.getOutType() == null || param.getCompanyId() == null || StringUtils.isEmpty(param.getSnCode())){
|
|
|
|
|
+ throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
|
|
+ }
|
|
|
|
|
+ Camera camera = this.getBySnCode(param.getSnCode());
|
|
|
|
|
+ if(camera == null){
|
|
|
|
|
+ throw new BusinessException(-1,"相机不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ CameraDetail detail = cameraDetailService.getByCameraId(camera.getId());
|
|
|
|
|
+ if(detail !=null){
|
|
|
|
|
+ throw new BusinessException(-1,"该相机已出库");
|
|
|
|
|
+ }
|
|
|
|
|
+ HashMap<String,Camera> hashMap = new HashMap<>();
|
|
|
|
|
+ hashMap.put(param.getSnCode(),camera);
|
|
|
|
|
+ this.saveBatchDetail(hashMap, Collections.singletonList(param));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ private void outs(List<CameraInOutParam> params){
|
|
|
|
|
+ List<String> snCodeList = params.parallelStream().map(CameraInOutParam::getSnCode).collect(Collectors.toList());
|
|
|
|
|
+ checkSnCode(snCodeList);
|
|
|
|
|
+
|
|
|
|
|
+ List<Camera> cameraList = this.getBySnCodes(snCodeList);
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> cameraIds = cameraList.parallelStream().map(Camera::getId).collect(Collectors.toList());
|
|
|
|
|
+ List<CameraDetail> cameraDetails = cameraDetailService.getByCameraIds(cameraIds);
|
|
|
|
|
+ HashMap<Long,CameraDetail> detailMap = new HashMap<>();
|
|
|
|
|
+ for (CameraDetail cameraDetail : cameraDetails) {
|
|
|
|
|
+ detailMap.put(cameraDetail.getCameraId(),cameraDetail);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ HashMap<String,Camera> snCodeMap = new HashMap<>();
|
|
|
|
|
+ for (Camera camera : cameraList) {
|
|
|
|
|
+ snCodeMap.put(camera.getSnCode(),camera);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Integer> errorList = new ArrayList<>();
|
|
|
|
|
+ for (String snCode : snCodeList) {
|
|
|
|
|
+ Camera camera = snCodeMap.get(snCode);
|
|
|
|
|
+ if(camera == null || detailMap.get(camera.getId()) !=null){
|
|
|
|
|
+ errorList.add(snCodeList.indexOf(snCode) +3);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ getResultIn(errorList);
|
|
|
|
|
+
|
|
|
|
|
+ this.saveBatchDetail(snCodeMap,params);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void saveBatchDetail( HashMap<String,Camera> snCodeMap,List<CameraInOutParam> params){
|
|
|
|
|
+ List<CameraDetail> cameraDetails = new ArrayList<>();
|
|
|
|
|
+ for (CameraInOutParam param : params) {
|
|
|
|
|
+ Camera camera = snCodeMap.get(param.getSnCode());
|
|
|
|
|
+ String wifiName = camera.getWifiName();
|
|
|
|
|
+ Integer type = CameraTypeEnum.getTypeByWifiNamePrefix(wifiName.substring(0,wifiName.lastIndexOf("_") +1));
|
|
|
|
|
+ CameraDetail cameraDetail = new CameraDetail();
|
|
|
|
|
+ cameraDetail.setOrderSn(param.getOrderSn());
|
|
|
|
|
+ cameraDetail.setOwn(param.getOutType());
|
|
|
|
|
+ cameraDetail.setCompanyId(param.getCompanyId());
|
|
|
|
|
+ cameraDetail.setAgency(CameraConstant.DEFAULT_AGENT);
|
|
|
|
|
+ cameraDetail.setCameraId(camera.getId());
|
|
|
|
|
+ cameraDetail.setCountry(0);//默认中国
|
|
|
|
|
+ if("aws".equals(ossType)){
|
|
|
|
|
+ cameraDetail.setCountry(1);//1-国外
|
|
|
|
|
+ }
|
|
|
|
|
+ cameraDetail.setType(type);
|
|
|
|
|
+ if (1 == cameraDetail.getType() || 9 == cameraDetail.getType() || 10 == cameraDetail.getType()){
|
|
|
|
|
+ cameraDetail.setTotalSpace(Long.valueOf(Constant.CAMERA_BASE_SPACE_VALUE));
|
|
|
|
|
+ cameraDetail.setUsedSpace(0L);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(type != 9 && type != 10){
|
|
|
|
|
+ type = type == 0 ? 1: 4;
|
|
|
|
|
+ }
|
|
|
|
|
+ cameraDetail.setGoodsId(Long.valueOf(type));
|
|
|
|
|
+ cameraDetails.add(cameraDetail);
|
|
|
|
|
+ }
|
|
|
|
|
+ cameraDetailService.saveBatch(cameraDetails);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void checkSnCode(List<String> snCodeList) {
|
|
|
|
|
+ HashMap<String,Integer> map = new HashMap<>();
|
|
|
|
|
+ for (String snCode : snCodeList) {
|
|
|
|
|
+ if(map.get(snCode) == null){
|
|
|
|
|
+ map.put(snCode,1);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ map.put(snCode,2);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> errorSnCode = new ArrayList<>();
|
|
|
|
|
+ for (String snCode : map.keySet()) {
|
|
|
|
|
+ if(map.get(snCode) > 1){
|
|
|
|
|
+ errorSnCode.add(snCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(errorSnCode.size() >0){
|
|
|
|
|
+ throw new BusinessException(-1,"存在重复的snCode:"+errorSnCode);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void uploadExcel(MultipartFile file, Integer type) throws IOException {
|
|
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
|
|
+ assert originalFilename != null;
|
|
|
|
|
+ String fileType=originalFilename.substring(originalFilename.lastIndexOf(".")+1);
|
|
|
|
|
+ if (!fileType.equalsIgnoreCase("xls") && !fileType.equalsIgnoreCase("xlsx")) {
|
|
|
|
|
+ throw new BusinessException(-1,"文件格式校验,需为excel文件;");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
|
|
|
|
|
+ List<String> wifiNameList = new ArrayList<>();
|
|
|
|
|
+ List<CameraInOutParam> params = new ArrayList<>();
|
|
|
|
|
+ for (HashMap<Integer, String> map : excelRowList) {
|
|
|
|
|
+ if(type == 0){
|
|
|
|
|
+ String wifiName = map.get(0);
|
|
|
|
|
+ wifiNameList.add(wifiName);
|
|
|
|
|
+ }else if(type == 1){
|
|
|
|
|
+ String snCode = map.get(0);
|
|
|
|
|
+ String outTypeString = map.get(1);
|
|
|
|
|
+ String companyName = map.get(2);
|
|
|
|
|
+ String orderSn = map.get(3);
|
|
|
|
|
+
|
|
|
|
|
+ CameraOutTypeEnum outTypeEnum = CameraOutTypeEnum.getByMsg(outTypeString);
|
|
|
|
|
+ if(outTypeEnum == null){
|
|
|
|
|
+ throw new BusinessException(-1,"出库类型错误:"+outTypeString);
|
|
|
|
|
+ }
|
|
|
|
|
+ int outType = outTypeEnum.getCode();
|
|
|
|
|
+ Company company = companyService.getCompanyByName(companyName);
|
|
|
|
|
+ CameraInOutParam param = new CameraInOutParam();
|
|
|
|
|
+ param.setCompanyId(company.getId());
|
|
|
|
|
+ param.setOutType(outType);
|
|
|
|
|
+ param.setOrderSn(orderSn);
|
|
|
|
|
+ param.setSnCode(snCode);
|
|
|
|
|
+ params.add(param);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(wifiNameList.size() >0){
|
|
|
|
|
+ this.ins(wifiNameList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(params.size() >0){
|
|
|
|
|
+ this.outs(params);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void updateCamera(CameraInOutParam param) {
|
|
|
|
|
+ if(param.getId() == null|| param.getOutType() == null){
|
|
|
|
|
+ throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
|
|
+ }
|
|
|
|
|
+ CameraDetail cameraDetail = cameraDetailService.getByCameraId(param.getId());
|
|
|
|
|
+ cameraDetail.setOwn(param.getOutType());
|
|
|
|
|
+ cameraDetail.setOrderSn(param.getOrderSn());
|
|
|
|
|
+ cameraDetailService.updateById(cameraDetail);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void deleteCamera(Long id) {
|
|
|
|
|
+ if(id == null){
|
|
|
|
|
+ throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.removeById(id);
|
|
|
|
|
+ cameraDetailService.deleteByCameraId(id);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|