package com.ruoyi.basic.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.basic.dto.CoalInfoDto; import com.ruoyi.basic.entity.CoalInfo; import com.ruoyi.basic.mapper.CoalInfoMapper; import com.ruoyi.basic.service.CoalInfoService; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.bean.BeanUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.util.Objects; /** *

* 煤种信息表 服务实现类 *

* * @author ruoyi * @since 2025-06-03 */ @Service @RequiredArgsConstructor public class CoalInfoServiceImpl extends ServiceImpl implements CoalInfoService { private final CoalInfoMapper coalInfoMapper; @Override public IPage selectCoalInfoList(Page page, CoalInfoDto coalInfoDto) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); if (StringUtils.hasText(coalInfoDto.getCoal())) { queryWrapper.like(CoalInfo::getCoal,coalInfoDto.getCoal()); } queryWrapper.orderByDesc(CoalInfo::getCreateTime); return coalInfoMapper.selectPage(page, queryWrapper); } @Override public int addOrEditCoalInfo(CoalInfoDto coalInfoDto) { CoalInfo coalInfo = new CoalInfo(); BeanUtils.copyProperties(coalInfoDto, coalInfo); coalInfo.setMaintainerId(SecurityUtils.getUserId()); coalInfo.setMaintenanceDate(DateUtils.getNowDate()); if (Objects.isNull(coalInfo.getId())) { return coalInfoMapper.insert(coalInfo); } else { return coalInfoMapper.updateById(coalInfo); } } @Override public int delCoalInfoByIds(Long[] ids) { // 检查参数 if (ids == null || ids.length == 0) { return 0; } // 构造更新条件 UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.in("id", ids) .set("deleted", 1); // 设置 deleted 为 1 表示已删除 // 执行批量逻辑删除 return coalInfoMapper.update(null, updateWrapper); } }