package com.dayou.controller;

import com.dayou.common.BaseEntity;
import com.dayou.vo.HeadlineSectionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.service.IReportSectionTemplateService;
import com.dayou.entity.ReportSectionTemplate;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import com.dayou.common.PullDownModel;
import com.dayou.utils.ConvertUtil;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
/**
 * 报告段落模板
 *
 * @author wucl
 * @since 2023-08-25
 */
@RestController
@RequestMapping("reportSectionTemplate")
@Slf4j
public class ReportSectionTemplateController extends BaseController {
    @Autowired
    private IReportSectionTemplateService reportSectionTemplateService;

    /**
    * 报告段落模板列表
    */
    @GetMapping("")
    public RestResponse<Page<HeadlineSectionVO>> page(HeadlineSectionVO reportSection, Page page){
        Page<HeadlineSectionVO> pages=reportSectionTemplateService.getPage(page,reportSection);
        return RestResponse.data(pages);
    }

    /**
     * 报告段落模板详情
     */
    @GetMapping("/{id}")
    public RestResponse<ReportSectionTemplate> detail(@PathVariable Long id){
        ReportSectionTemplate xReportSectionTemplate =reportSectionTemplateService.detail(id);
        return RestResponse.data(xReportSectionTemplate);
     }

    /**
     * 报告段落模板新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody ReportSectionTemplate reportSectionTemplate) {
        Boolean ret = reportSectionTemplateService.add(reportSectionTemplate);
        return RestResponse.data(ret);
    }

    /**
     * 报告段落模板更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody ReportSectionTemplate reportSectionTemplate) {
        Boolean ret = reportSectionTemplateService.update(reportSectionTemplate);
        return RestResponse.data(ret);
    }

    /**
     * 报告段落模板删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = reportSectionTemplateService.delete(id);
        return RestResponse.data(ret);
    }


    /**
     * 报告段落模板下拉列表
     */
    @GetMapping("/simpleAll")
    public RestResponse<List<PullDownModel>> simpleAll(){
        LambdaQueryWrapper<ReportSectionTemplate> lambdaQueryWrapper = new LambdaQueryWrapper<ReportSectionTemplate>()
        .select(ReportSectionTemplate::getId, ReportSectionTemplate::getName)
        .eq(ReportSectionTemplate::getDeleted,false);
        List<ReportSectionTemplate> list= reportSectionTemplateService.list(lambdaQueryWrapper);
        List<PullDownModel> ret=ConvertUtil.copyList(list, PullDownModel.class);
        return RestResponse.data(ret);
    }

    /**
     * 获取段落模板列表不分页
     * @param id
     * @return
     */
    @GetMapping("/headline/{id}")
    public RestResponse<List<ReportSectionTemplate>> getList(@PathVariable("id") Long id){
        List<ReportSectionTemplate> list = reportSectionTemplateService.list(new LambdaQueryWrapper<ReportSectionTemplate>().eq(ReportSectionTemplate::getHeadlineId, id)
                        .isNotNull(ReportSectionTemplate::getSection)
                .eq(BaseEntity::getDeleted, Boolean.FALSE));
        return RestResponse.data(list);
    }
}

