|
@@ -4,7 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.fdkankan.common.constant.AppConstant;
|
|
import com.fdkankan.common.constant.AppConstant;
|
|
|
|
+import com.fdkankan.common.constant.Constant;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
|
+import com.fdkankan.ucenter.common.AgentConstant;
|
|
|
|
+import com.fdkankan.ucenter.common.CameraTypeEnum;
|
|
import com.fdkankan.ucenter.common.PageInfo;
|
|
import com.fdkankan.ucenter.common.PageInfo;
|
|
import com.fdkankan.common.util.DateUtil;
|
|
import com.fdkankan.common.util.DateUtil;
|
|
import com.fdkankan.common.util.FileSizeUtil;
|
|
import com.fdkankan.common.util.FileSizeUtil;
|
|
@@ -242,39 +245,84 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void bind(Integer cameraType, String snCodes, String username) {
|
|
|
|
|
|
+ public List<String> bind(Integer cameraType, String snCodes, String username) {
|
|
User user = userService.getByUserName(username);
|
|
User user = userService.getByUserName(username);
|
|
String[] snCodeArr = snCodes.split(",");
|
|
String[] snCodeArr = snCodes.split(",");
|
|
List<String> snCodeList = Arrays.asList(snCodeArr);
|
|
List<String> snCodeList = Arrays.asList(snCodeArr);
|
|
|
|
+ List<String> existCodes = inCameraAndIncrement(user.getId(), snCodeList);
|
|
|
|
+
|
|
LambdaUpdateWrapper<Camera> wrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<Camera> wrapper = new LambdaUpdateWrapper<>();
|
|
wrapper.in(Camera::getSnCode,snCodeList);
|
|
wrapper.in(Camera::getSnCode,snCodeList);
|
|
List<Camera> list = this.list(wrapper);
|
|
List<Camera> list = this.list(wrapper);
|
|
- if(list.size() <=0){
|
|
|
|
- throw new BusinessException(AppConstant.FAILURE_CODE_4010, snCodes +"-"+ AppConstant.FAILURE_MSG_4010);
|
|
|
|
- }
|
|
|
|
- List<String> dbSnCode = list.stream().map(Camera::getSnCode).collect(Collectors.toList());
|
|
|
|
- for (String code : snCodeList) {
|
|
|
|
- if(!dbSnCode.contains(code)){
|
|
|
|
- throw new BusinessException(AppConstant.FAILURE_CODE_4010, code +"-"+ AppConstant.FAILURE_MSG_4010);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- Map<Long, Camera> cameraHashMap = list.stream().collect(Collectors.toMap(Camera::getId, camera -> camera, (o1, o2) -> o1));
|
|
|
|
- List<Long> cameraIds = new ArrayList<>(cameraHashMap.keySet());
|
|
|
|
- HashMap<Long, CameraDetail> detailHashMap = cameraDetailService.getByCameraIds(cameraIds);
|
|
|
|
- for (CameraDetail detail : detailHashMap.values()) {
|
|
|
|
- if(detail.getUserId() != null){
|
|
|
|
- throw new BusinessException(CameraConstant.FAILURE_CODE_6010, cameraHashMap.get(detail.getCameraId()).getSnCode() +"-"+ CameraConstant.FAILURE_MSG_6010);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ List<Long> cameraIds = list.parallelStream().map(Camera::getId).collect(Collectors.toList());
|
|
|
|
|
|
cameraDetailService.bindCamera(cameraIds,user.getId());
|
|
cameraDetailService.bindCamera(cameraIds,user.getId());
|
|
sceneService.bindOrUnCamera(cameraIds,user.getId());
|
|
sceneService.bindOrUnCamera(cameraIds,user.getId());
|
|
sceneProService.bindOrUnCamera(cameraIds,user.getId());
|
|
sceneProService.bindOrUnCamera(cameraIds,user.getId());
|
|
scenePlusService.bindOrUnCamera(cameraIds,user.getId());
|
|
scenePlusService.bindOrUnCamera(cameraIds,user.getId());
|
|
|
|
|
|
- if("local".equals(NacosProperty.uploadType)){ //局域网绑定相机,添加权益
|
|
|
|
- userIncrementService.addByCameraAndUser(cameraIds,user.getId());
|
|
|
|
|
|
+ return existCodes;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<String> inCameraAndIncrement(Long userId, List<String> snCodeList) {
|
|
|
|
+ if(snCodeList.size() <=0){
|
|
|
|
+ return snCodeList;
|
|
|
|
+ }
|
|
|
|
+ LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.in(Camera::getSnCode,snCodeList);
|
|
|
|
+ List<Camera> cameraList = list(wrapper);
|
|
|
|
+ List<String> inSnCodeList = new ArrayList<>();
|
|
|
|
+ if(cameraList.size() >0){
|
|
|
|
+ inSnCodeList = cameraList.parallelStream().map(Camera::getSnCode).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+ for (String snCode : snCodeList) {
|
|
|
|
+ if(inSnCodeList.contains(snCode)){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ Camera camera = new Camera();
|
|
|
|
+ camera.setWifiName(CameraTypeEnum.DOUBLE_EYE_TURN.getWifiNamePrefix() + snCode);
|
|
|
|
+ camera.setSnCode(snCode);
|
|
|
|
+ camera.setChildName(snCode);
|
|
|
|
+ camera.setWifiPassword(AgentConstant.WIFI_PASSWORD_VALUE);
|
|
|
|
+ camera.setChildPassword(AgentConstant.CHILD_PASSWORD_VALUE);
|
|
|
|
+ camera.setActivatedTime(DateUtil.date2String(new Date(),null));
|
|
|
|
+ camera.setIsOut(1);
|
|
|
|
+ camera.setRecStatus("A");
|
|
|
|
+ camera.setCreateTime(DateUserUtil.getDate(new Date()));
|
|
|
|
+ camera.setUpdateTime(DateUserUtil.getDate(new Date()));
|
|
|
|
+ save(camera);
|
|
|
|
+
|
|
|
|
+ CameraDetail detailEntity = new CameraDetail();
|
|
|
|
+ detailEntity.setCameraId(camera.getId());
|
|
|
|
+ detailEntity.setAgency(AgentConstant.DEFAULT_AGENT);
|
|
|
|
+ detailEntity.setCountry(0);//默认中国
|
|
|
|
+ detailEntity.setType(CameraTypeEnum.DOUBLE_EYE_TURN.getType());
|
|
|
|
+ //商品类型,type:1为8目,type:2为双目 3:为转台
|
|
|
|
+ detailEntity.setGoodsId((long) CameraTypeEnum.DOUBLE_EYE_TURN.getType());
|
|
|
|
+ detailEntity.setTotalSpace(Long.valueOf(Constant.CAMERA_BASE_SPACE_VALUE));
|
|
|
|
+ detailEntity.setUsedSpace(0L);
|
|
|
|
+ detailEntity.setRecStatus("A");
|
|
|
|
+ detailEntity.setCreateTime(DateUserUtil.getDate(new Date()));
|
|
|
|
+ detailEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
|
|
|
|
+ detailEntity.setLastRequestTime(new Date());
|
|
|
|
+ detailEntity.setOrderSn("");
|
|
|
|
+ detailEntity.setOwn(0);
|
|
|
|
+ cameraDetailService.save(detailEntity);
|
|
|
|
+
|
|
|
|
+ UserIncrement userIncrement = new UserIncrement();
|
|
|
|
+ userIncrement.setCameraId(camera.getId());
|
|
|
|
+ userIncrement.setKeyWord(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
+ userIncrement.setUserId(userId);
|
|
|
|
+ userIncrement.setOrderSn("gh_"+camera.getId());
|
|
|
|
+ userIncrement.setIncrementStartTime(DateUserUtil.getDate(new Date()));
|
|
|
|
+ userIncrement.setIncrementEndTime("2100-01-01 00:00:00");
|
|
|
|
+ userIncrement.setIsExpired(0);
|
|
|
|
+ userIncrement.setRecStatus("A");
|
|
|
|
+ userIncrement.setCreateTime(DateUserUtil.getDate(new Date()));
|
|
|
|
+ userIncrement.setUpdateTime(DateUserUtil.getDate(new Date()));
|
|
|
|
+ userIncrementService.save(userIncrement);
|
|
}
|
|
}
|
|
|
|
+ return inSnCodeList;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|