yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
package com.qianwen.smartman.modules.andon.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.google.common.collect.Lists;
import java.lang.invoke.SerializedLambda;
import java.util.List;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.common.utils.Lambda;
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.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.andon.convert.AndonReasonConvert;
import com.qianwen.smartman.modules.andon.entity.AndonReason;
import com.qianwen.smartman.modules.andon.mapper.AndonReasonMapper;
import com.qianwen.smartman.modules.andon.service.IAndonReasonService;
import com.qianwen.smartman.modules.andon.vo.AndonReasonSaveVO;
import com.qianwen.smartman.modules.andon.vo.AndonReasonUpdateVO;
import com.qianwen.smartman.modules.andon.vo.AndonReasonVO;
import com.qianwen.smartman.modules.cps.vo.IdsVO;
import com.qianwen.smartman.modules.system.service.ICodeGeneratorService;
import com.qianwen.smartman.modules.tpm.enums.MetaTypeEnum;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/andon/service/impl/AndonReasonServiceImpl.class */
public class AndonReasonServiceImpl extends BladeServiceImpl<AndonReasonMapper, AndonReason> implements IAndonReasonService {
    private final ICodeGeneratorService codeGeneratorService;
    public AndonReasonServiceImpl(ICodeGeneratorService codeGeneratorService) {
        this.codeGeneratorService = codeGeneratorService;
      }
      
      public IPage<AndonReasonVO> pageQuery(Query query, String typeId) {
        IPage<AndonReason> page = page(Condition.getPage(query), Lambda.eq(AndonReason::getAndonTypeId, typeId)
            .orderByDesc(AndonReason::getCreateTime,  AndonReason::getCode));
        return AndonReasonConvert.INSTANCE.convert(page);
      }
      
      
 
    @Override // org.springblade.modules.andon.service.IAndonReasonService
    public AndonReasonVO addReason(AndonReasonSaveVO vo) {
        reasonCodeGenerator(vo);
        checkDuplicateCode(vo.getCode());
        AndonReason reason = new AndonReason().setAndonTypeId(vo.getAndonTypeId()).setCode(vo.getCode()).setName(vo.getName()).setRemark(vo.getRemark());
        save(reason);
        return AndonReasonConvert.INSTANCE.convert(reason);
    }
 
    @Override // org.springblade.modules.andon.service.IAndonReasonService
    public Boolean updateReason(AndonReasonUpdateVO vo) {
         
        int nums = this.baseMapper.recordsReason(Lists.newArrayList(new Long[]{vo.getId()}));
 
        if (nums > 0) {
          throw new ServiceException(MessageUtils.message("andon.type.reason.not.update", new Object[0])); 
        }
               //Lambda.<AndonReason>updateWrapper(this.baseMapper).set(AndonReason::getName, vo.getName()).set(AndonReason::getRemark, vo.getRemark()).eq(AndonReason::getId, vo.getId()).update();
        return Lambda.<AndonReason>updateWrapper(this.baseMapper).set(AndonReason::getName, vo.getName()).set(AndonReason::getRemark, vo.getRemark()).eq(AndonReason::getId, vo.getId()).update();
          //Boolean.valueOf(((LambdaUpdateChainWrapper)((LambdaUpdateChainWrapper)((LambdaUpdateChainWrapper)Lambda.updateWrapper(this.baseMapper).set(AndonReason::getName, vo.getName())).set(AndonReason::getRemark, vo.getRemark())).eq(BaseEntity::getId, vo.getId())).update());
    }
 
    @Override // org.springblade.modules.andon.service.IAndonReasonService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean removeReason(IdsVO vo) {
        List<Long> ids = Func.toLongList(vo.getIds());
        int nums = this.baseMapper.recordsReason(ids);
        if (nums > 0) {
            throw new ServiceException(MessageUtils.message("andon.type.reason.not.remove", new Object[0]));
        }
        return Boolean.valueOf(removeBatchByIds(ids));
    }
 
    private void reasonCodeGenerator(AndonReasonSaveVO vo) {
        if (Func.isBlank(vo.getCode())) {
            String code = this.codeGeneratorService.getGeneratorCode(vo, MetaTypeEnum.ANDON_REASON_TYPE.getCode());
            if (Func.isBlank(code)) {
                throw new ServiceException(MessageUtils.message("cps.tpm.maintain.coding.rules", new Object[0]));
            }
            vo.setCode(code);
        }
    }
 
    private void checkDuplicateCode(String code) {
        List<AndonReason> list = list(Lambda.eq((v0) -> {
            return v0.getCode();
        }, code));
        if (Func.isNotEmpty(list)) {
            throw new ServiceException(MessageUtils.message("andon.type.reason.code.dub", new Object[0]));
        }
    }
}