package com.iailab.module.pms.coalquality.modules.detection.service.impl; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.iems.common.utils.SerialNumUtils; import com.iailab.module.pms.coalquality.modules.detection.dao.QualityQuickDao; import com.iailab.module.pms.coalquality.modules.detection.dto.QualityQuickDTO; import com.iailab.module.pms.coalquality.modules.detection.dto.QualityQuickItemDTO; import com.iailab.module.pms.coalquality.modules.detection.entity.QualityQuickEntity; import com.iailab.module.pms.coalquality.modules.detection.service.QualityQuickItemService; import com.iailab.module.pms.coalquality.modules.detection.service.QualityQuickService; import com.iailab.module.pms.coalquality.modules.detection.vo.QuickPageReqVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author DongYukun * @Description * @createTime 2023年12月27日 9:53:00 */ @Slf4j @Service public class QualityQuickServiceImpl extends BaseServiceImpl implements QualityQuickService { @Autowired private SerialNumUtils serialNumUtils; private String BUSINESS_CODE = "QualityQuick"; @Autowired private QualityQuickItemService qualityQuickItemService; @Override public PageResult page(QuickPageReqVO reqVO) { PageResult page = baseDao.selectPage(reqVO); return BeanUtils.toBean(page, QualityQuickDTO.class); } @Override public QualityQuickDTO get(String id) { QualityQuickEntity entity = baseDao.selectById(id); QualityQuickDTO dto = ConvertUtils.sourceToTarget(entity, QualityQuickDTO.class); Map parmas = new HashMap<>(1); parmas.put("lsh", dto.getLsh()); List itemList = qualityQuickItemService.queryList(parmas); dto.setItemList(itemList); return dto; } @Override public void save(QualityQuickDTO dto) { dto.setLsh(serialNumUtils.getByBusinessDate(BUSINESS_CODE, dto.getDatetime(), 4)); QualityQuickEntity entity = ConvertUtils.sourceToTarget(dto, QualityQuickEntity.class); insert(entity); dto.getItemList().stream().forEach( item->{ item.setLsh(dto.getLsh()); qualityQuickItemService.save(item); } ); } @Override public void update(QualityQuickDTO dto) { QualityQuickEntity entity = ConvertUtils.sourceToTarget(dto, QualityQuickEntity.class); updateById(entity); qualityQuickItemService.deleteByLsh(dto.getLsh()); dto.getItemList().forEach( item->{ item.setLsh(dto.getLsh()); qualityQuickItemService.save(item); } ); } @Override @Transactional(rollbackFor = Exception.class) public void delete(String[] ids) { QualityQuickEntity dto = baseDao.selectById(ids[0]); baseDao.deleteByIds(Arrays.asList(ids)); qualityQuickItemService.deleteByLsh(dto.getLsh()); } }