XiaoRuby
2023-07-26 cdaff9ab0d1b676e3b429171d6de0887c98f488c
standard-server/src/main/java/com/yuanchu/limslaboratory/service/impl/ProductServiceImpl.java
@@ -1,13 +1,13 @@
package com.yuanchu.limslaboratory.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yuanchu.limslaboratory.pojo.Product;
import com.yuanchu.limslaboratory.mapper.ProductMapper;
import com.yuanchu.limslaboratory.service.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.limslaboratory.service.UserService;
import com.yuanchu.limslaboratory.utils.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import com.yuanchu.limslaboratory.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
@@ -30,66 +30,21 @@
    @Resource
    private ProductMapper productMapper;
    @Autowired
    private UserService userService;
    @Override
    public Integer addProductInformation(Product product) {
        return productMapper.insert(product);
    }
    @Override
    public List<Map<String, Object>> getListProductInformation(Integer materialId) {
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Product::getMaterialId, materialId);
        wrapper.select(Product::getId, Product::getName, Product::getFather);
        wrapper.groupBy(Product::getFather);
        List<Map<String, Object>> products = productMapper.selectMaps(wrapper);
        for (Map<String, Object> product:products){
            if (!ObjectUtils.isEmpty(product.get("father"))){
                product.remove("name");
                product.remove("id");
                LambdaQueryWrapper<Product> wrapper1 = new LambdaQueryWrapper<>();
                wrapper1.eq(Product::getFather, product.get("father"));
                wrapper1.select(Product::getId, Product::getName);
                List<Map<String, Object>> maps = productMapper.selectMaps(wrapper1);
                product.put("sonProduct", maps);
            }
        }
        for (Map<String, Object> product:products){
            System.out.println(product);
        }
        return products;
    }
    @Override
    public Map<String, Object> getProductInformation(Integer productId) {
        Map<String, Object> productMap = productMapper.getProductInformation(productId);
        String userName = userService.selectByUserId((Integer) productMap.get("user_id"));
        productMap.remove("user_id");
        productMap.put("userName", userName);
        return productMap;
    }
    @Override
    public Integer deleteProductInformation(Integer productId) {
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
        LambdaUpdateWrapper<Product> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Product::getId, productId);
        return productMapper.delete(wrapper);
        wrapper.set(Product::getState, 0);
        return productMapper.update(new Product(), wrapper);
    }
    @Override
    public void deleteProductEqMaterialId(List<String> materialListId) {
        for (String materialId : materialListId){
            LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(Product::getMaterialId, materialId);
            wrapper.select(Product::getId);
            List<Product> products = productMapper.selectList(wrapper);
            List<Integer> productDeleteId = new ArrayList<>();
            for (Product product : products){
                productDeleteId.add(product.getId());
            }
            productMapper.deleteBatchIds(productDeleteId);
    public void MaterialIdDeleteProduct(List<String> deleteMaterialId) {
        for (String materialId : deleteMaterialId){
            LambdaUpdateWrapper<Product> wrapper = new LambdaUpdateWrapper<>();
            wrapper.eq(Product::getId, materialId);
            wrapper.set(Product::getState, 0);
            productMapper.update(new Product(), wrapper);
        }
    }
}