Helius
2021-06-16 5728be2af515b2200e782aa201ca5d4d67d9ea47
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
package com.ibeetl.admin.console.service;
 
import com.ibeetl.admin.console.dao.XzxOrderBatchInfoDao;
import com.ibeetl.admin.core.entity.XzxOrderBatchInfo;
import com.ibeetl.admin.core.service.CoreBaseService;
import com.ibeetl.admin.core.util.PlatformException;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
/**
 * XzxOrderBatchInfo Service
 */
 
@Service
@Transactional
public class XzxOrderBatchInfoService extends CoreBaseService<XzxOrderBatchInfo> {
 
    @Autowired private XzxOrderBatchInfoDao xzxOrderBatchInfoDao;
 
    public PageQuery<XzxOrderBatchInfo>queryByCondition(PageQuery query){
        PageQuery ret =  xzxOrderBatchInfoDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }
 
    public void batchDelXzxOrderBatchInfo(List<Long> ids){
        try {
            xzxOrderBatchInfoDao.batchDelXzxOrderBatchInfoByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除XzxOrderBatchInfo失败", e);
        }
    }
 
    public Map<String,Object> queryBatchInfoDetailList(String weightError, String  startTime,String  endTime,String userId,String vehicleId,String page, String limit){
        int p = 0;
        int lm = 10;
        if(null!=page&&!"".equals(page)){
            p = (Integer.parseInt(page) - 1) * Integer.parseInt(limit);
        }
        if(null!=limit&&!"".equals(limit)){
            lm = Integer.parseInt(limit);
        }
        List<Map<String,Object>> data = xzxOrderBatchInfoDao.queryBatchInfoDetailList(weightError, startTime,endTime,userId,vehicleId,p,lm);
        List<Map<String,String>> dataTimeWeightList = new ArrayList<>();
        for (Map<String,Object> obj:data) {
            //同一天的空车重量相同,对应打卡空车重量也相同。
            String orderId = obj.get("orderId").toString();
            if(orderId.equals("0")){
                Map<String,String> map = new HashMap<>();
                String time = obj.get("createtime").toString();
                String[] dayStr = time.split(" ");
                String cweight = obj.get("cweight").toString();
                map.put("day",dayStr[0]);
                map.put("clockWeight",cweight);
                dataTimeWeightList.add(map);
                obj.put("clockWeight","-");
            }
        }
        //赋值给载重车的空车重量
        for (Map<String,Object> obj:data) {
            String orderId = obj.get("orderId").toString();
            BigDecimal we = new BigDecimal("0");
            if(!"0".equals(orderId)){
                String time = obj.get("createtime").toString();
                String timeStr = time.split(" ")[0];
                Map<String,Object> clockObj =xzxOrderBatchInfoDao.queryEmptyWeight(weightError, timeStr+" 00:00:00",timeStr+" 23:59:59",userId,vehicleId);
                if(null!=clockObj){
                    obj.put("clockWeight",clockObj.get("cweight").toString());
                    we = new BigDecimal(obj.get("cweight").toString()).subtract(new BigDecimal(clockObj.get("cweight").toString()));
                }
            }else{
                we = new BigDecimal(obj.get("cweight").toString()).subtract(new BigDecimal(obj.get("vweight").toString()));
 
            }
            obj.put("weightError",we.toString());
        }
 
        Map<String, Object> map = new HashMap<>();
        map.put("data", data);
        map.put("count", xzxOrderBatchInfoDao.queryBatchInfoDetailCount(weightError, startTime,endTime,userId,vehicleId));
        map.put("code", 0);
        return map;
    }
 
    public Map<String,Object> queryClockDetailList(String weightError, String  startTime,String  endTime,String userId,String vehicleId,String page, String limit){
        int p = 0;
        int lm = 10;
        if(null!=page&&!"".equals(page)){
            p = (Integer.parseInt(page) - 1) * Integer.parseInt(limit);
        }
        if(null!=limit&&!"".equals(limit)){
            lm = Integer.parseInt(limit);
        }
        List<Map<String,Object>> data = xzxOrderBatchInfoDao.queryClockDetailList(weightError, startTime,endTime,userId,vehicleId,p,lm);
        for (Map<String,Object> obj:data) {
            obj.put("clockWeight","-");
            BigDecimal we = new BigDecimal("0");
            we = new BigDecimal(obj.get("cweight").toString()).subtract(new BigDecimal(obj.get("vweight").toString()));
            obj.put("weightError",we.toString());
 
        }
        Map<String, Object> map = new HashMap<>();
        map.put("data", data);
        map.put("count", xzxOrderBatchInfoDao.queryClockDetailCount(weightError, startTime,endTime,userId,vehicleId));
        map.put("code", 0);
        return map;
    }
 
    public Map<String,Object> queryBatchDetailList(String weightError, String  startTime,String  endTime,String userId,String vehicleId,String page, String limit){
        int p = 0;
        int lm = 10;
        if(null!=page&&!"".equals(page)){
            p = (Integer.parseInt(page) - 1) * Integer.parseInt(limit);
        }
        if(null!=limit&&!"".equals(limit)){
            lm = Integer.parseInt(limit);
        }
        List<Map<String,Object>> data = xzxOrderBatchInfoDao.queryBatchDetailList(weightError, startTime,endTime,userId,vehicleId,p,lm);
        for (Map<String,Object> obj:data) {
            //计算当天打卡空车重量
            String time = obj.get("createtime").toString();
            String timeStr = time.split(" ")[0];
            Map<String,Object> clockObj =xzxOrderBatchInfoDao.queryEmptyWeight(weightError, timeStr+" 00:00:00",timeStr+" 23:59:59",userId,vehicleId);
            if(null!=clockObj){
                obj.put("clockWeight",clockObj.get("cweight").toString());
 
                BigDecimal we = new BigDecimal("0");
                we = new BigDecimal(obj.get("bweight").toString()).subtract(new BigDecimal(clockObj.get("cweight").toString()));
                obj.put("weightError",we.toString());
            }
 
 
        }
        Map<String, Object> map = new HashMap<>();
        map.put("data", data);
        map.put("count", xzxOrderBatchInfoDao.queryBatchDetailCount(weightError, startTime,endTime,userId,vehicleId));
        map.put("code", 0);
        return map;
    }
}