| 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;  | 
|     }  | 
| }  |