//package com.backendsys.controller.Cms;
//
//import com.backendsys.aspect.HttpRequestAspect;
//import com.backendsys.entity.Cms.CmsArticleDTO;
//import com.backendsys.entity.PageDTO;
//import com.backendsys.service.Cms.CmsArticleService;
//import com.backendsys.utils.response.Result;
//import com.backendsys.utils.response.ResultEnum;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.Map;
//
///**
// * 资讯
// */
//@RestController
//public class CmsArticleController {
//
//    @Autowired
//    private HttpRequestAspect httpRequestAspect;
//
//    @Autowired
//    private CmsArticleService cmsArticleService;
//
//    // @Validated @Translate CmsArticleDTO cmsArticleDTO
//    // 使用这个写法，让实体类自动添加 lang 参数，这个参数来自于 Cookie
//
//    @PreAuthorize("@sr.hasPermission('10.3')")
//    @GetMapping("/api/cms/article/getArticle")
//    public Result getArticle(@Validated PageDTO pageDTO, @Validated CmsArticleDTO cmsArticleDTO) {
//        return Result.success(cmsArticleService.queryArticle(pageDTO.getPage_num(), pageDTO.getPage_size(), cmsArticleDTO));
//    }
//
//    @PreAuthorize("@sr.hasPermission('10.3.1')")
//    @GetMapping("/api/cms/article/getArticleDetail")
//    public Result getArticleDetail(@Validated(CmsArticleDTO.Detail.class) CmsArticleDTO cmsArticleDTO) {
//        return Result.success(cmsArticleService.queryArticleDetail(cmsArticleDTO));
//    }
//
//    // @PreAuthorize("@sr.hasPermission('5.3.1')")
//    // @GetMapping("/api/cms/article/getArticleTranslation")
//    // public Result getArticleTranslation(@Validated(CmsArticleDTO.Detail.class) CmsArticleDTO cmsArticleDTO) {
//    //     return Result.success(cmsArticleService.queryArticleTranslation(cmsArticleDTO));
//    // }
//
//    @PreAuthorize("@sr.hasPermission('10.3.2')")
//    @PostMapping("/api/cms/article/createArticle")
//    public Result createArticle(@Validated(CmsArticleDTO.Create.class) @RequestBody CmsArticleDTO cmsArticleDTO) {
//        // [查询] 自身 UserId
//        Long user_id = httpRequestAspect.getUserId();
//        cmsArticleDTO.setUser_id(user_id);
//        return Result.success(cmsArticleService.insertArticle(cmsArticleDTO), "创建成功");
//    }
//
//    @PreAuthorize("@sr.hasPermission('10.3.3')")
//    // @QueryNullCheck(serviceClass = CmsArticleService.class, serviceMethod = "queryArticleDetail", argField = "article_id", message = "资讯不存在")
//    @PutMapping("/api/cms/article/updateArticle")
//    public Result updateArticle(@Validated(CmsArticleDTO.Update.class) @RequestBody CmsArticleDTO cmsArticleDTO) {
//        return Result.success(cmsArticleService.updateArticle(cmsArticleDTO), "更新成功");
//    }
//
//    @PreAuthorize("@sr.hasPermission('10.3.4')")
//    // @QueryNullCheck(serviceClass = CmsArticleService.class, serviceMethod = "queryArticleDetail", argField = "article_id", message = "资讯不存在")
//    @DeleteMapping("/api/cms/article/deleteArticle")
//    public Result deleteArticle(@Validated(CmsArticleDTO.Delete.class) @RequestBody CmsArticleDTO cmsArticleDTO) {
//        return Result.success(cmsArticleService.deleteArticle(cmsArticleDTO), "删除成功");
//    }
//
//    @PreAuthorize("@sr.hasPermission('10.3.4')")
//    @DeleteMapping("/api/cms/article/deleteArticleBatch")
//    public Result deleteArticleBatch(@Validated(CmsArticleDTO.Delete.class) @RequestBody CmsArticleDTO cmsArticleDTO) {
//        return Result.success(cmsArticleService.deleteArticleBatch(cmsArticleDTO.getArticle_ids()), "删除成功");
//    }
//
//    /**
//     * 资讯列表 (公共)
//     */
//    @GetMapping("/api/public/cms/article/getArticle")
//    public Result getPublicArticle(@Validated PageDTO pageDTO, @Validated CmsArticleDTO cmsArticleDTO) {
//        cmsArticleDTO.setStatus(1); // 已启用
//        // cmsArticleDTO.setAudit_status(2); // 审核通过
//        return Result.success(cmsArticleService.queryArticle(pageDTO.getPage_num(), pageDTO.getPage_size(), cmsArticleDTO));
//    }
//    /**
//     * 资讯详情 (公共)
//     */
//    @GetMapping("/api/public/cms/article/getArticleDetail")
//    public Result getPublicArticleDetail(@Validated CmsArticleDTO cmsArticleDTO) {
//
//        Map<String, Object> cmsArticle = cmsArticleService.queryArticleDetailPublic(cmsArticleDTO);
//        if (cmsArticle == null) {
//            return Result.error(ResultEnum.DATABASE_OPERATION_FAILED.getCode(), "资讯不存在");
//        }
//        if ((Integer) cmsArticle.get("status") != 1) {
//            return Result.error(ResultEnum.STATUS_ERROR.getCode(), ResultEnum.STATUS_ERROR.getMessage());
//        }
//        // if ((Integer) cmsArticle.get("audit_status") != 2) {
//        //     return Result.error(ResultEnum.STATUS_ERROR.getCode(), "资讯审核中");
//        // }
//        Long article_id = cmsArticleDTO.getArticle_id();
//        cmsArticle.put("article_id", article_id);
//        return Result.success(cmsArticle);
//    }
//
//}
