作者 王勇

删除挂车时,增加校验

... ... @@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sunyo.wlpt.vehicle.manage.common.Common;
import com.sunyo.wlpt.vehicle.manage.domain.LandRoadVeRecord;
import com.sunyo.wlpt.vehicle.manage.mapper.LandRoadVeRecordMapper;
import com.sunyo.wlpt.vehicle.manage.response.ResultJson;
import com.sunyo.wlpt.vehicle.manage.utils.IdUtils;
import io.netty.util.internal.StringUtil;
... ... @@ -15,8 +16,7 @@ import com.sunyo.wlpt.vehicle.manage.domain.LandRoadTrailerRecord;
import com.sunyo.wlpt.vehicle.manage.mapper.LandRoadTrailerRecordMapper;
import com.sunyo.wlpt.vehicle.manage.service.LandRoadTrailerRecordService;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
* @author 子诚
... ... @@ -29,8 +29,13 @@ public class LandRoadTrailerRecordServiceImpl implements LandRoadTrailerRecordSe
@Resource
private LandRoadTrailerRecordMapper landRoadTrailerRecordMapper;
@Resource
private LandRoadVeRecordMapper landRoadVeRecordMapper;
/**
* 删除
* <p>
* 删除挂车时,要确定该挂车是否被车辆是挂载?没有被挂载,可以被删除
*
* @param id primaryKey
* @return
... ... @@ -38,6 +43,12 @@ public class LandRoadTrailerRecordServiceImpl implements LandRoadTrailerRecordSe
@Override
public ResultJson deleteByPrimaryKey(String id)
{
String trailerLicenseNo = landRoadTrailerRecordMapper.selectByPrimaryKey(id).getTrailerLicenseNo();
List<LandRoadVeRecord> landRoadVeRecordList = landRoadVeRecordMapper.selectByTrailerLicenseNo(trailerLicenseNo);
if (landRoadVeRecordList.size() > 0) {
return ResultJson.error("500", "该挂车已经被车牌号为:" + landRoadVeRecordList.get(0).getDomesticLisenceNo()
+ "的车辆所挂载,无法删除;");
}
return landRoadTrailerRecordMapper.deleteByPrimaryKey(id) > 0
? ResultJson.success("200", "删除挂车信息,成功")
: ResultJson.error("500", "删除挂车信息失败");
... ... @@ -45,6 +56,7 @@ public class LandRoadTrailerRecordServiceImpl implements LandRoadTrailerRecordSe
/**
* 批量删除
* 判断每一个id对应的挂车是否被使用
*
* @param ids 被删除的id,多个以,相隔的字符串
* @return
... ... @@ -52,10 +64,25 @@ public class LandRoadTrailerRecordServiceImpl implements LandRoadTrailerRecordSe
@Override
public ResultJson batchRemoveByIds(String ids)
{
String[] idList = ids.split(",");
return landRoadTrailerRecordMapper.batchRemoveByIds(idList) > 0
? ResultJson.success("200", "批量删除挂车信息,成功")
: ResultJson.error("500", "批量删除挂车信息,失败");
String resultMsg = "";
int index = 0;
String[] IdList = ids.split(",");
for (int i = 0; i < IdList.length; i++) {
String id = IdList[i];
String trailerLicenseNo = landRoadTrailerRecordMapper.selectByPrimaryKey(id).getTrailerLicenseNo();
List<LandRoadVeRecord> landRoadVeRecordList = landRoadVeRecordMapper.selectByTrailerLicenseNo(trailerLicenseNo);
if (landRoadVeRecordList.size() > 0) {
String errorMsg = "挂车(" + trailerLicenseNo + ")已经被车牌号为:" + landRoadVeRecordList.get(0).getDomesticLisenceNo()
+ "的车辆所挂载,无法删除;";
resultMsg += errorMsg;
continue;
}
index += landRoadTrailerRecordMapper.deleteByPrimaryKey(id);
}
return index > 0
? ResultJson.success("200", "批量删除挂车信息,成功!" + resultMsg)
: ResultJson.error("500", "批量删除挂车信息,失败" + resultMsg);
}
@Override
... ...