|
@ -1,11 +1,30 @@ |
|
|
package com.kms.yxgh.df.service; |
|
|
package com.kms.yxgh.df.service; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
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.DfException; |
|
|
|
|
|
import com.kms.yxgh.df.domain.dto.DfPlanDetailDto; |
|
|
|
|
|
import com.kms.yxgh.df.domain.dto.DfPlanDetailDto.OperatorDto; |
|
|
|
|
|
import com.kms.yxgh.df.domain.dto.DfPointDto; |
|
|
import com.kms.yxgh.df.domain.entity.DfPlan; |
|
|
import com.kms.yxgh.df.domain.entity.DfPlan; |
|
|
|
|
|
import com.kms.yxgh.df.domain.entity.DfPlanOperator; |
|
|
|
|
|
import com.kms.yxgh.df.domain.entity.DfPoint; |
|
|
import com.kms.yxgh.df.mapper.DfPlanMapper; |
|
|
import com.kms.yxgh.df.mapper.DfPlanMapper; |
|
|
import com.kms.yxgh.df.mapper.DfPlanOperatorMapper; |
|
|
import com.kms.yxgh.df.mapper.DfPlanOperatorMapper; |
|
|
|
|
|
import com.kms.yxgh.df.mapper.DfPointMapper; |
|
|
|
|
|
import com.kms.yxgh.util.BeanCopyUtils; |
|
|
|
|
|
import com.kms.yxgh.util.StreamUtils; |
|
|
import com.shuili.common.core.service.BaseService; |
|
|
import com.shuili.common.core.service.BaseService; |
|
|
|
|
|
import com.shuili.common.exception.BaseException; |
|
|
|
|
|
import com.shuili.common.utils.StringUtils; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.function.Consumer; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 堤防巡视检查计划Service接口 |
|
|
* 堤防巡视检查计划Service接口 |
|
@ -18,5 +37,136 @@ import org.springframework.stereotype.Service; |
|
|
public class DfPlanService extends BaseService<DfPlanMapper, DfPlan> { |
|
|
public class DfPlanService extends BaseService<DfPlanMapper, DfPlan> { |
|
|
|
|
|
|
|
|
private final DfPlanOperatorMapper dfPlanOperatorMapper; |
|
|
private final DfPlanOperatorMapper dfPlanOperatorMapper; |
|
|
|
|
|
private final DfPointMapper dfPointMapper; |
|
|
|
|
|
|
|
|
|
|
|
public DfPlanDetailDto getDetailById(String id) { |
|
|
|
|
|
DfPlan dfPlan = this.getById(id); |
|
|
|
|
|
DfPlanDetailDto dto = BeanCopyUtils.copy(dfPlan, DfPlanDetailDto.class); |
|
|
|
|
|
if (dto != null) { |
|
|
|
|
|
dto.setOtherConfig(JSON.parseObject(dfPlan.getOtherConfig())); |
|
|
|
|
|
Wrapper<DfPlanOperator> wp = Wrappers.<DfPlanOperator>lambdaQuery() |
|
|
|
|
|
.select(DfPlanOperator::getId, DfPlanOperator::getOperatorUid) |
|
|
|
|
|
.eq(DfPlanOperator::getPlanId, id); |
|
|
|
|
|
dto.setOperators(StreamUtils.toList(dfPlanOperatorMapper.selectList(wp), (o) -> { |
|
|
|
|
|
OperatorDto itemDto = new OperatorDto(); |
|
|
|
|
|
itemDto.setId(o.getId()); |
|
|
|
|
|
itemDto.setUid(o.getOperatorUid()); |
|
|
|
|
|
itemDto.setName(o.getOperatorName()); |
|
|
|
|
|
return itemDto; |
|
|
|
|
|
})); |
|
|
|
|
|
} |
|
|
|
|
|
return dto; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public DfPlanDetailDto add(DfPlanDetailDto dto) { |
|
|
|
|
|
DfPlan dfPlan = BeanCopyUtils.copy(dto, DfPlan.class); |
|
|
|
|
|
if (dfPlan != null) { |
|
|
|
|
|
if (checkNameDistinct(dfPlan.getId(), dfPlan.getName())) { |
|
|
|
|
|
dfPlan.setOtherConfig(JSON.toJSONString(dto.getOtherConfig())); |
|
|
|
|
|
BaseEntityUtils.preInsert(dfPlan); |
|
|
|
|
|
getBaseMapper().insert(dfPlan); |
|
|
|
|
|
String id = dfPlan.getId(); |
|
|
|
|
|
if (CollectionUtil.isNotEmpty(dto.getOperators())) { |
|
|
|
|
|
dto.getOperators().forEach(insertOperator(id)); |
|
|
|
|
|
} |
|
|
|
|
|
return this.getDetailById(id); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new DfException("存在相同的名称"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Consumer<OperatorDto> insertOperator(String id) { |
|
|
|
|
|
return (o) -> { |
|
|
|
|
|
DfPlanOperator item = new DfPlanOperator(); |
|
|
|
|
|
item.setPlanId(id); |
|
|
|
|
|
item.setOperatorName(o.getName()); |
|
|
|
|
|
item.setOperatorUid(o.getUid()); |
|
|
|
|
|
BaseEntityUtils.preInsert(item); |
|
|
|
|
|
dfPlanOperatorMapper.insert(item); |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public DfPlanDetailDto update(DfPlanDetailDto dto) { |
|
|
|
|
|
if (exist(dto.getId())) { |
|
|
|
|
|
DfPlan dfPlan = BeanCopyUtils.copy(dto, DfPlan.class); |
|
|
|
|
|
if (dfPlan != null) { |
|
|
|
|
|
if (checkNameDistinct(dfPlan.getId(), dfPlan.getName())) { |
|
|
|
|
|
dfPlan.setOtherConfig(JSON.toJSONString(dto.getOtherConfig())); |
|
|
|
|
|
BaseEntityUtils.preUpdate(dfPlan); |
|
|
|
|
|
getBaseMapper().updateById(dfPlan); |
|
|
|
|
|
String id = dfPlan.getId(); |
|
|
|
|
|
deleteItems(id); |
|
|
|
|
|
if (CollectionUtil.isNotEmpty(dto.getOperators())) { |
|
|
|
|
|
dto.getOperators().forEach(insertOperator(id)); |
|
|
|
|
|
} |
|
|
|
|
|
return this.getDetailById(id); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new DfException("存在相同的名称"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
throw new BaseException("源数据不存在,请确认id值是否正确"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public Boolean deleteById(String id) { |
|
|
|
|
|
boolean rt = removeById(id); |
|
|
|
|
|
if (rt) { |
|
|
|
|
|
deleteItems(id); |
|
|
|
|
|
} |
|
|
|
|
|
return rt; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public Boolean addPoints(String id, List<DfPointDto> points) { |
|
|
|
|
|
Wrapper<DfPoint> wp = Wrappers.<DfPoint>lambdaQuery() |
|
|
|
|
|
.eq(DfPoint::getPlanId, id); |
|
|
|
|
|
dfPointMapper.delete(wp); |
|
|
|
|
|
if (CollectionUtil.isNotEmpty(points)) { |
|
|
|
|
|
points.forEach(po -> { |
|
|
|
|
|
DfPoint point = BeanCopyUtils.copy(po, DfPoint.class); |
|
|
|
|
|
if (point != null) { |
|
|
|
|
|
point.setPlanId(id); |
|
|
|
|
|
BaseEntityUtils.preInsert(point); |
|
|
|
|
|
dfPointMapper.insert(point); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<DfPointDto> getPoints(String id) { |
|
|
|
|
|
Wrapper<DfPoint> wp = Wrappers.<DfPoint>lambdaQuery() |
|
|
|
|
|
.eq(DfPoint::getPlanId, id); |
|
|
|
|
|
return StreamUtils.toList(dfPointMapper.selectList(wp), |
|
|
|
|
|
(o) -> BeanCopyUtils.copy(o, DfPointDto.class)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void deleteItems(String id) { |
|
|
|
|
|
Wrapper<DfPlanOperator> wp = Wrappers.<DfPlanOperator>lambdaQuery() |
|
|
|
|
|
.eq(DfPlanOperator::getPlanId, id); |
|
|
|
|
|
dfPlanOperatorMapper.delete(wp); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean checkNameDistinct(String id, String name) { |
|
|
|
|
|
Wrapper<DfPlan> wp = Wrappers.<DfPlan>lambdaQuery() |
|
|
|
|
|
.eq(DfPlan::getName, name) |
|
|
|
|
|
.ne(StringUtils.isNotEmpty(id), DfPlan::getId, id); |
|
|
|
|
|
return this.getBaseMapper().selectCount(wp) <= 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean exist(String id) { |
|
|
|
|
|
Wrapper<DfPlan> wp = Wrappers.<DfPlan>lambdaQuery() |
|
|
|
|
|
.eq(DfPlan::getId, id); |
|
|
|
|
|
return this.getBaseMapper().selectCount(wp) > 0; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|