|
|
@ -4,24 +4,27 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.kms.yxgh.base.DfException; |
|
|
|
import com.kms.yxgh.df.dto.DfCheckingDetailDto; |
|
|
|
import com.kms.yxgh.df.dto.DfCheckingDetailDto.DfCheckingItemDto; |
|
|
|
import com.kms.yxgh.df.domain.DfChecking; |
|
|
|
import com.kms.yxgh.df.domain.DfCheckingItem; |
|
|
|
import com.kms.yxgh.df.domain.DfPlan; |
|
|
|
import com.kms.yxgh.df.dto.DfCheckingDetailDto; |
|
|
|
import com.kms.yxgh.df.dto.DfCheckingDetailDto.DfCheckingItemDto; |
|
|
|
import com.kms.yxgh.df.mapper.DfCheckingItemMapper; |
|
|
|
import com.kms.yxgh.df.mapper.DfCheckingMapper; |
|
|
|
import com.kms.yxgh.df.mapper.DfPlanMapper; |
|
|
|
import com.kms.yxgh.util.BeanCopyUtils; |
|
|
|
import com.kms.yxgh.util.StreamUtils; |
|
|
|
import com.shuili.common.core.domain.SearchParam; |
|
|
|
import com.shuili.common.core.service.BaseService; |
|
|
|
import com.shuili.common.utils.StringUtils; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
/** |
|
|
|
* 堤防巡视检查Service接口 |
|
|
@ -33,117 +36,126 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
@AllArgsConstructor |
|
|
|
public class DfCheckingService extends BaseService<DfCheckingMapper, DfChecking> { |
|
|
|
|
|
|
|
private final DfCheckingItemMapper dfCheckingItemMapper; |
|
|
|
public final static String PART_SEPARATOR = ":"; |
|
|
|
|
|
|
|
public List<DfChecking> selectSimple(SearchParam<DfChecking> sp) { |
|
|
|
Wrapper<DfChecking> wp = Wrappers.<DfChecking>lambdaQuery() |
|
|
|
.select(DfChecking::getId, DfChecking::getName) |
|
|
|
.eq(DfChecking::getType, sp.getData().getType()); |
|
|
|
return getBaseMapper().selectList(wp); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public DfCheckingDetailDto getDetailById(String id) { |
|
|
|
DfChecking checking = this.getById(id); |
|
|
|
DfCheckingDetailDto dto = BeanCopyUtils.copy(checking, DfCheckingDetailDto.class); |
|
|
|
if (dto != null) { |
|
|
|
Wrapper<DfCheckingItem> wp = Wrappers.<DfCheckingItem>lambdaQuery() |
|
|
|
.select(DfCheckingItem::getId, DfCheckingItem::getParts, DfCheckingItem::getContent) |
|
|
|
.eq(DfCheckingItem::getXcId, id); |
|
|
|
dto.setItems(StreamUtils.toList(dfCheckingItemMapper.selectList(wp), (o) -> { |
|
|
|
DfCheckingItemDto itemDto = new DfCheckingItemDto(); |
|
|
|
itemDto.setContent(o.getContent()); |
|
|
|
itemDto.setId(o.getId()); |
|
|
|
itemDto.setParts(Arrays.stream(StringUtils.split(o.getParts(), PART_SEPARATOR)) |
|
|
|
.sorted(Comparator.comparingInt(String::length)).collect(Collectors.toList())); |
|
|
|
return itemDto; |
|
|
|
})); |
|
|
|
private final DfCheckingItemMapper dfCheckingItemMapper; |
|
|
|
private final DfPlanMapper dfPlanMapper; |
|
|
|
public final static String PART_SEPARATOR = ":"; |
|
|
|
|
|
|
|
public List<DfChecking> selectSimple(SearchParam<DfChecking> sp) { |
|
|
|
Wrapper<DfChecking> wp = Wrappers.<DfChecking>lambdaQuery() |
|
|
|
.select(DfChecking::getId, DfChecking::getName) |
|
|
|
.eq(DfChecking::getType, sp.getData().getType()); |
|
|
|
return getBaseMapper().selectList(wp); |
|
|
|
} |
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public DfCheckingDetailDto add(DfCheckingDetailDto dto) { |
|
|
|
DfChecking checking = BeanCopyUtils.copy(dto, DfChecking.class); |
|
|
|
if (checking != null) { |
|
|
|
if (checkNameDistinct(checking.getId(), checking.getName())) { |
|
|
|
getBaseMapper().insert(checking); |
|
|
|
String id = checking.getId(); |
|
|
|
if (CollectionUtil.isNotEmpty(dto.getItems())) { |
|
|
|
dto.getItems().forEach((o) -> { |
|
|
|
DfCheckingItem item = new DfCheckingItem(); |
|
|
|
item.setXcId(id); |
|
|
|
item.setContent(o.getContent()); |
|
|
|
item.setParts(String.join(PART_SEPARATOR, o.getParts())); |
|
|
|
dfCheckingItemMapper.insert(item); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
public DfCheckingDetailDto getDetailById(String id) { |
|
|
|
DfChecking checking = this.getById(id); |
|
|
|
DfCheckingDetailDto dto = BeanCopyUtils.copy(checking, DfCheckingDetailDto.class); |
|
|
|
if (dto != null) { |
|
|
|
Wrapper<DfCheckingItem> wp = Wrappers.<DfCheckingItem>lambdaQuery() |
|
|
|
.select(DfCheckingItem::getId, DfCheckingItem::getParts, DfCheckingItem::getContent) |
|
|
|
.eq(DfCheckingItem::getXcId, id); |
|
|
|
dto.setItems(StreamUtils.toList(dfCheckingItemMapper.selectList(wp), (o) -> { |
|
|
|
DfCheckingItemDto itemDto = new DfCheckingItemDto(); |
|
|
|
itemDto.setContent(o.getContent()); |
|
|
|
itemDto.setId(o.getId()); |
|
|
|
itemDto.setParts(Arrays.stream(StringUtils.split(o.getParts(), PART_SEPARATOR)) |
|
|
|
.sorted(Comparator.comparingInt(String::length)).collect(Collectors.toList())); |
|
|
|
return itemDto; |
|
|
|
})); |
|
|
|
} |
|
|
|
return this.getDetailById(id); |
|
|
|
} else { |
|
|
|
throw new DfException("该名称已存在"); |
|
|
|
} |
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public DfCheckingDetailDto add(DfCheckingDetailDto dto) { |
|
|
|
DfChecking checking = BeanCopyUtils.copy(dto, DfChecking.class); |
|
|
|
if (checking != null) { |
|
|
|
if (checkNameDistinct(checking.getId(), checking.getName())) { |
|
|
|
getBaseMapper().insert(checking); |
|
|
|
String id = checking.getId(); |
|
|
|
if (CollectionUtil.isNotEmpty(dto.getItems())) { |
|
|
|
dto.getItems().forEach((o) -> { |
|
|
|
DfCheckingItem item = new DfCheckingItem(); |
|
|
|
item.setXcId(id); |
|
|
|
item.setContent(o.getContent()); |
|
|
|
item.setParts(String.join(PART_SEPARATOR, o.getParts())); |
|
|
|
dfCheckingItemMapper.insert(item); |
|
|
|
}); |
|
|
|
} |
|
|
|
return this.getDetailById(id); |
|
|
|
} else { |
|
|
|
throw new DfException("该名称已存在"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public DfCheckingDetailDto update(DfCheckingDetailDto dto) { |
|
|
|
if (exist(dto.getId())) { |
|
|
|
DfChecking checking = BeanCopyUtils.copy(dto, DfChecking.class); |
|
|
|
if (checking != null) { |
|
|
|
if (checkNameDistinct(checking.getId(), checking.getName())) { |
|
|
|
getBaseMapper().updateById(checking); |
|
|
|
String id = checking.getId(); |
|
|
|
deleteItems(id); |
|
|
|
if (CollectionUtil.isNotEmpty(dto.getItems())) { |
|
|
|
dto.getItems().forEach((o) -> { |
|
|
|
DfCheckingItem item = new DfCheckingItem(); |
|
|
|
item.setXcId(id); |
|
|
|
item.setContent(o.getContent()); |
|
|
|
item.setParts(String.join(PART_SEPARATOR, o.getParts())); |
|
|
|
dfCheckingItemMapper.insert(item); |
|
|
|
}); |
|
|
|
} |
|
|
|
return this.getDetailById(id); |
|
|
|
} else { |
|
|
|
throw new DfException("该名称已存在"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
throw new DfException("源数据不存在,请确认id值是否正确"); |
|
|
|
|
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public DfCheckingDetailDto update(DfCheckingDetailDto dto) { |
|
|
|
if (exist(dto.getId())) { |
|
|
|
DfChecking checking = BeanCopyUtils.copy(dto, DfChecking.class); |
|
|
|
if (checking != null) { |
|
|
|
if (checkNameDistinct(checking.getId(), checking.getName())) { |
|
|
|
getBaseMapper().updateById(checking); |
|
|
|
String id = checking.getId(); |
|
|
|
deleteItems(id); |
|
|
|
if (CollectionUtil.isNotEmpty(dto.getItems())) { |
|
|
|
dto.getItems().forEach((o) -> { |
|
|
|
DfCheckingItem item = new DfCheckingItem(); |
|
|
|
item.setXcId(id); |
|
|
|
item.setContent(o.getContent()); |
|
|
|
item.setParts(String.join(PART_SEPARATOR, o.getParts())); |
|
|
|
dfCheckingItemMapper.insert(item); |
|
|
|
}); |
|
|
|
} |
|
|
|
return this.getDetailById(id); |
|
|
|
} else { |
|
|
|
throw new DfException("该名称已存在"); |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Boolean deleteById(String id) { |
|
|
|
if (isUsed(id)) { |
|
|
|
throw new DfException("已被巡查计划,不能删除!"); |
|
|
|
} |
|
|
|
} |
|
|
|
boolean rt = removeById(id); |
|
|
|
if (rt) { |
|
|
|
deleteItems(id); |
|
|
|
} |
|
|
|
return rt; |
|
|
|
} |
|
|
|
throw new DfException("源数据不存在,请确认id值是否正确"); |
|
|
|
|
|
|
|
} |
|
|
|
private boolean isUsed(String id) { |
|
|
|
return dfPlanMapper.selectCount(Wrappers.<DfPlan>lambdaQuery() |
|
|
|
.eq(DfPlan::getXcId, id)) > 0; |
|
|
|
} |
|
|
|
|
|
|
|
private void deleteItems(String id) { |
|
|
|
Wrapper<DfCheckingItem> wp = Wrappers.<DfCheckingItem>lambdaQuery() |
|
|
|
.eq(DfCheckingItem::getXcId, id); |
|
|
|
dfCheckingItemMapper.delete(wp); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkNameDistinct(String id, String name) { |
|
|
|
Wrapper<DfChecking> wp = Wrappers.<DfChecking>lambdaQuery() |
|
|
|
.eq(DfChecking::getName, name) |
|
|
|
.ne(StringUtils.isNotEmpty(id), DfChecking::getId, id); |
|
|
|
return this.getBaseMapper().selectCount(wp) <= 0; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Boolean deleteById(String id) { |
|
|
|
boolean rt = removeById(id); |
|
|
|
if (rt) { |
|
|
|
deleteItems(id); |
|
|
|
private boolean exist(String id) { |
|
|
|
Wrapper<DfChecking> wp = Wrappers.<DfChecking>lambdaQuery() |
|
|
|
.eq(DfChecking::getId, id); |
|
|
|
return this.getBaseMapper().selectCount(wp) > 0; |
|
|
|
} |
|
|
|
return rt; |
|
|
|
} |
|
|
|
|
|
|
|
private void deleteItems(String id) { |
|
|
|
Wrapper<DfCheckingItem> wp = Wrappers.<DfCheckingItem>lambdaQuery() |
|
|
|
.eq(DfCheckingItem::getXcId, id); |
|
|
|
dfCheckingItemMapper.delete(wp); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkNameDistinct(String id, String name) { |
|
|
|
Wrapper<DfChecking> wp = Wrappers.<DfChecking>lambdaQuery() |
|
|
|
.eq(DfChecking::getName, name) |
|
|
|
.ne(StringUtils.isNotEmpty(id), DfChecking::getId, id); |
|
|
|
return this.getBaseMapper().selectCount(wp) <= 0; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean exist(String id) { |
|
|
|
Wrapper<DfChecking> wp = Wrappers.<DfChecking>lambdaQuery() |
|
|
|
.eq(DfChecking::getId, id); |
|
|
|
return this.getBaseMapper().selectCount(wp) > 0; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|