| | |
| | | package org.springblade.mdm.basesetting.producedivision.service; |
| | | |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.excel.util.ExcelUtil; |
| | | import org.springblade.mdm.basesetting.producedivision.entity.ProduceDivision; |
| | | import org.springblade.mdm.basesetting.producedivision.entity.QinzheFgb; |
| | | import org.springblade.mdm.basesetting.producedivision.mapper.QinzheFgbMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springblade.mdm.basesetting.producedivision.vo.DivisionExcel; |
| | | import org.springblade.mdm.basesetting.producedivision.vo.ImportResult; |
| | | 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<QinzheFgbMapper, QinzheFgb> { |
| | | /** |
| | | * 根据零件号获取数据 |
| | | * @param ljh 零件号 |
| | | * @return 分工表实体,找不到返回null |
| | | */ |
| | | public QinzheFgb getByLjh(String ljh) { |
| | | return lambdaQuery().eq(QinzheFgb::getLjh, ljh).list().stream().findFirst().orElse(null); |
| | | } |
| | | |
| | | /** |
| | | * 查询分页 |
| | |
| | | return this.lambdaQuery().like(StringUtils.isNotBlank(name),QinzheFgb::getZggy,name).page(Condition.getPage(query)); |
| | | } |
| | | */ |
| | | |
| | | public List<String> seletDropList(String ljh) { |
| | | return this.baseMapper.seletDropList(ljh); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 导入勤哲分工表 |
| | | * @param file excel文件 |
| | | * @return 导入结果 |
| | | */ |
| | | @Transactional |
| | | public void importFgb(MultipartFile file) { |
| | | |
| | | List<QinzheFgbExcel> list = ExcelUtil.read(file, QinzheFgbExcel.class); |
| | | List<QinzheFgb> entityList = new ArrayList<>(); |
| | | |
| | | for(QinzheFgbExcel qzExcel: list){ |
| | | QinzheFgb fgb = new QinzheFgb(); |
| | | BeanUtils.copyProperties(qzExcel,fgb); |
| | | fgb.setSource("QZ"); |
| | | entityList.add(fgb); |
| | | } |
| | | |
| | | saveIfNotExists(entityList); |
| | | } |
| | | |
| | | /** |
| | | * 不存在则保存 |
| | | * @param entityList 数据列表 |
| | | */ |
| | | @Transactional |
| | | void saveIfNotExists(List<QinzheFgb> entityList) { |
| | | |
| | | List<QinzheFgb> 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, "MDM").update(); |
| | | } |
| | | } |