廖井涛
2024-10-22 178f3650c79a862af82642a152a861d686b2baaa
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
package com.example.erp.service.mm;
 
import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.erp.entity.mm.MaterialStore;
import com.example.erp.entity.userInfo.Log;
import com.example.erp.entity.userInfo.SysError;
import com.example.erp.mapper.mm.BasicWarehouseTypeMapper;
import com.example.erp.mapper.mm.MaterialInventoryMapper;
import com.example.erp.mapper.mm.MaterialStoreMapper;
import com.example.erp.service.userInfo.LogService;
import com.example.erp.service.userInfo.SysErrorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
import java.text.DecimalFormat;
import java.util.*;
 
@Service
@DS("mm")
@Transactional(rollbackFor = Exception.class)
public class MaterialStoreService {
    @Autowired
    MaterialStoreMapper materialStoreMapper;
    @Autowired
    MaterialInventoryMapper materialInventoryMapper;
    @Autowired
    BasicWarehouseTypeMapper basicWarehouseTypeMapper;
    @Autowired
    SysErrorService sysErrorService;
    @Autowired
    LogService logService;
 
    public String saveMaterialStore(Map<String,Object> object) {
        String saveState = "true";
        //设置回滚点
        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
        try {
            String id = "";
            String type = "";
            String json = "";
            double width = 0.0;
            double height = 0.0;
            double singlePieceArea=0.0;
            if (object.get("id") != null) {
                id = object.get("id").toString();
            }
            if (object.get("type") != null) {
                type = object.get("type").toString();
            }
            if (object.get("json") != null) {
                json = object.get("json").toString();
            }
            if (object.get("width") != null) {
                width = Double.parseDouble(object.get("width").toString());
            }
            if (object.get("height") != null) {
                height = Double.parseDouble(object.get("height").toString());
            }
 
            Log log = new Log();
            log.setOperatorId(object.get("userId").toString());
            log.setOperator(object.get("userName").toString());
            log.setContent(object.toString());
 
            DecimalFormat decimalFormat = new DecimalFormat("#0.00");
            singlePieceArea= Double.parseDouble(decimalFormat.format(width * height / 100000));
            Integer jsonCount=materialStoreMapper.selectMaterialStoreJson(json);
            if(jsonCount==0){
                if(Long.parseLong(id)>0){
                    materialStoreMapper.updateMaterialStore(type,json, Long.valueOf(id));
                    if (Objects.equals(type, "原片")){
                        materialInventoryMapper.updateMaterialInventoryArea(Long.valueOf(id),singlePieceArea);
                    }
                    log.setFunction("saveMaterialStore修改");
                }else{
                    materialStoreMapper.insertMaterialStore(type,json);
                    log.setFunction("saveMaterialStore新增");
                }
            }else{
                saveState = "false1";
            }
            logService.saveLog(log);
 
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
            //将异常传入数据库
            SysError sysError = new SysError();
            sysError.setError(e+Arrays.toString(e.getStackTrace()));
            sysError.setFunc("saveMaterialStore");
            sysErrorService.insert(sysError);
            saveState = "false";
 
        }
        return saveState;
 
    }
 
    public Map<String, Object> getSelectMaterialStore(Integer pageNum, Integer pageSize, MaterialStore materialStore) {
        Integer offset = (pageNum - 1) * pageSize;
 
        Map<String, Object> map = new HashMap<>();
        map.put("data", materialStoreMapper.getSelectMaterialStore(offset, pageSize, materialStore));
        map.put("total", materialStoreMapper.getSelectMaterialStorePageTotal(offset, pageSize, materialStore));
        return map;
    }
 
    public String deleteMaterialStore(Map<String,Object> object) {
        String saveState = "true";
        //设置回滚点
        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
        try {
            String id = "";
            if (object.get("id") != null) {
                id = object.get("id").toString();
            }
            if(id!=null){
                Integer materialCount=materialStoreMapper.selectMaterialStore(Long.valueOf(id));
                if(materialCount==0){
                    materialStoreMapper.deleteMaterialStore(Long.valueOf(id));
                }else{
                    saveState="false1";
                }
 
            }
            Log log = new Log();
            log.setOperatorId(object.get("userId").toString());
            log.setOperator(object.get("userName").toString());
            log.setContent(object.toString());
            log.setFunction("deleteMaterialStore删除:"+id);
            logService.saveLog(log);
 
 
 
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
            //将异常传入数据库
            SysError sysError = new SysError();
            sysError.setError(e+Arrays.toString(e.getStackTrace()));
            sysError.setFunc("deleteMaterialStore");
            sysErrorService.insert(sysError);
            saveState = "false";
 
        }
        return saveState;
 
    }
 
 
 
 
 
 
 
 
}