¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.eam.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.SimpleVersionGenerateUtil; |
| | | import org.jeecg.modules.eam.base.entity.BaseFactory; |
| | | import org.jeecg.modules.eam.base.entity.BaseFactoryUser; |
| | | import org.jeecg.modules.eam.base.service.IBaseFactoryService; |
| | | import org.jeecg.modules.eam.base.service.IBaseFactoryUserService; |
| | | import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationStandardEnum; |
| | | import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandard; |
| | | import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandardDetail; |
| | | import org.jeecg.modules.eam.mapper.EamTechnicalStatusEvaluationStandardMapper; |
| | | import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationStandardRequest; |
| | | import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardDetailService; |
| | | import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: ææ¯ç¶æé´å®è§è |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-07-07 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service |
| | | public class EamTechnicalStatusEvaluationStandardServiceImpl extends ServiceImpl<EamTechnicalStatusEvaluationStandardMapper, EamTechnicalStatusEvaluationStandard> implements IEamTechnicalStatusEvaluationStandardService { |
| | | |
| | | @Autowired |
| | | private IBaseFactoryUserService baseFactoryUserService; |
| | | @Autowired |
| | | private IBaseFactoryService baseFactoryService; |
| | | @Autowired |
| | | private IEamTechnicalStatusEvaluationStandardDetailService standardDetailService; |
| | | |
| | | @Override |
| | | public IPage<EamTechnicalStatusEvaluationStandard> queryPageList(Page<EamTechnicalStatusEvaluationStandard> page, EamTechnicalStatusEvaluationStandard query) { |
| | | QueryWrapper<EamTechnicalStatusEvaluationStandard> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("ems.del_flag", CommonConstant.DEL_FLAG_0); |
| | | //ç¨æ·æ°æ®æé |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | return page; |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) { |
| | | //éæ©äºè®¾å¤ï¼æ ¹æ®è®¾å¤idè¿æ»¤è®¾å¤ |
| | | List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(",")); |
| | | queryWrapper.in("e.equipment_code", equipArr); |
| | | } else { |
| | | //没æéæ©è®¾å¤ï¼æ ¹æ®ä¸å¿è¿æ»¤è®¾å¤ |
| | | List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService. |
| | | list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId())); |
| | | if (!CollectionUtils.isEmpty(baseFactoryUserList)) { |
| | | List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList()); |
| | | List<String> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList()); |
| | | queryWrapper.in("e.factory_code", factoryCode); |
| | | } else { |
| | | return page; |
| | | } |
| | | } |
| | | if (query != null) { |
| | | //ç¼ç æ¨¡ç³æ¥è¯¢ |
| | | if (StringUtils.isNotBlank(query.getStandardCode())) { |
| | | queryWrapper.like("ems.standard_code", query.getStandardCode()); |
| | | } |
| | | //åç§° æ¨¡ç³æ¥è¯¢ |
| | | if (StringUtils.isNotBlank(query.getStandardName())) { |
| | | queryWrapper.like("ems.standard_name", query.getStandardName()); |
| | | } |
| | | //è®¾å¤ |
| | | if (StringUtils.isNotBlank(query.getEquipmentId())) { |
| | | queryWrapper.eq("ems.equipment_id", query.getEquipmentId()); |
| | | } |
| | | |
| | | //ä¿å
»åç±» |
| | | if (StringUtils.isNotBlank(query.getStandardStatus())) { |
| | | queryWrapper.eq("ems.standard_status", query.getStandardStatus()); |
| | | } |
| | | } |
| | | queryWrapper.orderByDesc("ems.create_time"); |
| | | return this.getBaseMapper().queryPageList(page, queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addEamTechnicalStatusEvaluationStandard(EamTechnicalStatusEvaluationStandardRequest request) { |
| | | EamTechnicalStatusEvaluationStandard entity = new EamTechnicalStatusEvaluationStandard(); |
| | | BeanUtils.copyProperties(request, entity); |
| | | entity.setStandardStatus(TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name()); |
| | | //çæ¬éå¢ |
| | | entity.setStandardVersion(SimpleVersionGenerateUtil.getInitVersion()); |
| | | //设å¤å¤ç |
| | | entity.setEquipmentId(request.getEquipmentId()); |
| | | //å 餿 è®° |
| | | entity.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | //é夿§æ ¡éª |
| | | EamTechnicalStatusEvaluationStandard exist = checkDuplicate(entity.getEquipmentId(), null); |
| | | if(exist != null){ |
| | | throw new JeecgBootException("è§èå·²åå¨ï¼ä¸è½é夿·»å ï¼"); |
| | | } |
| | | this.getBaseMapper().insert(entity); |
| | | //å¤çæç»æ°æ® |
| | | if(CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | request.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setStandardId(entity.getId()); |
| | | }); |
| | | standardDetailService.saveBatch(request.getTableDetailList()); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public EamTechnicalStatusEvaluationStandard checkDuplicate(String equipmentId, String id) { |
| | | LambdaQueryWrapper<EamTechnicalStatusEvaluationStandard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(EamTechnicalStatusEvaluationStandard::getEquipmentId, equipmentId); |
| | | queryWrapper.eq(EamTechnicalStatusEvaluationStandard::getDelFlag, CommonConstant.DEL_FLAG_0); |
| | | //å¾
æäº¤ãå¯ç¨ç¶æ |
| | | queryWrapper.in(EamTechnicalStatusEvaluationStandard::getStandardStatus, Arrays.asList(TechnicalStatusEvaluationStandardEnum.ENABLE.name(), TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name())); |
| | | queryWrapper.orderByDesc(EamTechnicalStatusEvaluationStandard::getStandardVersion); |
| | | if(StringUtils.isNotBlank(id)){ |
| | | queryWrapper.ne(EamTechnicalStatusEvaluationStandard::getId, id); |
| | | } |
| | | List<EamTechnicalStatusEvaluationStandard> list = this.getBaseMapper().selectList(queryWrapper); |
| | | if(CollectionUtil.isEmpty(list)) { |
| | | return null; |
| | | } |
| | | return list.get(0); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean editEamTechnicalStatusEvaluationStandard(EamTechnicalStatusEvaluationStandardRequest request) { |
| | | EamTechnicalStatusEvaluationStandard entity = this.getBaseMapper().selectById(request.getId()); |
| | | if(entity == null){ |
| | | throw new JeecgBootException("ç¼è¾çæ°æ®å·²å é¤ï¼è¯·å·æ°éè¯ï¼"); |
| | | } |
| | | entity.setStandardName(request.getStandardName()); |
| | | entity.setEvaluationPeriod(request.getEvaluationPeriod()); |
| | | this.getBaseMapper().updateById(entity); |
| | | //å¤ç详æ
|
| | | if(CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | List<EamTechnicalStatusEvaluationStandardDetail> addList = new ArrayList<>(); |
| | | List<EamTechnicalStatusEvaluationStandardDetail> updateList = new ArrayList<>(); |
| | | request.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setStandardId(entity.getId()); |
| | | if(tableDetail.getId() == null){ |
| | | addList.add(tableDetail); |
| | | }else { |
| | | updateList.add(tableDetail); |
| | | } |
| | | }); |
| | | if(CollectionUtil.isNotEmpty(addList)){ |
| | | standardDetailService.saveBatch(addList); |
| | | } |
| | | if(CollectionUtil.isNotEmpty(updateList)){ |
| | | standardDetailService.updateBatchById(updateList); |
| | | } |
| | | } |
| | | if(CollectionUtil.isNotEmpty(request.getRemoveDetailList())) { |
| | | List<String> ids = request.getRemoveDetailList().stream().map(EamTechnicalStatusEvaluationStandardDetail::getId).collect(Collectors.toList()); |
| | | standardDetailService.removeBatchByIds(ids); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean upgrade(EamTechnicalStatusEvaluationStandardRequest request) { |
| | | EamTechnicalStatusEvaluationStandard entity = this.getBaseMapper().selectById(request.getId()); |
| | | if(entity == null){ |
| | | throw new JeecgBootException("åççæ°æ®å·²å é¤ï¼è¯·å·æ°éè¯ï¼"); |
| | | } |
| | | |
| | | //æ°å¢ä¸ä¸ªçæ¬ |
| | | EamTechnicalStatusEvaluationStandard newEntity = new EamTechnicalStatusEvaluationStandard(); |
| | | newEntity.setStandardCode(request.getStandardCode()); |
| | | newEntity.setStandardName(request.getStandardName()); |
| | | newEntity.setEvaluationPeriod(request.getEvaluationPeriod()); |
| | | newEntity.setStandardStatus(TechnicalStatusEvaluationStandardEnum.ENABLE.name()); |
| | | //çæ¬éå¢ |
| | | newEntity.setStandardVersion(SimpleVersionGenerateUtil.addVersion(entity.getStandardVersion())); |
| | | //设å¤å¤ç |
| | | newEntity.setEquipmentId(request.getEquipmentId()); |
| | | //å 餿 è®° |
| | | newEntity.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | //é夿§æ ¡éª |
| | | EamTechnicalStatusEvaluationStandard exist = checkDuplicate(newEntity.getEquipmentId(), entity.getId()); |
| | | if(exist != null){ |
| | | throw new JeecgBootException("é´å®è§èå·²åå¨ï¼ä¸è½é夿·»å ï¼"); |
| | | } |
| | | this.getBaseMapper().insert(newEntity); |
| | | //å¤çæç»æ°æ® |
| | | if(CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | request.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setId(null); |
| | | tableDetail.setCreateBy(null); |
| | | tableDetail.setUpdateBy(null); |
| | | tableDetail.setCreateTime(null); |
| | | tableDetail.setUpdateTime(null); |
| | | tableDetail.setStandardId(newEntity.getId()); |
| | | }); |
| | | standardDetailService.saveBatch(request.getTableDetailList()); |
| | | } |
| | | //ç¦ç¨åæ¥ççæ¬ |
| | | entity.setStandardStatus(TechnicalStatusEvaluationStandardEnum.DISABLE.name()); |
| | | this.getBaseMapper().updateById(entity); |
| | | return true; |
| | | } |
| | | } |