package com.gkhy.exam.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.gkhy.exam.common.api.CommonPage; import com.gkhy.exam.common.api.CommonResult; import com.gkhy.exam.common.constant.UserConstant; import com.gkhy.exam.common.utils.PageUtils; import com.gkhy.exam.common.utils.SecurityUtils; import com.gkhy.exam.system.domain.Material; import com.gkhy.exam.system.domain.WarehousingRecord; import com.gkhy.exam.system.mapper.MaterialMapper; import com.gkhy.exam.system.service.MaterialService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.List; /** *

* 服务实现类 *

* * @author hh * @since 2025-10-11 14:20:49 */ @Service public class MaterialServiceImpl extends ServiceImpl implements MaterialService { @Autowired private MaterialMapper materialMapper; @Override public CommonPage selectMaterialList(Material material) { PageUtils.startPage(); List materials = materialMapper.selectMaterialList(material); return CommonPage.restPage(materials); } @Override public CommonResult saveMaterial(Material material) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Material::getMaterialName, material.getMaterialName()); queryWrapper.eq(Material::getDelFlag, UserConstant.ENABLE); queryWrapper.eq(Material::getCompanyId, material.getCompanyId()); queryWrapper.eq(Material::getSpecification, material.getSpecification()); if (material.getId() == null){ long count = materialMapper.selectCount(queryWrapper); if (count > 0){ return CommonResult.failed("该规格物料已存在"); } material.setCreateTime(LocalDateTime.now()); material.setCreateBy(SecurityUtils.getUsername()); materialMapper.insert(material); }else { queryWrapper.ne(Material::getId, material.getId()); long count = materialMapper.selectCount(queryWrapper); if (count > 0){ return CommonResult.failed("该规格物料已存在"); } material.setUpdateTime(LocalDateTime.now()); material.setUpdateBy(SecurityUtils.getUsername()); materialMapper.updateById(material); } return CommonResult.success(); } @Override public CommonResult deletedMaterial(Long id) { materialMapper.update(new Material(), new LambdaUpdateWrapper().eq(Material::getId, id) .set(Material::getDelFlag, UserConstant.DEPT_DISABLE) .set(Material::getUpdateTime, LocalDateTime.now()) .set(Material::getUpdateBy, SecurityUtils.getUsername())); return CommonResult.success("删除成功"); } }