package org.springblade.mdm.basesetting.producedivision.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springblade.core.excel.util.ExcelUtil; import org.springblade.mdm.basesetting.producedivision.entity.QinzheFgb; import org.springblade.mdm.basesetting.producedivision.mapper.QinzheFgbMapper; import org.springblade.mdm.basesetting.producedivision.vo.QinzheFgbExcel; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.util.ArrayList; import java.util.List; @Service public class QinzheFgbService extends ServiceImpl { /** * 根据零件号获取数据 * @param ljh 零件号 * @return 分工表实体,找不到返回null */ public QinzheFgb getByLjh(String ljh) { return lambdaQuery().eq(QinzheFgb::getLjh, ljh).list().stream().findFirst().orElse(null); } public List seletDropList(String ljh) { return this.baseMapper.seletDropList(ljh); } /** * 导入勤哲分工表 * @param file excel文件 * @return 导入结果 */ @Transactional public void importFgb(MultipartFile file) { List list = ExcelUtil.read(file, QinzheFgbExcel.class); List entityList = new ArrayList<>(); for(QinzheFgbExcel qzExcel: list){ QinzheFgb fgb = new QinzheFgb(); BeanUtils.copyProperties(qzExcel,fgb); fgb.setSource(QinzheFgb.SOURCE_MDM); entityList.add(fgb); } saveIfNotExists(entityList); } /** * 不存在则保存 * @param entityList 数据列表 */ @Transactional void saveIfNotExists(List entityList) { List willSaveList = entityList.stream().filter(e -> !exists(e)).toList(); this.saveBatch(willSaveList); } /** * 判断数据是否存在 * @param entity 实体 * @return 是否存在 */ boolean exists(QinzheFgb entity){ return lambdaQuery().eq(QinzheFgb::getLjh, entity.getLjh()) .eq(QinzheFgb::getCph, entity.getCph()).eq(QinzheFgb::getZggy, entity.getZggy()).count() > 0; } /** * 修改勤哲分工表数据 * @param fgb 数据实体 */ public void updateFgb(QinzheFgb fgb) { lambdaUpdate().eq(QinzheFgb::getLjh, fgb.getLjh()) .set(QinzheFgb::getZggy, fgb.getZggy()) .set(QinzheFgb::getCph, fgb.getCph()).set(QinzheFgb::getSource,QinzheFgb.SOURCE_MDM).update(); } }