package com.yida.data.form.apply.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.entity.applyForm.CoreOfficialSeal;
import com.yida.data.form.apply.service.CoreOfficialSealService;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.customForm.dto.apply.OfficialSealSaveDTO;
import com.yida.data.customForm.dto.apply.OfficialSealSelectPageDTO;
import com.yida.data.customForm.vo.apply.OfficialSealInfoVO;
import com.yida.data.customForm.vo.apply.OfficialSealSelectPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 学校公章管理 Controller
 *
 * @author ZYJ
 * @date 2023/11/17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/officialSeal")
@Api(tags = "后台--学校公章管理")
public class CoreOfficialSealController {

    private final CoreOfficialSealService coreOfficialSealService;

    @ApiOperation("查询学校公章列表数据")
    @PostMapping("/listOfficialSealPage")
    public ResultBean<IPage<OfficialSealSelectPageVO>> listOfficialSealPage(OfficialSealSelectPageDTO dto) {
        IPage<OfficialSealSelectPageVO> page = coreOfficialSealService.listOfficialSealPage(dto);
        return ResultBean.buildSuccess(page);
    }

    @ApiOperation("查询学校所有公章数据")
    @PostMapping("/listOfficialSeal")
    public ResultBean<List<CoreOfficialSeal>> listOfficialSeal(@RequestParam @ApiParam(value = "学校id") Long schoolId) {
        return ResultBean.buildSuccess(coreOfficialSealService.list(Wrappers.lambdaQuery(new CoreOfficialSeal())
                .eq(CoreOfficialSeal::getDeptId, schoolId)));
    }

    @ApiOperation("查询公章详情")
    @GetMapping("/getOfficialSealInfo")
    public ResultBean<OfficialSealInfoVO> getOfficialSealInfo(
            @RequestParam @ApiParam(value = "公章id", required = true) Long id) {
        return ResultBean.buildSuccess(coreOfficialSealService.getOfficialSealInfo(id));
    }

    @ApiOperation("删除公章")
    @GetMapping("/deleteOfficialSeal")
    public ResultBean<String> deleteOfficialSeal(
            @RequestParam @ApiParam(value = "公章id", required = true) Long id) {
        coreOfficialSealService.deleteOfficialSeal(id);
        return ResultBean.buildSuccess();
    }

    @ApiOperation(value = "保存公章", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveOfficialSeal", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean<String> saveOfficialSeal(@RequestBody OfficialSealSaveDTO dto) {
        coreOfficialSealService.saveOfficialSeal(dto);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("修改公章状态")
    @GetMapping("updateEnableStatus")
    public ResultBean<String> updateEnableStatus(
            @ApiParam(value = "公章id", required = true) @RequestParam Long id,
            @ApiParam(value = "状态. 0为停用，1为启用", required = true) @RequestParam Integer enableStatus) {
        coreOfficialSealService.updateEnableStatus(id, enableStatus);
        return ResultBean.buildSuccess();
    }
}
