Ver Fonte

产品管理

zx há 1 ano atrás
pai
commit
e339dc0a1a

+ 0 - 5
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/ProdMaterialController.java

@@ -73,11 +73,6 @@ public class ProdMaterialController {
     }
 
 
-    /**
-     * 是否可删除物料
-     * 查看该工序有没有被使用(计划中)
-     * TODO
-     */
     @RequestMapping("/isDelete")
     public HttpRespMsg isDeleteProdMaterial (Integer id){
         return prodMaterialService.isDelete(request,id);

+ 7 - 4
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/ProductController.java

@@ -1,8 +1,11 @@
 package com.management.platform.controller;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.management.platform.entity.Plan;
 import com.management.platform.entity.Product;
 import com.management.platform.mapper.UserMapper;
+import com.management.platform.service.PlanService;
 import com.management.platform.service.ProductService;
 import com.management.platform.util.HttpRespMsg;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -31,6 +34,8 @@ public class ProductController {
     UserMapper userMapper;
     @Resource
     ProductService productService;
+    @Resource
+    PlanService planService;
 
     @RequestMapping("/getProductPage")
     public HttpRespMsg getProductPage(Integer cateId, @RequestParam Integer pageIndex, @RequestParam Integer pageSize, String name, String code) {
@@ -51,10 +56,8 @@ public class ProductController {
 
     @RequestMapping("/delete")
     public HttpRespMsg delete(Integer id) {
-        HttpRespMsg msg = new HttpRespMsg();
-        //TODO : 需检测是否被使用
-        productService.removeById(id);
-        return msg;
+
+        return productService.delete(id);
     }
 
     /**

+ 2 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/ProductService.java

@@ -21,4 +21,6 @@ public interface ProductService extends IService<Product> {
     HttpRespMsg saveProductInfo(Product product, HttpServletRequest request);
 
     HttpRespMsg getProductInfo(HttpServletRequest request, Integer id);
+
+    HttpRespMsg delete(Integer id);
 }

+ 1 - 2
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/ProdMaterialServiceImpl.java

@@ -65,8 +65,7 @@ public class ProdMaterialServiceImpl extends ServiceImpl<ProdMaterialMapper, Pro
     @Override
     public HttpRespMsg isDelete(HttpServletRequest request, Integer id) {
         HttpRespMsg msg = new HttpRespMsg();
-        //TODO: 检查工序是否已经被使用,被使用的不能删除
-
+        //TODO: 检查物料是否已经被使用,被使用的不能删除
         boolean flag=true;
         msg.setData(flag);
         return msg;

+ 28 - 4
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/ProductServiceImpl.java

@@ -5,16 +5,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.management.platform.entity.*;
-import com.management.platform.mapper.ProdMaterialMapper;
-import com.management.platform.mapper.ProdProcedureMapper;
-import com.management.platform.mapper.ProductMapper;
-import com.management.platform.mapper.UserMapper;
+import com.management.platform.mapper.*;
 import com.management.platform.service.ProdMaterialService;
 import com.management.platform.service.ProdProcedureService;
 import com.management.platform.service.ProductService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.util.HttpRespMsg;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
@@ -32,6 +30,7 @@ import java.util.Map;
  * @since 2023-07-02
  */
 @Service
+@Transactional
 public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
     @Resource
     ProductMapper productMapper;
@@ -45,6 +44,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
     ProdMaterialMapper prodMaterialMapper;
     @Resource
     ProdMaterialService prodMaterialService;
+    @Resource
+    PlanMapper planMapper;
+
 
     @Override
     public HttpRespMsg getProductPage(Integer cateId, Integer pageIndex, Integer pageSize, String name, String code, HttpServletRequest request) {
@@ -117,4 +119,26 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
         map.put("")*/
         return null;
     }
+
+    @Override
+    public HttpRespMsg delete(Integer id) {
+        HttpRespMsg msg = new HttpRespMsg();
+        //TODO : 需检测是否被使用
+        int count = planMapper.selectCount(
+                new LambdaQueryWrapper<Plan>()
+                        .eq(id != null, Plan::getProductId, id)
+        );
+        System.out.println(count);
+        if(count==0){
+
+            prodProcedureMapper.delete(new LambdaQueryWrapper<ProdProcedure>().eq(id!=null,ProdProcedure::getProductId,id));
+            prodMaterialMapper.delete(new LambdaQueryWrapper<ProdMaterial>().eq(id!=null,ProdMaterial::getProductId,id));
+            productMapper.deleteById(id);
+
+        }else{
+            msg.setError("this product is used!");
+        }
+
+        return msg;
+    }
 }