package com.yida.data.school.secondClass.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.school.secondClass.EduSecondClassVenueExhibit;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.dto.secondClass.ListVenueExhibitDTO;
import com.yida.data.school.secondClass.service.EduSecondClassVenueExhibitService;
import com.yida.data.school.vo.secondClass.VenueExhibitVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Controller
 *
 * @author zhanghaijun
 * @date 2022-04-18 09:39:53
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/secondClass/venue/exhibit")
@RequiredArgsConstructor
public class EduSecondClassVenueExhibitController {

    private final EduSecondClassVenueExhibitService eduSecondClassVenueExhibitService;

    @ApiOperation("分页查询展品")
    @GetMapping("/listExhibitPage")
    public ResultBean<IPage<VenueExhibitVO>> listExhibitPage(ListVenueExhibitDTO dto) {
        return ResultBean.buildSuccess(eduSecondClassVenueExhibitService.listExhibitPage(dto));
    }

    @ApiOperation("保存展品")
    @PostMapping("/saveExhibit")
    public ResultBean saveExhibit(@RequestBody EduSecondClassVenueExhibit exhibit) {
        exhibit.setDeptId(FebsUtil.getTopDeptId());
        eduSecondClassVenueExhibitService.saveExhibit(exhibit);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("修改分组")
    @GetMapping("/changeGroup")
    public ResultBean changeGroup(Long[] exhibitIds,
        @ApiParam("分组id，为空代表清除分组") @RequestParam(required = false, defaultValue = "0") Long groupId) {
        eduSecondClassVenueExhibitService.changeGroup(exhibitIds, groupId);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("删除展品")
    @PostMapping("/delExhibit")
    public ResultBean delExhibit(@RequestBody List<Long> ids) {
        eduSecondClassVenueExhibitService.delExhibit(ids);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("改变排序")
    @GetMapping("/changeSort")
    public ResultBean changeSort(Long id, Long anotherId) {
        eduSecondClassVenueExhibitService.changeSort(id, anotherId);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("查询详情")
    @GetMapping("/getInfo")
    public ResultBean<VenueExhibitVO> getInfo(Long id) {
        return ResultBean.buildSuccess(eduSecondClassVenueExhibitService.getInfo(id));
    }

    @ApiOperation("统计展品数量")
    @GetMapping("/countExhibit")
    public ResultBean<Integer> countExhibit(Long venueId, @ApiParam("0-未分组，1-全部") @RequestParam(required = false) Long groupId) {
        return ResultBean.buildSuccess(eduSecondClassVenueExhibitService.countExhibit(venueId, groupId));
    }

}
