cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package cn.stylefeng.guns.modular.dq.materialTraceability.service.impl;
 
import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.bs.bomInfo.entity.BomInfo;
import cn.stylefeng.guns.modular.bs.bomInfo.service.BomInfoService;
import cn.stylefeng.guns.modular.bs.lineInfo.entity.LineInfo;
import cn.stylefeng.guns.modular.bs.lineInfo.service.LineInfoService;
import cn.stylefeng.guns.modular.bs.locationInfo.entity.LocationInfo;
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
import cn.stylefeng.guns.modular.dq.materialTraceability.entity.MaterialTraceability;
import cn.stylefeng.guns.modular.dq.materialTraceability.mapper.MaterialTraceabilityMapper;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.result.MaterialTraceabilityResult;
import  cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.entity.ProductionOrderBatchInfo;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.io.Serializable;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Stream;
 
/**
 * <p>
 * 物料追溯 服务实现类
 * </p>
 *
 * @author cl
 * @since 2022-10-29
 */
@Service
public class MaterialTraceabilityServiceImpl extends ServiceImpl<MaterialTraceabilityMapper, MaterialTraceability> implements MaterialTraceabilityService {
    private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
    @Autowired
    private BomInfoService bomInfoService;
 
    @Autowired
    private MaterialTraceabilityService traceabilityService;
 
    @Autowired
    private LocationInfoService locationInfoService;
 
    @Override
    public void add(MaterialTraceabilityParam param){
//        param.setAssemblyUser(LoginContextHolder.getContext().getUser().getUsername());
//        param.setAssemblyTime(new Date());
//        param.setProductNo(getSfcCode(param.getLocationCode()+"_S_SFC_CODE"));
        MaterialTraceability entity = getEntity(param);
        this.save(entity);
    }
 
    @Override
    public void lineFeedingAddItem(MaterialTraceabilityParam param) {
        param.setAssemblyUser(LoginContextHolder.getContext().getUser().getUsername());
        param.setAssemblyTime(new Date());
        param.setProductNo(getSfcCode(param.getLocationCode()+"_S_SFC_CODE"));
        MaterialTraceability entity = getEntity(param);
        this.save(entity);
    }
 
    @Override
    public List<MaterialTraceabilityResult> exportTable(MaterialTraceabilityParam param) {
        return this.baseMapper.customList(param);
    }
 
    @Override
    public void delete(MaterialTraceabilityParam param){
        this.removeById(getKey(param));
    }
 
    @Override
    public void update(MaterialTraceabilityParam param){
        MaterialTraceability oldEntity = getOldEntity(param);
        MaterialTraceability newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }
 
    public static String getSfcCode(String str){
        String sfcCode = "";
        try {
            Class<?> clazz = Class.forName("cn.stylefeng.guns.plcserver.opc.GlobalVariable");
            Field[] fields = clazz.getFields();
            for (Field field : fields) {
                String name = field.getName();
                if (name.equals(str)) {
                    try {
                        return String.valueOf(field.get(null));
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return sfcCode;
    }
 
    @Override
    public MaterialTraceabilityResult findBySpec(MaterialTraceabilityParam param){
        return null;
    }
 
    @Override
    public List<MaterialTraceabilityResult> findListBySpec(MaterialTraceabilityParam param){
        return this.baseMapper.customList(param);
    }
 
    @Override
    public LayuiPageInfo findPageBySpec(MaterialTraceabilityParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }
 
    @Override
    public int barCodeCheck(ProductionOrderBatchInfoParam productionOrderBatchInfoParam) {
        int i =  traceabilityService.count(new QueryWrapper<MaterialTraceability>()
                .eq("work_order_no", productionOrderBatchInfoParam.getWorkOrderNo())
                .eq("material_code", productionOrderBatchInfoParam.getMaterialCode())
        );
        return i;
    }
 
    private Serializable getKey(MaterialTraceabilityParam param){
        return param.getId();
    }
 
    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }
 
    private MaterialTraceability getOldEntity(MaterialTraceabilityParam param) {
        return this.getById(getKey(param));
    }
 
    private MaterialTraceability getEntity(MaterialTraceabilityParam param) {
        MaterialTraceability entity = new MaterialTraceability();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
    @Override
    public int updateSFC(String sfcCode, String childSfcCode) {
        return this.baseMapper.updateSFC(sfcCode, childSfcCode);
    }
 
 
}