李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
package com.chinaztt.mes.production.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.chinaztt.mes.basic.entity.Location;
import com.chinaztt.mes.basic.entity.Part;
import com.chinaztt.mes.common.numgen.NumberGenerator;
import com.chinaztt.mes.plan.entity.ManufacturingOrder;
import com.chinaztt.mes.production.dto.HandymanTypeDTO;
import com.chinaztt.mes.production.entity.ArtificialInformationRelation;
import com.chinaztt.mes.production.entity.HandymanType;
import com.chinaztt.mes.production.excel.HandymanTypeData;
import com.chinaztt.mes.production.mapper.ArtificialInformationRelationMapper;
import com.chinaztt.mes.production.mapper.HandymanTypeMapper;
import com.chinaztt.mes.production.service.HandymanTypeService;
import com.chinaztt.mes.warehouse.entity.Stock;
import com.chinaztt.mes.warehouse.excel.StockData;
import com.chinaztt.ztt.common.core.util.R;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
 
/**
 * 杂工类型维护
 *
 * @author cxf
 * @date 2020-12-01 13:13:44
 */
@Service
@AllArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class HandymanTypeServiceImpl extends ServiceImpl<HandymanTypeMapper, HandymanType> implements HandymanTypeService {
    private NumberGenerator<HandymanType> handymanTypeNumberGenerator;
    private ArtificialInformationRelationMapper artificialInformationRelationMapper;
 
    @Override
    public boolean save(HandymanType handymanType) {
        checkHandymanNo(handymanType);
        return SqlHelper.retBool(baseMapper.insert(handymanType));
    }
 
    @Override
    public boolean updateById(HandymanType handymanType) {
        checkHandymanNo(handymanType);
        return SqlHelper.retBool(baseMapper.updateById(handymanType));
    }
 
    private void checkHandymanNo(HandymanType handymanType) {
        if (StringUtils.isBlank(handymanType.getHandymanNo())) {
            // 1. 自动生成人工编号
            handymanType.setHandymanNo(handymanTypeNumberGenerator.generateNumberWithPrefix(HandymanType.DIGIT, HandymanType.PREFIX + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATE_PATTERN) + "-", HandymanType::getHandymanNo));
        } else {
            // 2.判断是否重复
            List<HandymanType> repeatNumbers = baseMapper.selectList(Wrappers.<HandymanType>query().lambda().eq(HandymanType::getHandymanNo, handymanType.getHandymanNo()).ne(HandymanType::getId, handymanType.getId()));
            if (CollectionUtil.isNotEmpty(repeatNumbers)) {
                throw new RuntimeException("编号重复");
            }
        }
    }
 
    @Override
    public IPage<List<HandymanType>> getHandymanType(Page page, QueryWrapper<HandymanType> gen, Long id) {
        return baseMapper.getHandymanType(page, gen, id);
    }
 
    @Override
    public IPage<List<HandymanType>> getHandyman(Page page, QueryWrapper<HandymanType> gen, Long id) {
        return baseMapper.getHandyman(page, gen, id);
    }
 
    @Override
    public R<Boolean> delHandyTypeRelation(Long id, Long id1) {
        artificialInformationRelationMapper.delete(Wrappers.<ArtificialInformationRelation>lambdaQuery().eq(ArtificialInformationRelation::getProductionHandymanJoinId, id1).eq(ArtificialInformationRelation::getProductionHandymanId, id));
        return R.ok();
    }
 
    @Override
    public void importExcel(List<HandymanTypeData> list) {
        if (CollectionUtil.isEmpty(list)) {
            return;
        }
        for (HandymanTypeData data : list) {
            baseMapper.insert(data);
        }
    }
 
    @Override
    public IPage<List<HandymanTypeDTO>> fetchListByTemplateId(Page page, QueryWrapper<HandymanTypeDTO> gen) {
        return baseMapper.fetchListByTemplateId(page, gen);
    }
 
    @Override
    public IPage<List<HandymanTypeDTO>> fetchListFilterTemplateId(Page page, QueryWrapper<HandymanTypeDTO> gen, Long handymanTemplateId) {
        return baseMapper.fetchListFilterTemplateId(page, gen, handymanTemplateId);
    }
 
    @Override
    public HandymanTypeDTO getHandymanTypeById(Long id) {
        return baseMapper.getHandymanTypeById(id);
    }
}