车辆导入导出
This commit is contained in:
@ -24,6 +24,7 @@ import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 车辆管理Controller
|
||||
@ -44,8 +45,10 @@ public class ZcCarController extends BaseController
|
||||
|
||||
@RequiresPermissions("operation:car:view")
|
||||
@GetMapping()
|
||||
public String car()
|
||||
public String car(ModelMap mmap)
|
||||
{
|
||||
List<Company> companyList = companyService.getCompanyList(new Company(),getSysUser()); // 获取运营商列表
|
||||
mmap.put("companyList", companyList); // 将运营商列表传递到前端
|
||||
return prefix + "/car";
|
||||
}
|
||||
|
||||
@ -58,6 +61,10 @@ public class ZcCarController extends BaseController
|
||||
public TableDataInfo list(ZcCar zcCar)
|
||||
{
|
||||
startPage();
|
||||
// 运营者账号,只能查询所属商户数据
|
||||
if(UserConstants.USER_TYPE_02 .equals(getSysUser().getUserType())){
|
||||
zcCar.setOperatorId(getSysUser().getGroupId());
|
||||
}
|
||||
List<ZcCar> list = zcCarService.selectZcCarList(zcCar);
|
||||
return getDataTable(list);
|
||||
}
|
||||
@ -71,6 +78,10 @@ public class ZcCarController extends BaseController
|
||||
@ResponseBody
|
||||
public AjaxResult export(ZcCar zcCar)
|
||||
{
|
||||
// 运营者账号,只能查询所属商户数据
|
||||
if(UserConstants.USER_TYPE_02 .equals(getSysUser().getUserType())){
|
||||
zcCar.setOperatorId(getSysUser().getGroupId());
|
||||
}
|
||||
List<ZcCar> list = zcCarService.selectZcCarList(zcCar);
|
||||
ExcelUtil<ZcCar> util = new ExcelUtil<ZcCar>(ZcCar.class);
|
||||
return util.exportExcel(list, "车辆管理数据");
|
||||
@ -134,9 +145,25 @@ public class ZcCarController extends BaseController
|
||||
&& OperationConstants.USER_VIN_NOT_UNIQUE.equals(zcCarService.checkVinUnique(zcCar))) {
|
||||
return error("修改失败,车机号已存在");
|
||||
}
|
||||
|
||||
return toAjax(zcCarService.updateZcCar(zcCar));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配车辆
|
||||
*/
|
||||
@RequiresPermissions("operation:car:distribute")
|
||||
@GetMapping("/distribute/{id}")
|
||||
public String distribute(@PathVariable("id") Long id, ModelMap mmap)
|
||||
{
|
||||
List<Company> companyList = companyService.getCompanyList(new Company(),getSysUser()); // 获取运营商列表
|
||||
mmap.put("companyList", companyList); // 将运营商列表传递到前端
|
||||
|
||||
ZcCar zcCar = zcCarService.selectZcCarById(id);
|
||||
mmap.put("zcCar", zcCar);
|
||||
return prefix + "/distribute";
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除车辆管理
|
||||
*/
|
||||
@ -164,7 +191,20 @@ public class ZcCarController extends BaseController
|
||||
public AjaxResult importTemplate()
|
||||
{
|
||||
ExcelUtil<ZcCar> util = new ExcelUtil<ZcCar>(ZcCar.class);
|
||||
return util.importTemplateExcel("车辆数据");
|
||||
return util.importTemplateExcel("车辆数据模板");
|
||||
}
|
||||
|
||||
@Log(title = "车辆管理-导入", businessType = BusinessType.IMPORT)
|
||||
@RequiresPermissions("operation:car:import")
|
||||
@PostMapping("/importData")
|
||||
@ResponseBody
|
||||
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
|
||||
{
|
||||
ExcelUtil<ZcCar> util = new ExcelUtil<ZcCar>(ZcCar.class);
|
||||
List<ZcCar> carList = util.importExcel(file.getInputStream());
|
||||
String message = zcCarService.importCar(carList, updateSupport, getSysUser());
|
||||
return AjaxResult.success(message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -80,6 +80,10 @@ public class ZcRentCarRuleController extends BaseController
|
||||
@ResponseBody
|
||||
public AjaxResult export(ZcRentCarRule zcRentCarRule)
|
||||
{
|
||||
// 运营者账号,只能查询所属商户数据
|
||||
if(UserConstants.USER_TYPE_02 .equals(getSysUser().getUserType())){
|
||||
zcRentCarRule.setOperatingCompanyId(getSysUser().getGroupId());
|
||||
}
|
||||
List<ZcRentCarRule> list = zcRentCarRuleService.selectZcRentCarRuleList(zcRentCarRule);
|
||||
ExcelUtil<ZcRentCarRule> util = new ExcelUtil<ZcRentCarRule>(ZcRentCarRule.class);
|
||||
return util.exportExcel(list, "租车计费规则数据");
|
||||
|
||||
@ -30,31 +30,26 @@ public class ZcCar extends BaseEntity
|
||||
private String licensePlate;
|
||||
|
||||
/** 车辆品牌ID */
|
||||
@Excel(name = "车辆品牌ID")
|
||||
private Long brandId;
|
||||
|
||||
/** 车辆品牌名称 */
|
||||
@Excel(name = "车辆品牌名称")
|
||||
@Excel(name = "车辆品牌")
|
||||
private String brandName;
|
||||
|
||||
/** 车辆型号ID */
|
||||
@Excel(name = "车辆型号ID")
|
||||
private Long modelId;
|
||||
|
||||
/** 车辆型号名称 */
|
||||
@Excel(name = "车辆型号名称")
|
||||
@Excel(name = "车辆型号")
|
||||
private String modelName;
|
||||
|
||||
/** 支持电池类型 */
|
||||
@Excel(name = "支持电池类型")
|
||||
private String batteryType;
|
||||
|
||||
/** 整车重量(kg) */
|
||||
@Excel(name = "整车重量(kg)")
|
||||
private String weight;
|
||||
|
||||
/** 最高时速(km/h) */
|
||||
@Excel(name = "最高时速(km/h)")
|
||||
private String maxSpeed;
|
||||
|
||||
/** LOT识别号 */
|
||||
@ -75,15 +70,12 @@ public class ZcCar extends BaseEntity
|
||||
private String belongType;
|
||||
|
||||
/** 车辆图片 */
|
||||
@Excel(name = "车辆图片")
|
||||
private String images;
|
||||
|
||||
/** BRS车辆状态 */
|
||||
@Excel(name = "BRS车辆状态")
|
||||
private String brsStatus;
|
||||
|
||||
/** IoT设备状态 */
|
||||
@Excel(name = "IoT设备状态")
|
||||
private String iotStatus;
|
||||
|
||||
/** IoT识别码 */
|
||||
@ -91,31 +83,26 @@ public class ZcCar extends BaseEntity
|
||||
private String iotCode;
|
||||
|
||||
/** 所属运营商ID */
|
||||
@Excel(name = "所属运营商ID")
|
||||
private Long operatorId;
|
||||
|
||||
/** 所属运营商名称 */
|
||||
@Excel(name = "所属运营商名称")
|
||||
@Excel(name = "所属运营商")
|
||||
private String operatorName;
|
||||
|
||||
/** 所属门店ID */
|
||||
@Excel(name = "所属门店ID")
|
||||
private Long storeId;
|
||||
|
||||
/** 所属门店名称 */
|
||||
@Excel(name = "所属门店名称")
|
||||
@Excel(name = "所属门店")
|
||||
private String storeName;
|
||||
|
||||
/** 应用套餐ID */
|
||||
@Excel(name = "应用套餐ID")
|
||||
private Long packageId;
|
||||
|
||||
/** 应用套餐名称 */
|
||||
@Excel(name = "应用套餐名称")
|
||||
private String packageName;
|
||||
|
||||
/** 状态 */
|
||||
@Excel(name = "状态")
|
||||
private String status;
|
||||
|
||||
/** 删除标志 */
|
||||
|
||||
@ -2,6 +2,7 @@ package com.ruoyi.operation.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.operation.domain.ZcCar;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 车型管理Mapper接口
|
||||
@ -35,6 +36,8 @@ public interface ZcCarMapper
|
||||
*/
|
||||
public int insertZcCar(ZcCar zcCar);
|
||||
|
||||
int batchInsert(@Param("list") List<ZcCar> carList);
|
||||
|
||||
/**
|
||||
* 修改车型管理
|
||||
*
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.ruoyi.operation.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.operation.domain.ZcCar;
|
||||
|
||||
/**
|
||||
@ -68,4 +70,8 @@ public interface IZcCarService
|
||||
String checkVinUnique(ZcCar zcCar);
|
||||
|
||||
public int changeStatus(ZcCar zcCar);
|
||||
|
||||
public String importCar(List<ZcCar> carList, Boolean isUpdateSupport, SysUser user);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,24 @@
|
||||
package com.ruoyi.operation.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.DictUtils;
|
||||
import com.ruoyi.common.utils.ShiroUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.bean.BeanValidators;
|
||||
import com.ruoyi.operation.domain.Company;
|
||||
import com.ruoyi.operation.domain.CompanyStore;
|
||||
import com.ruoyi.operation.service.ICompanyService;
|
||||
import com.ruoyi.operation.service.ICompanyStoreService;
|
||||
import com.ruoyi.operation.util.OperationConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.operation.mapper.ZcCarMapper;
|
||||
@ -11,6 +26,8 @@ import com.ruoyi.operation.domain.ZcCar;
|
||||
import com.ruoyi.operation.service.IZcCarService;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
|
||||
import javax.validation.Validator;
|
||||
|
||||
/**
|
||||
* 车型管理Service业务层处理
|
||||
*
|
||||
@ -20,9 +37,18 @@ import com.ruoyi.common.core.text.Convert;
|
||||
@Service
|
||||
public class ZcCarServiceImpl implements IZcCarService
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(ZcCarServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private ZcCarMapper zcCarMapper;
|
||||
|
||||
@Autowired
|
||||
private ICompanyService companyService;
|
||||
@Autowired
|
||||
private ICompanyStoreService companyStoreService;
|
||||
|
||||
protected Validator validator;
|
||||
|
||||
/**
|
||||
* 查询车型管理
|
||||
*
|
||||
@ -57,6 +83,7 @@ public class ZcCarServiceImpl implements IZcCarService
|
||||
public int insertZcCar(ZcCar zcCar)
|
||||
{
|
||||
zcCar.setCreateTime(DateUtils.getNowDate());
|
||||
zcCar.setUpdateTime(DateUtils.getNowDate());
|
||||
return zcCarMapper.insertZcCar(zcCar);
|
||||
}
|
||||
|
||||
@ -113,5 +140,82 @@ public class ZcCarServiceImpl implements IZcCarService
|
||||
return zcCarMapper.updateZcCar(zcCar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String importCar(List<ZcCar> carList, Boolean isUpdateSupport, SysUser user) {
|
||||
if (StringUtils.isNull(carList) || carList.size() == 0)
|
||||
{
|
||||
throw new ServiceException("导入车辆数据不能为空!");
|
||||
}
|
||||
|
||||
// 一次性查询所有运营商和门店,构建成 Map 用于快速查找
|
||||
List<Company> companyList = companyService.getCompanyList(new Company(),user); // 获取运营商列表
|
||||
Map<String, Long> companyMap = companyList.stream()
|
||||
.collect(Collectors.toMap(Company::getCompanyName, Company::getId));
|
||||
|
||||
List<CompanyStore> storeList = companyStoreService.selectCompanyStoreList(new CompanyStore());
|
||||
Map<String, Long> storeMap = storeList.stream()
|
||||
.collect(Collectors.toMap(CompanyStore::getName, CompanyStore::getId));
|
||||
|
||||
|
||||
int successNum = 0;
|
||||
int failureNum = 0;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder failureMsg = new StringBuilder();
|
||||
List<ZcCar> processedList = new ArrayList<ZcCar>();
|
||||
for (ZcCar car : carList)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 验证是否存在这个用户
|
||||
ZcCar u = zcCarMapper.checkVinUnique(car.getVin());
|
||||
if (StringUtils.isNull(u))
|
||||
{
|
||||
// 车辆归属字典转换
|
||||
car.setBelongType(DictUtils.getDictValue("key_car_belong_type", car.getBelongType(), car.getBelongType()));
|
||||
// 设置运营商ID
|
||||
if (StringUtils.isNotEmpty(car.getOperatorName()) && companyMap.containsKey(car.getOperatorName())) {
|
||||
car.setOperatorId(companyMap.get(car.getOperatorName()));
|
||||
}
|
||||
|
||||
// 设置门店ID
|
||||
if (StringUtils.isNotEmpty(car.getStoreName()) && storeMap.containsKey(car.getStoreName())) {
|
||||
car.setStoreId(storeMap.get(car.getStoreName()));
|
||||
}
|
||||
car.setCreateBy(user.getLoginName());
|
||||
|
||||
this.insertZcCar(car);
|
||||
// processedList.add(car);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、车机号 " + car.getVin() + " 导入成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>" + failureNum + "、车机号 " + car.getVin() + " 已存在");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、车机号 " + car.getVin() + " 导入失败:";
|
||||
failureMsg.append(msg + e.getMessage());
|
||||
log.error(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (failureNum > 0)
|
||||
{
|
||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||
throw new ServiceException(failureMsg.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// zcCarMapper.batchInsert(processedList);
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||
}
|
||||
return successMsg.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user