Browse Source

feat:监督检查-添加水闸状态启用性校验

master_tdsql
huangrenya 1 year ago
parent
commit
112aceeb64
  1. 25
      shuili-system/src/main/java/com/kms/yxgh/base/enums/SuperviseWayStatus.java
  2. 2
      shuili-system/src/main/java/com/kms/yxgh/sz/controller/SzSuperviseWayController.java
  3. 140
      shuili-system/src/main/java/com/kms/yxgh/sz/service/SzSuperviseWayService.java

25
shuili-system/src/main/java/com/kms/yxgh/base/enums/SuperviseWayStatus.java

@ -0,0 +1,25 @@
package com.kms.yxgh.base.enums;
import lombok.Getter;
/**
* 监督检查办法状态
* @author hry
* @date 2024/3/4 18:57
*/
@Getter
public enum SuperviseWayStatus {
ENABLE("启用", "0"),
STOP("停用", "1"),
;
private final String value;
private final String name;
SuperviseWayStatus(String name, String value) {
this.name = name;
this.value = value;
}
}

2
shuili-system/src/main/java/com/kms/yxgh/sz/controller/SzSuperviseWayController.java

@ -67,7 +67,7 @@ public class SzSuperviseWayController extends BaseController {
@ApiOperation("水闸监督检查办法复制")
@Log(title = "水闸监督检查办法复制", businessType = BusinessType.INSERT)
@PostMapping("/copy/{id}")
public Response<Boolean> copyInfo(@PathVariable String id) throws IOException {
public Response<Boolean> copyInfo(@PathVariable String id) {
return Response.ok(superviseWayService.copyInfo(id));
}

140
shuili-system/src/main/java/com/kms/yxgh/sz/service/SzSuperviseWayService.java

@ -4,8 +4,8 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kms.framework.config.ServerConfig;
import com.kms.yxgh.base.DfException;
import com.kms.yxgh.base.enums.SuperviseWayStatus;
import com.kms.yxgh.sz.domain.SzSuperviseWay;
import com.kms.yxgh.sz.domain.SzSuperviseWayProject;
import com.kms.yxgh.sz.domain.SzSuperviseWayProjectItem;
@ -21,7 +21,6 @@ import com.shuili.common.config.ShuiliConfig;
import com.shuili.common.constant.Constants;
import com.shuili.common.core.service.BaseService;
import com.shuili.common.utils.DateUtils;
import com.shuili.common.utils.FastDfsUtil;
import com.shuili.common.utils.file.FileDownloadUtils;
import com.shuili.common.utils.uuid.IdUtils;
import lombok.AllArgsConstructor;
@ -42,10 +41,8 @@ import java.util.stream.Collectors;
@AllArgsConstructor
public class SzSuperviseWayService extends BaseService<SzSuperviseWayMapper, SzSuperviseWay> {
private final SzSuperviseWayProjectMapper wayProjectService;
private final SzSuperviseWayProjectMapper wayProjectMapper;
private final SzSuperviseWayProjectItemMapper projectItemMapper;
private final ServerConfig serverConfig;
private final FastDfsUtil fastDfsUtil;
@Transactional(rollbackFor = Exception.class)
public SzSuperviseWayDto addOrModify(SzSuperviseWayDto dto) {
@ -53,10 +50,37 @@ public class SzSuperviseWayService extends BaseService<SzSuperviseWayMapper, SzS
throw new DfException("源数据不存在,请确认id值是否正确");
}
SzSuperviseWay superviseWay = BeanCopyUtils.copy(dto, SzSuperviseWay.class);
checkWayStatus(superviseWay, dto.getId(), dto.getStatus());
this.saveOrUpdate(superviseWay);
return BeanCopyUtils.copy(superviseWay, SzSuperviseWayDto.class);
}
/**
* 校验状态
*/
private void checkWayStatus(SzSuperviseWay way, String id, String updateStatus){
SzSuperviseWay enable = getEnableWay();
if (ObjectUtil.isNotNull(id)) {
// 修改校验是否启用一条
SzSuperviseWayDto wayDto = getDetailById(id);
if (wayDto.getId().equals(enable.getId()) && updateStatus.equals(SuperviseWayStatus.STOP.getValue())) {
throw new DfException("需启用一项管理办法");
} else {
enable.setStatus(SuperviseWayStatus.STOP.getValue());
this.updateById(enable);
}
}else{
// 若新增没有启用的则设为默认启用的,否则为禁用
way.setStatus(enable == null ? SuperviseWayStatus.ENABLE.getValue() : SuperviseWayStatus.STOP.getValue());
}
}
private SzSuperviseWay getEnableWay(){
// 获取启用的监督检查办法
return this.getOne(Wrappers.<SzSuperviseWay>lambdaQuery().eq(SzSuperviseWay::getStatus, SuperviseWayStatus.ENABLE.getValue()));
}
public SzSuperviseWayDto getDetailById(String id) {
SzSuperviseWay superviseWay = this.getById(id);
return BeanCopyUtils.copy(superviseWay, SzSuperviseWayDto.class);
@ -64,57 +88,57 @@ public class SzSuperviseWayService extends BaseService<SzSuperviseWayMapper, SzS
@Transactional(rollbackFor = Exception.class)
public Boolean copyInfo(String id) {
String localPath = ShuiliConfig.getProfile();
try {
// 1.1 查询监督检查办法对象
SzSuperviseWay superviseWay = this.getById(id);
SzSuperviseWay superviseWayNew = BeanCopyUtils.copy(superviseWay, SzSuperviseWay.class);
superviseWay.setName("新建管理办法");
// 1.2 复制文件
if (StringUtils.isNotBlank(superviseWay.getSuperviseCheckWay())) {
String checkWayUrl = superviseWay.getSuperviseCheckWay();
String index = checkWayUrl.substring(checkWayUrl.lastIndexOf("."));
String path = DateUtils.datePath() + "/" + IdUtils.fastUUID() + index;
System.out.println("-----------test--------------" + localPath + Constants.RESOURCE_PREFIX + path);
FileDownloadUtils.downloadFile(checkWayUrl, localPath, localPath + Constants.RESOURCE_PREFIX + path);
String serverUrl = checkWayUrl.substring(0, checkWayUrl.lastIndexOf("/profile"));
superviseWayNew.setSuperviseCheckWay(serverUrl + Constants.RESOURCE_PREFIX + "/" + path);
}
// 1.1 查询监督检查办法对象
SzSuperviseWay superviseWay = this.getById(id);
// 1.2 复制文件
if (StringUtils.isNotBlank(superviseWay.getSuperviseCheckWay())) {
copyFile(superviseWay.getSuperviseCheckWay(), superviseWay);
}
superviseWay.setName("新建管理办法");
superviseWay.setId(null);
superviseWay.setStatus("1");
this.saveOrUpdate(superviseWay);
// 1.3 查询水闸监督检查办法项目
List<SzSuperviseWayProjectDto> projectList = listData(superviseWay.getId());
superviseWay.setId(null);
this.saveOrUpdate(superviseWay);
if (projectList.isEmpty()) {
// 1.3 查询水闸监督检查办法项目
List<SzSuperviseWayProjectDto> projectList = listData(id);
if (projectList.isEmpty()) {
return true;
}
List<SzSuperviseWayProject> list = BeanCopyUtils.copyList(projectList, SzSuperviseWayProject.class);
list.forEach(v -> {
List<SzSuperviseWayProjectItem> listItem = projectItemMapper.selectList(
Wrappers.<SzSuperviseWayProjectItem>lambdaQuery().eq(SzSuperviseWayProjectItem::getProjectId, v.getId()));
// 新增项目
v.setId(null);
v.setWayId(superviseWay.getId());
wayProjectMapper.insert(v);
// 1.4 新增水闸监督检查办法项目内容
if (!listItem.isEmpty()) {
listItem.forEach(val -> {
val.setId(null);
val.setProjectId(v.getId());
projectItemMapper.insert(val);
});
}
});
return true;
}
List<SzSuperviseWayProject> list = BeanCopyUtils.copyList(projectList, SzSuperviseWayProject.class);
list.forEach(v -> {
List<SzSuperviseWayProjectItem> listItem = projectItemMapper.selectList(
Wrappers.<SzSuperviseWayProjectItem>lambdaQuery().eq(SzSuperviseWayProjectItem::getProjectId, v.getId()));
// 新增项目
v.setId(null);
v.setWayId(superviseWayNew.getId());
wayProjectService.insert(v);
// 1.4 新增水闸监督检查办法项目内容
if (!listItem.isEmpty()) {
listItem.forEach(val -> {
val.setId(null);
val.setProjectId(v.getId());
projectItemMapper.insert(val);
});
private void copyFile(String checkWayFile, SzSuperviseWay superviseWayNew) {
String localPath = ShuiliConfig.getProfile();
try {
String suffix = checkWayFile.substring(checkWayFile.lastIndexOf("."));
String serverUrl = checkWayFile.substring(0, checkWayFile.lastIndexOf("/profile"));
// 文件名地址
String pathName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + suffix;
// 复制文件
FileDownloadUtils.downloadFile(checkWayFile, localPath, localPath + Constants.RESOURCE_PREFIX + pathName);
superviseWayNew.setSuperviseCheckWay(serverUrl + Constants.RESOURCE_PREFIX + "/" + pathName);
} catch (Exception e) {
e.printStackTrace();
}
});
}catch (Exception e){
e.printStackTrace();
}
return true;
}
@ -126,33 +150,33 @@ try {
public SzSuperviseWayProjectDto getDataById(String dataId) {
SzSuperviseWayProject superviseWayData = wayProjectService.selectById(dataId);
SzSuperviseWayProject superviseWayData = wayProjectMapper.selectById(dataId);
return BeanCopyUtils.copy(superviseWayData, SzSuperviseWayProjectDto.class);
}
@Transactional(rollbackFor = Exception.class)
public SzSuperviseWayProjectDto addData(SzSuperviseWayProjectDto dataDto) {
SzSuperviseWayProject superviseWayData = BeanCopyUtils.copy(dataDto, SzSuperviseWayProject.class);
wayProjectService.insert(BeanCopyUtils.copy(dataDto, superviseWayData));
wayProjectMapper.insert(BeanCopyUtils.copy(dataDto, superviseWayData));
return BeanCopyUtils.copy(superviseWayData, SzSuperviseWayProjectDto.class);
}
@Transactional(rollbackFor = Exception.class)
public SzSuperviseWayProjectDto updateData(SzSuperviseWayProjectDto dataDto) {
SzSuperviseWayProject dataEntity = BeanCopyUtils.copy(dataDto, SzSuperviseWayProject.class);
wayProjectService.updateById(dataEntity);
wayProjectMapper.updateById(dataEntity);
return dataDto;
}
@Transactional(rollbackFor = Exception.class)
public boolean deleteByDataId(String id) {
wayProjectService.deleteById(id);
wayProjectMapper.deleteById(id);
return true;
}
public List<SzSuperviseWayProjectDto> listData(String wayId) {
List<SzSuperviseWayProject> list = wayProjectService.selectList(
List<SzSuperviseWayProject> list = wayProjectMapper.selectList(
Wrappers.<SzSuperviseWayProject>lambdaQuery().eq(SzSuperviseWayProject::getWayId, wayId));
return BeanCopyUtils.copyList(list, SzSuperviseWayProjectDto.class);
}
@ -173,7 +197,7 @@ try {
public SzSuperviseWayProjectItemDto getDataItemById(String id) {
SzSuperviseWayProjectItem projectItem = projectItemMapper.selectById(id);
return BeanCopyUtils.copy(projectItem, SzSuperviseWayProjectItemDto.class);
}
}
@Transactional(rollbackFor = Exception.class)
public SzSuperviseWayProjectItemDto addDataItem(SzSuperviseWayProjectItemDto dto) {
@ -199,7 +223,7 @@ try {
public SzSuperviseWayOtherDto getEnableSuperviseWay() {
SzSuperviseWayOtherDto superviseWayOtherDto = new SzSuperviseWayOtherDto();
// 1.1 查询启用的水闸监督检查办法
SzSuperviseWay enable = this.getOne(Wrappers.<SzSuperviseWay>lambdaQuery().eq(SzSuperviseWay::getStatus, "0"));
SzSuperviseWay enable = getEnableWay();
if (enable == null) {
return superviseWayOtherDto;
}

Loading…
Cancel
Save