package com.smartor.service.impl;
|
|
import java.util.List;
|
|
import com.ruoyi.common.exception.base.BaseException;
|
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DtoConversionUtils;
|
import com.smartor.domain.HeLibrary;
|
import com.smartor.domain.HeLibraryTag;
|
import com.smartor.domain.HeLibraryVO;
|
import com.smartor.mapper.HeLibraryMapper;
|
import com.smartor.mapper.HeLibraryTagMapper;
|
import com.smartor.service.IHeLibraryService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.collections4.CollectionUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
/**
|
* 宣教资料库Service业务层处理
|
*
|
* @author ruoyi
|
* @date 2023-12-24
|
*/
|
@Slf4j
|
@Service
|
public class HeLibraryServiceImpl implements IHeLibraryService {
|
@Autowired
|
private HeLibraryMapper heLibraryMapper;
|
|
@Autowired
|
private HeLibraryTagMapper heLibraryTagMapper;
|
|
/**
|
* 查询宣教资料库
|
*
|
* @param id 宣教资料库主键
|
* @return 宣教资料库
|
*/
|
@Override
|
public HeLibrary selectHeLibraryById(Long id) {
|
return heLibraryMapper.selectHeLibraryById(id);
|
}
|
|
/**
|
* 查询宣教资料库列表
|
*
|
* @param heLibrary 宣教资料库
|
* @return 宣教资料库
|
*/
|
@Override
|
public List<HeLibrary> selectHeLibraryList(HeLibrary heLibrary) {
|
return heLibraryMapper.selectHeLibraryList(heLibrary);
|
}
|
|
/**
|
* 新增宣教资料库
|
*
|
* @param heLibrary 宣教资料库
|
* @return 结果
|
*/
|
@Override
|
public int insertHeLibrary(HeLibrary heLibrary) {
|
heLibrary.setCreateTime(DateUtils.getNowDate());
|
return heLibraryMapper.insertHeLibrary(heLibrary);
|
}
|
|
/**
|
* 修改宣教资料库
|
*
|
* @param heLibrary 宣教资料库
|
* @return 结果
|
*/
|
@Override
|
public int updateHeLibrary(HeLibrary heLibrary) {
|
heLibrary.setUpdateTime(DateUtils.getNowDate());
|
return heLibraryMapper.updateHeLibrary(heLibrary);
|
}
|
|
/**
|
* 批量删除宣教资料库
|
*
|
* @param ids 需要删除的宣教资料库主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteHeLibraryByIds(Long[] ids) {
|
return heLibraryMapper.deleteHeLibraryByIds(ids);
|
}
|
|
/**
|
* 删除宣教资料库信息
|
*
|
* @param id 宣教资料库主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteHeLibraryById(Long id) {
|
return heLibraryMapper.deleteHeLibraryById(id);
|
}
|
|
/**
|
* 新增或修改宣教详情
|
*/
|
@Override
|
public Integer saveOrUpdateScript(HeLibraryVO heLibraryVO) {
|
Integer i = null;
|
HeLibrary heLibrary = DtoConversionUtils.sourceToTarget(heLibraryVO, HeLibrary.class);
|
if (heLibraryVO.getIsoperation() != null && heLibraryVO.getIsoperation() == 1) {
|
//新增
|
i = heLibraryMapper.insertHeLibrary(heLibrary);
|
} else if (heLibraryVO.getIsoperation() != null && heLibraryVO.getIsoperation() == 2) {
|
//修改
|
i = heLibraryMapper.updateHeLibrary(heLibrary);
|
}
|
log.info("新增或修改宣教详情的id为:{}", heLibrary.getId());
|
|
//对标签进行处理
|
for (HeLibraryTag heLibraryTag : heLibraryVO.getHeLibraryTagList()) {
|
if (heLibraryTag.getIsoperation() != null && heLibraryTag.getIsoperation() == 1) {
|
//新增
|
heLibraryTag.setHeid(heLibrary.getId());
|
heLibraryTagMapper.insertHeLibraryTag(heLibraryTag);
|
} else if (heLibraryTag.getIsoperation() != null && heLibraryTag.getIsoperation() == 2) {
|
//修改
|
heLibraryTag.setHeid(heLibrary.getId());
|
heLibraryTagMapper.updateHeLibraryTag(heLibraryTag);
|
} else if (heLibraryTag.getIsoperation() != null && heLibraryTag.getIsoperation() == 3) {
|
//删除
|
if (heLibraryTag.getId() == null) {
|
log.info("删除失败,模板指标id为空");
|
} else {
|
heLibraryTagMapper.deleteHeLibraryTagById(heLibraryTag.getId());
|
}
|
}
|
}
|
|
return i;
|
}
|
|
@Override
|
public HeLibraryVO selectInfoByCondition(HeLibrary heLibrary) {
|
log.info("查询模板详情根据条件的入参为:{}", heLibrary);
|
List<HeLibrary> heLibraries = selectHeLibraryList(heLibrary);
|
if (CollectionUtils.isEmpty(heLibraries)) {
|
log.info("提供的条件,查询宣教数据为空:{}", heLibraries);
|
throw new BaseException("提供的条件,查询宣教数据为空");
|
}
|
|
//用于返参
|
HeLibraryVO heLibraryVO = DtoConversionUtils.sourceToTarget(heLibraries.get(0), HeLibraryVO.class);
|
//根据宣教ID查询宣教指标集合
|
HeLibraryTag heLibraryTag = new HeLibraryTag();
|
heLibraryTag.setHeid(heLibraryVO.getId());
|
List<HeLibraryTag> heLibraryTags = heLibraryTagMapper.selectHeLibraryTagList(heLibraryTag);
|
heLibraryVO.setHeLibraryTagList(heLibraryTags);
|
|
return heLibraryVO;
|
}
|
}
|