|
|
@@ -34,26 +34,35 @@ import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.his.vo.FsStoreOrderExcelVO;
|
|
|
import com.fs.his.vo.FsStoreOrderStoreExcelVO;
|
|
|
import com.fs.hisStore.domain.*;
|
|
|
+import com.fs.hisStore.dto.StoreOrderProductDTO;
|
|
|
import com.fs.hisStore.mapper.FsStoreOrderItemScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStoreVerifyCodeScrmMapper;
|
|
|
import com.fs.hisStore.param.FsStoreOrderExpressEditParam;
|
|
|
import com.fs.hisStore.param.FsStoreOrderParam;
|
|
|
import com.fs.hisStore.service.*;
|
|
|
import com.fs.hisStore.utils.UserUtil;
|
|
|
-import com.fs.hisStore.vo.FsStoreOrderAuditLogVO;
|
|
|
-import com.fs.hisStore.vo.FsStoreOrderVO;
|
|
|
-import com.fs.hisStore.vo.FsStoreProductDeliverExcelVO;
|
|
|
+import com.fs.hisStore.vo.*;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 订单Controller
|
|
|
@@ -120,6 +129,18 @@ public class FsStoreOrderScrmController extends BaseController
|
|
|
@Autowired
|
|
|
private FsStoreVerifyCodeScrmMapper fsStoreVerifyCodeService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IFsStorePaymentScrmService fsStorePaymentService;
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreScrmService fsStoreScrmService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreProductScrmService fsStoreProductService;
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreAfterSalesScrmService fsStoreAfterSalesService;
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreAfterSalesItemScrmService fsStoreAfterSalesItemService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取订单评价详细信息
|
|
|
*/
|
|
|
@@ -499,4 +520,160 @@ public class FsStoreOrderScrmController extends BaseController
|
|
|
public AjaxResult editDeliveryId(@RequestBody FsStoreOrderScrm fsStoreOrder) {
|
|
|
return toAjax(fsStoreOrderService.updateFsStoreOrder(fsStoreOrder));
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/downloadExcel/{id}")
|
|
|
+ public void downloadExcel(@PathVariable("id") Long id, HttpServletResponse response) {
|
|
|
+ //商城订单
|
|
|
+ FsStoreOrderScrm fsStoreOrderScrm = fsStoreOrderService.selectFsStoreOrderById(id);
|
|
|
+
|
|
|
+ FsStoreScrm fsStoreScrm = fsStoreScrmService.selectFsStoreByStoreId(fsStoreOrderScrm.getStoreId());
|
|
|
+
|
|
|
+ fsStorePaymentService.selectFsStorePaymentByOrderId(fsStoreOrderScrm.getId());
|
|
|
+ //拿到所有的商品
|
|
|
+ List<FsStoreOrderItemVO> orderItems = orderItemService.selectFsStoreOrderItemListByOrderId(fsStoreOrderScrm.getId());
|
|
|
+
|
|
|
+ String templatePath = "/打印详情表格.xlsx";
|
|
|
+
|
|
|
+ Workbook workbook = null;
|
|
|
+ InputStream fis = null;
|
|
|
+ ServletOutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ fis = this.getClass().getResourceAsStream(templatePath);
|
|
|
+ if (fis == null) {
|
|
|
+ throw new RuntimeException("模板文件未找到: " + templatePath);
|
|
|
+ }
|
|
|
+ workbook = new XSSFWorkbook(fis);
|
|
|
+ Sheet sheet = workbook.getSheetAt(0); // 第一个工作表
|
|
|
+ int startCol = 1;
|
|
|
+ /**销售出库明细单**/
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ for (int i = 0; i < orderItems.size(); i++) {
|
|
|
+ StoreOrderProductDTO cartInfo = JSONObject.parseObject(orderItems.get(i).getJsonInfo(), StoreOrderProductDTO.class);
|
|
|
+ setCellValue(sheet, 9, startCol + i, cartInfo.getSku());//规格(型号)
|
|
|
+ setCellValue(sheet, 13, startCol + i, String.valueOf(cartInfo.getNum()));//数量
|
|
|
+ setCellValue(sheet, 14, startCol + i, String.valueOf(cartInfo.getPrice()));//单价(元)
|
|
|
+ setCellValue(sheet, 15, startCol + i, String.valueOf(cartInfo.getPrice()));//金额(元)
|
|
|
+ FsStoreProductScrm fsStoreProductScrm = fsStoreProductService.selectFsStoreProductById(cartInfo.getProductId());
|
|
|
+ setCellValue(sheet, 10, startCol + i, fsStoreProductScrm != null && fsStoreProductScrm.getManufacturer()!= null ?fsStoreProductScrm.getManufacturer(): "");//生产企业名称
|
|
|
+ setCellValue(sheet, 8, startCol + i, cartInfo.getProductName() == null ? fsStoreProductScrm != null && fsStoreProductScrm.getCommonName()!= null ?fsStoreProductScrm.getCommonName() : cartInfo.getProductName():"");//商品名称
|
|
|
+ }
|
|
|
+ String payTimeStr = null;
|
|
|
+ Date payTime = fsStoreOrderScrm.getPayTime();
|
|
|
+ if (payTime != null) {
|
|
|
+ payTimeStr = sdf.format(payTime);
|
|
|
+ }
|
|
|
+ setCellValue(sheet, 2, 1, fsStoreOrderScrm.getOrderCode());//订单编号
|
|
|
+ setCellValue(sheet, 3, 1, fsStoreScrm != null?fsStoreScrm.getStoreName():"");//店铺名称
|
|
|
+ setCellValue(sheet, 4, 1, fsStoreScrm != null?fsStoreScrm.getFullName():"");//企业全称
|
|
|
+ setCellValue(sheet, 5, 1, fsStoreScrm != null?fsStoreScrm.getEnterpriseAddress():"");//经营地址 营业执照上的地址
|
|
|
+ setCellValue(sheet, 6, 1, fsStoreScrm != null?fsStoreScrm.getRefundPhone():"");//联系电话 这个地方拉取商家入驻的时候填写的退货电话
|
|
|
+ setCellValue(sheet, 7, 1, payTimeStr);//销售日期 订单支付时间
|
|
|
+ setCellValue(sheet, 11, 1, fsStoreOrderScrm.getBatchNumber());//生产批号(药品) / 序列号(器械)
|
|
|
+ setCellValue(sheet, 12, 1, fsStoreOrderScrm.getVerifyCode());//有效期/追溯码
|
|
|
+ setCellValue(sheet, 16, 1, String.valueOf(fsStoreOrderScrm.getTotalPrice()));//合计金额(元)
|
|
|
+
|
|
|
+
|
|
|
+ /**销售退款明细单**/
|
|
|
+ List<FsStorePaymentScrm> fsStorePaymentScrms = fsStorePaymentService.selectFsStorePaymentByOrderIdAndStatus(fsStoreOrderScrm.getId());
|
|
|
+ if (!CollectionUtils.isEmpty(fsStorePaymentScrms)) {
|
|
|
+ List<FsStoreAfterSalesVO> fsStoreAfterSalesVOS = fsStoreAfterSalesService.selectFsStoreAfterSalesVOByOrderCode(fsStoreOrderScrm.getOrderCode());
|
|
|
+ FsStoreAfterSalesItemScrm map = new FsStoreAfterSalesItemScrm();
|
|
|
+ map.setStoreAfterSalesId(fsStoreAfterSalesVOS.get(0).getId());
|
|
|
+ List<FsStoreAfterSalesItemScrm> items = fsStoreAfterSalesItemService.selectFsStoreAfterSalesItemList(map);
|
|
|
+ setCellValue(sheet, 24, 1, fsStorePaymentScrms.get(0).getBankSerialNo());//退款单号 fs_store_payment_scrm支付明细表
|
|
|
+ setCellValue(sheet, 25, 1, fsStoreOrderScrm.getOrderCode());//原销售订单编号
|
|
|
+ setCellValue(sheet, 26, 1, fsStoreScrm.getStoreName());//店铺名称
|
|
|
+ setCellValue(sheet, 27, 1, fsStoreScrm.getEnterpriseAddress());//经营地址 营业执照上的地址
|
|
|
+ setCellValue(sheet, 28, 1, fsStoreScrm.getRefundPhone());//联系电话 这个地方拉取商家入驻的时候填写的退货电话
|
|
|
+ setCellValue(sheet, 29, 1, sdf.format(fsStorePaymentScrms.get(0).getRefundTime()));//退货日期
|
|
|
+ int startNul = 1;
|
|
|
+ Integer total = 0;
|
|
|
+ for (int i = 0; i < items.size(); i++) {
|
|
|
+ setCellValue(sheet, 32, startNul + i, items.get(0).getMah());//生产企业名称
|
|
|
+ Integer tal = 0;
|
|
|
+ String jsonInfo = items.get(i).getJsonInfo();
|
|
|
+ if (StringUtils.isNotEmpty(jsonInfo)) {
|
|
|
+ StoreOrderProductDTO cartInfo = JSONObject.parseObject(jsonInfo, StoreOrderProductDTO.class);
|
|
|
+ setCellValue(sheet, 30, startNul + i, cartInfo.getProductName());//商品名称 如果为空取通用名称,
|
|
|
+ setCellValue(sheet, 31, startNul + i, cartInfo.getSku());//规格(型号)
|
|
|
+ setCellValue(sheet, 33, startNul + i, cartInfo.getBarCode());//生产批号 / 序列号 这应该药品的追溯码一样,都是发货的时候才会上传
|
|
|
+
|
|
|
+ setCellValue(sheet, 35, startNul + i, String.valueOf(cartInfo.getNum()));//退货数量
|
|
|
+ setCellValue(sheet, 36, startNul + i, String.valueOf(cartInfo.getPrice()));//单价(元)
|
|
|
+ setCellValue(sheet, 37, startNul + i, cartInfo.getNum() == null || cartInfo.getPrice() == null ? "" : String.valueOf(cartInfo.getPrice().multiply(new BigDecimal(cartInfo.getNum()))));//退货金额(元) 单个产品的单价*数量
|
|
|
+ if (cartInfo.getNum() != null && cartInfo.getPrice() != null) {
|
|
|
+ tal = cartInfo.getNum() * (Integer.valueOf(String.valueOf(cartInfo.getPrice())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ total += tal;
|
|
|
+ }
|
|
|
+ setCellValue(sheet, 34, 1, fsStoreOrderScrm.getVerifyCode());//有效期/追溯码 这应该药品的追溯码一样,都是发货的时候才会上传
|
|
|
+
|
|
|
+ setCellValue(sheet, 38, 1, String.valueOf(total));//退款金额(元) 退款金额
|
|
|
+ setCellValue(sheet, 39, 1, fsStoreAfterSalesVOS.get(0).getReasons());//退货原因 fs_store_after_sales_scrm
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置响应头
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+
|
|
|
+ // 这里设置文件名为订单号或其他标识
|
|
|
+ String fileName = "打印详情表格.xlsx";
|
|
|
+ // 对文件名进行URL编码,防止中文乱码
|
|
|
+ fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
|
|
|
+
|
|
|
+ // 将工作簿写入响应输出流
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
+ workbook.write(outputStream);
|
|
|
+ workbook.close();
|
|
|
+ outputStream.flush();
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ // 可以返回错误信息或重定向到错误页面
|
|
|
+ try {
|
|
|
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "生成Excel文件时出错");
|
|
|
+ } catch (IOException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ // 按照创建顺序的逆序关闭资源
|
|
|
+ try {
|
|
|
+ if (workbook != null) {
|
|
|
+ workbook.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("关闭Workbook失败", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (fis != null) {
|
|
|
+ fis.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("关闭输入流失败", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (outputStream != null) {
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("关闭输出流失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void setCellValue(Sheet sheet, int rowNum, int colNum, String value) {
|
|
|
+ Row row = sheet.getRow(rowNum);
|
|
|
+ if (row == null) {
|
|
|
+ row = sheet.createRow(rowNum);
|
|
|
+ }
|
|
|
+ Cell cell = row.getCell(colNum);
|
|
|
+ if (cell == null) {
|
|
|
+ cell = row.createCell(colNum);
|
|
|
+ }
|
|
|
+ cell.setCellValue(value);
|
|
|
+ }
|
|
|
}
|