From 3bd3767aeb905dd8a560e251658d5b272a51ccf4 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 03 四月 2026 11:17:13 +0800
Subject: [PATCH] fix: 新增台账没有状态

---
 src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java |  149 +++++++++++++++++++++++++++++++++++--------------
 1 files changed, 105 insertions(+), 44 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java b/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
index c498b93..4f00394 100644
--- a/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
+++ b/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
@@ -3,20 +3,35 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+// import com.ruoyi.approve.mapper.ApproveProcessMapper;
+// import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl;
+// import com.ruoyi.approve.vo.ApproveProcessVO;
+// import com.ruoyi.common.enums.FileNameType;
+import com.ruoyi.approve.service.IApproveProcessService;
+import com.ruoyi.approve.vo.ApproveProcessVO;
+import com.ruoyi.common.utils.OrderUtils;
+// import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
+// import com.ruoyi.framework.security.LoginUser;
+import com.ruoyi.framework.security.LoginUser;
 import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.domain.AjaxResult;
-import com.ruoyi.sales.mapper.ShipmentApprovalMapper;
+// import com.ruoyi.other.service.impl.TempFileServiceImpl;
+// import com.ruoyi.procurementrecord.utils.StockUtils;
+import com.ruoyi.sales.dto.ShippingInfoDto;
+// import com.ruoyi.sales.mapper.ShipmentApprovalMapper;
 import com.ruoyi.sales.mapper.ShippingInfoMapper;
 import com.ruoyi.sales.pojo.SalesLedger;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
-import com.ruoyi.sales.pojo.ShipmentApproval;
+// import com.ruoyi.sales.pojo.ShipmentApproval;
 import com.ruoyi.sales.pojo.ShippingInfo;
 import com.ruoyi.sales.service.ISalesLedgerProductService;
 import com.ruoyi.sales.service.ISalesLedgerService;
 import com.ruoyi.sales.service.ShippingInfoService;
+// import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.collections4.CollectionUtils;
@@ -25,6 +40,9 @@
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+// import java.time.LocalDate;
+import java.time.LocalDate;
 import java.util.List;
 
 /**
@@ -38,61 +56,106 @@
 
     @Autowired
     private ShippingInfoService shippingInfoService;
-    @Autowired
-    private ShipmentApprovalMapper shipmentApprovalMapper;
+
+    // @Autowired
+    // private CommonFileServiceImpl commonFileService;
+
+     @Autowired
+     private IApproveProcessService approveProcessService;
+
+    // @Autowired
+    // private StockUtils stockUtils;
+
     @Autowired
     private ISalesLedgerProductService salesLedgerProductService;
+
+    @Autowired
+    private ISalesLedgerService salesLedgerService;
+
+    @Autowired
+    private com.ruoyi.sales.mapper.SalesLedgerProductMapper salesLedgerProductMapper;
 
 
     @GetMapping("/listPage")
     @ApiOperation("鍙戣揣淇℃伅鍒楄〃")
     public AjaxResult listPage(Page page, ShippingInfo req) {
-        IPage<ShippingInfo> listPage = shippingInfoService.listPage(page,req);
+        IPage<ShippingInfoDto> listPage = shippingInfoService.listPage(page,req);
         return AjaxResult.success(listPage);
     }
 
     @PostMapping("/add")
     @ApiOperation("娣诲姞鍙戣揣淇℃伅")
     @Transactional(rollbackFor = Exception.class)
-    public AjaxResult add(@RequestBody ShippingInfo req) {
-        LambdaQueryWrapper<ShippingInfo> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(ShippingInfo::getSalesLedgerId, req.getSalesLedgerId());
-        wrapper.eq(ShippingInfo::getSalesLedgerProductId, req.getSalesLedgerProductId());
-        List<ShippingInfo> list = shippingInfoService.list(wrapper);
-        if(!CollectionUtils.isEmpty(list)){
-            return AjaxResult.error("鍙戣揣淇℃伅宸插瓨鍦�");
+    @Log(title = "鍙戣揣淇℃伅绠$悊", businessType = BusinessType.INSERT)
+    public AjaxResult add(@RequestBody ShippingInfoDto req) throws Exception {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        
+        if (req.getSalesLedgerId() == null) {
+            return AjaxResult.error("鍏宠仈璁㈠崟 ID 涓嶈兘涓虹┖");
         }
-        boolean save = shippingInfoService.save(req);
-        if(save){
-            ShippingInfo shippingInfo = shippingInfoService.getOne(wrapper);
-            ShipmentApproval shipmentApproval = new ShipmentApproval();
-            shipmentApproval.setSalesLedgerId(req.getSalesLedgerId());
-            shipmentApproval.setSalesLedgerProductId(req.getSalesLedgerProductId());
-            shipmentApproval.setApproveUserId(req.getApproverId());
-            shipmentApproval.setApproveStatus(2);
-            shipmentApproval.setShippingInfoId(shippingInfo.getId());
-            shipmentApprovalMapper.insert(shipmentApproval);
 
-            SalesLedgerProduct salesLedgerProduct = salesLedgerProductService.getById(req.getSalesLedgerProductId());
-            if(salesLedgerProduct != null){
-                salesLedgerProduct.setApproveStatus(2);
-                salesLedgerProductService.updateById(salesLedgerProduct);
+        SalesLedger salesLedger = salesLedgerService.getById(req.getSalesLedgerId());
+        if (salesLedger == null) {
+            return AjaxResult.error("鍏宠仈璁㈠崟涓嶅瓨鍦�");
+        }
+
+        // 妫�鏌ユ槸鍚﹀凡缁忓湪瀹℃壒涓垨宸插彂璐�
+        if (salesLedger.getDeliveryStatus() != null && salesLedger.getDeliveryStatus() >= 2 && !salesLedger.getDeliveryStatus().equals(3)) {
+             return AjaxResult.error("璇ヨ鍗曞凡鍦ㄥ鎵逛腑鎴栧凡鍙戣揣锛屾棤娉曢噸澶嶅彂璧�");
+        }
+
+        String shNo = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH");
+
+        //  鍙戣捣璁㈠鎵�
+        ApproveProcessVO approveProcessVO = new ApproveProcessVO();
+        approveProcessVO.setApproveType(7);
+        approveProcessVO.setApproveDeptId(loginUser.getCurrentDeptId());
+        // 瀹℃壒鐞嗙敱鍖呭惈鍚堝悓鍙凤紝鐢ㄤ簬鍚庣画瀹℃壒閫氳繃鍚庢壘鍥炶鍗�
+        approveProcessVO.setApproveReason("鍙戣揣瀹℃壒:" + salesLedger.getSalesContractNo());
+        approveProcessVO.setApproveUserIds(req.getApproveUserIds());
+        approveProcessVO.setApproveUser(loginUser.getUserId());
+        approveProcessVO.setApproveTime(LocalDate.now().toString());
+        approveProcessService.addApprove(approveProcessVO);
+
+        //  鏇存柊閿�鍞彴璐︾姸鎬佷负 2 (瀹℃壒涓�)
+        salesLedger.setDeliveryStatus(2);
+        salesLedgerService.updateById(salesLedger);
+
+        //  涓鸿鍗曚笅鐨勬瘡涓�涓骇鍝佺敓鎴愬彂璐у彴璐﹁褰� (鏄剧ず鍗曚釜浜у搧)
+        List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>()
+                .eq(SalesLedgerProduct::getSalesLedgerId, salesLedger.getId()));
+        
+        if (CollectionUtils.isNotEmpty(products)) {
+            for (SalesLedgerProduct product : products) {
+                ShippingInfo si = new ShippingInfo();
+                si.setSalesLedgerId(salesLedger.getId());
+                si.setSalesLedgerProductId(product.getId());
+                si.setShippingNo(shNo);
+                si.setStatus("寰呭鏍�");
+                si.setType(req.getType()); // 鏉ユ簮/绫诲瀷
+                shippingInfoService.save(si);
             }
-
         }
-        return save ? AjaxResult.success() : AjaxResult.error();
+
+        return AjaxResult.success("鍙戣揣瀹℃壒宸插彂璧�");
+    }
+
+    @ApiOperation("鍙戣揣鎵e簱瀛�")
+    @PostMapping("/deductStock")
+    @Transactional(rollbackFor = Exception.class)
+    @Log(title = "鍙戣揣淇℃伅绠$悊", businessType = BusinessType.UPDATE)
+    public AjaxResult deductStock(@RequestBody ShippingInfoDto req) throws IOException {
+        return shippingInfoService.deductStock( req) ? AjaxResult.success() : AjaxResult.error();
     }
 
     @PostMapping("/update")
     @ApiOperation("淇敼鍙戣揣淇℃伅")
+    @Transactional(rollbackFor = Exception.class)
+    @Log(title = "鍙戣揣淇℃伅绠$悊", businessType = BusinessType.UPDATE)
     public AjaxResult update(@RequestBody ShippingInfo req) {
         ShippingInfo byId = shippingInfoService.getById(req.getId());
         if (byId == null) {
             return AjaxResult.error("鍙戣揣淇℃伅涓嶅瓨鍦�");
-        }
-        Long userId = getLoginUser().getUserId();
-        if(!userId.equals(Long.parseLong(byId.getCreateUser().toString()))){
-            return AjaxResult.error("鎮ㄦ病鏈夋潈闄愪慨鏀规鍙戣揣淇℃伅");
         }
         boolean update = shippingInfoService.updateById(req);
         return update ? AjaxResult.success() : AjaxResult.error();
@@ -100,19 +163,11 @@
 
     @DeleteMapping("/delete")
     @ApiOperation("鍒犻櫎鍙戣揣淇℃伅")
+    @Transactional(rollbackFor = Exception.class)
+    @Log(title = "鍙戣揣淇℃伅绠$悊", businessType = BusinessType.DELETE)
     public AjaxResult delete(@RequestBody List<Long> ids) {
-        Long userId = getLoginUser().getUserId();
-        ids.forEach(id -> {
-            ShippingInfo byId = shippingInfoService.getById(id);
-            if (byId == null) {
-                throw new RuntimeException("鍙戣揣淇℃伅涓嶅瓨鍦�");
-            }
-            if(!userId.equals(Long.parseLong(byId.getCreateUser().toString()))){
-                throw new RuntimeException("鎮ㄦ病鏈夋潈闄愬垹闄ゆ鍙戣揣淇℃伅");
-            }
-        });
-        boolean delete = shippingInfoService.removeBatchByIds(ids);
-        return delete ? AjaxResult.success("鍒犻櫎鎴愬姛") : AjaxResult.error("鍒犻櫎澶辫触");
+
+        return shippingInfoService.delete(ids) ? AjaxResult.success("鍒犻櫎鎴愬姛") : AjaxResult.error("鍒犻櫎澶辫触");
     }
 
     @Autowired
@@ -129,4 +184,10 @@
         util.exportExcel(response, list, "鍙戣揣淇℃伅");
     }
 
+
+    @GetMapping("/getByCustomerName")
+    @ApiOperation("閫氳繃瀹㈡埛鍚嶇О鏌ヨ")
+    public AjaxResult getByCustomerName(String customerName) {
+        return AjaxResult.success(shippingInfoService.getShippingInfoByCustomerName(customerName));
+    }
 }

--
Gitblit v1.9.3