xiaoyong931011
2021-06-30 e708a57acad17877869fd3b418f7f9ea529841da
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
package com.xzx.gc.user.service;
 
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzx.gc.common.exception.PlatformException;
import com.xzx.gc.entity.UserVehicleRel;
import com.xzx.gc.entity.VehicleInfo;
import com.xzx.gc.model.admin.VehicleModel;
import com.xzx.gc.user.mapper.VehicleInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
@Transactional
@Slf4j
public class VehicleInfoService {
 
    @Autowired
    private VehicleInfoMapper vehicleInfoMapper;
 
    @Autowired
    private UserVehicleRelService userVehicleRelService;
 
    @Autowired
    private CityPartnerService cityPartnerService;
 
    public void batchDelXzxUserVehicleInfo(List<Long> ids){
        try {
            vehicleInfoMapper.batchDelXzxUserVehicleInfoByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除XzxUserVehicleInfo失败", e);
        }
    }
 
    public Map<String, Object> queryByVehicleInfoList(String vehicleNo, String page, String limit, String partnerId) {
 
        List<String> partnerIds = new ArrayList<>();
        if(null!=partnerId&&!"".equals(partnerId)){
            partnerIds.add(partnerId);
        }else{
            partnerIds = cityPartnerService.queryPartnerByCurrent();
        }
        Map<String, Object> map = new HashMap<>();
        page=StrUtil.isBlank(page)?"0":page;
        limit=StrUtil.isBlank(page)?"0":limit;
        PageHelper.startPage(Convert.toInt(page),Convert.toInt(limit));
        List<Map<String,Object>> queryByVehicleInfoListDtos = vehicleInfoMapper.queryByVehicleInfoList(vehicleNo, partnerIds);
        PageInfo<Map<String,Object>> pageInfo=new PageInfo<>(queryByVehicleInfoListDtos);
        for (Map<String,Object> rmap:queryByVehicleInfoListDtos) {
            rmap.put("relid",rmap.get("relId").toString());
            rmap.put("userid",rmap.get("userId").toString());
            rmap.put("storageid",rmap.get("storageId").toString());
            rmap.put("vehicleno",rmap.get("vehicleNo").toString());
        }
        map.put("count", pageInfo.getTotal());
        map.put("data", pageInfo.getList());
        map.put("code", 0);
        return map;
    }
 
    public void save(VehicleInfo xzxUserVehicleInfo) {
        vehicleInfoMapper.insertSelective(xzxUserVehicleInfo);
    }
 
    public VehicleInfo queryById(Long id) {
        return vehicleInfoMapper.selectByPrimaryKey(id);
    }
 
    public boolean update(VehicleInfo oldInfo) {
        return vehicleInfoMapper.updateByPrimaryKeySelective(oldInfo)>0?true:false;
    }
 
 
 
    /**
     * 添加车辆
     * @param model
     */
    public Long addVehicleInfo(VehicleModel model){
        String userId=model.getUserId();
        String storageId=model.getStorageId();
        if(null!=storageId){
            model.setStorageId(storageId);
        }
        model.setCreateTime(DateUtil.now());
        model.setDelFlag(0);
        VehicleInfo xzxUserVehicleInfo =getInfo(model);
        save(xzxUserVehicleInfo);
 
        //先删除所有关联车辆
        userVehicleRelService.deleteByUserId(userId);
 
        UserVehicleRel rel = new UserVehicleRel();
        rel.setDelFlag((short)0);
        rel.setVehicleId(xzxUserVehicleInfo.getId());
        rel.setUserId(userId);
        userVehicleRelService.save(rel);
        return xzxUserVehicleInfo.getId();
    }
 
    private VehicleInfo getInfo (VehicleModel model){
        VehicleInfo info = new VehicleInfo();
        info.setCreateTime(model.getCreateTime());
        info.setDelFlag(model.getDelFlag().shortValue());
        info.setStorageId(Integer.parseInt(model.getStorageId()));
        info.setLoadWeight(model.getLoadWeight());
//        info.setType(model.getType().shortValue());
        info.setVehicleNo(model.getVehicleNo());
        info.setWeight(model.getWeight());
//        info.setColor(model.getColor().shortValue());
        return info;
    }
}