|
@@ -1,14 +1,26 @@
|
|
|
package com.fdkankan.manage.service.impl;
|
|
package com.fdkankan.manage.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.fdkankan.common.constant.Constant;
|
|
|
|
|
+import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
|
|
+import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
|
|
+import com.fdkankan.manage.entity.CameraDetail;
|
|
|
import com.fdkankan.manage.entity.ScenePro;
|
|
import com.fdkankan.manage.entity.ScenePro;
|
|
|
import com.fdkankan.manage.mapper.ISceneProMapper;
|
|
import com.fdkankan.manage.mapper.ISceneProMapper;
|
|
|
|
|
+import com.fdkankan.manage.service.ICameraDetailService;
|
|
|
import com.fdkankan.manage.service.ISceneProService;
|
|
import com.fdkankan.manage.service.ISceneProService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.fdkankan.manage.vo.response.GroupByUserIdCount;
|
|
import com.fdkankan.manage.vo.response.GroupByUserIdCount;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* <p>
|
|
* <p>
|
|
@@ -21,6 +33,11 @@ import java.util.List;
|
|
|
@Service
|
|
@Service
|
|
|
public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
|
|
public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ ICameraDetailService cameraDetailService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private UploadToOssUtil uploadToOssUtil;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList) {
|
|
public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList) {
|
|
|
HashMap<Long,Long> map = new HashMap<>();
|
|
HashMap<Long,Long> map = new HashMap<>();
|
|
@@ -28,4 +45,84 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
result.forEach(entity ->map.put(entity.getUserId(),entity.getCount()));
|
|
result.forEach(entity ->map.put(entity.getUserId(),entity.getCount()));
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void unbindCamera(Long cameraId) {
|
|
|
|
|
+ LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ wrapper.set(ScenePro::getUserId,null)
|
|
|
|
|
+ .eq(ScenePro::getCameraId,cameraId);
|
|
|
|
|
+ this.update(wrapper);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<ScenePro> getListByCameraId(Long cameraId) {
|
|
|
|
|
+ LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(ScenePro::getCameraId,cameraId);
|
|
|
|
|
+ return this.list(wrapper);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void lockBySpace(Long cameraId) {
|
|
|
|
|
+ CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId);
|
|
|
|
|
+ if(cameraDetail == null){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ //恢复10G基本容量
|
|
|
|
|
+ cameraDetail.setTotalSpace(Long.parseLong(Constant.EXPANSION_SPACE_VALUE_1G ) * 10L);
|
|
|
|
|
+ cameraDetailService.updateById(cameraDetail);
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(ScenePro::getCameraId,cameraId)
|
|
|
|
|
+ .eq(ScenePro::getPayStatus,1)
|
|
|
|
|
+ .eq(ScenePro::getSceneScheme,4);
|
|
|
|
|
+ List<ScenePro> list = this.list(wrapper);
|
|
|
|
|
+ Long beyondSpace = cameraDetail.getUsedSpace() - cameraDetail.getTotalSpace();
|
|
|
|
|
+ Long accumulateSpace = 0L;
|
|
|
|
|
+ List<Long> lockedIds = new ArrayList<>();
|
|
|
|
|
+ if (list != null && list.size() > 0){
|
|
|
|
|
+ for (ScenePro scenePro : list){
|
|
|
|
|
+ accumulateSpace += scenePro.getSpace();
|
|
|
|
|
+ if (accumulateSpace.compareTo(beyondSpace) > 0){
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ lockedIds.add(scenePro.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ lockOrUnLockScenes(lockedIds,-2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // payStatus 为 -2 封存,为 1 解封
|
|
|
|
|
+ private void lockOrUnLockScenes(List<Long> lockedIds,Integer payStatus) {
|
|
|
|
|
+ if (lockedIds == null || lockedIds.size() == 0){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.set(ScenePro::getPayStatus,payStatus)
|
|
|
|
|
+ .in(ScenePro::getId,lockedIds);
|
|
|
|
|
+ this.update(updateWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.in(ScenePro::getId,lockedIds);
|
|
|
|
|
+ List<ScenePro> list = this.list(wrapper);
|
|
|
|
|
+ for (ScenePro scenePro : list) {
|
|
|
|
|
+ try{
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("payStatus", payStatus);
|
|
|
|
|
+ FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + scenePro.getNum() + "/scene.json", map);
|
|
|
|
|
+ com.alibaba.fastjson.JSONObject statusJson = new com.alibaba.fastjson.JSONObject();
|
|
|
|
|
+
|
|
|
|
|
+ //临时将-2改成1,app还没完全更新
|
|
|
|
|
+ statusJson.put("status", scenePro.getStatus() == -2 ? 1 : scenePro.getStatus());
|
|
|
|
|
+ statusJson.put("webSite", scenePro.getWebSite());
|
|
|
|
|
+ statusJson.put("sceneNum", scenePro.getNum());
|
|
|
|
|
+ statusJson.put("thumb", scenePro.getThumb());
|
|
|
|
|
+ statusJson.put("payStatus", scenePro.getPayStatus());
|
|
|
|
|
+ FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+scenePro.getNum()+ File.separator+"status.json", statusJson.toString());
|
|
|
|
|
+ uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+scenePro.getNum()+File.separator+"status.json",
|
|
|
|
|
+ "data/data"+scenePro.getNum()+File.separator+"status.json");
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|