guoyuji
2024-03-27 baeae530bc5dfdd23359f34b047f449c1541359f
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
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.SysError;
import com.example.erp.mapper.mm.BasicWarehouseTypeMapper;
import com.example.erp.mapper.mm.MaterialStoreMapper;
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.util.*;
 
@Service
@DS("mm")
@Transactional(rollbackFor = Exception.class)
public class MaterialStoreService {
    @Autowired
    MaterialStoreMapper materialStoreMapper;
    @Autowired
    BasicWarehouseTypeMapper basicWarehouseTypeMapper;
    @Autowired
    SysErrorService sysErrorService;
 
    public Boolean saveMaterialStore(Map<String,Object> object) {
        boolean saveState = true;
            String id = "";
            String type = "";
            String json = "";
            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(Long.parseLong(id)>0){
                materialStoreMapper.updateMaterialStore(type,json, Long.valueOf(id));
            }else{
                materialStoreMapper.insertMaterialStore(type,json);
            }
 
        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 Boolean deleteMaterialStore(Map<String,Object> object) {
        boolean saveState = true;
        //设置回滚点
        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
        try {
            String id = "";
            if (object.get("id") != null) {
                id = object.get("id").toString();
            }
            if(id!=null){
                materialStoreMapper.deleteMaterialStore(Long.valueOf(id));
            }
 
 
 
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
            //将异常传入数据库
            SysError sysError = new SysError();
            sysError.setError(e.toString());
            sysError.setFunc("saveOrder");
            sysErrorService.insert(sysError);
            saveState = false;
 
        }
        return saveState;
 
    }
 
 
 
 
 
 
 
 
}