feat(sip): 添加合同清单模板下载功能

- 在 application.yml 中添加 excelTemplate 配置项,用于指定 Excel 模板路径- 修改 OrderInfoController,增加 listExport 方法用于下载合同清单模板- 更新 RuoYiConfig 类,添加 getExcelTemplate 和 setExcelTemplate 方法
- 优化 DeliveryListServiceImpl 中的年份解析逻辑,增加空值判断
master
chenhao 2025-05-20 17:46:37 +08:00
parent fa3c8634c2
commit 4a3c292d14
4 changed files with 38 additions and 7 deletions

View File

@ -12,7 +12,7 @@ ruoyi:
profile: D:\ruoyi\uploadPath profile: D:\ruoyi\uploadPath
# 获取ip地址开关 # 获取ip地址开关
addressEnabled: false addressEnabled: false
excelTemplate: D:\ruoyi\excelTemplate
# 开发环境配置 # 开发环境配置
server: server:
# 服务器的HTTP端口默认为80 # 服务器的HTTP端口默认为80

View File

@ -26,6 +26,7 @@ public class RuoYiConfig
/** 上传路径 */ /** 上传路径 */
private static String profile; private static String profile;
private static String excelTemplate;
/** 获取地址开关 */ /** 获取地址开关 */
private static boolean addressEnabled; private static boolean addressEnabled;
@ -121,4 +122,12 @@ public class RuoYiConfig
{ {
return getProfile() + "/upload"; return getProfile() + "/upload";
} }
public static String getExcelTemplate() {
return excelTemplate;
}
public void setExcelTemplate(String excelTemplate) {
RuoYiConfig.excelTemplate = excelTemplate;
}
} }

View File

@ -1,17 +1,23 @@
package com.ruoyi.sip.controller; package com.ruoyi.sip.controller;
import java.io.File;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.sip.domain.*; import com.ruoyi.sip.domain.*;
import com.ruoyi.sip.service.IProductInfoService; import com.ruoyi.sip.service.IProductInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -24,6 +30,9 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/** /**
* Controller * Controller
* *
@ -32,6 +41,7 @@ import org.springframework.web.multipart.MultipartFile;
*/ */
@Controller @Controller
@RequestMapping("/manage/order") @RequestMapping("/manage/order")
@Slf4j
public class OrderInfoController extends BaseController public class OrderInfoController extends BaseController
{ {
private String prefix = "manage/order"; private String prefix = "manage/order";
@ -169,11 +179,23 @@ public class OrderInfoController extends BaseController
@RequiresPermissions("sip:list:export") @RequiresPermissions("sip:list:export")
@Log(title = "发货清单", businessType = BusinessType.EXPORT) @Log(title = "发货清单", businessType = BusinessType.EXPORT)
@PostMapping("/list/export") @PostMapping("/list/export")
@ResponseBody public void listExport(HttpServletRequest request, HttpServletResponse response) {
public AjaxResult listExport(OrderList orderList) { try
List<OrderList> list = orderInfoService.listExport(orderList); {
ExcelUtil<OrderList> util = new ExcelUtil<OrderList>(OrderList.class);
return util.exportExcel(list, "合同清单数据"); // 本地资源路径
String localPath = RuoYiConfig.getExcelTemplate();
// 下载名称
String fileName = "合同清单明细.xlsx";
String downloadPath = localPath+ File.separator+ fileName;
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, fileName);
FileUtils.writeBytes(downloadPath, response.getOutputStream());
}
catch (Exception e)
{
log.error("下载文件失败", e);
}
} }
@PostMapping("/list/importData") @PostMapping("/list/importData")
@ResponseBody @ResponseBody

View File

@ -235,7 +235,7 @@ public class DeliveryListServiceImpl implements IDeliveryListService {
} }
private static Date updateStartTimeAndAddList(DeliveryInfoVo deliveryInfoVo, ProductInfo productInfo, Date startTime, List<DeliveryInfoVo.ServiceInfo> serviceInfoList) { private static Date updateStartTimeAndAddList(DeliveryInfoVo deliveryInfoVo, ProductInfo productInfo, Date startTime, List<DeliveryInfoVo.ServiceInfo> serviceInfoList) {
int year = Integer.parseInt(productInfo.getValue()); int year = productInfo.getValue() == null ? 0 : Integer.parseInt(productInfo.getValue());
DeliveryInfoVo.ServiceInfo serviceInfo = deliveryInfoVo.new ServiceInfo(); DeliveryInfoVo.ServiceInfo serviceInfo = deliveryInfoVo.new ServiceInfo();
serviceInfo.setServiceLevel(productInfo.getValue()); serviceInfo.setServiceLevel(productInfo.getValue());
serviceInfo.setServiceDescribe(productInfo.getDescription()); serviceInfo.setServiceDescribe(productInfo.getDescription());