|
|
@ -1,7 +1,5 @@ |
|
|
|
package com.kms.yxgh.df.service; |
|
|
|
|
|
|
|
import static com.kms.yxgh.df.service.DfCheckingService.PART_SEPARATOR; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
@ -13,12 +11,8 @@ import com.kms.yxgh.base.enums.CheckingStatus; |
|
|
|
import com.kms.yxgh.base.enums.RecordStatus; |
|
|
|
import com.kms.yxgh.df.domain.DfRecord; |
|
|
|
import com.kms.yxgh.df.domain.DfRecordItem; |
|
|
|
import com.kms.yxgh.df.dto.DfCheckingDetailDto; |
|
|
|
import com.kms.yxgh.df.dto.DfPlanDetailDto; |
|
|
|
import com.kms.yxgh.df.dto.DfRecordDetailDto; |
|
|
|
import com.kms.yxgh.df.dto.*; |
|
|
|
import com.kms.yxgh.df.dto.DfRecordDetailDto.DfRecordItemDto; |
|
|
|
import com.kms.yxgh.df.dto.DfRecordSearchDto; |
|
|
|
import com.kms.yxgh.df.dto.StartPlan; |
|
|
|
import com.kms.yxgh.df.mapper.DfRecordItemMapper; |
|
|
|
import com.kms.yxgh.df.mapper.DfRecordMapper; |
|
|
|
import com.kms.yxgh.util.BeanCopyUtils; |
|
|
@ -28,17 +22,15 @@ import com.shuili.common.core.domain.entity.SysUser; |
|
|
|
import com.shuili.common.core.service.BaseService; |
|
|
|
import com.shuili.common.utils.DateUtils; |
|
|
|
import com.shuili.common.utils.StringUtils; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static com.kms.yxgh.df.service.DfCheckingService.PART_SEPARATOR; |
|
|
|
|
|
|
|
/** |
|
|
|
* 堤防巡视检查记录Service接口 |
|
|
|
* |
|
|
@ -49,130 +41,131 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
@AllArgsConstructor |
|
|
|
public class DfRecordService extends BaseService<DfRecordMapper, DfRecord> { |
|
|
|
|
|
|
|
private final DfRecordItemMapper dfRecordItemMapper; |
|
|
|
private final DfCheckingService dfCheckingService; |
|
|
|
private final DfPlanService dfPlanService; |
|
|
|
private final SysUserService userService; |
|
|
|
private final DfRecordItemMapper dfRecordItemMapper; |
|
|
|
private final DfCheckingService dfCheckingService; |
|
|
|
private final DfPlanService dfPlanService; |
|
|
|
private final SysUserService userService; |
|
|
|
|
|
|
|
public IPage<DfRecordSearchDto> search(SearchParam<DfRecord> sp) { |
|
|
|
IPage<DfRecord> page = selectPage(sp); |
|
|
|
if (CollectionUtil.isNotEmpty(page.getRecords())) { |
|
|
|
List<String> ids = page.getRecords().stream().map(DfRecord::getId) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
Wrapper<DfRecordItem> wp = Wrappers.<DfRecordItem>lambdaQuery() |
|
|
|
.in(DfRecordItem::getRecordId, ids) |
|
|
|
.eq(DfRecordItem::getStatus, CheckingStatus.ABNORMAL.getValue()); |
|
|
|
Map<String, List<DfRecordItem>> items = Optional.ofNullable(dfRecordItemMapper.selectList(wp)) |
|
|
|
.map(list -> list.stream().collect( |
|
|
|
Collectors.groupingBy(DfRecordItem::getRecordId, Collectors.toList()))) |
|
|
|
.orElseGet(Collections::emptyMap); |
|
|
|
public IPage<DfRecordSearchDto> search(SearchParam<DfRecord> sp) { |
|
|
|
IPage<DfRecord> page = selectPage(sp); |
|
|
|
if (CollectionUtil.isNotEmpty(page.getRecords())) { |
|
|
|
List<String> ids = page.getRecords().stream().map(DfRecord::getId) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
Wrapper<DfRecordItem> wp = Wrappers.<DfRecordItem>lambdaQuery() |
|
|
|
.in(DfRecordItem::getRecordId, ids) |
|
|
|
.eq(DfRecordItem::getStatus, CheckingStatus.ABNORMAL.getValue()); |
|
|
|
Map<String, List<DfRecordItem>> items = Optional.ofNullable(dfRecordItemMapper.selectList(wp)) |
|
|
|
.map(list -> list.stream().collect( |
|
|
|
Collectors.groupingBy(DfRecordItem::getRecordId, Collectors.toList()))) |
|
|
|
.orElseGet(Collections::emptyMap); |
|
|
|
|
|
|
|
List<DfRecordSearchDto> records = page.getRecords().stream().map(r -> { |
|
|
|
DfRecordSearchDto dto = BeanCopyUtils.copy(r, DfRecordSearchDto |
|
|
|
.class); |
|
|
|
if (dto != null) { |
|
|
|
dto.setParts(items.getOrDefault(r.getId(), Collections.emptyList()) |
|
|
|
.stream().map(item -> { |
|
|
|
List<String> parts = Arrays.stream(item.getParts().split(PART_SEPARATOR)) |
|
|
|
.sorted(Comparator.comparingInt(String::length)).collect(Collectors.toList()); |
|
|
|
return parts.get(parts.size() - 1); |
|
|
|
}).collect(Collectors.toList())); |
|
|
|
dto.setOperatorName(Optional.ofNullable(userService.getWithRedis(r.getCreateUid())).map( |
|
|
|
SysUser::getNickName).orElse("")); |
|
|
|
List<DfRecordSearchDto> records = page.getRecords().stream().map(r -> { |
|
|
|
DfRecordSearchDto dto = BeanCopyUtils.copy(r, DfRecordSearchDto |
|
|
|
.class); |
|
|
|
if (dto != null) { |
|
|
|
dto.setParts(items.getOrDefault(r.getId(), Collections.emptyList()) |
|
|
|
.stream().map(item -> { |
|
|
|
List<String> parts = Arrays.stream(item.getParts().split(PART_SEPARATOR)) |
|
|
|
.sorted(Comparator.comparingInt(String::length)).collect(Collectors.toList()); |
|
|
|
return parts.get(parts.size() - 1); |
|
|
|
}).collect(Collectors.toList())); |
|
|
|
dto.setOperatorName(Optional.ofNullable(userService.getWithRedis(r.getCreateUid())).map( |
|
|
|
SysUser::getNickName).orElse("")); |
|
|
|
} |
|
|
|
return dto; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
Page<DfRecordSearchDto> recordSearchDtoPage = new Page<>(page.getCurrent(), page.getSize(), |
|
|
|
page.getTotal()); |
|
|
|
recordSearchDtoPage.setRecords(records); |
|
|
|
return recordSearchDtoPage; |
|
|
|
} else { |
|
|
|
return new Page<>(page.getCurrent(), page.getSize(), page.getTotal()); |
|
|
|
} |
|
|
|
return dto; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
Page<DfRecordSearchDto> recordSearchDtoPage = new Page<>(page.getCurrent(), page.getSize(), |
|
|
|
page.getTotal()); |
|
|
|
recordSearchDtoPage.setRecords(records); |
|
|
|
return recordSearchDtoPage; |
|
|
|
} else { |
|
|
|
return new Page<>(page.getCurrent(), page.getSize(), page.getTotal()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public DfRecordDetailDto start(StartPlan startPlan) { |
|
|
|
DfPlanDetailDto planDetailDto = dfPlanService.getDetailById(startPlan.getPlanId()); |
|
|
|
if (planDetailDto != null) { |
|
|
|
DfCheckingDetailDto checkingDetailDto = dfCheckingService.getDetailById( |
|
|
|
planDetailDto.getXcId()); |
|
|
|
if (checkingDetailDto != null) { |
|
|
|
DfRecord record = new DfRecord(); |
|
|
|
record.setPlanId(startPlan.getPlanId()); |
|
|
|
record.setName(planDetailDto.getName() + DateUtils.getTime()); |
|
|
|
record.setStatus(RecordStatus.CHECKING.getValue()); |
|
|
|
getBaseMapper().insert(record); |
|
|
|
String id = record.getId(); |
|
|
|
if (CollectionUtil.isNotEmpty(checkingDetailDto.getItems())) { |
|
|
|
checkingDetailDto.getItems().forEach(o -> { |
|
|
|
DfRecordItem item = new DfRecordItem(); |
|
|
|
item.setRecordId(id); |
|
|
|
item.setContent(o.getContent()); |
|
|
|
item.setParts(String.join(PART_SEPARATOR, o.getParts())); |
|
|
|
item.setStatus(CheckingStatus.NORMAL.getValue()); |
|
|
|
item.setProblem(""); |
|
|
|
dfRecordItemMapper.insert(item); |
|
|
|
}); |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public DfRecordDetailDto start(StartPlan startPlan) { |
|
|
|
DfPlanDetailDto planDetailDto = dfPlanService.getDetailById(startPlan.getPlanId()); |
|
|
|
if (planDetailDto != null) { |
|
|
|
planDetailDto.setId(null); |
|
|
|
DfCheckingDetailDto checkingDetailDto = dfCheckingService.getDetailById( |
|
|
|
planDetailDto.getXcId()); |
|
|
|
if (checkingDetailDto != null) { |
|
|
|
DfRecord record = new DfRecord(); |
|
|
|
record.setPlanId(startPlan.getPlanId()); |
|
|
|
record.setName(planDetailDto.getName() + DateUtils.getTime()); |
|
|
|
record.setStatus(RecordStatus.CHECKING.getValue()); |
|
|
|
getBaseMapper().insert(record); |
|
|
|
String id = record.getId(); |
|
|
|
if (CollectionUtil.isNotEmpty(checkingDetailDto.getItems())) { |
|
|
|
checkingDetailDto.getItems().forEach(o -> { |
|
|
|
DfRecordItem item = new DfRecordItem(); |
|
|
|
item.setRecordId(id); |
|
|
|
item.setContent(o.getContent()); |
|
|
|
item.setParts(String.join(PART_SEPARATOR, o.getParts())); |
|
|
|
item.setStatus(CheckingStatus.NORMAL.getValue()); |
|
|
|
item.setProblem(""); |
|
|
|
dfRecordItemMapper.insert(item); |
|
|
|
}); |
|
|
|
} |
|
|
|
return this.getDetailById(id); |
|
|
|
} else { |
|
|
|
throw new DfException("查询巡查检查项数据异常"); |
|
|
|
} |
|
|
|
} |
|
|
|
return this.getDetailById(id); |
|
|
|
} else { |
|
|
|
throw new DfException("查询巡查检查项数据异常"); |
|
|
|
} |
|
|
|
throw new DfException("查询巡查计划"); |
|
|
|
} |
|
|
|
throw new DfException("查询巡查计划"); |
|
|
|
} |
|
|
|
|
|
|
|
public DfRecordDetailDto getDetailById(String id) { |
|
|
|
DfRecord record = this.getBaseMapper().selectById(id); |
|
|
|
if (record != null) { |
|
|
|
DfRecordDetailDto dto = BeanCopyUtils.copy(record, DfRecordDetailDto.class); |
|
|
|
Wrapper<DfRecordItem> wp = Wrappers.<DfRecordItem>lambdaQuery() |
|
|
|
.eq(DfRecordItem::getRecordId, id); |
|
|
|
List<DfRecordItem> items = dfRecordItemMapper.selectList(wp); |
|
|
|
if (CollectionUtil.isNotEmpty(items) && dto != null) { |
|
|
|
dto.setItems(StreamUtils.toList(items, r -> { |
|
|
|
DfRecordItemDto itemDto = BeanCopyUtils.copy(r, DfRecordItemDto.class); |
|
|
|
if (itemDto != null) { |
|
|
|
itemDto.setParts(Arrays.stream(StringUtils.split(r.getParts(), PART_SEPARATOR)) |
|
|
|
.sorted(Comparator.comparingInt(String::length)).collect(Collectors.toList())); |
|
|
|
} |
|
|
|
return itemDto; |
|
|
|
})); |
|
|
|
} |
|
|
|
return dto; |
|
|
|
public DfRecordDetailDto getDetailById(String id) { |
|
|
|
DfRecord record = this.getBaseMapper().selectById(id); |
|
|
|
if (record != null) { |
|
|
|
DfRecordDetailDto dto = BeanCopyUtils.copy(record, DfRecordDetailDto.class); |
|
|
|
Wrapper<DfRecordItem> wp = Wrappers.<DfRecordItem>lambdaQuery() |
|
|
|
.eq(DfRecordItem::getRecordId, id); |
|
|
|
List<DfRecordItem> items = dfRecordItemMapper.selectList(wp); |
|
|
|
if (CollectionUtil.isNotEmpty(items) && dto != null) { |
|
|
|
dto.setItems(StreamUtils.toList(items, r -> { |
|
|
|
DfRecordItemDto itemDto = BeanCopyUtils.copy(r, DfRecordItemDto.class); |
|
|
|
if (itemDto != null) { |
|
|
|
itemDto.setParts(Arrays.stream(StringUtils.split(r.getParts(), PART_SEPARATOR)) |
|
|
|
.sorted(Comparator.comparingInt(String::length)).collect(Collectors.toList())); |
|
|
|
} |
|
|
|
return itemDto; |
|
|
|
})); |
|
|
|
} |
|
|
|
return dto; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public DfRecordDetailDto update(DfRecordDetailDto dfRecord) { |
|
|
|
if (CollectionUtil.isNotEmpty(dfRecord.getItems())) { |
|
|
|
dfRecord.getItems().forEach(o -> { |
|
|
|
DfRecordItem item = new DfRecordItem(); |
|
|
|
item.setRecordId(dfRecord.getId()); |
|
|
|
item.setContent(o.getContent()); |
|
|
|
item.setParts(String.join(PART_SEPARATOR, o.getParts())); |
|
|
|
item.setStatus(o.getStatus()); |
|
|
|
item.setProblem(o.getProblem()); |
|
|
|
dfRecordItemMapper.updateById(item); |
|
|
|
}); |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public DfRecordDetailDto update(DfRecordDetailDto dfRecord) { |
|
|
|
if (CollectionUtil.isNotEmpty(dfRecord.getItems())) { |
|
|
|
dfRecord.getItems().forEach(o -> { |
|
|
|
DfRecordItem item = new DfRecordItem(); |
|
|
|
item.setRecordId(dfRecord.getId()); |
|
|
|
item.setContent(o.getContent()); |
|
|
|
item.setParts(String.join(PART_SEPARATOR, o.getParts())); |
|
|
|
item.setStatus(o.getStatus()); |
|
|
|
item.setProblem(o.getProblem()); |
|
|
|
dfRecordItemMapper.updateById(item); |
|
|
|
}); |
|
|
|
} |
|
|
|
return dfRecord; |
|
|
|
} |
|
|
|
return dfRecord; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Boolean deleteById(String id) { |
|
|
|
boolean rt = removeById(id); |
|
|
|
if (rt) { |
|
|
|
deleteItems(id); |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Boolean deleteById(String id) { |
|
|
|
boolean rt = removeById(id); |
|
|
|
if (rt) { |
|
|
|
deleteItems(id); |
|
|
|
} |
|
|
|
return rt; |
|
|
|
} |
|
|
|
return rt; |
|
|
|
} |
|
|
|
|
|
|
|
private void deleteItems(String id) { |
|
|
|
Wrapper<DfRecordItem> wp = Wrappers.<DfRecordItem>lambdaQuery() |
|
|
|
.eq(DfRecordItem::getRecordId, id); |
|
|
|
dfRecordItemMapper.delete(wp); |
|
|
|
} |
|
|
|
private void deleteItems(String id) { |
|
|
|
Wrapper<DfRecordItem> wp = Wrappers.<DfRecordItem>lambdaQuery() |
|
|
|
.eq(DfRecordItem::getRecordId, id); |
|
|
|
dfRecordItemMapper.delete(wp); |
|
|
|
} |
|
|
|
} |
|
|
|