liusheng
2024-04-16 63e17909e1eee7ff54c38827a4096cbad82e5dad
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/IvrTaskcallController.java
@@ -1,104 +1,153 @@
package com.smartor.controller;
package com.ruoyi.web.controller.smartor;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.smartor.domain.IvrTaskcall;
import com.smartor.service.IIvrTaskcallService;
import com.ruoyi.common.utils.poi.ExcelUtil;
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.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.smartor.domain.*;
import com.smartor.service.IIvrTaskSingleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * 语音任务呼叫Controller
 *
 * @author smartor
 * @date 2023-03-24
 * 单一任务(随访)Controller
 *
 * @author ruoyi
 * @date 2024-02-02
 */
@Api(description = "单一任务(随访宣教)")
@RestController
@RequestMapping("/smartor/ivrtaskcall")
public class IvrTaskcallController extends BaseController
{
@RequestMapping("/smartor/tasksingle")
public class IvrTaskcallController extends BaseController {
    @Autowired
    private IIvrTaskcallService ivrTaskcallService;
    private IIvrTaskSingleService ivrTaskcallService;
    /**
     * 查询语音任务呼叫列表
     * 查询患者随访信息
     */
    @PreAuthorize("@ss.hasPermi('smartor:ivrtaskcall:list')")
    @GetMapping("/list")
    public TableDataInfo list(IvrTaskcall ivrTaskcall)
    {
        startPage();
        List<IvrTaskcall> list = ivrTaskcallService.selectIvrTaskcallList(ivrTaskcall);
        return getDataTable(list);
    @ApiOperation("查询患者随访信息")
    @PreAuthorize("@ss.hasPermi('system:taskcall:list')")
    @PostMapping("/patItem")
    public TableDataInfo patItem(@RequestBody IvrTaskSingle ivrTaskcall) {
        PageUtils.startPageByPost(ivrTaskcall.getPageNum(), ivrTaskcall.getPageSize());
        return getDataTable(ivrTaskcallService.patItem(ivrTaskcall));
    }
    /**
     * 导出语音任务呼叫列表
     * 导出单一任务(随访宣教)列表
     */
    @PreAuthorize("@ss.hasPermi('smartor:ivrtaskcall:export')")
    @Log(title = "语音任务呼叫", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:taskcall:export')")
    @Log(title = "单一任务(随访宣教)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IvrTaskcall ivrTaskcall)
    {
        List<IvrTaskcall> list = ivrTaskcallService.selectIvrTaskcallList(ivrTaskcall);
        ExcelUtil<IvrTaskcall> util = new ExcelUtil<IvrTaskcall>(IvrTaskcall.class);
        util.exportExcel(response, list, "语音任务呼叫数据");
    public void export(HttpServletResponse response, IvrTaskSingle ivrTaskcall) {
        List<IvrTaskSingle> list = ivrTaskcallService.selectIvrTaskcallList(ivrTaskcall);
        ExcelUtil<IvrTaskSingle> util = new ExcelUtil<IvrTaskSingle>(IvrTaskSingle.class);
        util.exportExcel(response, list, "单一任务(随访)数据");
    }
    /**
     * 获取语音任务呼叫详细信息
     * 获取单一任务(随访)详细信息
     */
    @PreAuthorize("@ss.hasPermi('smartor:ivrtaskcall:query')")
    @GetMapping(value = "/{callid}")
    public AjaxResult getInfo(@PathVariable("callid") Long callid)
    {
        return success(ivrTaskcallService.selectIvrTaskcallByCallid(callid));
    @PreAuthorize("@ss.hasPermi('system:taskcall:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ivrTaskcallService.selectIvrTaskcallById(id));
    }
    /**
     * 新增语音任务呼叫
     * 新增或修改删除单一任务
     */
    @PreAuthorize("@ss.hasPermi('smartor:ivrtaskcall:add')")
    @Log(title = "语音任务呼叫", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IvrTaskcall ivrTaskcall)
    {
        return toAjax(ivrTaskcallService.insertIvrTaskcall(ivrTaskcall));
    @ApiOperation("新增或修改删除单一任务")
    @PreAuthorize("@ss.hasPermi('system:task:add')")
    @Log(title = "单一任务(随访)", businessType = BusinessType.INSERT)
    @PostMapping("/insertOrUpdateTask")
    public AjaxResult insertOrUpdateHeTask(@RequestBody IvrTaskSingleVO ivrTaskcallVO) {
        return toAjax(ivrTaskcallService.insertOrUpdateTask(ivrTaskcallVO));
    }
    /**
     * 修改语音任务呼叫
     */
    @PreAuthorize("@ss.hasPermi('smartor:ivrtaskcall:edit')")
    @Log(title = "语音任务呼叫", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IvrTaskcall ivrTaskcall)
    {
        return toAjax(ivrTaskcallService.updateIvrTaskcall(ivrTaskcall));
    }
    /**
     * 删除语音任务呼叫
     * 根据条件查询任务信息
     */
    @PreAuthorize("@ss.hasPermi('smartor:ivrtaskcall:remove')")
    @Log(title = "语音任务呼叫", businessType = BusinessType.DELETE)
   @DeleteMapping("/{callids}")
    public AjaxResult remove(@PathVariable Long[] callids)
    {
        return toAjax(ivrTaskcallService.deleteIvrTaskcallByCallids(callids));
    @ApiOperation("根据条件查询任务信息")
    @PostMapping("/queryTaskByCondition")
    public AjaxResult queryTaskByCondition(@RequestBody IvrTaskSingleVO ivrTaskcallVO) {
        //根据入参查询信息
        IvrTaskSingle ivrTaskcall = DtoConversionUtils.sourceToTarget(ivrTaskcallVO, IvrTaskSingle.class);
        List<IvrTaskSingle> list = ivrTaskcallService.selectIvrTaskcallList(ivrTaskcall);
        //定义患者与单一任务关联表集合
        List<PatTaskRelevance> patTaskRelevances = new ArrayList<>();
        //将查出来的数据倒入IvrTaskcallVO中
        IvrTaskSingleVO ivrTaskcallVO2 = DtoConversionUtils.sourceToTarget(list.get(0), IvrTaskSingleVO.class);
        String sendTimeSlot = list.get(0).getSendTimeSlot();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            //获取到发送时间的集合
            if (StringUtils.isNotEmpty(sendTimeSlot)) {
                List<TaskSendTimeVO> taskSendTimeVOList = objectMapper.readValue(sendTimeSlot, List.class);
                ivrTaskcallVO2.setSendTimeslot(taskSendTimeVOList);
            }
            //文本变量参数
            if (StringUtils.isNotEmpty(list.get(0).getTextParam())) {
                Map<String, Map<String, String>> textParam = objectMapper.readValue(list.get(0).getTextParam(), Map.class);
                ivrTaskcallVO2.setTextParam(textParam);
            }
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        for (IvrTaskSingle ivrTaskcall1 : list) {
            PatTaskRelevance patTaskRelevance = new PatTaskRelevance();
            //获取到患者信息,并放入到集合中
            patTaskRelevance.setName(ivrTaskcall1.getSendname());
            patTaskRelevance.setAge(ivrTaskcall1.getAge());
            patTaskRelevance.setSfzh(ivrTaskcall1.getSfzh());
            patTaskRelevance.setPhone(ivrTaskcall1.getPhone());
            patTaskRelevance.setAddr(ivrTaskcall1.getAddr());
            patTaskRelevances.add(patTaskRelevance);
        }
        ivrTaskcallVO2.setPatTaskRelevances(patTaskRelevances);
        return success(ivrTaskcallVO2);
    }
    /**
     * 任务发送执行
     */
    @ApiOperation("任务发送执行")
    @PostMapping("/heTaskSend")
    public AjaxResult heTaskSend(@RequestBody IvrTaskSingleVO ivrTaskcallVO) {
        return toAjax(ivrTaskcallService.heTaskSend(ivrTaskcallVO));
    }
    /**
     * 电话回调任务
     */
    @ApiOperation("电话回调任务")
    @PostMapping("/phoneCallBack")
    public AjaxResult phoneCallBack(@RequestBody PhoneCallBackVO phoneCallBackVO) {
        //如果uuid在redis中找不到,那就直接报异常
        return success(ivrTaskcallService.phoneCallBack(phoneCallBackVO));
    }
}