|
@@ -0,0 +1,115 @@
|
|
|
+package com.xiaoan.service.backend.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.crypto.SecureUtil;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.xiaoan.common.constant.MsgCode;
|
|
|
+import com.xiaoan.common.exception.BaseRuntimeException;
|
|
|
+import com.xiaoan.common.model.PageDto;
|
|
|
+import com.xiaoan.common.util.FileUtils;
|
|
|
+import com.xiaoan.common.util.ResultJson;
|
|
|
+import com.xiaoan.dao.backend.CameraVersionMapper;
|
|
|
+import com.xiaoan.dao.backend.IBaseMapper;
|
|
|
+import com.xiaoan.domain.backend.CameraVersionEntity;
|
|
|
+import com.xiaoan.domain.dto.request.CameraVersionRequest;
|
|
|
+import com.xiaoan.service.BaseServiceImpl;
|
|
|
+import com.xiaoan.service.backend.CameraVersionService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
+
|
|
|
+import javax.imageio.IIOException;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Base64;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by Hb_zzZ on 2020/2/27.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Transactional
|
|
|
+public class CameraVersionServiceImpl extends BaseServiceImpl<CameraVersionEntity, Long> implements CameraVersionService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CameraVersionMapper entityMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IBaseMapper<CameraVersionEntity, Long> getBaseMapper() {
|
|
|
+ return this.entityMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CameraVersionEntity> findAllBySearchKey(PageDto param) {
|
|
|
+ PageHelper.startPage(param.getPageNum(), param.getPageSize());
|
|
|
+ return entityMapper.findAllBySearchKey(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void upload(MultipartFile file, CameraVersionRequest param, String savePath) throws Exception {
|
|
|
+ if (!file.isEmpty()&& file.getSize() <= 0) {
|
|
|
+ throw new BaseRuntimeException(MsgCode.e_COMMON_3001, "文件为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> uploadMap = FileUtils.upload(file, savePath);
|
|
|
+
|
|
|
+ String path = uploadMap.get("path");
|
|
|
+ String name = uploadMap.get("name");
|
|
|
+
|
|
|
+ // 添加对象信息
|
|
|
+ CameraVersionEntity versionEntity = new CameraVersionEntity();
|
|
|
+ versionEntity.setName(name);
|
|
|
+ versionEntity.setFileUrl(path);
|
|
|
+ versionEntity.setVersion(param.getVersion());
|
|
|
+ versionEntity.setDescription(param.getDescription());
|
|
|
+ versionEntity.setStatus("I");
|
|
|
+ versionEntity.setFileMd5(SecureUtil.md5(new File(path)));
|
|
|
+
|
|
|
+ this.save(versionEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultJson updateStatus(Long id, String status) {
|
|
|
+
|
|
|
+ CameraVersionEntity cameraVersionEntity = entityMapper.selectByPrimaryKey(id);
|
|
|
+ if (cameraVersionEntity == null){
|
|
|
+ throw new BaseRuntimeException(MsgCode.e_COMMON_3001, "id不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 仅有有一台相机是活动状态
|
|
|
+ // 查找所以活动状态相机
|
|
|
+ Condition condition = new Condition(CameraVersionEntity.class);
|
|
|
+ condition.createCriteria().andEqualTo("status", "A");
|
|
|
+ List<CameraVersionEntity> entityList = entityMapper.selectByCondition(condition);
|
|
|
+ for (CameraVersionEntity entity : entityList) {
|
|
|
+ entity.setStatus("I");
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ entityMapper.updateByPrimaryKey(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ cameraVersionEntity.setStatus(status);
|
|
|
+ cameraVersionEntity.setUpdateTime(new Date());
|
|
|
+ entityMapper.updateByPrimaryKey(cameraVersionEntity);
|
|
|
+
|
|
|
+ return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultJson findByStatus() {
|
|
|
+ Condition condition = new Condition(CameraVersionEntity.class);
|
|
|
+ // condition property参数是实体类
|
|
|
+ condition.createCriteria().andEqualTo("status", "A");
|
|
|
+ condition.createCriteria().andEqualTo("recStatus", "A");
|
|
|
+ List<CameraVersionEntity> cameraVersionEntities = entityMapper.selectByCondition(condition);
|
|
|
+ CameraVersionEntity entity = null;
|
|
|
+ if (cameraVersionEntities.size() > 0) {
|
|
|
+ entity = cameraVersionEntities.get(0);
|
|
|
+ }
|
|
|
+ return new ResultJson(MsgCode.SUCCESS_CODE, entity);
|
|
|
+ }
|
|
|
+}
|