hjg
2024-02-05 301115d5e96b56cd093eee3fcff2d60a15184162
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
package com.mandi.fendan.service.impl;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
 
import javax.annotation.Resource;
import javax.transaction.Transactional;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
 
import com.mandi.common.ParamFileter.RegexCheck;
import com.mandi.dao.common.Daomethod;
import com.mandi.dao.common.ObjectResult;
import com.mandi.dao.common.PageRequest;
import com.mandi.dao.common.PageResult;
import com.mandi.fendan.mapper.Fd_BsheetMapper;
import com.mandi.fendan.mapper.Fd_CompanyMapper;
import com.mandi.fendan.mapper.Fd_VehicleMapper;
import com.mandi.fendan.mapper.VehicleXSTDMapper;
import com.mandi.fendan.persist.Fd_Bsheet;
import com.mandi.fendan.persist.Fd_Company;
import com.mandi.fendan.persist.Fd_Vehicle;
import com.mandi.fendan.persist.VehicleStatus;
import com.mandi.fendan.persist.VehicleType;
import com.mandi.fendan.persist.Vehicle_XSTD;
import com.mandi.fendan.service.Ifd_vehicleService;
import com.mandi.fendan.util.persist.Serviceenum;
import com.mandi.system.persist.Login;
import com.mandi.system.persist.UserType;
@Service
public class Fd_VehicleService implements Ifd_vehicleService {
    @Resource
    private Fd_VehicleMapper Fd_Vcper;
    @Resource
    private Fd_CompanyMapper fdcper;
    @Resource
    private Fd_BsheetMapper fdbper;
    @Resource
    private VehicleXSTDMapper vxper;
    
    
    @Override
    public ObjectResult<Fd_Vehicle> getFd_VehicleById(String id) {
        ObjectResult<Fd_Vehicle> prr = new ObjectResult<Fd_Vehicle>();
        if(!StringUtils.isBlank(id)){
            Fd_Vehicle fve = Fd_Vcper.get(id);
            prr.setCode(0);
            prr.setItem(fve);
        }else{
            prr.setCode(1);
            prr.setErrmsg("查询值为空,不能查询!");;
        }
        
        return prr;
 
    }
    public ObjectResult<Fd_Vehicle> getFd_VehicleByFd_VehicleId(String vehicleId) {
        ObjectResult<Fd_Vehicle> prr = new ObjectResult<Fd_Vehicle>();
        if(!StringUtils.isBlank(vehicleId)){
            Fd_Vehicle fcy = Fd_Vcper.getByVehicleId(vehicleId);
            prr.setCode(0);
            prr.setItem(fcy);
        }else{
            prr.setCode(1);
            prr.setErrmsg("车牌号不能为空");;
        }
        
        return prr;
    }
    @Override
    public PageResult<Map<String, Object>> getList(Map<String,Object> map,PageRequest pr) {
        PageResult<Map<String, Object>> prr=new PageResult<Map<String, Object>>();
 
        map.put("pagesize", pr.getPageSize());
        map.put("page", pr.getStart());
        map.put("type", VehicleType.公司车.toString());
        List<Map<String, Object>> list;
        if(pr.isNeedPages())
        {
            int pages=Fd_Vcper.getPages(map);
            pages=Daomethod.countpages(pages, pr.getPageSize());
            prr.setPages(pages);
            list=Fd_Vcper.getList2(map);
        }else{
            list=Fd_Vcper.getList1(map);
            prr.setPages(0);
        }
        
        prr.setCode(0);
        prr.setList(list);
        return prr;
    }
 
    @Override
    public PageResult<Map<String, Object>> getalllist(Login lg,String companyNo,String vId) {
        PageResult<Map<String, Object>> prr=new PageResult<Map<String, Object>>();
        List<Map<String, Object>> ll=new ArrayList<Map<String,Object>>();
        if(lg==null){
            prr.setCode(1);
            prr.setErrmsg("请登录账号!");
            return prr;
        }
        String cmc=companyNo;
        Map<String, Object> map=new HashMap<String, Object>();
        if(StringUtils.isEmpty(companyNo)){
            if(UserType.admin.toString().equals(lg.getWorkerno())){
                map.put("companyNo","");
                cmc="";
            }else{
                prr.setList(ll);
                prr.setCode(0);
                return prr;
            }
        }else{
            map.put("companyNo",companyNo);
        }
        map.put("vehicleId",vId);
        List<Map<String, Object>> clist=Fd_Vcper.getCompanyVehicle(map);
        if(clist==null){
            clist=new ArrayList<Map<String,Object>>();
        }
        List<Map<String, Object>> rlist=new ArrayList<Map<String,Object>>();
        if(clist!=null){
            List<Vehicle_XSTD> vxlist=vxper.getlistbycomNo(cmc);
            for (Map<String, Object> map2 : clist) {
                String vehicleId=map2.get("vehicleId")==null?"":map2.get("vehicleId").toString();
//                List<Vehicle_XSTD> vxlist=vxper.getlistbyVehicleId(vehicleId);
                if(vxlist!=null){
                    for (Vehicle_XSTD vehicle_XSTD2 : vxlist) {
                        try{
                            if(vehicle_XSTD2.getVehicleId().equals(vehicleId)){        
                                map2.put("fdCnum", Integer.parseInt(map2.get("fdCnum")==null?"0":map2.get("fdCnum").toString())+vehicle_XSTD2.getFd_num());
                                map2.put("fdCweight", Double.parseDouble(map2.get("fdCweight")==null?"0":map2.get("fdCweight").toString())+vehicle_XSTD2.getFd_weight());
                                if(vehicle_XSTD2.getCompanyNo()!=null&&vehicle_XSTD2.getCompanyNo().equals(lg.getDepartno())){
                                    map2.put("fdnum", Double.parseDouble(map2.get("fdnum")==null?"0":map2.get("fdnum").toString())+vehicle_XSTD2.getFd_weight());
                                    map2.put("fdweight", Double.parseDouble(map2.get("fdweight")==null?"0":map2.get("fdweight").toString())+vehicle_XSTD2.getFd_weight());
                                }
                            }
                        } catch (Exception e) {
                            prr.setCode(1);
                            prr.setErrmsg("数据转换错误,请刷新页面重新获取数据!");
                            return prr;
                        }
                    }
                }
                rlist.add(map2);
            }
        }
        prr.setCode(0);
        prr.setList(rlist);
        return prr;
    }
    
    @Override
    public ObjectResult<Boolean> validVehicle(Login lg, String vehicleId) {
        ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
        if(!StringUtils.isEmpty(vehicleId)){
            boolean boo=RegexCheck.isVehicleID(vehicleId);
            if(!boo){
                orr.setCode(1);
                orr.setErrmsg("车牌号验证不正确,请输入正确的车牌号!");
                return orr;
            }
        }else{
            orr.setCode(1);
            orr.setErrmsg("参数车牌号为空,请输入!");
            return orr;
        }
        orr.setCode(0);
        return orr;
    }
    
    @Override
    @Transactional(rollbackOn=Exception.class)
    public ObjectResult<Fd_Vehicle> saveFd_Vehicle(Fd_Vehicle cq,Login lg) throws Exception {
        ObjectResult<Fd_Vehicle> or = new ObjectResult<Fd_Vehicle>();
        if(lg==null){
            or.setCode(1);
            or.setErrmsg("请登录账号!");
            return or;
        }
        if(cq==null){
            or.setCode(1);
            or.setErrmsg("车辆对象为空,不能保存!");
        }else{
            if(StringUtils.isEmpty(cq.getVehicleId())||StringUtils.isEmpty(cq.getIDNum())||StringUtils.isEmpty(cq.getPhone())||StringUtils.isEmpty(cq.getDriver())){
                or.setCode(1);
                or.setErrmsg("必填项不能为空!");
                return or;
            }
            String companyNo=cq.getCompanyNo();
            Fd_Company fdc=fdcper.getByCompanyNo(companyNo);
            if(fdc==null){
                or.setCode(1);
                or.setErrmsg("运输公司未找到,车辆信息不能保存,请选择正确的运输公司!");    
                return or;
            }
            if(StringUtils.isEmpty(cq.getVehicleId())){
                or.setCode(1);
                or.setErrmsg("车牌号不能为空,请修改后保存!");    
                return or;
            }
            boolean boo=RegexCheck.isVehicleID(cq.getVehicleId());
            if(!boo){
                or.setCode(1);
                or.setErrmsg("车牌号不正确,请修改!");    
                return or;
            }
            Fd_Vehicle cc=Fd_Vcper.getByVehicleId(cq.getVehicleId());
            if(cc!=null){
                if(!cc.getId().equals(cq.getId())){
                    or.setCode(1);
                    or.setErrmsg("该车牌号已经存在,不能重复保存!");    
                    return or;
                }
            }
            
//                if(cq.getId()!=null){
            Fd_Vehicle fd_Vehicle = Fd_Vcper.getByVehicleId(cq.getVehicleId());
            if(fd_Vehicle==null){
                cq.setId(UUID.randomUUID()+"");
                cq.setState(true);
                cq.setStatus(VehicleStatus.未配车);
                cq.setType(VehicleType.公司车);
                int insert = Fd_Vcper.insert(cq);
                if(insert>0){
                    or.setCode(0);
                    or.setItem(cq);
                }else{
                    or.setCode(1);
                    or.setErrmsg("保存失败");
                }
            }else{
                cq.setStatus(cc.getStatus());
                cq.setType(cc.getType());
                int update = Fd_Vcper.update(cq);
                or.setCode(0);
                or.setItem(cq);
            }
//                }else{
//                    or.setCode(1);
//                    or.setErrmsg("对象主键不能为空");
//                }
            
//            Fd_Company_Vehicle fdvc=fdcvper.getbyIDs(cq.getVehicleId(), lg.getDepartno());
//            if(fdvc==null){
//                fdvc=new Fd_Company_Vehicle();
//                fdvc.setCompanyNo(lg.getDepartno());
//                fdvc.setVehicleId(cq.getVehicleId());
//                fdcvper.insert(fdvc);
//            }
            
 
        }
        return or;
    }
    
    
    
 
    @Override
    @Transactional(rollbackOn=Exception.class)
    public ObjectResult<Boolean> changeState(String vehicleId, Login lg, boolean state)
            throws Exception {
        ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
        if(lg==null){
            orr.setCode(1);
            orr.setErrmsg("账号未登录,请重新登录!");
            return orr;
        }
        Fd_Vehicle fv= Fd_Vcper.getByVehicleId(vehicleId);
        if(fv==null){
            orr.setCode(1);
            orr.setErrmsg("该车辆不存在!");
            return orr;
        }
        if(!UserType.admin.toString().equals(lg.getWorkerno())){
            if(!StringUtils.isEmpty(lg.getDepartno())){
                if(!lg.getDepartno().equals(fv.getCompanyNo())){
                    orr.setCode(1);
                    orr.setErrmsg("你没有权限修改分本公司车辆!");
                    return orr;
                }
            }
        }
        fv.setState(state);
        Fd_Vcper.update(fv);
        orr.setCode(0);
        orr.setItem(state);
        return orr;
    }
    @Override
    @Transactional(rollbackOn=Exception.class)
    public ObjectResult<Boolean> delFd_Vehicle(String vehicleId) throws Exception {
        
        ObjectResult<Boolean> prr = new ObjectResult<Boolean>();
        if(!StringUtils.isBlank(vehicleId)){
            Fd_Vehicle fdv=Fd_Vcper.getByVehicleId(vehicleId);
            if(fdv!=null){
                List<Fd_Bsheet> fdb=fdbper.getListbyVehicleId(vehicleId,Serviceenum.在办);
                if(fdb!=null&&!fdb.isEmpty()){
                    prr.setCode(1);
                    prr.setErrmsg("车辆有在办的提单,不能删除,等业务办完之后再删除!");
                    return prr;
                }
//                if(fdv.getStatus()!=VehicleStatus.未配车){
//                    prr.setCode(1);
//                    prr.setErrmsg("车辆状态不是未配车状态,不能删除!");
//                    return prr;
//                }
            }
            int i = Fd_Vcper.delByVehicleId(vehicleId);
//            fdcvper.delbyID(vehicleId);
            prr.setCode(0);
            prr.setItem(true);
        }else{
            prr.setCode(1);
            prr.setItem(false);
            prr.setErrmsg("车牌号不能为空");;
        }
        
        return prr;
    }
 
}