bug修复
This commit is contained in:
@ -90,6 +90,10 @@ public class ZcCarBrandController extends BaseController
|
||||
@ResponseBody
|
||||
public AjaxResult addSave(ZcCarBrand zcCarBrand)
|
||||
{
|
||||
if (ZcCarBrand.NOT_UNIQUE.equals(zcCarBrandService.checkNameUnique(zcCarBrand)))
|
||||
{
|
||||
return error("新增失败,品牌名称'" + zcCarBrand.getBrandName() + "'已存在");
|
||||
}
|
||||
return toAjax(zcCarBrandService.insertZcCarBrand(zcCarBrand));
|
||||
}
|
||||
|
||||
@ -114,6 +118,10 @@ public class ZcCarBrandController extends BaseController
|
||||
@ResponseBody
|
||||
public AjaxResult editSave(ZcCarBrand zcCarBrand)
|
||||
{
|
||||
if (ZcCarBrand.NOT_UNIQUE.equals(zcCarBrandService.checkNameUnique(zcCarBrand)))
|
||||
{
|
||||
return error("新增失败,品牌名称'" + zcCarBrand.getBrandName() + "'已存在");
|
||||
}
|
||||
return toAjax(zcCarBrandService.updateZcCarBrand(zcCarBrand));
|
||||
}
|
||||
|
||||
|
||||
@ -49,6 +49,9 @@ public class ZcCarBrand extends BaseEntity
|
||||
/** 车型管理信息 */
|
||||
private List<ZcCarModel> zcCarModelList;
|
||||
|
||||
public final static String UNIQUE = "0";
|
||||
public final static String NOT_UNIQUE = "1";
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
|
||||
@ -84,4 +84,6 @@ public interface ZcCarBrandMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteZcCarModelByBrandId(Long id);
|
||||
|
||||
public ZcCarBrand checkNameUnique(ZcCarBrand zcCarBrand);
|
||||
}
|
||||
|
||||
@ -58,4 +58,6 @@ public interface IZcCarBrandService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteZcCarBrandById(Long id);
|
||||
|
||||
public String checkNameUnique(ZcCarBrand zcCarBrand);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.ruoyi.operation.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.operation.domain.Company;
|
||||
import com.ruoyi.operation.service.IZcCarModelService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -118,6 +119,17 @@ public class ZcCarBrandServiceImpl implements IZcCarBrandService
|
||||
return zcCarBrandMapper.deleteZcCarBrandById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String checkNameUnique(ZcCarBrand zcCarBrand) {
|
||||
Long id = StringUtils.isNull(zcCarBrand.getId()) ? -1L : zcCarBrand.getId();
|
||||
ZcCarBrand info = zcCarBrandMapper.checkNameUnique(zcCarBrand);
|
||||
if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue())
|
||||
{
|
||||
return ZcCarBrand.NOT_UNIQUE;
|
||||
}
|
||||
return ZcCarBrand.UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增车型管理信息
|
||||
*
|
||||
|
||||
@ -12,18 +12,14 @@ 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.domain.*;
|
||||
import com.ruoyi.operation.service.*;
|
||||
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;
|
||||
import com.ruoyi.operation.domain.ZcCar;
|
||||
import com.ruoyi.operation.service.IZcCarService;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -47,6 +43,10 @@ public class ZcCarServiceImpl implements IZcCarService
|
||||
private ICompanyService companyService;
|
||||
@Autowired
|
||||
private ICompanyStoreService companyStoreService;
|
||||
@Autowired
|
||||
private IZcCarBrandService zcCarBrandService;
|
||||
@Autowired
|
||||
private IZcCarModelService zcCarModelService;
|
||||
|
||||
protected Validator validator;
|
||||
|
||||
@ -187,6 +187,17 @@ public class ZcCarServiceImpl implements IZcCarService
|
||||
Map<String, Long> storeMap = storeList.stream()
|
||||
.collect(Collectors.toMap(CompanyStore::getName, CompanyStore::getId));
|
||||
|
||||
// 一次性查询所有品牌,构建成 Map 用于快速查找
|
||||
List<ZcCarBrand> carBrandList = zcCarBrandService.selectZcCarBrandList(new ZcCarBrand());
|
||||
Map<String, Long> carBrandMap = carBrandList.stream()
|
||||
.collect(Collectors.toMap(ZcCarBrand::getBrandName, ZcCarBrand::getId));
|
||||
|
||||
// 一次性查询所有型号,构建成 Map 用于快速查找
|
||||
List<ZcCarModel> carModelList = zcCarModelService.selectZcCarModelList(new ZcCarModel());
|
||||
Map<String, Long> carModelMap = carModelList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
item -> item.getBrandName() + "-" + item.getModelName(),
|
||||
ZcCarModel::getId));
|
||||
|
||||
int successNum = 0;
|
||||
int failureNum = 0;
|
||||
@ -204,6 +215,23 @@ public class ZcCarServiceImpl implements IZcCarService
|
||||
|
||||
// 只有当所有唯一性校验都通过时才插入数据
|
||||
if (StringUtils.isNull(u) && StringUtils.isNull(u2) && StringUtils.isNull(u3)) {
|
||||
// 设置品牌
|
||||
if (StringUtils.isNotEmpty(car.getBrandName()) && carBrandMap.containsKey(car.getBrandName())) {
|
||||
car.setBrandId(carBrandMap.get(car.getBrandName()));
|
||||
}else{
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>" + failureNum + "、车辆品牌 " + car.getBrandName() + " 不存在");
|
||||
continue;
|
||||
}
|
||||
// 设置车型
|
||||
if (StringUtils.isNotEmpty(car.getModelName()) && carModelMap.containsKey(car.getBrandName()+"-"+car.getModelName())) {
|
||||
car.setModelId(carModelMap.get(car.getBrandName()+"-"+car.getModelName()));
|
||||
}else{
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>" + failureNum + "、车辆品牌 " + car.getBrandName() + " 的车辆型号 " + car.getModelName() + " 不存在");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 设置运营商ID
|
||||
if (StringUtils.isNotEmpty(car.getOperatorName()) && companyMap.containsKey(car.getOperatorName())) {
|
||||
car.setOperatorId(companyMap.get(car.getOperatorName()));
|
||||
|
||||
@ -68,6 +68,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
left join zc_car_model b on b.brand_id = a.id
|
||||
where a.id = #{id}
|
||||
</select>
|
||||
<select id="checkNameUnique" resultType="com.ruoyi.operation.domain.ZcCarBrand">
|
||||
SELECT * FROM zc_car_brand WHERE del_flag = 0 AND brand_name = #{brandName} limit 1
|
||||
</select>
|
||||
|
||||
<insert id="insertZcCarBrand" parameterType="ZcCarBrand" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into zc_car_brand
|
||||
|
||||
@ -142,6 +142,7 @@
|
||||
url: prefix + "/list",
|
||||
createUrl: prefix + "/add",
|
||||
updateUrl: prefix + "/edit/{id}",
|
||||
detailUrl: ctx + "orders/order/edit/{id}",
|
||||
removeUrl: prefix + "/remove",
|
||||
exportUrl: prefix + "/export",
|
||||
modalName: "订单分成统计",
|
||||
|
||||
Reference in New Issue
Block a user