Administrator
2023-03-10 1c4e40639d73faae3ba87156e0e4478c50b8ee33
提交 | 用户 | 时间
58d006 1 package com.mandi.fendan.service.impl;
A 2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7 import java.util.UUID;
8
9 import javax.annotation.Resource;
10 import javax.transaction.Transactional;
11
12 import org.apache.commons.lang3.StringUtils;
13 import org.springframework.stereotype.Service;
14
15 import com.mandi.common.ParamFileter.RegexCheck;
16 import com.mandi.dao.common.Daomethod;
17 import com.mandi.dao.common.ObjectResult;
18 import com.mandi.dao.common.PageRequest;
19 import com.mandi.dao.common.PageResult;
20 import com.mandi.fendan.mapper.Fd_BsheetMapper;
21 import com.mandi.fendan.mapper.Fd_CompanyMapper;
22 import com.mandi.fendan.mapper.Fd_VehicleMapper;
23 import com.mandi.fendan.mapper.VehicleXSTDMapper;
24 import com.mandi.fendan.persist.Fd_Bsheet;
25 import com.mandi.fendan.persist.Fd_Company;
26 import com.mandi.fendan.persist.Fd_Vehicle;
27 import com.mandi.fendan.persist.VehicleStatus;
28 import com.mandi.fendan.persist.VehicleType;
29 import com.mandi.fendan.persist.Vehicle_XSTD;
30 import com.mandi.fendan.service.Ifd_vehicleService;
31 import com.mandi.fendan.util.persist.Serviceenum;
32 import com.mandi.system.persist.Login;
33 import com.mandi.system.persist.UserType;
34 @Service
35 public class Fd_VehicleService implements Ifd_vehicleService {
36     @Resource
37     private Fd_VehicleMapper Fd_Vcper;
38     @Resource
39     private Fd_CompanyMapper fdcper;
40     @Resource
41     private Fd_BsheetMapper fdbper;
42     @Resource
43     private VehicleXSTDMapper vxper;
44     
45     
46     @Override
47     public ObjectResult<Fd_Vehicle> getFd_VehicleById(String id) {
48         ObjectResult<Fd_Vehicle> prr = new ObjectResult<Fd_Vehicle>();
49         if(!StringUtils.isBlank(id)){
50             Fd_Vehicle fve = Fd_Vcper.get(id);
51             prr.setCode(0);
52             prr.setItem(fve);
53         }else{
54             prr.setCode(1);
55             prr.setErrmsg("查询值为空,不能查询!");;
56         }
57         
58         return prr;
59
60     }
61     public ObjectResult<Fd_Vehicle> getFd_VehicleByFd_VehicleId(String vehicleId) {
62         ObjectResult<Fd_Vehicle> prr = new ObjectResult<Fd_Vehicle>();
63         if(!StringUtils.isBlank(vehicleId)){
64             Fd_Vehicle fcy = Fd_Vcper.getByVehicleId(vehicleId);
65             prr.setCode(0);
66             prr.setItem(fcy);
67         }else{
68             prr.setCode(1);
69             prr.setErrmsg("车牌号不能为空");;
70         }
71         
72         return prr;
73     }
74     @Override
75     public PageResult<Map<String, Object>> getList(Map<String,Object> map,PageRequest pr) {
76         PageResult<Map<String, Object>> prr=new PageResult<Map<String, Object>>();
77
78         map.put("pagesize", pr.getPageSize());
79         map.put("page", pr.getStart());
80         map.put("type", VehicleType.公司车.toString());
81         List<Map<String, Object>> list;
82         if(pr.isNeedPages())
83         {
84             int pages=Fd_Vcper.getPages(map);
85             pages=Daomethod.countpages(pages, pr.getPageSize());
86             prr.setPages(pages);
87             list=Fd_Vcper.getList2(map);
88         }else{
89             list=Fd_Vcper.getList1(map);
90             prr.setPages(0);
91         }
92         
93         prr.setCode(0);
94         prr.setList(list);
95         return prr;
96     }
97
98     @Override
99     public PageResult<Map<String, Object>> getalllist(Login lg,String companyNo,String vId) {
100         PageResult<Map<String, Object>> prr=new PageResult<Map<String, Object>>();
101         List<Map<String, Object>> ll=new ArrayList<Map<String,Object>>();
102         if(lg==null){
103             prr.setCode(1);
104             prr.setErrmsg("请登录账号!");
105             return prr;
106         }
107         String cmc=companyNo;
108         Map<String, Object> map=new HashMap<String, Object>();
109         if(StringUtils.isEmpty(companyNo)){
110             if(UserType.admin.toString().equals(lg.getWorkerno())){
111                 map.put("companyNo","");
112                 cmc="";
113             }else{
114                 prr.setList(ll);
115                 prr.setCode(0);
116                 return prr;
117             }
118         }else{
119             map.put("companyNo",companyNo);
120         }
121         map.put("vehicleId",vId);
122         List<Map<String, Object>> clist=Fd_Vcper.getCompanyVehicle(map);
123         if(clist==null){
124             clist=new ArrayList<Map<String,Object>>();
125         }
126         List<Map<String, Object>> rlist=new ArrayList<Map<String,Object>>();
127         if(clist!=null){
128             List<Vehicle_XSTD> vxlist=vxper.getlistbycomNo(cmc);
129             for (Map<String, Object> map2 : clist) {
130                 String vehicleId=map2.get("vehicleId")==null?"":map2.get("vehicleId").toString();
131 //                List<Vehicle_XSTD> vxlist=vxper.getlistbyVehicleId(vehicleId);
132                 if(vxlist!=null){
133                     for (Vehicle_XSTD vehicle_XSTD2 : vxlist) {
134                         try{
135                             if(vehicle_XSTD2.getVehicleId().equals(vehicleId)){        
136                                 map2.put("fdCnum", Integer.parseInt(map2.get("fdCnum")==null?"0":map2.get("fdCnum").toString())+vehicle_XSTD2.getFd_num());
137                                 map2.put("fdCweight", Double.parseDouble(map2.get("fdCweight")==null?"0":map2.get("fdCweight").toString())+vehicle_XSTD2.getFd_weight());
138                                 if(vehicle_XSTD2.getCompanyNo()!=null&&vehicle_XSTD2.getCompanyNo().equals(lg.getDepartno())){
139                                     map2.put("fdnum", Double.parseDouble(map2.get("fdnum")==null?"0":map2.get("fdnum").toString())+vehicle_XSTD2.getFd_weight());
140                                     map2.put("fdweight", Double.parseDouble(map2.get("fdweight")==null?"0":map2.get("fdweight").toString())+vehicle_XSTD2.getFd_weight());
141                                 }
142                             }
143                         } catch (Exception e) {
144                             prr.setCode(1);
145                             prr.setErrmsg("数据转换错误,请刷新页面重新获取数据!");
146                             return prr;
147                         }
148                     }
149                 }
150                 rlist.add(map2);
151             }
152         }
153         prr.setCode(0);
154         prr.setList(rlist);
155         return prr;
156     }
157     
158     @Override
159     public ObjectResult<Boolean> validVehicle(Login lg, String vehicleId) {
160         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
161         if(!StringUtils.isEmpty(vehicleId)){
162             boolean boo=RegexCheck.isVehicleID(vehicleId);
163             if(!boo){
164                 orr.setCode(1);
165                 orr.setErrmsg("车牌号验证不正确,请输入正确的车牌号!");
166                 return orr;
167             }
168         }else{
169             orr.setCode(1);
170             orr.setErrmsg("参数车牌号为空,请输入!");
171             return orr;
172         }
173         orr.setCode(0);
174         return orr;
175     }
176     
177     @Override
178     @Transactional(rollbackOn=Exception.class)
179     public ObjectResult<Fd_Vehicle> saveFd_Vehicle(Fd_Vehicle cq,Login lg) throws Exception {
180         ObjectResult<Fd_Vehicle> or = new ObjectResult<Fd_Vehicle>();
181         if(lg==null){
182             or.setCode(1);
183             or.setErrmsg("请登录账号!");
184             return or;
185         }
186         if(cq==null){
187             or.setCode(1);
188             or.setErrmsg("车辆对象为空,不能保存!");
189         }else{
190             if(StringUtils.isEmpty(cq.getVehicleId())||StringUtils.isEmpty(cq.getIDNum())||StringUtils.isEmpty(cq.getPhone())||StringUtils.isEmpty(cq.getDriver())){
191                 or.setCode(1);
192                 or.setErrmsg("必填项不能为空!");
193                 return or;
194             }
195             String companyNo=cq.getCompanyNo();
196             Fd_Company fdc=fdcper.getByCompanyNo(companyNo);
197             if(fdc==null){
198                 or.setCode(1);
199                 or.setErrmsg("运输公司未找到,车辆信息不能保存,请选择正确的运输公司!");    
200                 return or;
201             }
202             if(StringUtils.isEmpty(cq.getVehicleId())){
203                 or.setCode(1);
204                 or.setErrmsg("车牌号不能为空,请修改后保存!");    
205                 return or;
206             }
207             boolean boo=RegexCheck.isVehicleID(cq.getVehicleId());
208             if(!boo){
209                 or.setCode(1);
210                 or.setErrmsg("车牌号不正确,请修改!");    
211                 return or;
212             }
213             Fd_Vehicle cc=Fd_Vcper.getByVehicleId(cq.getVehicleId());
214             if(cc!=null){
215                 if(!cc.getId().equals(cq.getId())){
216                     or.setCode(1);
217                     or.setErrmsg("该车牌号已经存在,不能重复保存!");    
218                     return or;
219                 }
220             }
221             
222 //                if(cq.getId()!=null){
223             Fd_Vehicle fd_Vehicle = Fd_Vcper.getByVehicleId(cq.getVehicleId());
224             if(fd_Vehicle==null){
225                 cq.setId(UUID.randomUUID()+"");
226                 cq.setState(true);
227                 cq.setStatus(VehicleStatus.未配车);
228                 cq.setType(VehicleType.公司车);
229                 int insert = Fd_Vcper.insert(cq);
230                 if(insert>0){
231                     or.setCode(0);
232                     or.setItem(cq);
233                 }else{
234                     or.setCode(1);
235                     or.setErrmsg("保存失败");
236                 }
237             }else{
238                 cq.setStatus(cc.getStatus());
239                 cq.setType(cc.getType());
240                 int update = Fd_Vcper.update(cq);
241                 or.setCode(0);
242                 or.setItem(cq);
243             }
244 //                }else{
245 //                    or.setCode(1);
246 //                    or.setErrmsg("对象主键不能为空");
247 //                }
248             
249 //            Fd_Company_Vehicle fdvc=fdcvper.getbyIDs(cq.getVehicleId(), lg.getDepartno());
250 //            if(fdvc==null){
251 //                fdvc=new Fd_Company_Vehicle();
252 //                fdvc.setCompanyNo(lg.getDepartno());
253 //                fdvc.setVehicleId(cq.getVehicleId());
254 //                fdcvper.insert(fdvc);
255 //            }
256             
257
258         }
259         return or;
260     }
261     
262     
263     
264
265     @Override
266     @Transactional(rollbackOn=Exception.class)
267     public ObjectResult<Boolean> changeState(String vehicleId, Login lg, boolean state)
268             throws Exception {
269         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
270         if(lg==null){
271             orr.setCode(1);
272             orr.setErrmsg("账号未登录,请重新登录!");
273             return orr;
274         }
275         Fd_Vehicle fv= Fd_Vcper.getByVehicleId(vehicleId);
276         if(fv==null){
277             orr.setCode(1);
278             orr.setErrmsg("该车辆不存在!");
279             return orr;
280         }
281         if(!UserType.admin.toString().equals(lg.getWorkerno())){
282             if(!StringUtils.isEmpty(lg.getDepartno())){
283                 if(!lg.getDepartno().equals(fv.getCompanyNo())){
284                     orr.setCode(1);
285                     orr.setErrmsg("你没有权限修改分本公司车辆!");
286                     return orr;
287                 }
288             }
289         }
290         fv.setState(state);
291         Fd_Vcper.update(fv);
292         orr.setCode(0);
293         orr.setItem(state);
294         return orr;
295     }
296     @Override
297     @Transactional(rollbackOn=Exception.class)
298     public ObjectResult<Boolean> delFd_Vehicle(String vehicleId) throws Exception {
299         
300         ObjectResult<Boolean> prr = new ObjectResult<Boolean>();
301         if(!StringUtils.isBlank(vehicleId)){
302             Fd_Vehicle fdv=Fd_Vcper.getByVehicleId(vehicleId);
303             if(fdv!=null){
304                 List<Fd_Bsheet> fdb=fdbper.getListbyVehicleId(vehicleId,Serviceenum.在办);
305                 if(fdb!=null&&!fdb.isEmpty()){
306                     prr.setCode(1);
307                     prr.setErrmsg("车辆有在办的提单,不能删除,等业务办完之后再删除!");
308                     return prr;
309                 }
310 //                if(fdv.getStatus()!=VehicleStatus.未配车){
311 //                    prr.setCode(1);
312 //                    prr.setErrmsg("车辆状态不是未配车状态,不能删除!");
313 //                    return prr;
314 //                }
315             }
316             int i = Fd_Vcper.delByVehicleId(vehicleId);
317 //            fdcvper.delbyID(vehicleId);
318             prr.setCode(0);
319             prr.setItem(true);
320         }else{
321             prr.setCode(1);
322             prr.setItem(false);
323             prr.setErrmsg("车牌号不能为空");;
324         }
325         
326         return prr;
327     }
328
329 }