guoyujie
2 天以前 c4b9a339caff12e95f61c3d5dc950aafcc8c566c
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
165
166
167
168
169
170
171
172
173
174
175
package com.example.erp.service.sd;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.erp.dto.sd.CustomerDTO;
import com.example.erp.dto.sd.DeliveryDetailDTO;
import com.example.erp.dto.sd.DeliveryDetailProductDTO;
import com.example.erp.entity.sd.*;
import com.example.erp.entity.userInfo.Log;
import com.example.erp.entity.userInfo.SysError;
import com.example.erp.mapper.mm.FinishedGoodsInventoryMapper;
import com.example.erp.mapper.sd.*;
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.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
 
@Service
@DS("sd")
@Transactional(rollbackFor = Exception.class)
public class CustomerService {
    @Autowired
    CustomerMapper customerMapper;
    @Autowired
    SysErrorService sysErrorService;
    @Autowired
    LogService logService;
 
 
    public Map<String, Object> getSelectCustomer(Integer pageNum, Integer pageSize, Customer customer) {
        Integer offset = (pageNum - 1) * pageSize;
 
        Map<String, Object> map = new HashMap<>();
        map.put("data", customerMapper.getSelectCustomer(offset, pageSize, customer));
        map.put("total", customerMapper.getSelectCustomerPageTotal(offset, pageSize, customer));
        return map;
    }
 
 
    public Boolean insertCustomer(Map<String,Object> object) {
        boolean saveState = true;
        Log log = new Log();
        log.setOperatorId(object.get("userId").toString());
        log.setOperator(object.get("userName").toString());
        log.setContent(object.toString());
        //设置回滚点
        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
        try {
            Customer customer = JSONObject.parseObject(JSONObject.toJSONString(object.get("customer")), Customer.class);
           if(customer!=null){
               if (customer.getId()!=null && customer.getId()!=0){
                   customerMapper.updateCustomer(customer);
                   log.setFunction("insertCustomer修改");
               }else{
                   customerMapper.insertCustomer(customer);
                   log.setFunction("insertCustomer新增");
               }
               logService.saveLog(log);
 
           }
 
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
            //将异常传入数据库
            SysError sysError = new SysError();
            sysError.setError(Arrays.toString(e.getStackTrace()));
            sysError.setFunc("saveOrder");
            sysErrorService.insert(sysError);
            saveState = false;
 
        }
        return saveState;
 
    }
 
    public Boolean deleteCustomer(Map<String,Object> object) {
        boolean saveState = true;
        //设置回滚点
        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
        try {
            Customer customer = JSONObject.parseObject(JSONObject.toJSONString(object.get("customer")), Customer.class);
            if(customer!=null){
                if (customer.getId()!=null){
                    customerMapper.deleteCustomer(customer);
                }
                Log log = new Log();
                log.setOperatorId(object.get("userId").toString());
                log.setOperator(object.get("userName").toString());
                log.setContent(object.toString());
                log.setFunction("deleteCustomer删除");
                logService.saveLog(log);
 
            }
 
 
 
        } 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;
 
    }
 
    public Map<String, Object> getSelectCustomerOderDate(Integer pageNum, Integer pageSize,List<String> selectDate, OrderDetail orderDetail) {
        Integer offset = (pageNum - 1) * pageSize;
        String endDate = LocalDate.now().toString();
        String startDate = LocalDate.now().minusDays(15).toString();
        if(selectDate !=null && selectDate.size()==2){
            if(!selectDate.get(0).isEmpty()){
                startDate = selectDate.get(0);
            }
            if(!selectDate.get(1).isEmpty()){
                endDate = selectDate.get(1);
            }
        }
        Map<String, Object> map = new HashMap<>();
        if(Objects.equals(orderDetail.getOrder().getBatch(), "1")){
            map.put("data", customerMapper.getSelectCustomerOderDate(offset, pageSize,startDate,endDate, orderDetail));
            map.put("total", customerMapper.getSelectCustomerOderDatePageTotal(offset, pageSize,startDate,endDate, orderDetail));
        }else{
            map.put("data", customerMapper.getSelectCustomerDeliveryDate(offset, pageSize,startDate,endDate, orderDetail));
            map.put("total", customerMapper.getSelectCustomerDeliveryDatePageTotal(offset, pageSize,startDate,endDate, orderDetail));
        }
 
        List<String> list = new ArrayList<>();
        list.add(startDate);
        list.add(endDate);
        map.put("selectDate",list);
        return map;
    }
 
    public List<CustomerDTO> exportSelectCustomerOderDate(List<String> selectDate, OrderDetail orderDetail) {
        String endDate = LocalDate.now().toString();
        String startDate = LocalDate.now().minusDays(15).toString();
        if(selectDate !=null && selectDate.size()==2){
            if(!selectDate.get(0).isEmpty()){
                startDate = selectDate.get(0);
            }
            if(!selectDate.get(1).isEmpty()){
                endDate = selectDate.get(1);
            }
        }
        return customerMapper.exportSelectCustomerOderDate(startDate,endDate, orderDetail);
    }
 
    public List<CustomerDTO> exportSelectCustomerDeliveryDate(List<String> selectDate, OrderDetail orderDetail) {
        String endDate = LocalDate.now().toString();
        String startDate = LocalDate.now().minusDays(15).toString();
        if(selectDate !=null && selectDate.size()==2){
            if(!selectDate.get(0).isEmpty()){
                startDate = selectDate.get(0);
            }
            if(!selectDate.get(1).isEmpty()){
                endDate = selectDate.get(1);
            }
        }
        return customerMapper.exportSelectCustomerDeliveryDate(startDate,endDate, orderDetail);
    }
 
 
}