TaskTempController.java 2.15 KB
package vion.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vion.third.WechatMod;
import vion.dto.TaskTempDTO;
import vion.model.TaskTemp;
import vion.service.ITaskTempService;
import vion.vo.TaskTempVO;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 预工单
 */
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
public class TaskTempController {

    private final ITaskTempService taskTempService;
    private final WechatMod wechatMod;
    private final Converter converter;

    @GetMapping("/taskTemps")
    @SaCheckPermission(value = "taskTemp:list", orRole = "admin")
    public Page<TaskTempVO> getTaskTempList(TaskTempDTO data) {
        return taskTempService.getTaskTempList(data);
    }

    @GetMapping("/taskTemp")
    @SaCheckPermission(value = "taskTemp:query", orRole = "admin")
    public TaskTempVO getTaskTempById(Long id) {
        return taskTempService.getTaskTempById(id);
    }

    @PostMapping("/taskTemp")
    @SaCheckPermission(value = "taskTemp:editAndSave", orRole = "admin")
    public Object saveOrUpdateTaskTemp(TaskTempDTO data) {
        return taskTempService.saveOrUpdTaskTemp(data);
    }

    @GetMapping("/taskTemp/wechatCallback")
    public Object wechatCallback(String code, HttpServletResponse res) throws IOException {
        Object obj = wechatMod.wechatCallback(code);
        if (obj instanceof String) {
            res.sendRedirect("https://yunwei.vionyun.com/wap/?openid=" + obj);
        } else {
            return obj;
        }
        return "success";
    }

    @PostMapping("/taskTemp/{id}")
    @SaCheckPermission(value = "taskTemp:edit", orRole = "admin")
    public String upd(@PathVariable(name = "id") Long id, TaskTempDTO data) {
        TaskTemp taskTemp = converter.convert(data, new TaskTemp());
        taskTemp.setId(id);
        return taskTempService.updateById(taskTemp) ? "更新成功" : "更新失败";
    }
}