feat(sip): 添加创建人字段并优化订单导入功能
- 在 OrderDelivery 和 OrderInfo 模型中添加 createByName 字段 - 更新相关 mapper 和 SQL 文件以支持创建人字段 - 重构订单导入功能,提高代码复用性和异常处理能力 - 优化导入数据的校验逻辑,确保数据准确性master
parent
fd05069b40
commit
e43b87c17a
|
@ -130,6 +130,10 @@
|
||||||
return $.table.selectDictLabel(deliveryStatusDatas, value);
|
return $.table.selectDictLabel(deliveryStatusDatas, value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
field: 'createByName',
|
||||||
|
title: '创建人'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
|
|
|
@ -106,6 +106,10 @@
|
||||||
{
|
{
|
||||||
field: 'orderDate',
|
field: 'orderDate',
|
||||||
title: '合同签定日期'
|
title: '合同签定日期'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createByName',
|
||||||
|
title: '创建人'
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// field: 'status',
|
// field: 'status',
|
||||||
|
|
|
@ -204,45 +204,37 @@ public class OrderInfoController extends BaseController
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult listImportData(MultipartFile file, Long orderId) throws Exception
|
public AjaxResult listImportData(MultipartFile file, Long orderId) throws Exception
|
||||||
{
|
{
|
||||||
List<OrderList> orderListList = getOrderLists(file);
|
List<OrderList> orderListList = null;
|
||||||
|
try {
|
||||||
|
orderListList = orderInfoService.readData(file);
|
||||||
|
} catch (ServiceException e) {
|
||||||
|
return AjaxResult.error(e.getMessage());
|
||||||
|
}catch (Exception e) {
|
||||||
|
log.error("导入合同清单失败",e);
|
||||||
|
return AjaxResult.error("导入失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CollUtil.isEmpty(orderListList)){
|
||||||
|
return AjaxResult.error("导入数据不能为空");
|
||||||
|
}
|
||||||
return orderInfoService.listImportData(orderListList, orderId);
|
return orderInfoService.listImportData(orderListList, orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<OrderList> getOrderLists(MultipartFile file) throws Exception {
|
|
||||||
ExcelUtil<OrderList> util = new ExcelUtil<OrderList>(OrderList.class);
|
|
||||||
List<OrderList> orderListList = util.importExcel(file.getInputStream());
|
|
||||||
orderListList=orderListList.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
|
||||||
if (CollUtil.isEmpty(orderListList)){
|
|
||||||
orderListList = util.importExcel("价格明细清单", file.getInputStream(), 4);
|
|
||||||
}
|
|
||||||
if (CollUtil.isEmpty(orderListList)){
|
|
||||||
throw new ServiceException("excel模板错误,导入失败");
|
|
||||||
}
|
|
||||||
//只处理当前产品表有的数据
|
|
||||||
List<ProductInfo> productInfos = productInfoService.selectProductInfoList(new ProductInfo());
|
|
||||||
Map<String, ProductInfo> productInfoMap = productInfos.stream().collect(Collectors.toMap(ProductInfo::getProductCode, Function.identity(), (v1, v2) -> v1));
|
|
||||||
orderListList = orderListList.stream().filter(item -> item != null && StringUtils.isNotEmpty(item.getProductCode())
|
|
||||||
&& productInfoMap.containsKey(item.getProductCode()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
for (OrderList orderList : orderListList) {
|
|
||||||
orderList.setCreateBy(ShiroUtils.getUserId().toString());
|
|
||||||
ProductInfo productInfo = productInfoMap.get(orderList.getProductCode());
|
|
||||||
if (productInfo != null) {
|
|
||||||
orderList.setProductName(productInfo.getProductName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (CollUtil.isEmpty(orderListList)){
|
|
||||||
throw new ServiceException("导入excel的产品均未在产品库中,导入失败");
|
|
||||||
}
|
|
||||||
return orderListList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/list/readData")
|
@PostMapping("/list/readData")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult listReadData(MultipartFile file, Long orderId) throws Exception
|
public AjaxResult listReadData(MultipartFile file, Long orderId) throws Exception
|
||||||
{
|
{
|
||||||
List<OrderList> orderListList = getOrderLists(file);
|
List<OrderList> orderListList = null;
|
||||||
|
try {
|
||||||
|
orderListList = orderInfoService.readData(file);
|
||||||
|
} catch (ServiceException e) {
|
||||||
|
return AjaxResult.error(e.getMessage());
|
||||||
|
}catch (Exception e) {
|
||||||
|
log.error("导入合同清单失败",e);
|
||||||
|
return AjaxResult.error("导入失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return AjaxResult.success(orderListList);
|
return AjaxResult.success(orderListList);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,5 +76,6 @@ public class OrderDelivery extends BaseEntity
|
||||||
private Date deletedAt;
|
private Date deletedAt;
|
||||||
private String total;
|
private String total;
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
private String createByName;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,7 @@ public class OrderInfo extends BaseEntity
|
||||||
/** 合同清单信息 */
|
/** 合同清单信息 */
|
||||||
private List<OrderList> orderListList;
|
private List<OrderList> orderListList;
|
||||||
private String serialNumber;
|
private String serialNumber;
|
||||||
|
private String createByName;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.ruoyi.sip.domain.OrderInfo;
|
||||||
import com.ruoyi.sip.domain.OrderList;
|
import com.ruoyi.sip.domain.OrderList;
|
||||||
import com.ruoyi.sip.dto.ApiDataQueryDto;
|
import com.ruoyi.sip.dto.ApiDataQueryDto;
|
||||||
import com.ruoyi.sip.vo.OrderInfoVo;
|
import com.ruoyi.sip.vo.OrderInfoVo;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合同档案Service接口
|
* 合同档案Service接口
|
||||||
|
@ -78,4 +79,6 @@ public interface IOrderInfoService
|
||||||
List<OrderList> listExport(OrderList orderList);
|
List<OrderList> listExport(OrderList orderList);
|
||||||
|
|
||||||
AjaxResult listImportData(List<OrderList> orderListList, Long orderId);
|
AjaxResult listImportData(List<OrderList> orderListList, Long orderId);
|
||||||
|
|
||||||
|
List<OrderList> readData(MultipartFile file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,15 @@ import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.DictUtils;
|
import com.ruoyi.common.utils.DictUtils;
|
||||||
import com.ruoyi.common.utils.ShiroUtils;
|
import com.ruoyi.common.utils.ShiroUtils;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
import com.ruoyi.sip.domain.*;
|
import com.ruoyi.sip.domain.*;
|
||||||
import com.ruoyi.sip.dto.ApiDataQueryDto;
|
import com.ruoyi.sip.dto.ApiDataQueryDto;
|
||||||
import com.ruoyi.sip.service.IAgentInfoService;
|
import com.ruoyi.sip.service.IAgentInfoService;
|
||||||
import com.ruoyi.sip.service.ICustomerInfoService;
|
import com.ruoyi.sip.service.ICustomerInfoService;
|
||||||
|
import com.ruoyi.sip.service.IProductInfoService;
|
||||||
import com.ruoyi.sip.vo.OrderInfoVo;
|
import com.ruoyi.sip.vo.OrderInfoVo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -26,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import com.ruoyi.sip.mapper.OrderInfoMapper;
|
import com.ruoyi.sip.mapper.OrderInfoMapper;
|
||||||
import com.ruoyi.sip.service.IOrderInfoService;
|
import com.ruoyi.sip.service.IOrderInfoService;
|
||||||
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合同档案Service业务层处理
|
* 合同档案Service业务层处理
|
||||||
|
@ -42,6 +46,8 @@ public class OrderInfoServiceImpl implements IOrderInfoService
|
||||||
private IAgentInfoService agentInfoService;
|
private IAgentInfoService agentInfoService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ICustomerInfoService customerInfoService;
|
private ICustomerInfoService customerInfoService;
|
||||||
|
@Autowired
|
||||||
|
private IProductInfoService productInfoService;
|
||||||
/**
|
/**
|
||||||
* 查询合同档案
|
* 查询合同档案
|
||||||
*
|
*
|
||||||
|
@ -285,6 +291,71 @@ public class OrderInfoServiceImpl implements IOrderInfoService
|
||||||
// }
|
// }
|
||||||
return AjaxResult.success("导入成功");
|
return AjaxResult.success("导入成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<OrderList> readData(MultipartFile file) {
|
||||||
|
List<OrderList> orderListList = null;
|
||||||
|
try {
|
||||||
|
ExcelUtil<OrderList> util = new ExcelUtil<OrderList>(OrderList.class);
|
||||||
|
orderListList = util.importExcel(file.getInputStream());
|
||||||
|
orderListList=orderListList.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
||||||
|
if (CollUtil.isEmpty(orderListList)){
|
||||||
|
orderListList = util.importExcel("价格明细清单", file.getInputStream(), 4);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ServiceException("读取文件错误,导入失败");
|
||||||
|
}
|
||||||
|
if (CollUtil.isEmpty(orderListList)){
|
||||||
|
throw new ServiceException("excel模板错误,导入失败");
|
||||||
|
}
|
||||||
|
//只处理当前产品表有的数据
|
||||||
|
List<ProductInfo> productInfos = productInfoService.selectProductInfoList(new ProductInfo());
|
||||||
|
Map<String, ProductInfo> productInfoMap = productInfos.stream().collect(Collectors.toMap(ProductInfo::getProductCode, Function.identity(), (v1, v2) -> v1));
|
||||||
|
orderListList = orderListList.stream().filter(item -> item != null && StringUtils.isNotEmpty(item.getProductCode())
|
||||||
|
&& productInfoMap.containsKey(item.getProductCode()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
for (OrderList orderList : orderListList) {
|
||||||
|
orderList.setCreateBy(ShiroUtils.getUserId().toString());
|
||||||
|
ProductInfo productInfo = productInfoMap.get(orderList.getProductCode());
|
||||||
|
if (productInfo != null) {
|
||||||
|
orderList.setProductName(productInfo.getProductName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (CollUtil.isEmpty(orderListList)){
|
||||||
|
throw new ServiceException("导入excel的产品均未在产品库中,导入失败");
|
||||||
|
}
|
||||||
|
List<String> productCodeList = orderListList.stream()
|
||||||
|
.map(OrderList::getProductCode)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (productCodeList.isEmpty()) {
|
||||||
|
throw new ServiceException("文件为空或产品编码为空");
|
||||||
|
}
|
||||||
|
for (OrderList orderList : orderListList) {
|
||||||
|
|
||||||
|
if (orderList.getDiscount() == null) {
|
||||||
|
throw new ServiceException("折扣不能为空");
|
||||||
|
}
|
||||||
|
if (orderList.getDiscount().compareTo(BigDecimal.ONE) > 0 || orderList.getDiscount().compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
throw new ServiceException("折扣区间需在0-1之间");
|
||||||
|
}
|
||||||
|
if (orderList.getPrice() == null) {
|
||||||
|
throw new ServiceException("单价不能为空");
|
||||||
|
}
|
||||||
|
if (orderList.getQuantity() == null) {
|
||||||
|
throw new ServiceException("数量不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal amount = orderList.getPrice().multiply(new BigDecimal(orderList.getQuantity()));
|
||||||
|
if (orderList.getDiscount()!=null){
|
||||||
|
amount = amount.multiply(orderList.getDiscount()).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
orderList.setAmount(amount);
|
||||||
|
}
|
||||||
|
return orderListList;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, List<OrderList>> compareOrderLists(List<OrderList> orderInfoList, List<OrderList> orderListList) {
|
public Map<String, List<OrderList>> compareOrderLists(List<OrderList> orderInfoList, List<OrderList> orderListList) {
|
||||||
// 创建一个映射,用于快速查找订单
|
// 创建一个映射,用于快速查找订单
|
||||||
Map<String, OrderList> orderInfoMap = orderInfoList.stream()
|
Map<String, OrderList> orderInfoMap = orderInfoList.stream()
|
||||||
|
|
|
@ -29,11 +29,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
|
||||||
<select id="selectOrderDeliveryList" parameterType="OrderDelivery" resultMap="OrderDeliveryResult">
|
<select id="selectOrderDeliveryList" parameterType="OrderDelivery" resultMap="OrderDeliveryResult">
|
||||||
select t1.id, t1.order_id, t1.delivery_code, t1.delivery_date, t1.delivery_type, t1.logistics_company, t1.logistics_code, t1.receiver_name, t1.receiver_phone, t1.receiver_address, t1.delivery_status, t1.sign_time, t1.remark, t1.created_at, t1.updated_at, t1.deleted_at,
|
select t1.id, t1.order_id, t1.delivery_code, t1.delivery_date, t1.delivery_type, t1.logistics_company, t1.logistics_code, t1.receiver_name, t1.receiver_phone, t1.receiver_address, t1.delivery_status, t1.sign_time, t1.remark, t1.created_at, t1.updated_at, t1.deleted_at,
|
||||||
t2.order_code,t2.order_name,t3.total
|
t2.order_code,t2.order_name,t1.create_by,t1.update_by,t3.total,t4.user_name as create_by_name
|
||||||
|
|
||||||
from order_delivery t1
|
from order_delivery t1
|
||||||
left join order_info t2 on t1.order_id = t2.id
|
left join order_info t2 on t1.order_id = t2.id
|
||||||
left join (select count(1) as total,delivery_id from delivery_list group by delivery_id) t3 on t1.id = t3.delivery_id
|
left join (select count(1) as total,delivery_id from delivery_list group by delivery_id) t3 on t1.id = t3.delivery_id
|
||||||
|
left join sys_user t4 on t1.create_by=t4.user_id
|
||||||
<where>
|
<where>
|
||||||
t1.status=0
|
t1.status=0
|
||||||
<if test="orderId != null "> and t1.order_id = #{orderId}</if>
|
<if test="orderId != null "> and t1.order_id = #{orderId}</if>
|
||||||
|
|
|
@ -97,28 +97,55 @@
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectOrderInfoList" parameterType="OrderInfo" resultMap="OrderInfoResult">
|
<select id="selectOrderInfoList" parameterType="OrderInfo" resultMap="OrderInfoResult">
|
||||||
<include refid="selectOrderInfoVo"/>
|
select t1.id,
|
||||||
|
t1.project_code,
|
||||||
|
t1.order_code,
|
||||||
|
t1.version_code,
|
||||||
|
t1.order_name,
|
||||||
|
t1.customer_code,
|
||||||
|
t1.customer_name,
|
||||||
|
t1.customer_contact,
|
||||||
|
t1.customer_phone,
|
||||||
|
t1.customer_email,
|
||||||
|
t1.customer_address,
|
||||||
|
t1.industry_type,
|
||||||
|
t1.customer_postcode,
|
||||||
|
t1.order_type,
|
||||||
|
t1.order_agent_code,
|
||||||
|
t1.order_partner_code,
|
||||||
|
t1.bg_type,
|
||||||
|
t1.order_date,
|
||||||
|
t1.status,
|
||||||
|
t1.remark,
|
||||||
|
t1.created_at,
|
||||||
|
t1.updated_at,
|
||||||
|
t1.deleted_at,
|
||||||
|
t1.create_by,
|
||||||
|
t1.update_by,
|
||||||
|
t2.user_name as create_by_name
|
||||||
|
from order_info t1
|
||||||
|
left join sys_user t2 on t1.create_by=t2.user_id
|
||||||
<where>
|
<where>
|
||||||
and status=0
|
and t1.status=0
|
||||||
<if test="orderCode != null and orderCode != ''">and order_code like concat('%', #{orderCode}, '%')</if>
|
<if test="orderCode != null and orderCode != ''">and t1.order_code like concat('%', #{orderCode}, '%')</if>
|
||||||
<if test="orderName != null and orderName != ''">and order_name like concat('%', #{orderName}, '%')</if>
|
<if test="orderName != null and orderName != ''">and t1.order_name like concat('%', #{orderName}, '%')</if>
|
||||||
<if test="customerName != null and customerName != ''">and customer_name like concat('%', #{customerName},
|
<if test="customerName != null and customerName != ''">and t1.customer_name like concat('%', #{customerName},
|
||||||
'%')
|
'%')
|
||||||
</if>
|
</if>
|
||||||
<if test="orderType != null and orderType != ''">and order_type = #{orderType}</if>
|
<if test="orderType != null and orderType != ''">and t1.order_type = #{orderType}</if>
|
||||||
<choose>
|
<choose>
|
||||||
<when test="updatedAtStart!=null and updatedAtEnd!=null">
|
<when test="updatedAtStart!=null and updatedAtEnd!=null">
|
||||||
and updated_at between #{updatedAtStart} and #{updatedAtEnd}
|
and t1.updated_at between #{updatedAtStart} and #{updatedAtEnd}
|
||||||
</when>
|
</when>
|
||||||
<when test="updatedAtStart!=null">
|
<when test="updatedAtStart!=null">
|
||||||
and updated_at <![CDATA[ >= ]]> #{updatedAtStart}
|
and t1.updated_at <![CDATA[ >= ]]> #{updatedAtStart}
|
||||||
</when>
|
</when>
|
||||||
<when test="updatedAtEnd!=null">
|
<when test="updatedAtEnd!=null">
|
||||||
and updated_at <![CDATA[ <= ]]> #{updatedAtEnd}
|
and t1.updated_at <![CDATA[ <= ]]> #{updatedAtEnd}
|
||||||
</when>
|
</when>
|
||||||
</choose>
|
</choose>
|
||||||
<if test="serialNumber!=null and serialNumber!=''">
|
<if test="serialNumber!=null and serialNumber!=''">
|
||||||
and id in (SELECT order_id from order_delivery where id in (
|
and t1.id in (SELECT order_id from order_delivery where id in (
|
||||||
|
|
||||||
select delivery_id from delivery_list where serial_number=#{serialNumber}))
|
select delivery_id from delivery_list where serial_number=#{serialNumber}))
|
||||||
</if>
|
</if>
|
||||||
|
|
Loading…
Reference in New Issue