yangys
2024-03-27 44028c2d1a7f21da831cb07ecb1b4a7873d8627b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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]));
        }
    }
}