Min 1 tahun lalu
induk
melakukan
34bd2ac9f4

+ 75 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/controller/ProductController.java

@@ -1,9 +1,20 @@
 package com.management.platform.controller;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.management.platform.entity.Product;
+import com.management.platform.entity.Task;
+import com.management.platform.mapper.UserMapper;
+import com.management.platform.service.ProductService;
+import com.management.platform.service.TaskService;
+import com.management.platform.util.HttpRespMsg;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 
 /**
  * <p>
@@ -16,6 +27,70 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 @RequestMapping("/product")
 public class ProductController {
+    @Resource
+    private ProductService productService;
+    @Resource
+    private UserMapper userMapper;
+    @Resource
+    private HttpServletRequest request;
+    @Resource
+    private TaskService taskService;
+
+    @RequestMapping("/list")
+    public HttpRespMsg list(String userId,String productName,String productCode,Integer pageIndex,Integer pageSize){
+        Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
+        return productService.getList(companyId,userId,productName,productCode,pageIndex,pageSize);
+    }
+
+    @RequestMapping("/addOrUpdate")
+    public HttpRespMsg addOrUpdate(Product product){
+        HttpRespMsg msg=new HttpRespMsg();
+        Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
+        product.setCompanyId(companyId);
+        int count;
+        if(product.getId()==null){
+            count = productService.count(new LambdaQueryWrapper<Product>().eq(Product::getCompanyId, companyId).eq(Product::getProductCode, product.getProductCode()));
+        }else {
+            count = productService.count(new LambdaQueryWrapper<Product>().eq(Product::getCompanyId, companyId).ne(Product::getId,product.getId()).eq(Product::getProductCode, product.getProductCode()));
+        }
+        if(count>0){
+            msg.setError("产品编码为["+product.getProductCode()+"]的产品已存在");
+            return msg;
+        }
+        if(!productService.saveOrUpdate(product)){
+            msg.setError("验证失败");
+            return msg;
+        }
+        return msg;
+    }
+
+
+    @RequestMapping("/delete")
+    public HttpRespMsg delete(Integer id){
+        HttpRespMsg msg=new HttpRespMsg();
+        int count = taskService.count(new LambdaQueryWrapper<Task>().eq(Task::getProductId, id));
+        if(count>0){
+            msg.setError("当前产品已绑定到相关任务,删除失败");
+            return msg;
+        }
+        if(!productService.removeById(id)){
+            msg.setError("验证失败");
+            return msg;
+        }
+        return msg;
+    }
+
+    @RequestMapping("/getTemplate")
+    public HttpRespMsg getTemplate(Integer id){
+        HttpRespMsg msg=new HttpRespMsg();
+        return msg;
+    }
+
+    @RequestMapping("/importData")
+    public HttpRespMsg importData(MultipartFile file){
+        HttpRespMsg msg=new HttpRespMsg();
+        return msg;
+    }
 
 }
 

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

@@ -2,6 +2,7 @@ package com.management.platform.service;
 
 import com.management.platform.entity.Product;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.management.platform.util.HttpRespMsg;
 
 /**
  * <p>
@@ -13,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface ProductService extends IService<Product> {
 
+    HttpRespMsg getList(Integer companyId,String userId, String productName, String productCode, Integer pageIndex, Integer pageSize);
 }

+ 33 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/impl/ProductServiceImpl.java

@@ -1,10 +1,19 @@
 package com.management.platform.service.impl;
 
+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.management.platform.entity.Product;
 import com.management.platform.mapper.ProductMapper;
 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.util.StringUtils;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * <p>
@@ -17,4 +26,28 @@ import org.springframework.stereotype.Service;
 @Service
 public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
 
+    @Resource
+    private ProductMapper productMapper;
+
+    @Override
+    public HttpRespMsg getList(Integer companyId,String userId, String productName, String productCode, Integer pageIndex, Integer pageSize) {
+        HttpRespMsg msg=new HttpRespMsg();
+        LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(Product::getCompanyId,companyId);
+        if(!StringUtils.isEmpty(userId)){
+            queryWrapper.eq(Product::getCreatorId,userId);
+        }
+        if(!StringUtils.isEmpty(productName)){
+            queryWrapper.like(Product::getProductName,productName);
+        }
+        if(!StringUtils.isEmpty(productCode)){
+            queryWrapper.like(Product::getProductCode,productCode);
+        }
+        IPage<Product> productIPage = productMapper.selectPage(new Page<>(pageIndex, pageSize), queryWrapper);
+        Map map=new HashMap();
+        map.put("record",productIPage.getRecords());
+        map.put("total",productIPage.getTotal());
+        msg.setData(map);
+        return msg;
+    }
 }

+ 3 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/impl/UserServiceImpl.java

@@ -842,6 +842,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
     public HttpRespMsg getEmployeeList(Integer departmentId,Integer matchingType,String keyword, Integer status, Integer roleId, Integer onlyDirect, String cursor, Integer pageIndex, Integer pageSize, HttpServletRequest request) throws Exception {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         Boolean flag = false;
+        if(status.equals(3)){
+            status=null;
+        }
         if (status != null && status.equals(2)){
             status = 0;
             flag = true;