|
@@ -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;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|