package com.iailab.module.pms.coalquality.modules.analysis.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.module.pms.coalquality.modules.analysis.dao.CoalAnalysisFullDao; import com.iailab.module.pms.coalquality.modules.analysis.dto.CoalAnalysisFullDTO; import com.iailab.module.pms.coalquality.modules.analysis.dto.CoalAnalysisFullDetDTO; import com.iailab.module.pms.coalquality.modules.analysis.entity.CoalAnalysisFullEntity; import com.iailab.module.pms.coalquality.modules.analysis.service.CoalAnalysisFullDetService; import com.iailab.module.pms.coalquality.modules.analysis.service.CoalAnalysisFullService; import com.iailab.module.pms.coalquality.modules.analysis.vo.FullPageReqVO; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.text.DecimalFormat; import java.util.*; /** * @author PanZhibao * @Description * @createTime 2023年01月12日 17:09:00 */ @Service public class CoalAnalysisFullServiceImpl extends BaseServiceImpl implements CoalAnalysisFullService { @Autowired private CoalAnalysisFullDetService coalAnalysisFullDetService; private String BUSINESS_CODE = "CoalAnalysisFull"; private DecimalFormat df = new DecimalFormat("00"); @Override public PageResult page(FullPageReqVO fullPageReqVO) { PageResult page = baseDao.selectPage(fullPageReqVO); return BeanUtils.toBean(page, CoalAnalysisFullDTO.class); } @Override public CoalAnalysisFullDTO get(String id) { CoalAnalysisFullEntity entity = baseDao.selectById(id); CoalAnalysisFullDTO dto = ConvertUtils.sourceToTarget(entity, CoalAnalysisFullDTO.class); dto.setDetList(getDetList(dto.getId())); return dto; } private List getDetList(String fullId) { Map parmas = new HashMap<>(1); parmas.put("fullId", fullId); return coalAnalysisFullDetService.queryList(parmas); } @Override @Transactional(rollbackFor = Exception.class) public void save(CoalAnalysisFullDTO dto) { dto.setCode(dto.getNy().replace("-", "")); CoalAnalysisFullEntity entity = ConvertUtils.sourceToTarget(dto, CoalAnalysisFullEntity.class); entity.setId(UUID.randomUUID().toString()); entity.setCreateDate(new Date()); insert(entity); List detList = dto.getDetList(); // if (!CollectionUtils.isEmpty(detList)) { // for (int i = 0; i < detList.size(); i++) { // detList.get(i).setCode(entity.getCode() + df.format(i + 1)); // detList.get(i).setFullId(entity.getId()); // } // coalAnalysisFullDetService.saveList(detList); // } } @Override @Transactional(rollbackFor = Exception.class) public void update(CoalAnalysisFullDTO dto) { CoalAnalysisFullEntity entity = ConvertUtils.sourceToTarget(dto, CoalAnalysisFullEntity.class); entity.setUpdateDate(new Date()); updateById(entity); List detList = dto.getDetList(); // if (!CollectionUtils.isEmpty(detList)) { // detList.forEach(item -> { // item.setFullId(entity.getId()); // }); // coalAnalysisFullDetService.updateList(detList); // } } @Override @Transactional(rollbackFor = Exception.class) public void delete(String[] ids) { baseDao.deleteByIds(Arrays.asList(ids)); // Arrays.asList(ids).forEach(item -> { // coalAnalysisFullDetService.deleteByFullId(item); // }); } @Override public Long cheack(CoalAnalysisFullDTO dto) { String id = dto.getId(); String code = dto.getCode(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); queryWrapper.and(wrapper -> wrapper.eq("code", code)); return baseDao.selectCount(queryWrapper); } }