liusheng
2024-01-15 a0bcee3aa22b79f592c44cdb3dcdbd681490f265
smartor/src/main/java/com/smartor/service/impl/IvrLibaTargetServiceImpl.java
@@ -1,97 +1,195 @@
package com.smartor.service.impl;
import com.ruoyi.common.utils.DateUtils;
import com.smartor.domain.IvrLibaTarget;
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
{
public class IvrLibaTargetServiceImpl implements IIvrLibaTargetService {
    @Autowired
    private IvrLibaTargetMapper ivrLibaTargetMapper;
    @Autowired
    private IvrLibaTargetTagMapper ivrLibaTargetTagMapper;
    @Autowired
    private IvrLibaTargetoptionMapper ivrLibaTargetoptionMapper;
    /**
     * 查询指标选项库
     *
     * @param targetID 指标选项库主键
     *
     * @param id 指标选项库主键
     * @return 指标选项库
     */
    @Override
    public IvrLibaTarget selectIvrLibaTargetByTargetID(Long targetID)
    {
        return ivrLibaTargetMapper.selectIvrLibaTargetByTargetID(targetID);
    public IvrLibaTarget selectIvrLibaTargetByTargetID(Long id) {
        return ivrLibaTargetMapper.selectIvrLibaTargetByTargetID(id);
    }
    /**
     * 查询指标选项库列表
     *
     *
     * @param ivrLibaTarget 指标选项库
     * @return 指标选项库
     */
    @Override
    public List<IvrLibaTarget> selectIvrLibaTargetList(IvrLibaTarget ivrLibaTarget)
    {
    public List<IvrLibaTarget> selectIvrLibaTargetList(IvrLibaTarget ivrLibaTarget) {
        return ivrLibaTargetMapper.selectIvrLibaTargetList(ivrLibaTarget);
    }
    @Override
    public List<IvrLibaTargetVO> targetInfo(IvrLibaTarget ivrLibaTarget) {
        List<IvrLibaTarget> ivrLibaTargets = ivrLibaTargetMapper.selectIvrLibaTargetList(ivrLibaTarget);
        List<IvrLibaTargetVO> ivrLibaTargetVOS = DtoConversionUtils.sourceToTarget(ivrLibaTargets, IvrLibaTargetVO.class);
        for (IvrLibaTargetVO ivrLibaTarget1 : ivrLibaTargetVOS) {
            IvrLibaTargetoption ivrLibaTargetoption = new IvrLibaTargetoption();
            ivrLibaTargetoption.setTargetid(ivrLibaTarget1.getId());
            //获取该指标的选项
            List<IvrLibaTargetoption> ivrLibaTargetoptions = ivrLibaTargetoptionMapper.selectIvrLibaTargetoptionList(ivrLibaTargetoption);
            if (CollectionUtils.isNotEmpty(ivrLibaTargetoptions)) {
                ivrLibaTarget1.setTargetoptionList(ivrLibaTargetoptions);
            }
            //获取该指标的标签
            List<BaseTag> baseTags = ivrLibaTargetTagMapper.selectTagName(ivrLibaTarget1.getId());
            ivrLibaTarget1.setBaseTagList(baseTags);
        }
        //下面用左外感觉有点问题,where中的option的del会导致左边的查询不全,先不用吧
//        ivrLibaTargetMapper.targetInfo(ivrLibaTarget)
        return ivrLibaTargetVOS;
    }
    /**
     * 新增指标选项库
     *
     * @param ivrLibaTarget 指标选项库
     *
     * @param ivrLibaTargetVO 指标选项库
     * @return 结果
     */
    @Override
    public int insertIvrLibaTarget(IvrLibaTarget ivrLibaTarget)
    {
    @Transactional(rollbackFor = Exception.class)
    public int insertIvrLibaTarget(IvrLibaTargetVO ivrLibaTargetVO) {
        //新增指标信息
        IvrLibaTarget ivrLibaTarget = DtoConversionUtils.sourceToTarget(ivrLibaTargetVO, IvrLibaTarget.class);
        ivrLibaTarget.setCreateTime(DateUtils.getNowDate());
        return ivrLibaTargetMapper.insertIvrLibaTarget(ivrLibaTarget);
        ivrLibaTargetMapper.insertIvrLibaTarget(ivrLibaTarget);
        //新增该指标对应的标签信息
        for (BaseTag baseTag : ivrLibaTargetVO.getBaseTagList()) {
            IvrLibaTargetTag ivrLibaTargetTag = new IvrLibaTargetTag();
            ivrLibaTargetTag.setTagcategoryid(baseTag.getTagcategoryid());
            ivrLibaTargetTag.setTargetid(ivrLibaTarget.getId());
            //前端传来的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.getId());
            ivrLibaTargetoptionMapper.insertIvrLibaTargetoption(targetoption);
        }
        log.info("指标id为:{}", ivrLibaTarget.getId().intValue());
        return ivrLibaTarget.getId().intValue();
    }
    /**
     * 修改指标选项库
     *
     * @param ivrLibaTarget 指标选项库
     * 新增或修改指标选项库
     *
     * @param ivrLibaTargetVO 指标选项库
     * @return 结果
     */
    @Override
    public int updateIvrLibaTarget(IvrLibaTarget ivrLibaTarget)
    {
    @Transactional(rollbackFor = Exception.class)
    public int saveOrupdateIvrLibaTarget(IvrLibaTargetVO ivrLibaTargetVO) {
        IvrLibaTarget ivrLibaTarget = DtoConversionUtils.sourceToTarget(ivrLibaTargetVO, IvrLibaTarget.class);
        ivrLibaTarget.setUpdateTime(DateUtils.getNowDate());
        return ivrLibaTargetMapper.updateIvrLibaTarget(ivrLibaTarget);
        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.getId());
                    //前端传来的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.getId());
                    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.getId().intValue();
    }
    /**
     * 批量删除指标选项库
     *
     *
     * @param targetIDs 需要删除的指标选项库主键
     * @return 结果
     */
    @Override
    public int deleteIvrLibaTargetByTargetIDs(Long[] targetIDs)
    {
        return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetIDs(targetIDs);
    public int deleteIvrLibaTargetByTargetIDs(Long[] ids) {
        return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetIDs(ids);
    }
    /**
     * 删除指标选项库信息
     *
     *
     * @param targetID 指标选项库主键
     * @return 结果
     */
    @Override
    public int deleteIvrLibaTargetByTargetID(Long targetID)
    {
        return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetID(targetID);
    public int deleteIvrLibaTargetByTargetID(Long id) {
        return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetID(id);
    }
}