XiaoRuby
2023-07-26 30f6da8bf0143906b42fa600f6a604cea6c81f71
standard-server/src/main/java/com/yuanchu/limslaboratory/service/impl/MaterialServiceImpl.java
@@ -6,9 +6,9 @@
import com.yuanchu.limslaboratory.mapper.MaterialMapper;
import com.yuanchu.limslaboratory.service.MaterialService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.limslaboratory.utils.MyUtil;
import com.yuanchu.limslaboratory.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
@@ -27,52 +27,53 @@
public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> implements MaterialService {
    @Resource
    private MaterialMapper materialMapper;
    MaterialMapper materialMapper;
    //查询物料信息
    @Override
    public Integer addMaterialInformation(Material material) {
        return materialMapper.insert(material);
    public List<Material> selectMaterialLimit(int pageSize, int countSize) {
        return materialMapper.selectMaterialLimit((pageSize - 1) * countSize,pageSize * countSize);
    }
    //根据物料id查询物料信息
    @Override
    public List<Map<String, Object>> getListMaterialInformation(String specificationsId) {
        LambdaQueryWrapper<Material> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Material::getSpecificationsId, specificationsId);
        wrapper.select(Material::getId, Material::getName);
        return materialMapper.selectMaps(wrapper);
    public Map selectMaterialById(String materialId) {
        return materialMapper.selectMaterialById(materialId);
    }
    @Override
    public Integer deleteMaterialInformation(Integer materialId) {
        LambdaQueryWrapper<Material> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Material::getId, materialId);
        return materialMapper.delete(wrapper);
    }
    @Autowired
    private ProductService productService;
    @Override
    public Integer updateMaterialInformation(Material material) {
    public Integer deleteMaterialInformation(String materialId) {
        LambdaUpdateWrapper<Material> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Material::getId, material.getId());
        materialMapper.updateById(material);
        return materialMapper.update(material, updateWrapper);
        updateWrapper.eq(Material::getId, materialId);
        updateWrapper.set(Material::getState, 0);
        List<String> list = new ArrayList<>();
        list.add(materialId);
        int isDeleteSuccess = materialMapper.update(new Material(), updateWrapper);
        if (isDeleteSuccess == 1){
            productService.MaterialIdDeleteProduct(list);
            return 1;
        }
        return 0;
    }
    @Override
    public List<String> deleteMaterialEqSpecification(String specificationsId) {
        LambdaQueryWrapper<Material> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Material::getSpecificationsId, specificationsId);
        wrapper.select(Material::getId);
        List<Material> materials = materialMapper.selectList(wrapper);
        if (!ObjectUtils.isEmpty(materials)){
            List<String> list = new ArrayList<>();
            for (Material material:materials){
    public List<String> specificationsIdDeleteMaterial(List<Integer> deleteSpecificationsId) {
        List<String> list = new ArrayList<>();
        for (Integer serialNumberId:deleteSpecificationsId){
            LambdaQueryWrapper<Material> wrapper = new LambdaQueryWrapper<>();
            wrapper.select(Material::getId);
            List<Material> maps1 = materialMapper.selectList(wrapper);
            for (Material material:maps1){
                LambdaUpdateWrapper<Material> updateWrapper = new LambdaUpdateWrapper<>();
                updateWrapper.eq(Material::getId, material.getId());
                updateWrapper.set(Material::getState, 0);
                materialMapper.update(new Material(), updateWrapper);
                list.add(material.getId());
            }
            int isDeleteList = materialMapper.deleteBatchIds(list);
            if (isDeleteList != 0) {
                return list;
            }
        }
        return null;
        return list;
    }
}