package org.springblade.estate.feign;

import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.Func;
import org.springblade.estate.dto.AccessRecordCountDto;
import org.springblade.estate.dto.ArticleCountDto;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.estate.entity.Article;
import org.springblade.estate.vo.ArticleVO;
import org.springblade.estate.wrapper.ArticleWrapper;
import org.springblade.estate.service.IArticleService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-03-30
 */

@AllArgsConstructor
@RestController
@RequestMapping("/feign/article")

public class ArticleClient implements IArticleClient {

    private final IArticleService articleService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public ArticleVO detail(@SpringQueryMap Article article) {
        Article detail = articleService.getOne(Condition.getQueryWrapper(article));
        return ArticleWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<ArticleVO> list(@SpringQueryMap Article article) {
        return ArticleWrapper.build().listVO(articleService.list(Condition.getQueryWrapper(article)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody Article article) {
        return articleService.save(article);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody Article article) {
        return articleService.updateById(article);
        }

    /**
     * 新增或修改
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody Article article) {
        return articleService.saveOrUpdate(article);
        }


    /**
     * 删除
     */
    @Override
    @PostMapping("/remove")
    public boolean remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return articleService.deleteLogic(Func.toLongList(ids));
        }

	/**
	 * 数据统计
	 */
	@Override
	@GetMapping("/getArticleCount")
	public ArticleCountDto getArticleCount(){
		ArticleCountDto articleCountDto = new ArticleCountDto();
		articleCountDto.setDayCount(articleService.selectDayArticleCount());
		articleCountDto.setWeekCount(articleService.selectWeekArticleCount());
		articleCountDto.setMonthCount(articleService.selectMonthArticleCount());
		articleCountDto.setYearCount(articleService.selectYearArticleCount());
		return articleCountDto;
	}

}
