package com.zxdmy.excite.admin.controller.cloud.trace;


import cn.dev33.satoken.stp.StpUtil;
import com.zxdmy.excite.common.base.BaseController;
import com.zxdmy.excite.common.base.BaseResult;
import com.zxdmy.excite.common.entity.PageList;
import com.zxdmy.excite.framework.aop.AnnotationSaveReLog;
import com.zxdmy.excite.system.entity.req.lately.ReqCloudUserLately;
import com.zxdmy.excite.system.entity.req.space.ReqCloudFile;
import com.zxdmy.excite.system.entity.req.trace.ReqCloudFileTrace;
import com.zxdmy.excite.system.entity.vo.space.CloudFileVo;
import com.zxdmy.excite.system.entity.vo.trace.CloudFileTraceVo;
import com.zxdmy.excite.system.service.cloud.lately.ICloudUserLatelyService;
import com.zxdmy.excite.system.service.cloud.trace.ICloudFileTraceService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 最近文件表 前端控制器
 * </p>
 *
 * @author 沈松
 * @since 2026-01-29
 */
@Controller
@AllArgsConstructor
@RequestMapping("/cloud/trace")
public class CloudTraceController extends BaseController {

    private ICloudFileTraceService iCloudFileTraceService;

    @RequestMapping("index")
    public String index() {
        return "cloud/lately/index";
    }


    @GetMapping("/list")
    @ResponseBody
    public BaseResult getPageList(Integer page, Integer limit, ReqCloudFileTrace data) {
        try {
            page = 1;
            limit = 15;
            PageList<CloudFileTraceVo> dataPage = iCloudFileTraceService.queryByPage(page, limit, data);
            return success("获取列表成功", dataPage.getList(), (int) dataPage.getTotal());
        } catch (Exception e) {
            return error(500, "发生错误:" + e.getMessage());
        }
    }

    @PostMapping("/addSave")
    @ResponseBody
    @AnnotationSaveReLog
    public BaseResult addSave(@Validated ReqCloudFileTrace data) {
        try {
            if(iCloudFileTraceService.saveData(data)==1){
               return success("操作成功");
            }else{
                return error(400, "操作失败，系统错误");
            }
        } catch (Exception e) {
            return error(500, "发生错误:" + e.getMessage());
        }
    }

}
