From 527cbd85e37842d93d081f33916dca5c6f7156e0 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期日, 24 九月 2023 09:53:58 +0800
Subject: [PATCH] 修改   9.22

---
 inventory-server/src/main/java/com/yuanchu/mom/controller/SaleController.java |   52 +++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/inventory-server/src/main/java/com/yuanchu/mom/controller/SaleController.java b/inventory-server/src/main/java/com/yuanchu/mom/controller/SaleController.java
index c593771..dfc3a62 100644
--- a/inventory-server/src/main/java/com/yuanchu/mom/controller/SaleController.java
+++ b/inventory-server/src/main/java/com/yuanchu/mom/controller/SaleController.java
@@ -3,6 +3,7 @@
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.yuanchu.mom.pojo.dto.SaleMaterialDto;
 import com.yuanchu.mom.pojo.vo.SaleVo;
 import com.yuanchu.mom.service.RepertoryService;
 import com.yuanchu.mom.utils.JackSonUtil;
@@ -16,6 +17,7 @@
 import io.swagger.annotations.ApiOperation;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import springfox.documentation.spring.web.json.Json;
 
 import javax.annotation.Resource;
 import java.util.*;
@@ -39,8 +41,6 @@
     @Resource
     Jwt jwt;
 
-    @Resource
-    RepertoryService repertoryService;
 
     @ApiOperation(value = "鏌ヨ閿�鍞崟鍒楄〃")
     @ApiImplicitParams(value = {
@@ -62,9 +62,21 @@
 
     @ApiOperation(value = "鏂板閿�鍞崟")
     @PostMapping("/addSale")
-    public Result addSale(@RequestHeader("token") String token,@Validated @RequestBody SaleDto saleDto) throws Exception {
-            Map<String, String> data = JackSonUtil.unmarshal(jwt.readJWT(token).get("data"), Map.class);
-            saleService.addSale(data.get("name").replaceAll("\"", ""), saleDto);
+    public Result addSale(@RequestHeader("token") String token, @Validated @RequestBody SaleDto saleDto) throws Exception {
+        //鏍¢獙,鍚屼竴涓骇鍝佺殑瑙勬牸鍨嬪彿涓嶈兘鐩稿悓
+        List<SaleMaterialDto> saleMaterialList = saleDto.getSaleMaterialList();
+        // 浣跨敤鍝堝笇闆嗗悎鏉ュ垽鏂槸鍚﹀瓨鍦ㄧ浉鍚屽瓧娈靛�肩粍鍚�
+        Set<String> seen = new HashSet<>();
+        for (SaleMaterialDto saleMaterial: saleMaterialList) {
+            String key = saleMaterial.getName() + "," + saleMaterial.getSpecifications();
+            if (seen.contains(key)) {
+                return Result.fail("鍚屼竴涓骇鍝佺殑瑙勬牸鍨嬪彿涓嶈兘鐩稿悓");
+            } else {
+                seen.add(key);
+            }
+        }
+        Map<String, String> data = JackSonUtil.unmarshal(jwt.readJWT(token).get("data"), Map.class);
+        saleService.addSale(data.get("name").replaceAll("\"", ""), saleDto);
         return Result.success("鏂板鎴愬姛!");
     }
 
@@ -79,14 +91,14 @@
 
     @ApiOperation(value = "鏍规嵁閿�鍞崟id淇敼璇︽儏淇℃伅")
     @ApiImplicitParams(value = {
-            @ApiImplicitParam(name = "id", value = "閿�鍞崟id", dataTypeClass = Integer.class, required = true)
+            @ApiImplicitParam(name = "id", value = "閿�鍞崟id", dataTypeClass = Integer.class, required = true),
+            @ApiImplicitParam(name = "id", value = "json鏍煎紡鐨勯攢鍞崟鍐呭", dataTypeClass = Json.class, required = true)
     })
     @PostMapping("/updateSaleById")
-    public Result updateSaleById(@RequestHeader("token") String token,Integer id, String str) throws Exception {
+    public Result updateSaleById(@RequestHeader("token") String token, Integer id, String str) throws Exception {
         SaleVo saleVo = JackSonUtil.unmarshal(str, SaleVo.class);
         Map<String, String> data = JackSonUtil.unmarshal(jwt.readJWT(token).get("data"), Map.class);
-        saleService.updateSaleById(data.get("name").replaceAll("\"", ""),id, saleVo);
-        return Result.success("淇敼鎴愬姛!");
+        return Result.success(saleService.updateSaleById(data.get("name").replaceAll("\"", ""), id, saleVo));
     }
 
     @ApiOperation(value = "鏍规嵁閿�鍞崟id鍒犻櫎")
@@ -101,10 +113,10 @@
 
     @ApiOperation(value = "鎵归噺鍒犻櫎")
     @ApiImplicitParams(value = {
-            @ApiImplicitParam(name = "ids", value = "ids", dataTypeClass = Integer.class, dataType = "List",required = true)
+            @ApiImplicitParam(name = "ids", value = "ids", dataTypeClass = String.class,required = true)
     })
     @PostMapping("/delAllSale")
-    public Result delAllSale( @RequestParam("ids") List<Integer> ids) {
+    public Result delAllSale(String ids) {
         saleService.delAllSale(ids);
         return Result.success();
     }
@@ -115,11 +127,25 @@
             @ApiImplicitParam(name = "type", value = "鐘舵��", dataTypeClass = Integer.class, required = true)
     })
     @PostMapping("/check")
-    public Result check(@RequestHeader("token") String token,Integer id,Integer type) throws Exception {
+    public Result check(@RequestHeader("token") String token, Integer id, Integer type) throws Exception {
         Map<String, String> data = JackSonUtil.unmarshal(jwt.readJWT(token).get("data"), Map.class);
-        saleService.check(data.get("name").replaceAll("\"", ""),id,type);
+        saleService.check(data.get("name").replaceAll("\"", ""), id, type);
         return Result.success("瀹℃牳鎴愬姛");
     }
 
+    @ApiOperation(value = "鍚屾")
+    @PostMapping("/synchronization")
+    public Result synchronization(){
+        return Result.success(saleService.synchronization());
+    }
+
+    @ApiOperation(value = "涓嬭浇闄勪欢")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(name = "id", value = "閿�鍞崟id", dataTypeClass = Integer.class, required = true)
+    })
+    @PostMapping("/download")
+    public Result download(Integer id){
+        return Result.success(saleService.download(id));
+    }
 
 }

--
Gitblit v1.9.3