package org.springblade.party.feign;

import cn.hutool.core.lang.Assert;
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.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.party.entity.News;
import org.springblade.party.vo.NewsVO;
import org.springblade.party.wrapper.NewsWrapper;
import org.springblade.party.service.INewsService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 * 党内咨询列表表 client
 *
 * @author lianghanqiang
 * @since 2021-04-19
 */

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

public class NewsClient implements INewsClient {

    private final INewsService newsService;

    /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public NewsVO detail(News news) {
        News detail = newsService.getOne(Condition.getQueryWrapper(news));
        return NewsWrapper.build().entityVO(detail);
        }

    /**
     * 查询 党内咨询列表表
     */
    @Override
    @GetMapping("/list")
    public List<NewsVO> list(News news) {
		Assert.notNull(news.getBranchId(),"支部id不能为空");
        return NewsWrapper.build().listVO(newsService.list(Condition.getQueryWrapper(news)));
        }



    /**
     * 新增 党内咨询列表表
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody News news) {
        return newsService.save(news);
        }

    /**
     * 修改 党内咨询列表表
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody News news) {
        return newsService.updateById(news);
        }

    /**
     * 新增或修改 党内咨询列表表
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody News news) {
        return newsService.saveOrUpdate(news);
        }


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


}
