package com.smartor.service.impl; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DtoConversionUtils; import com.smartor.domain.*; import com.smartor.mapper.IvrLibaTargetMapper; import com.smartor.mapper.IvrLibaTargetTagMapper; import com.smartor.mapper.IvrLibaTargetoptionMapper; import com.smartor.service.IIvrLibaTargetService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; /** * 指标选项库Service业务层处理 * * @author ruoyi * @date 2023-12-14 */ @Slf4j @Service public class IvrLibaTargetServiceImpl implements IIvrLibaTargetService { @Autowired private IvrLibaTargetMapper ivrLibaTargetMapper; @Autowired private IvrLibaTargetTagMapper ivrLibaTargetTagMapper; @Autowired private IvrLibaTargetoptionMapper ivrLibaTargetoptionMapper; /** * 查询指标选项库 * * @param targetID 指标选项库主键 * @return 指标选项库 */ @Override public IvrLibaTarget selectIvrLibaTargetByTargetID(Long targetID) { return ivrLibaTargetMapper.selectIvrLibaTargetByTargetID(targetID); } /** * 查询指标选项库列表 * * @param ivrLibaTarget 指标选项库 * @return 指标选项库 */ @Override public List selectIvrLibaTargetList(IvrLibaTarget ivrLibaTarget) { return ivrLibaTargetMapper.selectIvrLibaTargetList(ivrLibaTarget); } @Override public List targetInfo(IvrLibaTarget ivrLibaTarget) { List ivrLibaTargets = ivrLibaTargetMapper.selectIvrLibaTargetList(ivrLibaTarget); List ivrLibaTargetVOS = DtoConversionUtils.sourceToTarget(ivrLibaTargets, IvrLibaTargetVO.class); for (IvrLibaTargetVO ivrLibaTarget1 : ivrLibaTargetVOS) { IvrLibaTargetoption ivrLibaTargetoption = new IvrLibaTargetoption(); ivrLibaTargetoption.setTargetid(ivrLibaTarget1.getTargetID()); //获取该指标的选项 List ivrLibaTargetoptions = ivrLibaTargetoptionMapper.selectIvrLibaTargetoptionList(ivrLibaTargetoption); if (CollectionUtils.isNotEmpty(ivrLibaTargetoptions)) { ivrLibaTarget1.setTargetoptionList(ivrLibaTargetoptions); } //获取该指标的标签 List baseTags = ivrLibaTargetTagMapper.selectTagName(ivrLibaTarget1.getTargetID()); ivrLibaTarget1.setBaseTagList(baseTags); } //下面用左外感觉有点问题,where中的option的del会导致左边的查询不全,先不用吧 // ivrLibaTargetMapper.targetInfo(ivrLibaTarget) return ivrLibaTargetVOS; } /** * 新增指标选项库 * * @param ivrLibaTargetVO 指标选项库 * @return 结果 */ @Override @Transactional(rollbackFor = Exception.class) public int insertIvrLibaTarget(IvrLibaTargetVO ivrLibaTargetVO) { //新增指标信息 IvrLibaTarget ivrLibaTarget = DtoConversionUtils.sourceToTarget(ivrLibaTargetVO, IvrLibaTarget.class); ivrLibaTarget.setCreateTime(DateUtils.getNowDate()); ivrLibaTargetMapper.insertIvrLibaTarget(ivrLibaTarget); //新增该指标对应的标签信息 for (BaseTag baseTag : ivrLibaTargetVO.getBaseTagList()) { IvrLibaTargetTag ivrLibaTargetTag = new IvrLibaTargetTag(); ivrLibaTargetTag.setTagcategoryid(baseTag.getTagcategoryid()); ivrLibaTargetTag.setTargetid(ivrLibaTarget.getTargetID()); //前端传来的baseTag的tagid就是指标标签的主键id,不是baseTag的主键 ivrLibaTargetTag.setTagid(baseTag.getTagid()); ivrLibaTargetTagMapper.insertIvrLibaTargetTag(ivrLibaTargetTag); } //新增该指标对应的指标选项信息 for (IvrLibaTargetoption targetoption : ivrLibaTargetVO.getTargetoptionList()) { if (ObjectUtils.isEmpty(targetoption)) continue; log.info("targetoption的数据为:{}", targetoption); targetoption.setTargetid(ivrLibaTarget.getTargetID()); ivrLibaTargetoptionMapper.insertIvrLibaTargetoption(targetoption); } log.info("指标id为:{}", ivrLibaTarget.getTargetID().intValue()); return ivrLibaTarget.getTargetID().intValue(); } /** * 新增或修改指标选项库 * * @param ivrLibaTargetVO 指标选项库 * @return 结果 */ @Override @Transactional(rollbackFor = Exception.class) public int saveOrupdateIvrLibaTarget(IvrLibaTargetVO ivrLibaTargetVO) { IvrLibaTarget ivrLibaTarget = DtoConversionUtils.sourceToTarget(ivrLibaTargetVO, IvrLibaTarget.class); ivrLibaTarget.setUpdateTime(DateUtils.getNowDate()); if (ivrLibaTargetVO.getIsoperation() != null && ivrLibaTargetVO.getIsoperation() == 1) { //新增 ivrLibaTargetMapper.insertIvrLibaTarget(ivrLibaTarget); } else if (ivrLibaTargetVO.getIsoperation() != null && ivrLibaTargetVO.getIsoperation() == 2) { //修改 ivrLibaTargetMapper.updateIvrLibaTarget(ivrLibaTarget); } if (CollectionUtils.isNotEmpty(ivrLibaTargetVO.getBaseTagList())) { for (BaseTag baseTag : ivrLibaTargetVO.getBaseTagList()) { if (baseTag.getIsoperation() != null && baseTag.getIsoperation() == 1) { //新增 IvrLibaTargetTag ivrLibaTargetTag = new IvrLibaTargetTag(); ivrLibaTargetTag.setTagcategoryid(baseTag.getTagcategoryid()); ivrLibaTargetTag.setTargetid(ivrLibaTarget.getTargetID()); //前端传来的baseTag的tagid就是指标标签的主键id,不是baseTag的主键 ivrLibaTargetTag.setTagid(baseTag.getTagid()); ivrLibaTargetTagMapper.insertIvrLibaTargetTag(ivrLibaTargetTag); } else if (baseTag.getIsoperation() != null && baseTag.getIsoperation() == 2) { //前端页面应该没有修改 } else if (baseTag.getIsoperation() != null && baseTag.getIsoperation() == 3) { //删除 ivrLibaTargetTagMapper.deleteIvrLibaTargetTagById(baseTag.getTagid()); } } } if (CollectionUtils.isNotEmpty(ivrLibaTargetVO.getTargetoptionList())) { for (IvrLibaTargetoption ivrLibaTargetoption : ivrLibaTargetVO.getTargetoptionList()) { if (ivrLibaTargetoption.getIsoperation() != null && ivrLibaTargetoption.getIsoperation() == 1) { //新增 ivrLibaTargetoption.setTargetid(ivrLibaTarget.getTargetID()); ivrLibaTargetoptionMapper.insertIvrLibaTargetoption(ivrLibaTargetoption); } else if (ivrLibaTargetoption.getIsoperation() != null && ivrLibaTargetoption.getIsoperation() == 2) { //修改 ivrLibaTargetoptionMapper.updateIvrLibaTargetoption(ivrLibaTargetoption); } else if (ivrLibaTargetoption.getIsoperation() != null && ivrLibaTargetoption.getIsoperation() == 3) { // 删除 ivrLibaTargetoptionMapper.deleteIvrLibaTargetoptionByTargetoptionid(ivrLibaTargetoption.getTargetoptionid()); } } } return ivrLibaTarget.getTargetID().intValue(); } /** * 批量删除指标选项库 * * @param targetIDs 需要删除的指标选项库主键 * @return 结果 */ @Override public int deleteIvrLibaTargetByTargetIDs(Long[] targetIDs) { return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetIDs(targetIDs); } /** * 删除指标选项库信息 * * @param targetID 指标选项库主键 * @return 结果 */ @Override public int deleteIvrLibaTargetByTargetID(Long targetID) { return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetID(targetID); } }