chenlu
2025-12-01 1e56bd5cc3be7f7957788f2606c7f56cb4d27f50
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
163
164
package com.example.erp.service.sd;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.erp.entity.sd.BasicGlassType;
import com.example.erp.entity.sd.ProcessAttributeConfig;
import com.example.erp.mapper.sd.BasicGlassTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
@Service
@DS("sd")
public class BasicGlassTypeService {
    @Autowired
    BasicGlassTypeMapper basicGlassTypeMapper;
    public List<BasicGlassType> getOneLevel() {
        return basicGlassTypeMapper.getOneLevel();
    }
 
    public List<BasicGlassType>  getTwoLevel() {
        return basicGlassTypeMapper.getTwoLevel();
    }
 
    public List<Map<String,String>> getAll() {
        List<BasicGlassType> oneGlassType = basicGlassTypeMapper.getOneLevel();
        List<BasicGlassType> twoGlassType = basicGlassTypeMapper.getTwoLevel();
        List<Map<String,String>> list = new ArrayList<>();
        for (BasicGlassType glassType : oneGlassType) {
            Map<String, String> map = new HashMap<>();
            map.put("value", glassType.getTypeId());
            map.put("label", glassType.getTypeName());
            map.put("children", "");
            List<String> equalList = new ArrayList<>();
            for (BasicGlassType basicGlassType : twoGlassType) {
                if (Objects.equals(basicGlassType.getBelong(), glassType.getTypeId())) {
                    Map<String,String> getMap = JSON.parseObject(JSON.toJSONString(basicGlassType), Map.class);
                    getMap.put("value",getMap.get("typeId"));
                    getMap.put("label",getMap.get("typeName"));
                    equalList.add(JSON.toJSONString(getMap)   );
                }
            }
            map.replace("children",equalList.toString());
            list.add(map);
        }
        return list;
    }
 
    public List<BasicGlassType> findAll() {
        return basicGlassTypeMapper.selectList(null);
    }
 
    public Boolean deleteById(Integer id) {
        return basicGlassTypeMapper.deleteById(id) > 0;
    }
 
    public List<Map<String,Object>> getOneLevelListMap() {
        List<BasicGlassType> oneGlassType = basicGlassTypeMapper.getOneLevel();
        List<Map<String,Object>> list = new ArrayList<>();
        for (BasicGlassType glassType : oneGlassType) {
            Map<String,Object> map = new HashMap<>();
            map.put("value", glassType.getTypeId());
            map.put("label", glassType.getTypeName());
            list.add(map);
        }
        return list;
    }
 
    public Boolean add(Map<String, Object> map) {
        List<Object> list = (List<Object>) map.get("glassLevel");
        if(list.get(0)==null
                || map.get("value") == null
                || map.get("value").equals("")){
            return false;
        }
        BasicGlassType basicGlassTypeS = new BasicGlassType();
        if(map.get("type").equals("add")){
            if(list.size()==1){
                BasicGlassType basicGlassType =  basicGlassTypeMapper.selectMaxType((Integer) list.get(0));
                int maxId = Integer.parseInt(basicGlassType.getTypeId());
                String newTypeId = String.format("%02d", maxId+1);
                basicGlassTypeS.setLevel((Integer) list.get(0));
                basicGlassTypeS.setTypeId(newTypeId);
                basicGlassTypeS.setTypeName((String) map.get("value"));
            }else if(list.size()==2) {
                BasicGlassType basicGlassType =  basicGlassTypeMapper.selectMaxTowLevelType((String) list.get(1));
                Integer maxId = null;
                if(basicGlassType==null){
                    maxId = 0;
                }else {
                    maxId = Integer.parseInt(basicGlassType.getTypeId().substring(2));
                }
 
                String newTypeId =list.get(1) + String.format("%02d", maxId+1);
                basicGlassTypeS.setLevel((Integer) list.get(0));
                basicGlassTypeS.setTypeId(newTypeId);
                basicGlassTypeS.setTypeName((String) map.get("value"));
                basicGlassTypeS.setBelong((String) list.get(1));
            }
            return basicGlassTypeMapper.insert(basicGlassTypeS)>0;
        }else{
            basicGlassTypeS.setId((Integer) map.get("id"));
            basicGlassTypeS.setTypeName((String) map.get("value"));
           return basicGlassTypeMapper.updateGlassTypeName(basicGlassTypeS);
        }
 
    }
 
    public List<ProcessAttributeConfig> findAllConfig() {
        return basicGlassTypeMapper.getFindAllConfig();
    }
 
    public List<Map<String,Object>> getOneLevelListMapConfig() {
        List<ProcessAttributeConfig> processAttributeConfigList = basicGlassTypeMapper.getOneLevelListMapConfig();
        List<Map<String,Object>> list = new ArrayList<>();
        for (ProcessAttributeConfig processAttributeConfig : processAttributeConfigList) {
            Map<String,Object> map = new HashMap<>();
            map.put("value", processAttributeConfig.getInputType());
            map.put("label", processAttributeConfig.getProcessName());
            list.add(map);
        }
        return list;
    }
 
    public Boolean addConfig(Map<String, Object> map) {
        List<Object> list = (List<Object>) map.get("glassLevel");
        if(list.get(0)==null
                || map.get("processType") == null
                || map.get("processType").equals("")){
            return false;
        }
        ProcessAttributeConfig processAttributeConfigS = new ProcessAttributeConfig();
        if(map.get("type").equals("add")){
            if(list.size()==1){
                ProcessAttributeConfig processAttributeConfig =  basicGlassTypeMapper.selectMaxTypeConfig((Integer) list.get(0));
                int maxId = Integer.parseInt(processAttributeConfig.getInputType());
                String newTypeId = String.format("%02d", maxId+1);
                processAttributeConfigS.setLevel((Integer) list.get(0));
                processAttributeConfigS.setInputType(newTypeId);
                processAttributeConfigS.setProcessType((String) map.get("processType"));
                processAttributeConfigS.setProcessName((String) map.get("processName"));
            }else if(list.size()==2) {
                processAttributeConfigS.setLevel((Integer) list.get(0));
                processAttributeConfigS.setInputType((String) map.get("inputType"));
                processAttributeConfigS.setProcessType((String) map.get("processType"));
                processAttributeConfigS.setProcessName((String) map.get("processName"));
                processAttributeConfigS.setBelong((String) list.get(1));
            }
            return basicGlassTypeMapper.insertProcessAttributeConfig(processAttributeConfigS);
        }else{
            processAttributeConfigS.setId((Integer) map.get("id"));
            processAttributeConfigS.setInputType((String) map.get("inputType"));
            processAttributeConfigS.setProcessType((String) map.get("processType"));
            processAttributeConfigS.setProcessName((String) map.get("processName"));
            return basicGlassTypeMapper.updateProcessAttributeConfig(processAttributeConfigS);
        }
 
    }
 
    public Boolean deleteProcessAttributeConfig(Integer id) {
        return basicGlassTypeMapper.deleteProcessAttributeConfig(id);
    }
}