package com.cool.bang.modules.business.controller;

import com.cool.bang.common.base.BaseController;
import com.cool.bang.common.base.BaseExamine;
import com.cool.bang.common.constant.ControllerConstant;
import com.cool.bang.common.web.request.PageDomain;
import com.cool.bang.common.web.response.Result;
import com.cool.bang.common.web.response.module.ResultTable;
import com.cool.bang.modules.business.domain.JobQualification;
import com.cool.bang.modules.business.service.IJobQualificationService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 资格申请
 *
 * @author Sy
 * @version 1.0.0
 * 2024-11-14 15:14
 */
@RestController
@RequestMapping(ControllerConstant.BUSINESS + "qualification/v1")
public class JobQualificationController extends BaseController {

    private IJobQualificationService jobQualificationService;

    @Autowired
    public JobQualificationController(IJobQualificationService jobQualificationService) {
        this.jobQualificationService = jobQualificationService;
    }

    @GetMapping
    @PreAuthorize("hasPermission('','business:qualification:main')")
    public ResultTable main(PageDomain pageDomain, JobQualification param) {
        PageInfo<JobQualification> jobQualificationPage = jobQualificationService.page(pageDomain, param);
        return pageTable(jobQualificationPage.getList(), jobQualificationPage.getTotal());
    }

    @GetMapping("{id}")
    @PreAuthorize("hasPermission('','business:qualification:main')")
    public Result get(@PathVariable Long id) {
        JobQualification jobQualification = jobQualificationService.queryById(id);
        jobQualification.setApprovalRecordList(getApprovalHistory(jobQualification.getId(), jobQualification.getFlowNumber()));
        return success(jobQualification);
    }

    @PostMapping
    @PreAuthorize("hasPermission('','business:qualification:add')")
    public Result add(@RequestBody JobQualification jobQualification) {
        jobQualification.insertConfigure();
        return decide(jobQualificationService.qualificationSave(jobQualification));
    }

    @PostMapping("examine")
    @PreAuthorize("hasPermission('','business:qualification:add')")
    public Result examine(@RequestBody BaseExamine param) {
        JobQualification jobQualification = jobQualificationService.queryById(param.getId());
        return decide(jobQualificationService.examine(param,jobQualification));
    }

    @PostMapping("edit")
    @PreAuthorize("hasPermission('','business:qualification:edit')")
    public Result edit(@RequestBody JobQualification jobQualification) {
        return decide(jobQualificationService.update(jobQualification));
    }

    @DeleteMapping("{id}")
    @PreAuthorize("hasPermission('','business:qualification:del')")
    public Result remove(@PathVariable Integer id) {
        return decide(jobQualificationService.removeById(id));
    }

}
