OtherController.java 3.18 KB
package cn.fw.dalaran.server.controller.app;

import cn.fw.common.web.annotation.ControllerMethod;
import cn.fw.common.web.auth.LoginAuthBean;
import cn.fw.common.web.auth.annotation.CurrentUser;
import cn.fw.dalaran.domain.param.LiveCheckParams;
import cn.fw.dalaran.domain.vo.LiveCheckVo;
import cn.fw.dalaran.service.biz.OtherBizService;
import cn.fw.data.base.domain.common.Message;
import cn.fw.security.auth.client.annotation.Authorization;
import cn.fw.security.auth.client.annotation.IgnoreAuth;
import cn.fw.security.auth.client.enums.AuthType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.File;
import java.util.Objects;

import static cn.fw.common.web.util.ResultBuilder.success;

/**
 * @author wmy3969
 * @version 1.0
 * @date 2022/6/7 10:56
 * @Description
 */
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@Authorization(AuthType.ERP)
@RequestMapping("/other")
@IgnoreAuth
public class OtherController {

    private final OtherBizService otherBizService;

    /**
     * 获取直播审计页面
     *
     * @param user   当前登录用户
     * @param dataId 待办id
     * @return
     */
    @GetMapping("/getLiveCheckPage")
    public Message<LiveCheckVo> getLiveCheck(@CurrentUser LoginAuthBean user, @NotNull(message = "请必须指定待办id") Long dataId) {
        return success(otherBizService.getLiveCheck(user.getUserId(), dataId));
    }

    /**
     * 保存审核结果
     *
     * @param param 审计结果封装
     * @return
     */
    @PostMapping("/saveCheckResult")
    public Message<Boolean> saveCheckResult(@CurrentUser LoginAuthBean user, @RequestBody @Valid LiveCheckParams param) {
        return success(otherBizService.saveCheckResult(user.getUserId(), param));
    }

    /**
     * 获取某条审计详情
     *
     * @param id 某条记录id
     * @return
     */
    @GetMapping("/getLiveCheckDetails")
    @ControllerMethod("获取某条审计详情")
    public Message<LiveCheckVo.liveSummary> getLiveCheckDetails(@NotNull(message = "请必须指定数据id") Long id) {
        return success(otherBizService.getLiveCheckDetails(id));
    }

    /**
     * 指定目录创建文件夹
     *
     * @param dir  目录
     * @param type 操作类型
     * @return
     */
    @GetMapping("/mkdir")
    public Message<Boolean> mkdir(@NotBlank(message = "请必须指定路径") String dir, @NotNull(message = "请必须指定操作类型") Integer type) {
        File file = new File(dir);
        boolean result = false;
        String handleType = "";
        if (Objects.equals(type, 1)) {
            handleType = "创建";
            if (!file.exists())
                result = file.mkdirs();
        } else {
            handleType = "删除";
            if (file.exists())
                result = file.delete();
        }
        log.info(String.format("%s文件夹, 路径为: %s, 结果为: %s", handleType, dir, result ? "成功" : "失败"));
        return success(result);
    }

}