Quellcode durchsuchen

销售端导出导入

xw vor 11 Stunden
Ursprung
Commit
248f46b143

+ 94 - 13
fs-company/src/main/java/com/fs/hisStore/controller/FsStoreOrderScrmController.java

@@ -44,12 +44,15 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -91,6 +94,12 @@ public class FsStoreOrderScrmController extends BaseController
     @Autowired
     private CloudHostProper cloudHostProper;
 
+    // 允许的文件扩展名
+    private static final String[] ALLOWED_EXCEL_EXTENSIONS = {".xlsx", ".xls"};
+
+    // 最大文件大小(5MB)
+    private static final long MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
+
     /**
      * 查询订单列表
      */
@@ -99,19 +108,6 @@ public class FsStoreOrderScrmController extends BaseController
     {
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         param.setCompanyId(loginUser.getCompany().getCompanyId());
-
-        // 郑多燕需求
-        if("广州郑多燕".equals(cloudHostProper.getCompanyName())){
-            // 根据当前销售所属的数据权限过滤订单;
-            List<CompanyUser> companyUsers = companyUserService.getDataScopeCompanyUser(loginUser.getUser().getUserId());
-            if(!companyUsers.isEmpty()){
-                List<Long> companyUserIds = companyUsers.stream().map(CompanyUser::getUserId).collect(Collectors.toList());
-                param.setCompanyUserIds(companyUserIds);
-            } else {
-                // 表示数据权限是本人
-                param.setCompanyUserId(loginUser.getUser().getUserId());
-            }
-        }
         startPage();
         if(!StringUtils.isEmpty(param.getCreateTimeRange())){
             param.setCreateTimeList(param.getCreateTimeRange().split("--"));
@@ -127,6 +123,91 @@ public class FsStoreOrderScrmController extends BaseController
     }
 
 
+    /**
+     * 发货单导出接口
+     * **/
+    @PreAuthorize("@ss.hasPermi('store:storeOrder:exportShippingOrder')")
+    @GetMapping("/exportShippingOrder")
+    public AjaxResult exportShippingOrder(FsStoreOrderParam param){
+        if ("".equals(param.getBeginTime()) && "".equals(param.getEndTime())){
+            param.setBeginTime(null);
+            param.setEndTime(null);
+        }
+        if(fsStoreOrderService.isEntityNull(param)){
+            param = new FsStoreOrderParam();
+        }
+        if(!StringUtils.isEmpty(param.getCreateTimeRange())){
+            param.setCreateTimeList(param.getCreateTimeRange().split("--"));
+        }
+        if(!StringUtils.isEmpty(param.getPayTimeRange())){
+            param.setPayTimeList(param.getPayTimeRange().split("--"));
+        }
+        if(!StringUtils.isEmpty(param.getDeliveryImportTimeRange())){
+            param.setDeliveryImportTimeList(param.getDeliveryImportTimeRange().split("--"));
+        }
+        if(!StringUtils.isEmpty(param.getDeliverySendTimeRange())){
+            param.setDeliverySendTimeList(param.getDeliverySendTimeRange().split("--"));
+        }
+        param.setNotHealth(1);
+        List<FsStoreOrderDeliveryNoteExportVO> storeOrderDeliveryNoteExportVOList=fsStoreOrderService.getDeliveryNote(param);
+        ExcelUtil<FsStoreOrderDeliveryNoteExportVO> util = new ExcelUtil<>(FsStoreOrderDeliveryNoteExportVO.class);
+        //通过商品ID获取关键字
+        String firstKeyword = storeOrderDeliveryNoteExportVOList.stream()
+                .map(FsStoreOrderDeliveryNoteExportVO::getKeyword)
+                .findFirst()
+                .orElse("无订单");
+        String fileName="077AC"+firstKeyword+new SimpleDateFormat("yyyyMMdd").format(new Date());
+        return util.exportExcel(storeOrderDeliveryNoteExportVOList, fileName);
+    }
+
+
+    //订单发货批量导入
+    @Log(title = "发货同步导入", businessType = BusinessType.IMPORT)
+    @PostMapping("/importDeliveryNoteExpress")
+    public R importDeliveryNoteExpress(@RequestParam("file") MultipartFile file, @RequestParam(name = "shipmentType",required = false) Integer shipmentType) {
+        // 1. 检查文件是否为空
+        if (file.isEmpty()) {
+            return R.error("上传的文件不能为空");
+        }
+        // 2. 检查文件大小
+        if (file.getSize() > MAX_FILE_SIZE) {
+            return R.error("文件大小不能超过5MB");
+        }
+        // 3. 检查文件扩展名
+        String fileName = file.getOriginalFilename();
+        if (fileName == null || !isValidExcelFile(fileName)) {
+            return R.error("请上传Excel文件(.xlsx或.xls格式)");
+        }
+
+        ExcelUtil<FsStoreOrderDeliveryNoteExportVO> util=new ExcelUtil<>(FsStoreOrderDeliveryNoteExportVO.class);
+        try {
+            List<FsStoreOrderDeliveryNoteExportVO> dtoList = util.importExcel(file.getInputStream());
+            if(dtoList.isEmpty()){
+                return R.error("操作失败,导入数据不能小于1条!");
+            }
+            if(dtoList.size() > 200){
+                return R.error("操作失败,导入数据不能大于200条!");
+            }
+            if(shipmentType == null){
+                shipmentType = 2;
+            }
+            return fsStoreOrderService.importDeliveryNoteExpress(dtoList,null,shipmentType);
+        }catch (Exception e){
+            logger.error("发货导入异常", e);
+            return R.error("导入失败:" + e.getMessage());
+        }
+    }
+
+    private boolean isValidExcelFile(String fileName) {
+        for (String ext : ALLOWED_EXCEL_EXTENSIONS) {
+            if (fileName.toLowerCase().endsWith(ext)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
     @GetMapping("/allList")
     public TableDataInfo allList(FsStoreOrderParam param)
     {

+ 7 - 0
fs-service/src/main/java/com/fs/hisStore/service/IFsStoreOrderScrmService.java

@@ -5,6 +5,7 @@ import com.fs.api.param.OrderListParam;
 import com.fs.api.vo.OrderListVO;
 import com.fs.common.core.domain.R;
 import com.fs.company.domain.CompanyUser;
+import com.fs.course.domain.FsCoursePlaySourceConfig;
 import com.fs.course.dto.FsOrderDeliveryNoteDTO;
 import com.fs.erp.domain.ErpOrder;
 import com.fs.his.dto.FsStoreOrderAmountScrmStatsQueryDto;
@@ -350,6 +351,12 @@ public interface IFsStoreOrderScrmService
 
     String selectFsStoreOrderProductStatistics(FsStoreOrderParam param);
 
+    /**
+     * 当从 fs_course_play_source_config 给支付单补全了 company_id 时,同步回写到订单表 fs_store_order_scrm,保证订单归属公司
+     */
+    void syncOrderCompanyFromPaymentIfSet(FsStoreOrderScrm order, FsStorePaymentScrm storePayment,
+                                          FsCoursePlaySourceConfig fsCoursePlaySourceConfig);
+
     int create(Long orderId, String type, String msg);
 
     R dfOrderResult(String body);

+ 33 - 0
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -4851,6 +4851,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                 FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
                 storePayment.setCompanyId(order.getCompanyId());
                 storePayment.setCompanyUserId(order.getCompanyUserId());
+                if (storePayment.getCompanyId() == null && fsCoursePlaySourceConfig != null && fsCoursePlaySourceConfig.getCompanyId() != null) {
+                    storePayment.setCompanyId(fsCoursePlaySourceConfig.getCompanyId());
+                }
+                syncOrderCompanyFromPaymentIfSet(order, storePayment, fsCoursePlaySourceConfig);
                 storePayment.setPayMode(merchantAppConfig.getMerchantType());
                 storePayment.setStatus(0);
                 storePayment.setPayCode(payCode);
@@ -5003,6 +5007,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
             storePayment.setCompanyId(order.getCompanyId());
             storePayment.setCompanyUserId(order.getCompanyUserId());
+            if (storePayment.getCompanyId() == null && fsCoursePlaySourceConfig != null && fsCoursePlaySourceConfig.getCompanyId() != null) {
+                storePayment.setCompanyId(fsCoursePlaySourceConfig.getCompanyId());
+            }
+            syncOrderCompanyFromPaymentIfSet(order, storePayment, fsCoursePlaySourceConfig);
             storePayment.setStatus(0);
             storePayment.setPayMode(merchantAppConfig.getMerchantType());
             storePayment.setPayCode(payCode);
@@ -5134,6 +5142,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
             storePayment.setCompanyId(order.getCompanyId());
             storePayment.setCompanyUserId(order.getCompanyUserId());
+            if (storePayment.getCompanyId() == null && fsCoursePlaySourceConfig != null && fsCoursePlaySourceConfig.getCompanyId() != null) {
+                storePayment.setCompanyId(fsCoursePlaySourceConfig.getCompanyId());
+            }
+            syncOrderCompanyFromPaymentIfSet(order, storePayment, fsCoursePlaySourceConfig);
             storePayment.setStatus(0);
             storePayment.setPayCode(payCode);
             storePayment.setPayMode(merchantAppConfig.getMerchantType());
@@ -5247,6 +5259,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
             storePayment.setCompanyId(order.getCompanyId());
             storePayment.setCompanyUserId(order.getCompanyUserId());
+            if (storePayment.getCompanyId() == null && fsCoursePlaySourceConfig != null && fsCoursePlaySourceConfig.getCompanyId() != null) {
+                storePayment.setCompanyId(fsCoursePlaySourceConfig.getCompanyId());
+            }
+            syncOrderCompanyFromPaymentIfSet(order, storePayment, fsCoursePlaySourceConfig);
             storePayment.setStatus(0);
             storePayment.setPayMode(merchantAppConfig.getMerchantType());
             storePayment.setPayCode(payCode);
@@ -5580,6 +5596,23 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
     }
 
     @Override
+    public void syncOrderCompanyFromPaymentIfSet(FsStoreOrderScrm order, FsStorePaymentScrm storePayment,
+                                                 FsCoursePlaySourceConfig fsCoursePlaySourceConfig) {
+        if (order == null || order.getId() == null || order.getCompanyId() != null) {
+            return;
+        }
+        if (storePayment == null || storePayment.getCompanyId() == null) {
+            return;
+        }
+        FsStoreOrderScrm updateOrder = new FsStoreOrderScrm();
+        updateOrder.setId(order.getId());
+        updateOrder.setCompanyId(storePayment.getCompanyId());
+        if (fsCoursePlaySourceConfig != null && fsCoursePlaySourceConfig.getCompanyUserId() != null && order.getCompanyUserId() == null) {
+            updateOrder.setCompanyUserId(fsCoursePlaySourceConfig.getCompanyUserId());
+        }
+        fsStoreOrderMapper.updateFsStoreOrder(updateOrder);
+    }
+
     public int create(Long orderId, String type, String msg) {
         FsStoreOrderLogsScrm logs=new FsStoreOrderLogsScrm();
         logs.setOrderId(orderId);

+ 8 - 2
fs-service/src/main/resources/mapper/hisStore/FsStoreOrderScrmMapper.xml

@@ -1486,8 +1486,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 and o.user_phone like CONCAT('%',#{maps.userPhone},'%')
             </if>
 
-            <!-- 按 tab 筛状态:有商户号时顶部金额统计该商户下全部已支付(含待发货),不再按 status 过滤 -->
-            <if test="maps.status != null and maps.status != 6 and (maps.merchantId == null or maps.merchantId == '')">
+            <!-- 按 tab 筛状态:有商户号或公司顶部金额统计该商户/公司下全部已支付,不再按 status 过滤 -->
+            <if test="maps.status != null and maps.status != 6 and (maps.merchantId == null or maps.merchantId == '') and maps.companyId == null">
                 and o.status = #{maps.status}
             </if>
             <if test="maps.status == 6">
@@ -1509,6 +1509,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
             <if test="maps.companyId != null   ">
                 and o.company_id =#{maps.companyId}
+                <!-- 按公司统计时只统计已支付且未退款(含待发货、status=1 已支付),与商户号逻辑一致 -->
+                and (
+                    o.status in (2, 3, 4, 5)
+                    or (o.status = 1 and (o.paid = 1 or o.pay_time is not null))
+                )
+                and (o.refund_status is null or o.refund_status = '0' or o.refund_status = '1')
             </if>
             <if test="maps.isHealth != null and maps.isHealth !=  ''   ">
                 and o.company_id is null