package com.smartor.service.impl;
|
|
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;
|
|
import java.util.List;
|
|
/**
|
* 宣教资料库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) {
|
Integer i = null;
|
for (Long id : ids) {
|
i = heLibraryMapper.deleteHeLibraryById(id);
|
}
|
return i;
|
}
|
|
|
/**
|
* 新增或修改宣教详情
|
*/
|
@Override
|
public Integer saveOrUpdateScript(HeLibraryVO heLibraryVO) {
|
HeLibrary heLibrary = DtoConversionUtils.sourceToTarget(heLibraryVO, HeLibrary.class);
|
if (heLibraryVO.getIsoperation() != null && heLibraryVO.getIsoperation() == 1) {
|
//新增
|
heLibraryMapper.insertHeLibrary(heLibrary);
|
} else if (heLibraryVO.getIsoperation() != null && heLibraryVO.getIsoperation() == 2) {
|
//修改
|
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());
|
// }
|
// }
|
// }
|
//
|
// //对科室进行处理
|
// for (TempDetpRelevance tempDetpRelevance : heLibraryVO.getTempDetpRelevances()) {
|
// if (tempDetpRelevance.getId() == null) {
|
// //新增
|
// tempDetpRelevance.setTempid(heLibrary.getId());
|
// tempDetpRelevance.setType(3L);
|
// tempDetpRelevanceMapper.insertTempDetpRelevance(tempDetpRelevance);
|
// } else {
|
// tempDetpRelevanceMapper.updateTempDetpRelevance(tempDetpRelevance);
|
// }
|
// }
|
|
return heLibrary.getId().intValue();
|
}
|
|
@Override
|
public List<HeLibraryVO> selectInfoByCondition(HeLibrary heLibrary) {
|
log.info("查询模板详情根据条件的入参为:{}", heLibrary);
|
List<HeLibrary> heLibraries = selectHeLibraryList(heLibrary);
|
if (CollectionUtils.isEmpty(heLibraries)) {
|
log.info("提供的条件,查询宣教数据为空:{}", heLibraries);
|
throw new BaseException("提供的条件,查询宣教数据为空");
|
}
|
List<HeLibraryVO> heLibraryVOS = DtoConversionUtils.sourceToTarget(heLibraries, HeLibraryVO.class);
|
if (CollectionUtils.isNotEmpty(heLibraryVOS) && heLibraryVOS.size() == 1) {
|
//根据宣教ID查询宣教指标集合
|
HeLibraryTag heLibraryTag = new HeLibraryTag();
|
heLibraryTag.setHeid(heLibraryVOS.get(0).getId());
|
List<HeLibraryTag> heLibraryTags = heLibraryTagMapper.selectHeLibraryTagList(heLibraryTag);
|
heLibraryVOS.get(0).setHeLibraryTagList(heLibraryTags);
|
}
|
return heLibraryVOS;
|
}
|
|
@Override
|
public List<HeLibraryVO> selectInfoByConditionXCH(HeLibrary heLibrary) {
|
List<HeLibraryVO> heLibraryVOS = selectInfoByCondition(heLibrary);
|
HeLibraryVO heLibraryVO = heLibraryVOS.get(0);
|
HeLibrary heLibrary1 = DtoConversionUtils.sourceToTarget(heLibraryVO, HeLibrary.class);
|
if (heLibrary1.getWatchCount() == null) {
|
heLibrary1.setWatchCount(0L);
|
}
|
heLibrary1.setWatchCount(heLibrary1.getWatchCount() + 1);
|
updateHeLibrary(heLibrary1);
|
return heLibraryVOS;
|
}
|
}
|