|
|
@@ -17,7 +17,6 @@ import com.fdkankan.manage.entity.Company;
|
|
|
import com.fdkankan.manage.entity.User;
|
|
|
import com.fdkankan.manage.mapper.ICameraMapper;
|
|
|
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;
|
|
|
@@ -25,9 +24,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -121,7 +118,7 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
saveBatchCamera(Collections.singletonList(wifiName));
|
|
|
}
|
|
|
|
|
|
- private void saveBatchCamera(List<String> wifiNameList){
|
|
|
+ private Integer saveBatchCamera(List<String> wifiNameList){
|
|
|
HashSet<String> wifiNameSet = new HashSet<>(wifiNameList);
|
|
|
List<Camera> cameraList = new ArrayList<>();
|
|
|
for (String wifiName : wifiNameSet) {
|
|
|
@@ -135,10 +132,11 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
camera.setActivatedTime(DateUtil.date2String(new Date(),DateUtil.DEFAULT_DATE_FORMAT));
|
|
|
cameraList.add(camera);
|
|
|
}
|
|
|
- this.saveBatch(cameraList);
|
|
|
- }
|
|
|
+ return this.saveBatch(cameraList) ? cameraList.size() : 0;
|
|
|
|
|
|
- private void ins(List<String> wifiNameList){
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public Integer ins(List<String> wifiNameList){
|
|
|
List<Integer> errorRow = getErrorRow(wifiNameList, null);
|
|
|
getResultIn(errorRow);
|
|
|
LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
|
|
|
@@ -149,7 +147,7 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
List<Integer> errorRow2 = getErrorRow(wifiNameList, newList);
|
|
|
getResultIn(errorRow2);
|
|
|
}
|
|
|
- saveBatchCamera(wifiNameList);
|
|
|
+ return saveBatchCamera(wifiNameList);
|
|
|
}
|
|
|
|
|
|
private void getResultIn(List<Integer> errorList){
|
|
|
@@ -203,37 +201,16 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
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);
|
|
|
+ @Override
|
|
|
+ public Integer outs(List<CameraInOutParam> params){
|
|
|
+ setCompanyIdByDb(params);
|
|
|
+ HashMap<String, Object> resultMap = getResultMap(params,1);
|
|
|
+ HashMap<String,Camera> snCodeMap = (HashMap<String, Camera>) resultMap.get("snCodeMap");
|
|
|
+ return this.saveBatchDetail(snCodeMap,params);
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void saveBatchDetail( HashMap<String,Camera> snCodeMap,List<CameraInOutParam> params){
|
|
|
+ private Integer saveBatchDetail(HashMap<String,Camera> snCodeMap, List<CameraInOutParam> params){
|
|
|
List<CameraDetail> cameraDetails = new ArrayList<>();
|
|
|
for (CameraInOutParam param : params) {
|
|
|
Camera camera = snCodeMap.get(param.getSnCode());
|
|
|
@@ -260,7 +237,7 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
cameraDetail.setGoodsId(Long.valueOf(type));
|
|
|
cameraDetails.add(cameraDetail);
|
|
|
}
|
|
|
- cameraDetailService.saveBatch(cameraDetails);
|
|
|
+ return cameraDetailService.saveBatch(cameraDetails) ? cameraDetails.size() : 0;
|
|
|
}
|
|
|
|
|
|
private void checkSnCode(List<String> snCodeList) {
|
|
|
@@ -286,49 +263,6 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
|
|
|
|
|
|
@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);
|
|
|
@@ -347,4 +281,71 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
this.removeById(id);
|
|
|
cameraDetailService.deleteByCameraId(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer updateCompany(List<CameraInOutParam> companyParams) {
|
|
|
+ setCompanyIdByDb(companyParams);
|
|
|
+ HashMap<String, Object> resultMap = getResultMap(companyParams,2);
|
|
|
+ HashMap<Long, CameraDetail> detailMap = (HashMap<Long, CameraDetail>) resultMap.get("detailMap");
|
|
|
+ HashMap<String, Camera> snCodeMap = (HashMap<String, Camera>) resultMap.get("snCodeMap");
|
|
|
+ List<CameraDetail> updateDetailList = new ArrayList<>();
|
|
|
+ for (CameraInOutParam companyParam : companyParams) {
|
|
|
+ Camera camera = snCodeMap.get(companyParam.getSnCode());
|
|
|
+ CameraDetail cameraDetail = detailMap.get(camera.getId());
|
|
|
+ cameraDetail.setCompanyId(companyParam.getCompanyId());
|
|
|
+ updateDetailList.add(cameraDetail);
|
|
|
+ }
|
|
|
+ return cameraDetailService.updateBatchById(updateDetailList) ? updateDetailList.size() : 0;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setCompanyIdByDb(List<CameraInOutParam> companyParams){
|
|
|
+ List<String> companyNames = companyParams.parallelStream().map(CameraInOutParam::getCompanyName).collect(Collectors.toList());
|
|
|
+ List<Company> companyList = companyService.getCompanyByNames(companyNames);
|
|
|
+ List<String> dbCompanyNames = companyList.parallelStream().map(Company::getCompanyName).collect(Collectors.toList());
|
|
|
+ List<Integer> errorRow = this.getErrorRow(companyNames, dbCompanyNames);
|
|
|
+ getResultIn(errorRow);
|
|
|
+ HashMap<String,Long> companyNameMap = new HashMap<>();
|
|
|
+ for (Company company : companyList) {
|
|
|
+ companyNameMap.put(company.getCompanyName(),company.getId());
|
|
|
+ }
|
|
|
+ for (CameraInOutParam companyParam : companyParams) {
|
|
|
+ companyParam.setCompanyId(companyNameMap.get(companyParam.getCompanyName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private HashMap<String, Object> getResultMap(List<CameraInOutParam> params, Integer type){
|
|
|
+ HashMap<String,Object> resultMap = new HashMap<>();
|
|
|
+ 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(type == 1 && (camera == null || detailMap.get(camera.getId()) !=null)){
|
|
|
+ errorList.add(snCodeList.indexOf(snCode) +3);
|
|
|
+ }
|
|
|
+ if(type == 2 && (camera == null || detailMap.get(camera.getId()) == null)){
|
|
|
+ errorList.add(snCodeList.indexOf(snCode) +3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ getResultIn(errorList);
|
|
|
+ resultMap.put("detailMap",detailMap);
|
|
|
+ resultMap.put("snCodeMap",snCodeMap);
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
}
|