|
|
@ -1,9 +1,35 @@ |
|
|
|
package com.kms.yxgh.df.service; |
|
|
|
|
|
|
|
import com.shuili.common.core.service.BaseService; |
|
|
|
import com.kms.yxgh.df.mapper.DfRecordMapper; |
|
|
|
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.toolkit.Wrappers; |
|
|
|
import com.kms.common.utils.BaseEntityUtils; |
|
|
|
import com.kms.yxgh.base.enums.CheckingStatus; |
|
|
|
import com.kms.yxgh.base.enums.RecordStatus; |
|
|
|
import com.kms.yxgh.df.domain.dto.DfCheckingDetailDto; |
|
|
|
import com.kms.yxgh.df.domain.dto.DfPlanDetailDto; |
|
|
|
import com.kms.yxgh.df.domain.dto.DfRecordDetailDto; |
|
|
|
import com.kms.yxgh.df.domain.dto.DfRecordDetailDto.DfRecordItemDto; |
|
|
|
import com.kms.yxgh.df.domain.dto.StartPlan; |
|
|
|
import com.kms.yxgh.df.domain.entity.DfRecord; |
|
|
|
import com.kms.yxgh.df.domain.entity.DfRecordItem; |
|
|
|
import com.kms.yxgh.df.mapper.DfRecordItemMapper; |
|
|
|
import com.kms.yxgh.df.mapper.DfRecordMapper; |
|
|
|
import com.kms.yxgh.util.BeanCopyUtils; |
|
|
|
import com.kms.yxgh.util.StreamUtils; |
|
|
|
import com.shuili.common.core.service.BaseService; |
|
|
|
import com.shuili.common.exception.BaseException; |
|
|
|
import com.shuili.common.utils.DateUtils; |
|
|
|
import com.shuili.common.utils.StringUtils; |
|
|
|
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接口 |
|
|
@ -12,6 +38,95 @@ import org.springframework.stereotype.Service; |
|
|
|
* @date 2023-11-09 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class DfRecordService extends BaseService<DfRecordMapper, DfRecord>{ |
|
|
|
@AllArgsConstructor |
|
|
|
public class DfRecordService extends BaseService<DfRecordMapper, DfRecord> { |
|
|
|
|
|
|
|
private final DfRecordItemMapper dfRecordItemMapper; |
|
|
|
private final DfCheckingService dfCheckingService; |
|
|
|
private final DfPlanService dfPlanService; |
|
|
|
|
|
|
|
@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.dateTimeNow()); |
|
|
|
record.setStatus(RecordStatus.CHECKING.getValue()); |
|
|
|
BaseEntityUtils.preInsert(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.setRecordId(""); |
|
|
|
BaseEntityUtils.preInsert(item); |
|
|
|
dfRecordItemMapper.insert(item); |
|
|
|
}); |
|
|
|
} |
|
|
|
return this.getDetailById(id); |
|
|
|
} else { |
|
|
|
throw new BaseException("查询巡查检查项数据异常"); |
|
|
|
} |
|
|
|
} |
|
|
|
throw new BaseException("查询巡查计划"); |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
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()); |
|
|
|
BaseEntityUtils.preUpdate(item); |
|
|
|
dfRecordItemMapper.updateById(item); |
|
|
|
}); |
|
|
|
} |
|
|
|
return dfRecord; |
|
|
|
} |
|
|
|
|
|
|
|
public Boolean deleteById(String id) { |
|
|
|
boolean rt = removeById(id); |
|
|
|
if (rt) { |
|
|
|
deleteItems(id); |
|
|
|
} |
|
|
|
return rt; |
|
|
|
} |
|
|
|
|
|
|
|
private void deleteItems(String id) { |
|
|
|
Wrapper<DfRecordItem> wp = Wrappers.<DfRecordItem>lambdaQuery() |
|
|
|
.eq(DfRecordItem::getRecordId, id); |
|
|
|
dfRecordItemMapper.delete(wp); |
|
|
|
} |
|
|
|
} |
|
|
|