package com.qianwen.smartman.modules.cps.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import java.lang.invoke.SerializedLambda;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Optional;
|
import java.util.stream.Collectors;
|
import com.qianwen.smartman.common.cache.RegionCache;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.core.log.exception.ServiceException;
|
import com.qianwen.core.mp.service.impl.BladeServiceImpl;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.cps.convert.CheckItemConvert;
|
import com.qianwen.smartman.modules.cps.dto.CheckItemSubmitDTO;
|
import com.qianwen.smartman.modules.cps.entity.CheckItem;
|
import com.qianwen.smartman.modules.cps.mapper.CheckItemMapper;
|
import com.qianwen.smartman.modules.cps.service.ICheckItemService;
|
import com.qianwen.smartman.modules.cps.vo.CheckItemSubmitVO;
|
import com.qianwen.smartman.modules.cps.vo.CheckItemUpdateVO;
|
import com.qianwen.smartman.modules.cps.vo.CheckItemVO;
|
import org.springframework.stereotype.Service;
|
|
@Service
|
public class CheckItemServiceImpl extends BladeServiceImpl<CheckItemMapper, CheckItem> implements ICheckItemService {
|
|
|
@Override // org.springblade.modules.cps.service.ICheckItemService
|
public List<CheckItem> createCheckItem(CheckItemSubmitVO vo) {
|
List<CheckItemSubmitDTO> items = vo.getItems();
|
List<String> names = (List) items.stream().map((v0) -> {
|
return v0.getName();
|
}).distinct().collect(Collectors.toList());
|
if (items.size() != names.size()) {
|
throw new ServiceException(MessageUtils.message("cps.tpm.check.item.exists", new Object[0]));
|
}
|
Long checkProjectId = vo.getCheckProjectId();
|
createNotSameName(checkProjectId, names);
|
List<CheckItem> checkItems = (List) items.stream().map(c -> {
|
return CheckItem.builder().checkProjectId(checkProjectId).name(c.getName()).valueType(c.getValueType()).standardValue(c.getStandardValue()).requirement(c.getRequirement()).build();
|
}).collect(Collectors.toList());
|
saveBatch(checkItems);
|
return checkItems;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICheckItemService
|
public boolean updateCheckItem(CheckItemUpdateVO vo) {
|
Long id = vo.getId();
|
String valueType = vo.getValueType();
|
String requirement = vo.getRequirement();
|
String standardValue = vo.getStandardValue();
|
String name = vo.getName();
|
Long checkProjectId = vo.getCheckProjectId();
|
if (Func.isNotBlank(name)) {
|
validSameName(checkProjectId, id, name);
|
}
|
|
return update(Wrappers.<CheckItem>lambdaUpdate()
|
.set(CheckItem::getValueType, valueType)
|
.set(CheckItem::getRequirement, requirement)
|
.set(CheckItem::getStandardValue, standardValue)
|
.set(CheckItem::getName, name)
|
.eq(CheckItem::getId, id));
|
/*
|
return update((Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
|
return v0.getValueType();
|
}, valueType)).set((v0) -> {
|
return v0.getRequirement();
|
}, requirement)).set((v0) -> {
|
return v0.getStandardValue();
|
}, standardValue)).set((v0) -> {
|
return v0.getName();
|
}, name)).eq((v0) -> {
|
return v0.getId();
|
}, id));*/
|
}
|
|
@Override // org.springblade.modules.cps.service.ICheckItemService
|
public List<CheckItemVO> listCheckItem(String projectId) {
|
List<CheckItem> list = list(Wrappers.<CheckItem>lambdaQuery().eq(CheckItem::getCheckProjectId, projectId).orderByAsc(CheckItem::getCreateTime));
|
|
return Optional.<List<CheckItem>>ofNullable(list)
|
.map(CheckItemConvert.INSTANCE::convert)
|
.orElse(new ArrayList<>());
|
/*
|
*
|
List<CheckItem> list = list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getCheckProjectId();
|
}, projectId)).orderByAsc((v0) -> {
|
return v0.getCreateTime();
|
}));
|
Optional ofNullable = Optional.ofNullable(list);
|
CheckItemConvert checkItemConvert = CheckItemConvert.INSTANCE;
|
checkItemConvert.getClass();
|
return (List) ofNullable.map(this::convert).orElse(new ArrayList());
|
*/
|
}
|
|
private void validSameName(Long checkProjectId, Long id, String name) {
|
long count = count(Wrappers.<CheckItem>lambdaQuery().eq(CheckItem::getCheckProjectId, checkProjectId).ne(CheckItem::getId, id).eq(CheckItem::getName, name));
|
/*
|
long count = count((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getCheckProjectId();
|
}, checkProjectId)).ne((v0) -> {
|
return v0.getId();
|
}, id)).eq((v0) -> {
|
return v0.getName();
|
}, name));*/
|
if (count > 0) {
|
throw new ServiceException(MessageUtils.message("cps.tpm.check.item.exists", new Object[0]));
|
}
|
}
|
|
private void createNotSameName(Long id, List<String> names) {
|
long count = count(Wrappers.<CheckItem>lambdaQuery().eq(CheckItem::getCheckProjectId, id).in(CheckItem::getName, names));
|
if (count > 0) {
|
throw new ServiceException(MessageUtils.message("cps.tpm.check.item.exists", new Object[0]));
|
}
|
}
|
}
|