liusheng
21 小时以前 e4e220916dd2a4aa649a9b0162e5b5ed0dc9d7e5
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
package com.ruoyi.web.controller.smartor;
 
import com.github.pagehelper.ISelect;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.RSAPublicKeyExample;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.smartor.domain.*;
import com.smartor.service.IServiceSubtaskService;
import com.smartor.service.IServiceTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 随访任务Controller
 *
 * @author smartor
 * @date 2023-03-24
 */
@Slf4j
@Api(description = "随访任务")
@RestController
@RequestMapping("/smartor/servicetask")
public class ServiceTaskController extends BaseController {
    @Autowired
    private IServiceTaskService serviceTaskService;
 
    @Autowired
    private IServiceSubtaskService iServiceTaskCallService;
 
    @Value("${pub_key}")
    private String pub_key;
 
    @Value("${pri_key}")
    private String pri_key;
 
    @Autowired
    private RSAPublicKeyExample rsaPublicKeyExample;
 
    /**
     * 查询语音任务列表
     */
    @ApiOperation("查询任务列表")
    //@PreAuthorize("@ss.hasPermi('smartor:ServiceTask:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ServiceTask serviceTask) {
        PageUtils.startPageByPost(serviceTask.getPageNum(), serviceTask.getPageSize());
//        List<ServiceTask> list = serviceTaskService.selectServiceTaskList(serviceTask);
        List<ServiceTask> list = serviceTaskService.selectServiceTaskAndtaskDeptList(serviceTask);
        List<ServiceTaskVO> serviceTaskVOS = DtoConversionUtils.sourceToTarget(list, ServiceTaskVO.class);
 
        if (CollectionUtils.isNotEmpty(serviceTaskVOS)) {
            for (ServiceTaskVO ServiceTaskVO : serviceTaskVOS) {
                ServiceSubtaskVO serviceSubtaskVO = new ServiceSubtaskVO();
                serviceSubtaskVO.setTaskid(ServiceTaskVO.getTaskid());
                serviceSubtaskVO.setStartOutHospTime(serviceTask.getStartOutHospTime());
                serviceSubtaskVO.setEndOutHospTime(serviceTask.getEndOutHospTime());
                List<ServiceSubtask> ServiceTaskcalls = iServiceTaskCallService.selectServiceSubtaskList(serviceSubtaskVO);
                if (CollectionUtils.isNotEmpty(ServiceTaskcalls)) {
                    //已发送(子任务中的 sendstate=1为被领取)
                    long yfs = ServiceTaskcalls.stream().filter(serviceTaskcall1 -> (serviceTaskcall1.getSendstate() != null && serviceTaskcall1.getSendstate() >= 3L) || (serviceTaskcall1.getSendstate() != null && serviceTaskcall1.getSendstate() == 1L)).collect(Collectors.toList()).stream().count();
                    //未发送
                    long wfs = ServiceTaskcalls.stream().filter(serviceTaskcall1 -> serviceTaskcall1.getSendstate() != null && serviceTaskcall1.getSendstate() == 2L).collect(Collectors.toList()).stream().count();
                    ServiceTaskVO.setYfs(yfs);
                    ServiceTaskVO.setWfs(wfs);
                }
 
            }
            //获取total
            long total = PageUtils.count(new ISelect() {
                @Override
                public void doSelect() {
                    serviceTask.setPageNum(null);
                    serviceTask.setPageSize(null);
                    serviceTaskService.selectServiceTaskAndtaskDeptList(serviceTask);
                }
            });
 
            return getDataTable2(total, serviceTaskVOS);
        }
 
        return getDataTable2(0, serviceTaskVOS);
    }
 
    /**
     * 导出任务列表
     */
    @ApiOperation("导出任务列表")
    //@PreAuthorize("@ss.hasPermi('smartor:ServiceTask:export')")
    @Log(title = "语音任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceTask ServiceTask) {
        List<ServiceTask> list = serviceTaskService.selectServiceTaskList(ServiceTask);
        ExcelUtil<ServiceTask> util = new ExcelUtil<ServiceTask>(ServiceTask.class);
        util.exportExcel(response, list, "语音任务数据");
    }
 
    /**
     * 获取任务详细信息
     */
    @ApiOperation("获取任务详细信息")
    //@PreAuthorize("@ss.hasPermi('smartor:ServiceTask:query')")
    @GetMapping(value = "/{taskid}")
    public AjaxResult getInfo(@PathVariable("taskid") Long taskid) {
        return success(serviceTaskService.selectServiceTaskByTaskid(taskid));
    }
 
    /**
     * 新增任务
     */
    @ApiOperation("新增任务")
    //@PreAuthorize("@ss.hasPermi('smartor:ServiceTask:add')")
    @Log(title = "语音任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ServiceTask ServiceTask) {
        SysUser user = getLoginUser().getUser();
        ServiceTask.setOrgid(user.getOrgid());
        return toAjax(serviceTaskService.insertServiceTask(ServiceTask));
    }
 
    /**
     * 修改语音任务
     */
    @ApiOperation("修改任务")
    //@PreAuthorize("@ss.hasPermi('smartor:ServiceTask:edit')")
    @Log(title = "任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ServiceTask ServiceTask) {
        return toAjax(serviceTaskService.updateServiceTask(ServiceTask));
    }
 
//    /**
//     * 删除语音任务
//     */
//    @ApiOperation("删除任务")
//    //@PreAuthorize("@ss.hasPermi('smartor:ServiceTask:remove')")
//    @Log(title = "语音任务", businessType = BusinessType.DELETE)
//    @GetMapping("/remove/{taskids}")
//    public AjaxResult remove(@PathVariable Long[] taskids) {
//        return toAjax(ServiceTaskService.deleteServiceTaskByTaskids(taskids));
//    }
//
 
    /**
     * 删除任务(包括它对应的患者信息)
     */
    @ApiOperation("删除任务(包括它对应的患者信息)")
    //@PreAuthorize("@ss.hasPermi('smartor:ServiceTask:remove')")
    @Log(title = "语音任务", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{taskId}")
    public AjaxResult removeTask(@PathVariable("taskId") String taskId) {
        if (StringUtils.isEmpty(taskId)) {
            AjaxResult.error("入参不能为空");
        }
        Long tid = Long.valueOf(taskId);
        return toAjax(serviceTaskService.deleteServiceTaskByTaskid(tid));
    }
 
    /**
     * 通过任务ID和患者ID获取单个人的题目信息
     *
     * @return
     */
    @ApiOperation("通过任务ID和患者ID获取单个人的题目信息")
    @PostMapping("/getScriptInfoByCondition")
    public AjaxResult getScriptInfoByCondition(@RequestBody ServiceTaskScriptQues serviceTaskScriptQues) {
        Long tid = null;
        Long pid = null;
        log.error("getScriptInfoByCondition入参为:{}", serviceTaskScriptQues);
        try {
            tid = Long.valueOf(rsaPublicKeyExample.decryptedData(serviceTaskScriptQues.getParam1(), pri_key));
            pid = Long.valueOf(rsaPublicKeyExample.decryptedData(serviceTaskScriptQues.getParam2(), pri_key));
        } catch (Exception e) {
            log.error("getScriptInfoByCondition报错了:{}", e.getMessage());
        }
 
        log.error("tid和pid的值为:{},{}", tid, pid);
        if (StringUtils.isEmpty(serviceTaskScriptQues.getPatfrom())) serviceTaskScriptQues.setPatfrom("0");
        return success(serviceTaskService.getScriptInfoByCondition(tid, pid, true, serviceTaskScriptQues.getPatfrom()));
    }
 
 
    /**
     * 通过任务ID和患者ID获取单个人的题目信息
     *
     * @return
     */
    @ApiOperation("通过任务ID和患者ID获取单个人的题目信息(小程序)")
    @PostMapping("/getScriptInfoByConditionXCH")
    public AjaxResult getScriptInfoByConditionXCH(@RequestBody ServiceTaskScriptQues serviceTaskScriptQues) {
        Long tid = null;
        Long pid = null;
        log.error("getScriptInfoByCondition入参为:{}", serviceTaskScriptQues);
        try {
            tid = Long.valueOf(serviceTaskScriptQues.getParam1());
            pid = Long.valueOf(serviceTaskScriptQues.getParam2());
        } catch (Exception e) {
            log.error("getScriptInfoByCondition报错了:{}", e.getMessage());
        }
 
        log.error("tid和pid的值为:{},{}", tid, pid);
        if (StringUtils.isEmpty(serviceTaskScriptQues.getPatfrom())) serviceTaskScriptQues.setPatfrom("0");
        return success(serviceTaskService.getScriptInfoByCondition(tid, pid, true, serviceTaskScriptQues.getPatfrom()));
    }
 
}