liusheng
8 天以前 9cc2f53b11205309754c2451be061ef5fc337f32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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;
    }
}