package com.czg.controller.admin;

import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.system.dto.OperationLogDTO;
import com.czg.system.entity.OperationLog;
import com.czg.system.service.OperationLogService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 日志管理
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/log")
public class SysLogController {
    @Resource
    private OperationLogService operationLogService;

    /**
     * 日志列表
     * @param param 参数
     * @return 分页信息
     */
    @SaAdminCheckPermission(parentName = "日志管理",value = "sysLog:list", name = "日志列表")
    @GetMapping
    public CzgResult<Page<OperationLogDTO>> get(OperationLogDTO param) {
        return CzgResult.success(operationLogService.page(param));
    }

    /**
     * 日志删除
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "日志管理",value = "sysLog:del", name = "日志删除")
    @DeleteMapping
    public CzgResult<Boolean> del() {
        return CzgResult.success(operationLogService.remove(new QueryWrapper().eq(OperationLog::getShopId, StpKit.USER.getShopId())));
    }
}
