XiaoRuby
2023-07-27 ad7151b14f2721b0fa40a903c6e65a2c511dd4c5
standard-server/src/main/java/com/yuanchu/limslaboratory/service/impl/ProductServiceImpl.java
@@ -2,10 +2,13 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.utils.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import com.yuanchu.limslaboratory.service.UserService;
import org.springframework.stereotype.Service;
@@ -15,6 +18,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
 * <p>
@@ -31,20 +35,40 @@
    private ProductMapper productMapper;
    @Override
    public Integer deleteProductInformation(Integer productId) {
    public void deleteProductInformation(List<Integer> SpecificationsId) {
        for (Integer materialId : SpecificationsId){
        LambdaUpdateWrapper<Product> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Product::getId, productId);
        wrapper.set(Product::getState, 0);
        return productMapper.update(new Product(), wrapper);
    }
    @Override
    public void MaterialIdDeleteProduct(List<String> deleteMaterialId) {
        for (String materialId : deleteMaterialId){
            LambdaUpdateWrapper<Product> wrapper = new LambdaUpdateWrapper<>();
            wrapper.eq(Product::getId, materialId);
            wrapper.eq(Product::getSpecifications_id, materialId);
            wrapper.set(Product::getState, 0);
            productMapper.update(new Product(), wrapper);
        }
    }
    @Override
    public IPage<Map<String, Object>> pageProductInformation(String productCodeOrName, Page<Objects> page) {
        IPage<Map<String, Object>> iPage = productMapper.pageProductInformation(productCodeOrName, page);
        List<Map<String, Object>> maps = iPage.getRecords();
        MyUtil.PrintLog(maps.toString());
        maps.forEach(map -> {
            int num = Integer.parseInt(map.get("num").toString());
            boolean children = false;
            if (num > 1){
                children = true;
            } else {
                Map<String, Object> product = productMapper.selectOneChildren(map.get("father"));
                map.putAll(product);
            }
            map.put("children", children);
            map.remove("num");
        });
        return iPage;
    }
    @Override
    public List<Map<String, Object>> pageFatherNameProductInformation(String fatherName) {
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Product::getFather, fatherName);
        wrapper.select(Product::getId, Product::getName, Product::getUnit, Product::getRequired, Product::getInternal);
        return productMapper.selectMaps(wrapper);
    }
}