package com.iailab.module.model.mcs.pre.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.iailab.framework.common.page.PageData; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.module.model.mcs.pre.dao.MmPredictItemDao; import com.iailab.module.model.mcs.pre.dto.MmPredictItemDTO; import com.iailab.module.model.mcs.pre.entity.*; import com.iailab.module.model.mcs.pre.enums.ItemIncreaseCodeEnum; import com.iailab.module.model.mcs.pre.enums.ItemTypeEnum; import com.iailab.module.model.mcs.pre.service.MmPredictItemService; import com.iailab.module.model.mcs.pre.service.SequenceNumService; import com.iailab.module.model.mcs.pre.vo.MmPredictItemRespVO; import com.iailab.module.model.mdk.vo.ItemVO; import com.iailab.module.model.mdk.vo.MergeItemVO; 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 javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.text.SimpleDateFormat; import java.util.*; /** * @author PanZhibao * @date 2021年04月26日 14:03 */ @Service("mmPredictItemService") public class MmPredictItemServiceImpl extends BaseServiceImpl implements MmPredictItemService { @Autowired private DmModuleItemServiceImpl dmModuleItemService; @Autowired private MmItemOutputServiceImpl mmItemOutputService; @Autowired private MmPredictModelServiceImpl mmPredictModelService; @Autowired private MmModelArithSettingsServiceImpl mmModelArithSettingsService; @Autowired private MmModelParamServiceImpl mmModelParamService; @Autowired private MmPredictMergeItemServiceImpl mmPredictMergeItemService; @Autowired private MmItemTypeImpl mmItemTypeImpl; @Autowired private SequenceNumService sequenceNumService; @Override public PageResult getPageList(Map params) { PageResult result = new PageResult(); IPage page = baseDao.getPageList( getPage(params, "CREATE_TIME", false), params ); result.setList(page.getRecords()); result.setTotal(page.getTotal()); return result; } private QueryWrapper getWrapper(Map params) { QueryWrapper wrapper = new QueryWrapper<>(); return wrapper; } @Override @Transactional(rollbackFor = Exception.class) public void savePredictItem(MmPredictItemDTO mmPredictItemDto) { MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem(); predictItem.setId(UUID.randomUUID().toString()); predictItem.setCreateTime(new Date()); predictItem.setUpdateTime(new Date()); MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); if (ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { SequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IM.toString()); String str = String.format("%010d", sequenceNumEntity.getSequenceNum()); predictItem.setItemno(sequenceNumEntity.getPrefix() + str); MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel(); SequenceNumEntity preMdlSequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.PRE_MDL.toString()); String preMdlStr = String.format("%04d", preMdlSequenceNumEntity.getSequenceNum()); mmPredictModel.setModelno(preMdlSequenceNumEntity.getPrefix() + preMdlStr); mmPredictModel.setItemid(predictItem.getId()); mmPredictModelService.savePredictModel(mmPredictModel); List mmModelArithSettingsList = mmPredictItemDto.getMmModelArithSettingsList(); mmModelArithSettingsList.forEach(item -> { item.setModelid(mmPredictModel.getId()); }); mmModelArithSettingsService.saveList(mmModelArithSettingsList); List mmModelParamList = mmPredictItemDto.getMmModelParamList(); mmModelParamList.forEach(item -> { item.setModelid(mmPredictModel.getId()); }); mmModelParamService.saveList(mmModelParamList); } else if (ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { SequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IC.toString()); String str = String.format("%010d", sequenceNumEntity.getSequenceNum()); predictItem.setItemno(sequenceNumEntity.getPrefix() + str); MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); mMmPredictMergeItem.setItemid(predictItem.getId()); mmPredictMergeItemService.savePredictMergeItem(mMmPredictMergeItem); } insert(predictItem); DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); dmModuleItem.setItemid(predictItem.getId()); dmModuleItemService.saveModuleItem(dmModuleItem); MmItemOutputEntity mmItemOutput = mmPredictItemDto.getMmItemOutput(); mmItemOutput.setItemid(predictItem.getId()); mmItemOutputService.saveMmItemOutput(mmItemOutput); } @Override @Transactional(rollbackFor = Exception.class) public void update(MmPredictItemDTO mmPredictItemDto) { MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem(); predictItem.setUpdateTime(new Date()); this.updateById(predictItem); MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); if (ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel(); mmPredictModelService.update(mmPredictModel); List mmModelArithSettingsList = mmPredictItemDto.getMmModelArithSettingsList(); mmModelArithSettingsList.forEach(item -> { item.setModelid(mmPredictModel.getId()); }); mmModelArithSettingsService.saveList(mmModelArithSettingsList); List mmModelParamList = mmPredictItemDto.getMmModelParamList(); mmModelParamList.forEach(item -> { item.setModelid(mmPredictModel.getId()); }); mmModelParamService.saveList(mmModelParamList); } else if (ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); mmPredictMergeItemService.update(mMmPredictMergeItem); } DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); dmModuleItemService.update(dmModuleItem); MmItemOutputEntity mmItemOutput = mmPredictItemDto.getMmItemOutput(); mmItemOutputService.update(mmItemOutput); } @Override @Transactional(rollbackFor = Exception.class) public void deleteBatch(String[] itemIds) { deleteBatchIds(Arrays.asList(itemIds)); mmPredictMergeItemService.deleteBatch(itemIds); mmPredictModelService.deleteBatch(itemIds); mmItemOutputService.deleteBatch(itemIds); } @Override public MmPredictItemDTO getDetailById(String id, Map params) { MmPredictItemDTO mmPredictItemDto = new MmPredictItemDTO(); MmPredictItemEntity predictItem = selectById(id); mmPredictItemDto.setMmPredictItem(predictItem); mmPredictItemDto.setDmModuleItem(dmModuleItemService.getByItemid(id)); mmPredictItemDto.setMmItemOutput(mmItemOutputService.getByItemid(id)); MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); if (ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { MmPredictModelEntity mmPredictModel = mmPredictModelService.getByItemid(id); mmPredictItemDto.setMmPredictModel(mmPredictModel); mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelid(mmPredictModel.getId())); mmPredictItemDto.setMmModelParamList(mmModelParamService.getByModelid(mmPredictModel.getId())); } else if (ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { mmPredictItemDto.setMmPredictMergeItem(mmPredictMergeItemService.getByItemid(id)); } return mmPredictItemDto; } @Override public boolean exportItemResult(HttpServletResponse response, HttpServletRequest request, String id, Map params) { //MmPredictItemDTO mmPredictItemDto = this.getPredictValuesById(id, params); //List itemResultList = mmPredictItemDto.getMmItemResultList(); return true; } @Override public int check(MmPredictItemEntity mmPredictItem) { String id = mmPredictItem.getId(); String itemname = mmPredictItem.getItemname(); String itemno = mmPredictItem.getItemno(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); queryWrapper.and(wrapper -> wrapper.eq("itemname", itemname).or().eq("itemno", itemno)); List list = baseDao.selectList(queryWrapper); return list.size(); } @Override public Long count() { QueryWrapper queryWrapper = new QueryWrapper<>(); return baseDao.selectCount(queryWrapper); } @Override public List getByModuleId(String moduleId) { Map params = new HashMap<>(); return baseDao.getByModuleId(params); } @Override public ItemVO getItemByItemNo(String itemNo) { if (StringUtils.isBlank(itemNo)) { return null; } Map params = new HashMap(1); params.put("ITEMNO", itemNo); List list = baseDao.getItem(params); if (CollectionUtils.isEmpty(list)) { return null; } return list.get(0); } @Override public ItemVO getItemById(String itemId) { if (StringUtils.isBlank(itemId)) { return null; } Map params = new HashMap(1); params.put("ITEMID", itemId); List list = baseDao.getItem(params); if (CollectionUtils.isEmpty(list)) { return null; } return list.get(0); } @Override public MergeItemVO getMergeItemByItemId(String itemId) { if (StringUtils.isBlank(itemId)) { return null; } Map params = new HashMap(1); params.put("ITEMID", itemId); List list = baseDao.getMergeItemByItemId(params); if (CollectionUtils.isEmpty(list)) { return null; } return list.get(0); } }