package com.iailab.module.pms.coalquality.modules.plan.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.plan.dao.QualityPlanDao; import com.iailab.module.pms.coalquality.modules.plan.dto.QualityPlanDTO; import com.iailab.module.pms.coalquality.modules.plan.dto.QualityPlanDetDTO; import com.iailab.module.pms.coalquality.modules.plan.entity.QualityPlanEntity; import com.iailab.module.pms.coalquality.modules.plan.service.QualityPlanDetService; import com.iailab.module.pms.coalquality.modules.plan.service.QualityPlanService; import com.iailab.module.pms.coalquality.modules.plan.vo.PlanMonthPageReqVO; 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 org.springframework.util.CollectionUtils; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.UUID; /** * 质量计划 * * @author PanZhibao * @Description * @createTime 2023年02月04日 14:45:00 */ @Service public class QualityPlanServiceImpl extends BaseServiceImpl implements QualityPlanService { @Autowired private QualityPlanDetService qualityPlanDetService; private String BUSINESS_CODE = "QualityPlan"; @Override public PageResult page(PlanMonthPageReqVO planMonthPageReqVO) { PageResult page = baseDao.selectPage(planMonthPageReqVO); return BeanUtils.toBean(page, QualityPlanDTO.class); } @Override public QualityPlanDTO get(String id) { QualityPlanEntity entity = baseDao.selectById(id); QualityPlanDTO result = ConvertUtils.sourceToTarget(entity, QualityPlanDTO.class); result.setDetList(qualityPlanDetService.getListByPlanId(id)); return result; } @Override @Transactional(rollbackFor = Exception.class) public void save(QualityPlanDTO dto) { // dto.setCode(serialNumUtils.getByBusinessDate(BUSINESS_CODE, new Date(), 4)); QualityPlanEntity entity = ConvertUtils.sourceToTarget(dto, QualityPlanEntity.class); entity.setId(UUID.randomUUID().toString()); entity.setCreateDate(new Date()); // entity.setCreator(SecurityUser.getUser().getId().toString()); insert(entity); List detList = dto.getDetList(); if (!CollectionUtils.isEmpty(detList)) { qualityPlanDetService.saveList(detList, entity.getId()); } } @Override @Transactional(rollbackFor = Exception.class) public void update(QualityPlanDTO dto) { QualityPlanEntity entity = ConvertUtils.sourceToTarget(dto, QualityPlanEntity.class); entity.setUpdateDate(new Date()); // entity.setUpdater(SecurityUser.getUserId().toString()); updateById(entity); List detList = dto.getDetList(); if (!CollectionUtils.isEmpty(detList)) { qualityPlanDetService.deleteByPlanId(entity.getId()); qualityPlanDetService.saveList(detList, entity.getId()); } } @Override @Transactional(rollbackFor = Exception.class) public void delete(String[] ids) { baseDao.deleteByIds(Arrays.asList(ids)); qualityPlanDetService.deleteByPlanIds(ids); } @Override public Long cheack(QualityPlanDTO 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); } }