lyhzzz 5 mēneši atpakaļ
vecāks
revīzija
11d5171f4e

+ 3 - 0
src/main/java/com/fdkankan/ucenter/common/constants/ResultCode.java

@@ -1,12 +1,15 @@
 package com.fdkankan.ucenter.common.constants;
 
 
+import com.fdkankan.common.constant.CameraConstant;
+
 public enum ResultCode {
 
 
     UPLOAD_ERROR2(500001, "上传失败。文件格式不对"),
     UPLOAD_ERROR(500002, "上传失败。"),
     UPLOAD_ERROR3(500003, "文件不存在!"),
+    CAMERA_NOT_EXIT(500004, "相机不存在或未绑定"),
 
     USER_NOT_LOGIN(3004, "用户未登录"),
     PARAM_MISS(3001, "参数缺失"),

+ 10 - 0
src/main/java/com/fdkankan/ucenter/controller/SceneCooperationController.java

@@ -71,6 +71,16 @@ public class SceneCooperationController extends BaseController {
         return Result.success(sceneCooperationService.saveBatchCooperation(param,username));
     }
 
+    @PostMapping("/saveCamera")
+    public Result saveCamera(@RequestBody SceneCooperationParam param){
+        String username = JwtUtil.getUsername(getToken());
+        if(StringUtils.isNotBlank(getLang())){
+            param.setLang(getLang());
+        }
+        param.setTimeZone(getTimeZone());
+        return Result.success(sceneCooperationService.saveCamera(param,username));
+    }
+
 
 
     /**

+ 5 - 0
src/main/java/com/fdkankan/ucenter/entity/ProductOrder.java

@@ -102,5 +102,10 @@ public class ProductOrder implements Serializable {
     @TableField("time_zone_off")
     private Integer timeZoneOff;
 
+    @TableField("lang")
+    private String lang;
 
+
+    @TableField("camera_id")
+    private Long cameraId;
 }

+ 4 - 1
src/main/java/com/fdkankan/ucenter/httpClient/service/LaserService.java

@@ -431,12 +431,15 @@ public class LaserService {
         return null ;
     }
 
-    public void saveBatchCooperation(List<String> numList2, String userName, List<String> userNameList) {
+    public void saveBatchCooperation(List<String> numList2,List<String> snCodeList, String userName, List<String> userNameList,String type) {
         if(userNameList.isEmpty()){
             userNameList.add(userName);
         }
         HashMap<String,Object> map = new HashMap<>();
         map.put("numList",numList2);
+        //map.put("type","camera":"scene");
+        map.put("type",type);
+        map.put("snCodeList",snCodeList);
         map.put("userNameList",userNameList);
         rabbitMqProducer.sendByWorkQueue("laser-batch-save-cooperation",map);
     }

+ 1 - 1
src/main/java/com/fdkankan/ucenter/service/IProductCooperationService.java

@@ -17,7 +17,7 @@ import java.util.List;
  */
 public interface IProductCooperationService extends IService<ProductCooperation> {
 
-    void add(ProductOrder productOrder, List<User> users,List<String> numList);
+    void add(ProductOrder productOrder, List<User> users,List<String> numList,Long cameraId);
 
     void paySuccess(String orderSn);
 }

+ 3 - 1
src/main/java/com/fdkankan/ucenter/service/IProductOrderService.java

@@ -16,7 +16,9 @@ import java.util.List;
  */
 public interface IProductOrderService extends IService<ProductOrder> {
 
-    ProductOrder createOrder(Integer totalCount, String key, User user,Integer payType, Integer timeZone);
+    ProductOrder createOrder(Integer totalCount, String key, User user,Integer payType, Integer timeZone,Long cameraId,String lang);
 
     void handleOrder(String orderSn, String tradeNo, String openId, Integer payType);
+
+    ProductOrder getByOrderSn(String orderSn);
 }

+ 5 - 2
src/main/java/com/fdkankan/ucenter/service/ISceneCooperationService.java

@@ -21,7 +21,8 @@ public interface ISceneCooperationService extends IService<SceneCooperation> {
 
     Long getCooperationSceneNum(Long userId, List<Integer> sceneSourceList);
 
-    void deleteCooperationList(List<ScenePro> sceneProList, List<ScenePlus> scenePlusList) ;
+    void deleteCooperationList(List<ScenePro> sceneProList, List<ScenePlus> scenePlusList,List<Long> userIds) ;
+    void deleteCooperationList(List<String> numList,List<Long> userIds) ;
 
     void saveBatchByList(List<ScenePro> sceneProList, List<ScenePlus> scenePlusList, Long userId ,List<Long>resourceIds);
 
@@ -45,6 +46,8 @@ public interface ISceneCooperationService extends IService<SceneCooperation> {
 
     ProductOrder saveBatchCooperation(SceneCooperationParam param, String username);
 
-    void successAddCooperation(List<String> numList,List<User> users,String lang,User loginUser);
+     void  successAddCooperation(List<String> numList,List<Long> userIds,Long loginUserId,Long cameraId,String lang);
 
+
+     ProductOrder saveCamera(SceneCooperationParam param, String username);
 }

+ 1 - 1
src/main/java/com/fdkankan/ucenter/service/impl/CameraDetailServiceImpl.java

@@ -137,7 +137,7 @@ public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, Ca
         //删除场景协作信息
         List<ScenePro> sceneProList = sceneProService.getListByCameraIds(cameraIds);
         List<ScenePlus> scenePlusList = scenePlusService.getListByCameraIds(cameraIds);
-        sceneCooperationService.deleteCooperationList(sceneProList,scenePlusList);
+        sceneCooperationService.deleteCooperationList(sceneProList,scenePlusList,null);
         fdkkLaserService.disableCooperation(detailMap, cameraMap);
         //解绑删除相机。文件夹与场景绑定关系
         List<Long > sceneIds = new ArrayList<>();

+ 2 - 2
src/main/java/com/fdkankan/ucenter/service/impl/CameraServiceImpl.java

@@ -364,7 +364,7 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
 
         List<ScenePro> sceneProList = sceneProService.getListByCameraIds(cameraIds);
         List<ScenePlus> scenePlusList = scenePlusService.getListByCameraIds(cameraIds);
-        sceneCooperationService.deleteCooperationList(sceneProList,scenePlusList);
+        sceneCooperationService.deleteCooperationList(sceneProList,scenePlusList,Arrays.asList(user.getId()));
 
         if(!v3List.isEmpty() && !sceneProList.isEmpty()){
             List<Long> v3Ids = v3List.stream().map(SceneResource::getId).collect(Collectors.toList());
@@ -395,7 +395,7 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
 
         List<ScenePro> sceneProList = sceneProService.getListByCameraIds(cameraIds);
         List<ScenePlus> scenePlusList = scenePlusService.getListByCameraIds(cameraIds);
-        sceneCooperationService.deleteCooperationList(sceneProList,scenePlusList);
+        sceneCooperationService.deleteCooperationList(sceneProList,scenePlusList,null);
         fdkkLaserService.disableCooperation(detailMap, cameraMap);
 
     }

+ 24 - 3
src/main/java/com/fdkankan/ucenter/service/impl/ProductCooperationServiceImpl.java

@@ -7,10 +7,16 @@ import com.fdkankan.ucenter.entity.User;
 import com.fdkankan.ucenter.mapper.IProductCooperationMapper;
 import com.fdkankan.ucenter.service.IProductCooperationService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.ucenter.service.IProductOrderService;
+import com.fdkankan.ucenter.service.ISceneCooperationService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -23,8 +29,13 @@ import java.util.List;
 @Service
 public class ProductCooperationServiceImpl extends ServiceImpl<IProductCooperationMapper, ProductCooperation> implements IProductCooperationService {
 
+    @Autowired
+    ISceneCooperationService sceneCooperationService;
+    @Autowired
+    IProductOrderService productOrderService;
+
     @Override
-    public void add(ProductOrder productOrder, List<User> users,List<String> numList) {
+    public void add(ProductOrder productOrder, List<User> users,List<String> numList,Long cameraId) {
         List<ProductCooperation> productCooperations = new ArrayList<>();
         for (String num : numList) {
             for (User user : users) {
@@ -32,6 +43,7 @@ public class ProductCooperationServiceImpl extends ServiceImpl<IProductCooperati
                 productCooperation.setOrderSn(productOrder.getOrderSn());
                 productCooperation.setCooperationUserId(user.getId());
                 productCooperation.setNum(num);
+                productCooperation.setCameraId(cameraId);
                 productCooperations.add(productCooperation);
             }
         }
@@ -43,11 +55,20 @@ public class ProductCooperationServiceImpl extends ServiceImpl<IProductCooperati
 
     @Override
     public void paySuccess(String orderSn) {
+        ProductOrder productOrder = productOrderService.getByOrderSn(orderSn);
+        if(productOrder == null){
+            return;
+        }
+
         LambdaQueryWrapper<ProductCooperation> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(ProductCooperation::getOrderSn,orderSn);
         List<ProductCooperation> list = this.list(wrapper);
+        if(list.isEmpty()){
+            return;
+        }
+        List<String> numList = list.stream().map(ProductCooperation::getNum).collect(Collectors.toList());
+        Set<Long> userIds = list.stream().map(ProductCooperation::getCooperationUserId).collect(Collectors.toSet());
 
-
-
+        sceneCooperationService.successAddCooperation(numList,new ArrayList<>(userIds),productOrder.getUserId(), productOrder.getCameraId(), productOrder.getLang());
     }
 }

+ 15 - 1
src/main/java/com/fdkankan/ucenter/service/impl/ProductOrderServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fdkankan.ucenter.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.ucenter.constant.OrderConstant;
@@ -40,7 +41,7 @@ public class ProductOrderServiceImpl extends ServiceImpl<IProductOrderMapper, Pr
 
 
     @Override
-    public ProductOrder createOrder(Integer totalCount, String key, User user,Integer payType, Integer timeZone) {
+    public ProductOrder createOrder(Integer totalCount, String key, User user,Integer payType, Integer timeZone,Long cameraId,String lang) {
         ProductOrder productOrder = new ProductOrder();
 
         Product product = productService.getByKey(key);
@@ -54,6 +55,8 @@ public class ProductOrderServiceImpl extends ServiceImpl<IProductOrderMapper, Pr
         productOrder.setUserId(user.getId());
         productOrder.setCount(totalCount);
         productOrder.setTimeZoneOff(timeZone);
+        productOrder.setCameraId(cameraId);
+        productOrder.setLang(lang);
 
         PayGoods payGoods = new PayGoods(product.getName(),totalCount,4,1);
         PayOrderVo payOrderVo = payService.downOrder(price.multiply(new BigDecimal(totalCount)), "cooperationOrder",user.getUserName(),user.getNickName(), Arrays.asList(payGoods),null);
@@ -81,4 +84,15 @@ public class ProductOrderServiceImpl extends ServiceImpl<IProductOrderMapper, Pr
 
         productCooperationService.paySuccess(orderSn);
     }
+
+    @Override
+    public ProductOrder getByOrderSn(String orderSn) {
+        LambdaQueryWrapper<ProductOrder> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(ProductOrder::getOrderSn,orderSn);
+        List<ProductOrder> list = this.list(wrapper);
+        if(list.isEmpty() ){
+            return null;
+        }
+        return list.get(0);
+    }
 }

+ 103 - 16
src/main/java/com/fdkankan/ucenter/service/impl/SceneCooperationServiceImpl.java

@@ -3,14 +3,15 @@ package com.fdkankan.ucenter.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.common.constant.SceneConstant;
-import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.ucenter.common.PageInfo;
 import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.common.SceneSourceUtil;
 import com.fdkankan.ucenter.common.constants.NacosProperty;
+import com.fdkankan.ucenter.common.constants.ResultCode;
 import com.fdkankan.ucenter.constant.LoginConstant;
 import com.fdkankan.ucenter.entity.*;
+import com.fdkankan.ucenter.exception.BusinessException;
 import com.fdkankan.ucenter.httpClient.service.LaserService;
 import com.fdkankan.ucenter.mapper.ISceneCooperationMapper;
 import com.fdkankan.ucenter.service.*;
@@ -75,15 +76,26 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
     }
 
     @Override
-    public void deleteCooperationList(List<ScenePro> sceneProList,List<ScenePlus> scenePlusList) {
+    public void deleteCooperationList(List<ScenePro> sceneProList,List<ScenePlus> scenePlusList,List<Long> userIds) {
         if(CollectionUtils.isEmpty(sceneProList) && CollectionUtils.isEmpty(scenePlusList)){
             return;
         }
         List<String> numList = sceneProList.stream().map(ScenePro::getNum).collect(Collectors.toList());
         List<String> numList2 = scenePlusList.stream().map(ScenePlus::getNum).collect(Collectors.toList());
         numList.addAll(numList2);
+        this.deleteCooperationList(numList,userIds);
+    }
+
+    @Override
+    public void deleteCooperationList(List<String> numList,List<Long> userIds) {
+        if(CollectionUtils.isEmpty(numList) ){
+            return;
+        }
         LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
         wrapper.in(SceneCooperation::getSceneNum,numList);
+        if(userIds != null && !userIds.isEmpty()){
+            wrapper.in(SceneCooperation::getUserId,userIds);
+        }
         List<SceneCooperation> list = this.list(wrapper);
         List<Long> ids = list.stream().map(SceneCooperation::getId).collect(Collectors.toList());
         if(ids.size() >0){
@@ -226,9 +238,9 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
         List<String> numList =  Arrays.asList(nums);
         List<ScenePro> proList = sceneProService.getListByNums(numList);
         List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
-        this.deleteCooperationList(proList,plusList);
+        this.deleteCooperationList(proList,plusList,Arrays.asList(user.getId()));
 
-        saveCooperationCommon(loginUser,param.getLang(),Arrays.asList(user),proList,plusList);
+        saveCooperationCommon(loginUser,param.getLang(),Arrays.asList(user),proList,plusList,null,"scene");
     }
 
     @Override
@@ -252,30 +264,97 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
         String[] nums = param.getSceneNum().split(",");
         List<String> numList =  Arrays.asList(nums);
 
-        ProductOrder productOrder = checkNeedPay(numList, users, loginUser, param.getPayType(), param.getTimeZone());
+        ProductOrder productOrder = checkNeedPay(numList, users, loginUser, param.getPayType(), param.getTimeZone(),null,param.getLang());
 
         if(productOrder == null){
             successAddCooperation(numList,users,param.getLang(),loginUser);
         }else {
-            productCooperationService.add(productOrder,users,numList);
+            productCooperationService.add(productOrder,users,numList,null);
         }
         return productOrder;
 
     }
 
+    @Override
+    public ProductOrder saveCamera(SceneCooperationParam param, String loginUserName) {
+        if(param.getCameraId() == null  || StringUtils.isEmpty(param.getUserName())){
+            throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
+        }
+        if(param.getUserName().equals( loginUserName)){
+            throw new BusinessException(LoginConstant.FAILURE_CODE_3025, LoginConstant.FAILURE_MSG_3025);
+        }
+        User user = userService.getByUserName(param.getUserName());
+        if(user == null){
+            throw new BusinessException(LoginConstant.FAILURE_CODE_3015,LoginConstant.FAILURE_MSG_3015);
+        }
+        User loginUser = userService.getByUserName(loginUserName);
+        Camera camera = cameraService.getById(param.getCameraId());
+        CameraDetail cameraDetail = cameraDetailService.getByCameraId(param.getCameraId());
+        if(camera == null || cameraDetail == null || cameraDetail.getUserId() == null){
+            throw new BusinessException(ResultCode.CAMERA_NOT_EXIT);
+        }
+        if(loginUser.getId().equals(cameraDetail.getUserId())){
+            throw new BusinessException(LoginConstant.FAILURE_CODE_3025, LoginConstant.FAILURE_MSG_3025);
+        }
+
+        List<ScenePro> v3List = sceneProService.getListByCameraId(param.getCameraId());
+        List<ScenePlus> v4List = scenePlusService.getListByCameraId(param.getCameraId());
+        List<String> v3NumList = v3List.stream().map(ScenePro::getNum).collect(Collectors.toList());
+        List<String> v4NumList = v4List.stream().map(ScenePlus::getNum).collect(Collectors.toList());
+
+        List<String> allList = new ArrayList<>();
+        allList.addAll(v3NumList);
+        allList.addAll(v4NumList);
+
+        ProductOrder productOrder = checkNeedPay(allList, Arrays.asList(user), loginUser, param.getPayType(), param.getTimeZone(),param.getCameraId(),param.getLang());
+        if(productOrder == null){
+            successAddCooperation(v3List,v4List,Arrays.asList(user),param.getLang(),loginUser,Arrays.asList(camera));
+            cameraDetailService.updateCooperationByIds(Arrays.asList(param.getCameraId()),user.getId());
+        }else {
+            productCooperationService.add(productOrder,Arrays.asList(user),allList,param.getCameraId());
+        }
+
+        return productOrder;
+    }
+
+    private void  successAddCooperation(List<String> numList,List<User> users,String lang,User loginUser){
+        List<ScenePro> proList = sceneProService.getListByNums(numList);
+        List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
+        List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
+        this.deleteCooperationList(proList,plusList,userIds);
+
+        saveCooperationCommon(loginUser,lang,users,proList,plusList,null,"scene");
+    }
 
     @Override
-    public void  successAddCooperation(List<String> numList,List<User> users,String lang,User loginUser){
+    public void  successAddCooperation(List<String> numList,List<Long> userIds,Long loginUserId,Long cameraId,String lang){
+        this.deleteCooperationList(numList,userIds);
         List<ScenePro> proList = sceneProService.getListByNums(numList);
         List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
-        this.deleteCooperationList(proList,plusList);
-        saveCooperationCommon(loginUser,lang,users,proList,plusList);
+        List<User> users = userService.listByIds(userIds);
+        User user = userService.getById(loginUserId);
+        if(cameraId != null ){
+            Camera camera = cameraService.getById(cameraId);
+            saveCooperationCommon(user,lang,users,proList,plusList,Arrays.asList(camera),"camera");
+            cameraDetailService.updateCooperationByIds(Arrays.asList(cameraId),userIds.get(0));
+        }else {
+            saveCooperationCommon(user,lang,users,proList,plusList,null,"scene");
+
+        }
+
+    }
+
+    private void  successAddCooperation(List<ScenePro> v3List,List<ScenePlus> v4List,List<User> users,String lang,User loginUser,List<Camera>cameraList){
+        List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
+        this.deleteCooperationList(v3List,v4List,userIds);
+        saveCooperationCommon(loginUser,lang,users,v3List,v4List,cameraList,"camera");
+
     }
 
 
 
-    private ProductOrder checkNeedPay(List<String> numList, List<User> users,User loginUser,Integer payType,Integer timeZone) {
-        Integer totalCount = users.size() -1;
+    private ProductOrder checkNeedPay(List<String> numList, List<User> users,User loginUser,Integer payType,Integer timeZone,Long cameraId,String lang) {
+        Integer totalCount = (users.size() -1) * numList.size();
         HashMap<String, List<User>> map = this.getByNumList(numList);
         for (String num : map.keySet()) {
             List<User> users1 = map.get(num);
@@ -293,14 +372,14 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
         if(totalCount <=0){
             return null;
         }
-        return productOrderService.createOrder(totalCount, "cooperation", loginUser, payType, timeZone);
+        return productOrderService.createOrder(totalCount, "cooperation", loginUser, payType, timeZone,cameraId,lang);
 
     }
 
     @Autowired
     LaserService laserService;
 
-    private void saveCooperationCommon(User LoginUser,String lang,List<User> userList,List<ScenePro> proList, List<ScenePlus> plusList){
+    private void saveCooperationCommon(User LoginUser,String lang,List<User> userList,List<ScenePro> proList, List<ScenePlus> plusList,List<Camera >cameraList,String type){
 
         for (User user : userList) {
             if( !proList.isEmpty()){
@@ -311,7 +390,13 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
             }
 
             if("aws".equals(NacosProperty.uploadType)){
-                mailTemplateService.sendSceneCooperation(proList,plusList,user.getUserName(),lang);
+                if("camera".equals(type) && cameraList != null){
+                    HashMap<Long, Camera> cameraMap = new HashMap<>();
+                    cameraList.forEach(e -> cameraMap.put(e.getId(),e));
+                    mailTemplateService.sendCameraCooperation(cameraMap,user.getUserName(),lang);
+                }else {
+                    mailTemplateService.sendSceneCooperation(proList,plusList,user.getUserName(),lang);
+                }
             }
         }
 
@@ -321,7 +406,9 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
         List<String> numList2 = collect2.stream().map(ScenePlus::getNum).collect(Collectors.toList());
         numList1.addAll(numList2);
         List<String> collect = userList.stream().map(User::getUserName).collect(Collectors.toList());
-        laserService.saveBatchCooperation(numList2,LoginUser.getUserName(),collect);
+
+        List<String> snCodeList = cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
+        laserService.saveBatchCooperation(numList2,snCodeList,LoginUser.getUserName(),collect,type);
 
     }
 
@@ -334,7 +421,7 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
         List<String> numList =  Arrays.asList(nums);
         List<ScenePro> proList = sceneProService.getListByNums(numList);
         List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
-        this.deleteCooperationList(proList,plusList);
+        this.deleteCooperationList(proList,plusList,null);
     }
 
     @Override