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
package com.qianwen.smartman.modules.smis.service.impl;
 
import java.util.List;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianwen.core.cache.utils.CacheUtil;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.constant.ExtCacheConstant;
import com.qianwen.smartman.common.enums.GlobalWcsTypeEnum;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.modules.smis.convert.GlobalWcsConvert;
import com.qianwen.smartman.modules.smis.entity.GlobalWcs;
import com.qianwen.smartman.modules.smis.entity.GlobalWcsOfRps;
import com.qianwen.smartman.modules.smis.mapper.GlobalWcsMapper;
import com.qianwen.smartman.modules.smis.service.IGlobalWcsService;
import com.qianwen.smartman.modules.smis.vo.WcsAchievementsUpdateVO;
import com.qianwen.smartman.modules.smis.vo.WcsAndAchievementsVO;
 
@Service
public class GlobalWcsServiceImpl extends ServiceImpl<GlobalWcsMapper, GlobalWcs> implements IGlobalWcsService {
    
 
    @Override
    public List<GlobalWcs> getGlobalWcsList(GlobalWcsTypeEnum globalWcsTypeEnum) {
         return list(Wrappers.<GlobalWcs>lambdaQuery().eq(GlobalWcs::getType, globalWcsTypeEnum.getType()).orderByAsc(GlobalWcs::getSeq));
         
    }
 
    @Override 
    public List<WcsAndAchievementsVO> getWcsAndAchievements() {
        return this.baseMapper.wcsAndAchievements();
    }
 
    @Override
    public GlobalWcs getByCode(String code, GlobalWcsTypeEnum globalWcsTypeEnum) {
        return getOne(Lambda.eq(GlobalWcs::getCode, code).eq(GlobalWcs::getType, globalWcsTypeEnum.getType()));
        
    }
 
    @Override
    @Transactional
    public void updateWcsAndAchievements(WcsAchievementsUpdateVO wcsAchievements) {
         lambdaUpdate()
                 .set(Func.isNotBlank(wcsAchievements.getName()), GlobalWcs::getName, wcsAchievements.getName())
                 .set(Func.isNotBlank(wcsAchievements.getColor()), GlobalWcs::getColor, wcsAchievements.getColor())
                 .eq(GlobalWcs::getCode, wcsAchievements.getCode()).update();
        
        GlobalWcsOfRps globalWcsOfRps = new GlobalWcsOfRps();
        globalWcsOfRps.setCode(wcsAchievements.getCode());
        globalWcsOfRps.setRps(wcsAchievements.getRps());
        globalWcsOfRps.setIsPlan(wcsAchievements.getIsPlan());
        globalWcsOfRps.insertOrUpdate();
        CacheUtil.clear(ExtCacheConstant.COLLECT_WORKSTATION, Boolean.FALSE);
    }
 
    @Override
    @Transactional
    public boolean insertWcsAndAchievements(WcsAchievementsUpdateVO wcsAchievementsUpdateVO) {
        if (count(Lambda.eq(GlobalWcs::getCode, wcsAchievementsUpdateVO.getCode())) > 0) {
            throw new ServiceException("编码已经存在");
        }
        GlobalWcs globalWcs = GlobalWcsConvert.INSTANCE.convert(wcsAchievementsUpdateVO);
        globalWcs.setType(GlobalWcsTypeEnum.FEEDBACK.getType());
        GlobalWcsOfRps globalWcsOfRps = new GlobalWcsOfRps();
        globalWcsOfRps.setCode(wcsAchievementsUpdateVO.getCode());
        globalWcsOfRps.setRps(wcsAchievementsUpdateVO.getRps());
        globalWcsOfRps.setIsPlan(wcsAchievementsUpdateVO.getIsPlan());
        globalWcsOfRps.insertOrUpdate();
        CacheUtil.clear(ExtCacheConstant.COLLECT_WORKSTATION, Boolean.FALSE);
        return save(globalWcs);
    }
}