|
@@ -5,8 +5,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.common.constant.Constant;
|
|
|
-import com.fdkankan.common.constant.ErrorCode;
|
|
|
-import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.manage.common.ExcelErrorUtil;
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
import com.fdkankan.common.response.PageInfo;
|
|
|
import com.fdkankan.common.util.DateUtil;
|
|
|
import com.fdkankan.manage.common.CameraTypeEnum;
|
|
@@ -53,6 +54,8 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
IScenePlusService scenePlusService;
|
|
|
@Autowired
|
|
|
ICompanyService companyService;
|
|
|
+ @Autowired
|
|
|
+ IExcelService excelService;
|
|
|
@Value("${upload.type}")
|
|
|
private String ossType;
|
|
|
|
|
@@ -99,16 +102,16 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
@Override
|
|
|
public void in(String wifiName) {
|
|
|
if(StringUtils.isEmpty(wifiName) ){
|
|
|
- throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
if( !wifiName.contains("_") || !wifiName.contains("4D")){
|
|
|
- throw new BusinessException(-1,"wifi名称格式错误");
|
|
|
+ throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
|
|
|
}
|
|
|
LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(Camera::getWifiName,wifiName);
|
|
|
long count = this.count(wrapper);
|
|
|
if(count > 0){
|
|
|
- throw new BusinessException(-1,"设备wifi名称重复");
|
|
|
+ throw new BusinessException(ResultCode.WIFI_NAME_REPEAT);
|
|
|
}
|
|
|
saveBatchCamera(Collections.singletonList(wifiName));
|
|
|
}
|
|
@@ -134,9 +137,7 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
for (Camera camera : cameraList) {
|
|
|
String wifiName = camera.getWifiName();
|
|
|
Integer type = CameraTypeEnum.getTypeByWifiNamePrefix(wifiName.substring(0,wifiName.lastIndexOf("_") +1));
|
|
|
- if(type == null){
|
|
|
- throw new BusinessException(-1,"wifi名称前缀错误!");
|
|
|
- }
|
|
|
+
|
|
|
CameraDetail cameraDetail = new CameraDetail();
|
|
|
cameraDetail.setAgency(CameraConstant.DEFAULT_AGENT);
|
|
|
cameraDetail.setCameraId(camera.getId());
|
|
@@ -161,35 +162,24 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
@Override
|
|
|
public Integer ins(List<String> wifiNameList){
|
|
|
List<Integer> errorRow = getErrorRow(wifiNameList);
|
|
|
- getResultIn(errorRow);
|
|
|
+ excelService.toExcelError(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);
|
|
|
+ excelService.toExcelError(errorRow2);
|
|
|
}
|
|
|
return 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<Integer> errorIndexList = new ArrayList<>();
|
|
|
Set<String> wifiNameSet = new HashSet<>();
|
|
|
- Integer index = 3;
|
|
|
+ Integer index = 0;
|
|
|
for (String wifiName : wifiNameList) {
|
|
|
index ++;
|
|
|
if(StringUtils.isBlank(wifiName)){
|
|
@@ -214,7 +204,7 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
if(dbList.size() <=0){
|
|
|
return errorIndexList;
|
|
|
}
|
|
|
- Integer index = 3;
|
|
|
+ Integer index = 0;
|
|
|
for (String wifiName : wifiNameList) {
|
|
|
index ++;
|
|
|
if(dbList.contains(wifiName)){
|
|
@@ -227,20 +217,20 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
@Override
|
|
|
public void out(CameraInOutParam param) {
|
|
|
if(param.getOutType() == null || param.getCompanyName() == null || param.getId() == null){
|
|
|
- throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
Company company = companyService.getCompanyByName(param.getCompanyName());
|
|
|
if(company == null){
|
|
|
- throw new BusinessException(-1,"客户名称不存在");
|
|
|
+ throw new BusinessException(ResultCode.COMPANY_NAME_NOT_EXIST);
|
|
|
}
|
|
|
param.setCompanyId(company.getId());
|
|
|
Camera camera = this.getById(param.getId());
|
|
|
if(camera == null){
|
|
|
- throw new BusinessException(-1,"相机不存在");
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
|
|
|
}
|
|
|
CameraDetail detail = cameraDetailService.getByCameraId(camera.getId());
|
|
|
if(detail ==null){
|
|
|
- throw new BusinessException(-1,"该相机未入库");
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_NOT_IN);
|
|
|
}
|
|
|
|
|
|
HashMap<Long,CameraDetail> detailMap = new HashMap<>();
|
|
@@ -268,7 +258,7 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
for (CameraInOutParam param : params) {
|
|
|
CameraDetail cameraDetail = detailMap.get(param.getId());
|
|
|
if(cameraDetail == null){
|
|
|
- throw new BusinessException(-1,"相机未入库");
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_NOT_IN);
|
|
|
}
|
|
|
cameraDetail.setOrderSn(param.getOrderSn());
|
|
|
cameraDetail.setOwn(param.getOutType());
|
|
@@ -281,46 +271,42 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
|
|
|
private void checkSnCode(List<String> snCodeList,List<String> dbSnCode) {
|
|
|
HashMap<String,Integer> map = new HashMap<>();
|
|
|
+ List<Integer> errorList = new ArrayList<>();
|
|
|
+ Integer index = 0;
|
|
|
for (String snCode : snCodeList) {
|
|
|
+ index ++;
|
|
|
if(StringUtils.isBlank(snCode)){
|
|
|
- map.put(snCode,2);
|
|
|
+ errorList.add(index);
|
|
|
}
|
|
|
if(map.get(snCode) == null){
|
|
|
map.put(snCode,1);
|
|
|
}else {
|
|
|
map.put(snCode,2);
|
|
|
+ errorList.add(index);
|
|
|
}
|
|
|
}
|
|
|
- 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);
|
|
|
- }
|
|
|
- List<String> errorSnCode2 = new ArrayList<>();
|
|
|
+ excelService.toExcelError(errorList);
|
|
|
|
|
|
+ Integer index2 = 0;
|
|
|
for (String snCode : snCodeList) {
|
|
|
+ index2 ++;
|
|
|
if(!dbSnCode.contains(snCode)){
|
|
|
- errorSnCode2.add(snCode);
|
|
|
+ errorList.add(index2);
|
|
|
}
|
|
|
}
|
|
|
- if(errorSnCode2.size() >0){
|
|
|
- throw new BusinessException(-1,"snCode:"+errorSnCode2+"不存在");
|
|
|
- }
|
|
|
+ excelService.toExcelError(errorList);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void updateCamera(CameraInOutParam param) {
|
|
|
if(param.getId() == null|| param.getOutType() == null){
|
|
|
- throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
CameraDetail cameraDetail = cameraDetailService.getByCameraId(param.getId());
|
|
|
if(cameraDetail == null){
|
|
|
- throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(param.getCompanyName())){
|
|
|
Company company = companyService.getCompanyByName(param.getCompanyName());
|
|
@@ -336,11 +322,11 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
@Override
|
|
|
public void deleteCamera(Long id) {
|
|
|
if(id == null){
|
|
|
- throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
CameraDetail cameraDetail = cameraDetailService.getByCameraId(id);
|
|
|
if(cameraDetail !=null && cameraDetail.getUserId()!=null){
|
|
|
- throw new BusinessException(-1,"相机已绑定,请先解绑后删除");
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_DEL_ERROR);
|
|
|
}
|
|
|
this.removeById(id);
|
|
|
cameraDetailService.deleteByCameraId(id);
|
|
@@ -370,22 +356,24 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
for (Company company : companyList) {
|
|
|
companyNameMap.put(company.getCompanyName(),company.getId());
|
|
|
}
|
|
|
+ List<Integer> errorList = new ArrayList<>();
|
|
|
+ Integer index = 0;
|
|
|
for (CameraInOutParam companyParam : companyParams) {
|
|
|
+ index ++;
|
|
|
if(StringUtils.isNotBlank(companyParam.getCompanyName())){
|
|
|
if(companyNameMap.get(companyParam.getCompanyName()) == null){
|
|
|
- throw new BusinessException(-1,"客户名称"+ companyParam.getCompanyName()+"-不存在");
|
|
|
+ errorList.add(index);
|
|
|
}
|
|
|
companyParam.setCompanyId(companyNameMap.get(companyParam.getCompanyName()));
|
|
|
}
|
|
|
}
|
|
|
+ excelService.toExcelError(errorList);
|
|
|
}
|
|
|
|
|
|
private HashMap<String, Object> getResultMap(List<CameraInOutParam> params){
|
|
|
HashMap<String,Object> resultMap = new HashMap<>();
|
|
|
List<String> snCodeList = params.parallelStream().map(CameraInOutParam::getSnCode).collect(Collectors.toList());
|
|
|
- if(snCodeList.size() <=0){
|
|
|
- throw new BusinessException(-1,"snCode为空");
|
|
|
- }
|
|
|
+
|
|
|
List<Camera> cameraList = this.getBySnCodes(snCodeList);
|
|
|
checkSnCode(snCodeList,cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList()));
|
|
|
|
|
@@ -404,11 +392,10 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
for (String snCode : snCodeList) {
|
|
|
Camera camera = snCodeMap.get(snCode);
|
|
|
if(camera == null || detailMap.get(camera.getId()) ==null){
|
|
|
- errorList.add(snCodeList.indexOf(snCode) +3);
|
|
|
- throw new BusinessException(-1,snCode +"不存在!");
|
|
|
+ errorList.add(snCodeList.indexOf(snCode) );
|
|
|
}
|
|
|
}
|
|
|
- getResultIn(errorList);
|
|
|
+ excelService.toExcelError(errorList);
|
|
|
resultMap.put("detailMap",detailMap);
|
|
|
resultMap.put("snCodeMap",snCodeMap);
|
|
|
return resultMap;
|