fix(sip): 优化数据库查询和异常处理
- 在 AgentInfoMapper、CustomerInfoMapper、PartnerInfoMapper 和 ProductInfoMapper 中添加 status=0 条件,以仅查询有效记录 - 修改 DeliveryListMapper 接口,增加 deleteDeliveryListByDeliveryId 方法 - 更新 DeliveryListServiceImpl,使用新的 deleteDeliveryListByDeliveryId 方法 - 在 GlobalExceptionHandler 中添加 DataAccessException 异常处理 - 修改 OrderInfoMapper 和 OrderInfoServiceImpl,增加合同号+版本号唯一性校验master
parent
6b617f0b26
commit
171ebad572
|
@ -4,6 +4,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.MissingPathVariableException;
|
||||
|
@ -71,6 +72,17 @@ public class GlobalExceptionHandler
|
|||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截 SQL 异常
|
||||
*/
|
||||
@ExceptionHandler(DataAccessException.class)
|
||||
public AjaxResult handleDataAccessException(DataAccessException e, HttpServletRequest request)
|
||||
{
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求地址'{}',发生SQL异常.", requestURI, e);
|
||||
return AjaxResult.error("数据库操作异常,请稍后重试或联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统异常
|
||||
*/
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Date;
|
|||
import java.util.StringJoiner;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.annotation.Excels;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import com.ruoyi.sip.domain.DeliveryList;
|
||||
import com.ruoyi.sip.dto.ApiDataQueryDto;
|
||||
import com.ruoyi.sip.vo.DeliveryInfoVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 发货清单Mapper接口
|
||||
|
@ -62,7 +63,9 @@ public interface DeliveryListMapper
|
|||
*/
|
||||
public int deleteDeliveryListByIds(String[] ids);
|
||||
|
||||
List<DeliveryList> listBySerialNumberList(List<DeliveryList> deliveryList);
|
||||
List<DeliveryList> listBySerialNumberList(@Param("list") List<DeliveryList> deliveryList, @Param("deliveryId") Long deliveryId);
|
||||
|
||||
List<DeliveryInfoVo> listNumberInfo(ApiDataQueryDto dto);
|
||||
|
||||
void deleteDeliveryListByDeliveryId(Long deliveryId);
|
||||
}
|
||||
|
|
|
@ -110,5 +110,6 @@ public interface OrderInfoMapper
|
|||
List<OrderList> listMaintenanceByOrderIdList(List<Long> orderIdList);
|
||||
|
||||
List<OrderList> listExport(OrderList orderList);
|
||||
Integer selectUniqueCount(OrderInfo orderInfo);
|
||||
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ public class DeliveryListServiceImpl implements IDeliveryListService {
|
|||
return AjaxResult.error("发货单中没有产品");
|
||||
}
|
||||
List<String> existsProductCodeList = orderLists.stream().map(OrderList::getProductCode).collect(Collectors.toList());
|
||||
List<String> notExistsProductCodeList = productCodeList.stream().filter(productCode -> !existsProductCodeList.contains(productCode)).collect(Collectors.toList());
|
||||
List<String> notExistsProductCodeList = productCodeList.stream().filter(productCode -> !existsProductCodeList.contains(productCode)).distinct().collect(Collectors.toList());
|
||||
if (!notExistsProductCodeList.isEmpty()) {
|
||||
return AjaxResult.error(StringUtils.format("编码为[{}]的产品在合同请单中未找到,请确认后重试;", String.join(",", notExistsProductCodeList)));
|
||||
}
|
||||
|
@ -131,12 +131,10 @@ public class DeliveryListServiceImpl implements IDeliveryListService {
|
|||
list.setDeliveryId(deliveryId);
|
||||
list.setCreateBy(ShiroUtils.getUserId().toString());
|
||||
}
|
||||
List<DeliveryList> deliveryLists = deliveryListMapper.listBySerialNumberList(deliveryList);
|
||||
List<DeliveryList> deliveryLists = deliveryListMapper.listBySerialNumberList(deliveryList,deliveryId);
|
||||
if (!deliveryLists.isEmpty()){
|
||||
return AjaxResult.error("产品序列号为[" + deliveryLists.stream().map(DeliveryList::getSerialNumber).collect(Collectors.joining(",")) + "]的产品已存在,请确认后重试;");
|
||||
}
|
||||
|
||||
|
||||
deliveryListMapper.insertBatch(deliveryList);
|
||||
return AjaxResult.success("导入成功");
|
||||
}
|
||||
|
|
|
@ -82,12 +82,19 @@ public class OrderInfoServiceImpl implements IOrderInfoService
|
|||
@Override
|
||||
public int insertOrderInfo(OrderInfo orderInfo)
|
||||
{
|
||||
//校验合同号是否重复
|
||||
Integer i = orderInfoMapper.selectUniqueCount(orderInfo);
|
||||
if (i!=null && i>0){
|
||||
throw new ServiceException("合同号+版本号已存在");
|
||||
}
|
||||
|
||||
orderInfo.setCreateBy(ShiroUtils.getUserId().toString());
|
||||
int rows = orderInfoMapper.insertOrderInfo(orderInfo);
|
||||
insertOrderList(orderInfo);
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改合同档案
|
||||
*
|
||||
|
@ -98,6 +105,11 @@ public class OrderInfoServiceImpl implements IOrderInfoService
|
|||
@Override
|
||||
public int updateOrderInfo(OrderInfo orderInfo)
|
||||
{
|
||||
//校验合同号是否重复
|
||||
Integer i = orderInfoMapper.selectUniqueCount(orderInfo);
|
||||
if (i!=null && i>0){
|
||||
throw new ServiceException("合同号+版本号已存在");
|
||||
}
|
||||
// List<OrderList> orderListList = orderInfo.getOrderListList();
|
||||
// Map<String, List<OrderList>> operateMap =
|
||||
// orderListList.stream().collect(Collectors.groupingBy(OrderList::getOperateFlag));
|
||||
|
|
|
@ -62,7 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where id = #{id}
|
||||
</select>
|
||||
<select id="selectCountByCode" resultType="java.lang.Integer">
|
||||
select count(1) from customer_info where customer_code = #{customerCode}
|
||||
select count(1) from customer_info where customer_code = #{customerCode} and status=0
|
||||
<if test="id != null">and id != #{id}</if>
|
||||
</select>
|
||||
|
||||
|
|
|
@ -50,6 +50,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
open="(" separator="," close=")">
|
||||
#{item.serialNumber}
|
||||
</foreach>
|
||||
<if test="deliveryId!=null">
|
||||
and delivery_id !=#{deliveryId}
|
||||
</if>
|
||||
</select>
|
||||
<select id="listNumberInfo" resultType="com.ruoyi.sip.vo.DeliveryInfoVo">
|
||||
SELECT
|
||||
|
@ -107,12 +110,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</trim>
|
||||
</insert>
|
||||
<insert id="insertBatch">
|
||||
insert into delivery_list (delivery_id, product_code, serial_number, remark, created_at, updated_at,create_by)
|
||||
insert ignore into delivery_list (delivery_id, product_code, serial_number, remark, created_at, updated_at,create_by)
|
||||
values
|
||||
<foreach collection="list" item="item" index="index"
|
||||
separator=",">
|
||||
(#{item.deliveryId}, #{item.productCode}, #{item.serialNumber}, #{item.remark}, now(),now(),#{item.createBy})
|
||||
</foreach>
|
||||
|
||||
</insert>
|
||||
|
||||
<update id="updateDeliveryList" parameterType="DeliveryList">
|
||||
|
@ -139,5 +143,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<delete id="deleteDeliveryListByDeliveryId">
|
||||
delete from delivery_list where delivery_id = #{deliveryId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
|
@ -256,6 +256,10 @@
|
|||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectUniqueCount" resultType="java.lang.Integer">
|
||||
select count(1) from order_info where order_code = #{orderCode} and version_code=#{versionCode} and status=0
|
||||
<if test="id != null">and id != #{id}</if>
|
||||
</select>
|
||||
|
||||
<insert id="insertOrderInfo" parameterType="OrderInfo" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into order_info
|
||||
|
|
|
@ -46,7 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
<select id="selectCountByCode" resultType="java.lang.Integer">
|
||||
select count(1) from agent_info
|
||||
where agent_code=#{agentCode}
|
||||
where agent_code=#{agentCode} and status=0
|
||||
<if test="id != null">and id!=#{id}</if>
|
||||
</select>
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where id = #{id}
|
||||
</select>
|
||||
<select id="selectCountByCode" resultType="java.lang.Integer">
|
||||
select count(1) from partner_info where partner_code = #{partnerCode}
|
||||
select count(1) from partner_info where partner_code = #{partnerCode} and status=0
|
||||
<if test="id != null">and id != #{id}</if>
|
||||
</select>
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</where>
|
||||
</select>
|
||||
<select id="selectCountByCode" resultType="java.lang.Integer">
|
||||
select count(1) from product_info where product_code=#{productCode}
|
||||
select count(1) from product_info where product_code=#{productCode} and status=0
|
||||
<if test="id!=null ">
|
||||
and id!=#{id}
|
||||
</if>
|
||||
|
|
Loading…
Reference in New Issue