xuhy
2024-12-13 2536f425d95d2e21aa1d61e942b52f10947c9300
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.dto.TechImportExcel;
import com.ruoyi.system.service.*;
import com.ruoyi.system.query.RegionQuery;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 职称系列 前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-09-19
 */
@RestController
@RequestMapping("/t-technical-title")
public class TTechnicalTitleController {
 
    @Resource
    private TTechnicalTitleService tTechnicalTitleService;
    @Resource
    private TRegionService regionService;
    @Resource
    private TTitleMajorService majorService;
    @Resource
    private TLevelService levelService;
    //添加接口
    @ApiOperation(value = "添加",tags = "后台-系统设置-职称系列")
    @PostMapping(value = "/add")
    public R add(@RequestBody TTechnicalTitle tTechnicalTitle){
        tTechnicalTitleService.save(tTechnicalTitle);
        return R.ok();
    }
    @ApiOperation(value = "职称分类",tags = "后台-下拉框")
    @PostMapping(value = "/select")
    public R<List<TTechnicalTitle>> select(){
        return R.ok(tTechnicalTitleService.list());
    }
 
 
    @ApiOperation(value = "树状图",tags = "web-下拉框")
    @PostMapping(value = "/tree")
    public R<List<TTechnicalTitle>> tree(){
        List<TLevel> list2 = levelService.list();
 
        List<TTechnicalTitle> list = tTechnicalTitleService.list();
        for (TTechnicalTitle tTechnicalTitle : list) {
            tTechnicalTitle.setName(tTechnicalTitle.getTitileName());
            List<TTitleMajor> list1 = majorService.lambdaQuery().eq(TTitleMajor::getTechnicalId, tTechnicalTitle.getId()).list();
            for (TTitleMajor tTitleMajor : list1) {
                tTitleMajor.setName(tTitleMajor.getMajorName());
//                tTitleMajor.setMajors(list2);
            }
            tTechnicalTitle.setMajors(list1);
        }
        return R.ok(list);
    }
 
 
 
    //编辑接口
    @ApiOperation(value = "编辑",tags = "后台-系统设置-职称系列")
    @PostMapping(value = "/edit")
    public R edit(@RequestBody TTechnicalTitle tTechnicalTitle){
        tTechnicalTitleService.updateById(tTechnicalTitle);
 
        // 修改专业的地区
        majorService.lambdaUpdate().eq(TTitleMajor::getTechnicalId, tTechnicalTitle.getId()).set(TTitleMajor::getRegionIds, tTechnicalTitle.getRegionIds()).update();
        return R.ok();
    }
 
    @Resource
    private TUserChangeDetailService userChangeDetailService;
    @Resource
    private TConsultationService consultationService;
    @Resource
    private TDeclareNoticeService declareNoticeService;
    @Resource
    private TCommitteeTechnicalService committeeTechnicalService;
    @Resource
    private TCommitteeService committeeService;
    @Resource
    private TInformationService informationService;
    @Resource
    private TCourseService courseService;
    //批量删除接口
    @ApiOperation(value = "删除",tags = "后台-系统设置-职称系列")
    @PostMapping(value = "/deleteByIds")
    public R deleteByIds(String ids){
        List<String> list = Arrays.asList(ids.split(","));
        for (String s : list) {
            //判断是否有关联数据
            Long count = userChangeDetailService.lambdaQuery().eq(TUserChangeDetail::getTitleId, s).count();
            if (count>0){
                return R.fail("当前职称已有用户设为偏好,无法删除");
            }
            Long count1 = consultationService.lambdaQuery().eq(TConsultation::getTitleId, s).count();
            if (count1>0){
                return R.fail("当前职称已设置咨询,无法删除");
            }
            Long count2 = declareNoticeService.lambdaQuery().eq(TDeclareNotice::getTechnicalId, s).count();
            if (count2>0){
                return R.fail("当前职称已设置申报通知,无法删除");
            }
            Long count3 = committeeTechnicalService.lambdaQuery().eq(TCommitteeTechnical::getTechnicalId, s).count();
            if (count3>0){
                return R.fail("当前职称已设置委员会可评审职称,无法删除");
            }
            Long count4 = committeeService.lambdaQuery().eq(TCommittee::getTechnicalId, s).count();
            if (count4>0){
                return R.fail("当前职称已设置评审委员会,无法删除");
            }
            Long count5 = informationService.lambdaQuery().eq(TInformation::getTechnicalId, s).count();
            if (count5>0){
                return R.fail("当前职称已设置资料,无法删除");
            }
            Long count6 = majorService.lambdaQuery().eq(TTitleMajor::getTechnicalId, s).count();
            if (count6>0){
                return R.fail("当前职称已设置专业,无法删除");
            }
            Long count7 = courseService.lambdaQuery().eq(TCourse::getTechnicalId, s).count();
            if (count7>0){
                return R.fail("当前职称已设置课程,无法删除");
            }
        }
        tTechnicalTitleService.removeByIds(list);
        return R.ok();
    }
    //分页查询
    @ApiOperation(value = "查询",tags = "后台-系统设置-职称系列")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TTechnicalTitle>> pageList(@RequestBody RegionQuery regionQuery){
        return R.ok(tTechnicalTitleService.pageList(regionQuery));
    }
 
 
 
    @ApiOperation(value = "导入",tags = "后台-系统设置-职称系列")
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @PostMapping("/export")
    public R export (@RequestParam("file") MultipartFile file) {
        List<TTechnicalTitle> tTechnicalTitles = new ArrayList<>();
 
 
 
        int errorLines = 0;
        int successLines = 0;
        ImportParams params = new ImportParams();
//        params.setTitleRows(1);//标题行数
        params.setHeadRows(1); //表头行数
        String msg = null;
        InputStream inputStream = null;
 
        List<String> failMsg = new ArrayList<>();
 
        try {
            inputStream = file.getInputStream();
            List<TechImportExcel> techImportExcels = ExcelImportUtil.importExcel(inputStream, TechImportExcel.class, params);
            for (TechImportExcel techImportExcel : techImportExcels) {
 
                List<Integer> regionIds;
                if (techImportExcel.getAddress() == null || StringUtils.isEmpty(techImportExcel.getAddress())) {
                    msg = "第" + techImportExcels.indexOf(techImportExcel) + "行,地区不能为空";
                    failMsg.add(msg);
                    continue;
                } else {
                    if("全部".equals(techImportExcel.getAddress())){
                        List<TRegion> list = regionService.lambdaQuery().list();
                        regionIds = list.stream().map(TRegion::getId).collect(Collectors.toList());
                    }else {
                        String[] split = techImportExcel.getAddress().split(";");
                        regionIds = new ArrayList<>();
                        for (String s : split) {
                            TRegion region = regionService.lambdaQuery().like(TRegion::getName, s).one();
                            if (region == null) {
                                msg = "第" + techImportExcels.indexOf(techImportExcel) + "行,地区不存在";
                                failMsg.add(msg);
                            } else {
                                regionIds.add(region.getId());
                            }
                        }
                        if (regionIds.size() != split.length) {
                            continue;
                        }
                    }
                }
                TTechnicalTitle tTechnicalTitle = new TTechnicalTitle();
                tTechnicalTitle.setTitileName(techImportExcel.getTitileName());
                tTechnicalTitle.setRegionIds(StringUtils.join(regionIds, ","));
                tTechnicalTitles.add(tTechnicalTitle);
            }
 
            if (failMsg.size()==0){
                tTechnicalTitleService.saveBatch(tTechnicalTitles);
            }else {
                return R.fail(failMsg);
            }
 
        } catch (Exception e) {
            e.printStackTrace();
//            logger.error("批量购入导入失败:{}",e.getMessage());
//            importRecordService.removeById(tImportRecord.getId());
            return R.fail("批量导入失败!");
        }finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                throw new ServiceException(e.getMessage());
            }
        }
 
 
        return R.ok();
    }
 
 
}