package com.yunzhupaas.base.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.Operation;
import com.yunzhupaas.base.PaginationTime;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.base.model.vo.PrintLogVO;
import com.yunzhupaas.base.vo.PaginationVO;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.permission.service.UserService;
import com.yunzhupaas.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import cn.hutool.core.bean.BeanUtil;
import com.yunzhupaas.base.ActionResult;
import com.yunzhupaas.base.entity.PrintLogEntity;
import com.yunzhupaas.base.service.PrintLogService;
import org.springframework.validation.annotation.Validated;
import com.yunzhupaas.base.model.printlog.PrintLogInfo;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@Tag(name = "打印模板日志", description = "PrintLogController")
@RestController
@RequestMapping("/api/system/printLog")
public class PrintLogController {
    @Autowired
    private PrintLogService printLogService;

    

    @Autowired
    private UserService userService;

    /**
     * 获取列表
     *
     * @param page 分页模型
     * @return
     */
    @Operation(summary = "获取列表")
    @Parameters({
            @Parameter(name = "id", description = "打印模板ID", required = true)
    })
    @SaCheckPermission("system.printDev")
    @GetMapping("/{id}")
    public ActionResult<?> list(@PathVariable("id") String printId, PaginationTime page) {
        List<PrintLogVO> list = printLogService.list(printId, page);
        PaginationVO paginationVO = JsonUtil.getJsonToBean(page, PaginationVO.class);
        return ActionResult.page(list, paginationVO);
    }

    /**
     * 保存信息
     *
     * @param info 实体对象
     * @return
     */
    @Operation(summary = "保存信息")
    @Parameters({
            @Parameter(name = "info", description = "实体对象", required = true)
    })
    @SaCheckPermission("system.printDev")
    @PostMapping("save")
    public ActionResult<?> save(@RequestBody @Validated PrintLogInfo info) {
        PrintLogEntity printLogEntity = BeanUtil.copyProperties(info, PrintLogEntity.class);
        UserInfo userInfo = UserProvider.getUser();

        printLogEntity.setId(RandomUtil.uuId());
        printLogEntity.setCreatorTime(new Date());
        printLogEntity.setCreatorUserId(userInfo.getUserId());
        printLogService.save(printLogEntity);
        return ActionResult.success(MsgCode.SU002);
    }


}

