package com.liquidnet.client.admin.web.controller.zhengzai.adam;

import com.github.pagehelper.PageInfo;
import com.liquidnet.client.admin.common.annotation.Log;
import com.liquidnet.client.admin.common.core.controller.BaseController;
import com.liquidnet.client.admin.common.core.domain.AjaxResult;
import com.liquidnet.client.admin.common.core.page.TableDataInfo;
import com.liquidnet.client.admin.common.enums.BusinessType;
import com.liquidnet.client.admin.zhengzai.adam.service.IAdamCaomeiBadgeApplyAuditAdminService;
import com.liquidnet.service.adam.dto.param.AdamCaomeiBadgeApplyAuditSearchParam;
import com.liquidnet.service.adam.dto.vo.AdamCaomeiBadgeApplyAuditDetailVo;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(tags = "草莓护照-补签审核")
@Controller
@RequestMapping("adam/caomei/badgeApplyAudit")
public class AdamCaomeiBadgeApplyAuditController extends BaseController {

    private final String prefix = "zhengzai/adam/caomei/badgeApplyAudit";

    @Autowired
    private IAdamCaomeiBadgeApplyAuditAdminService badgeApplyAuditAdminService;

    @RequiresPermissions("adam:caomei:badgeApplyAudit:list")
    @GetMapping()
    public String view() {
        return prefix + "/list";
    }

    @RequiresPermissions("adam:caomei:badgeApplyAudit:list")
    @PostMapping("list")
    @ResponseBody
    public TableDataInfo list(AdamCaomeiBadgeApplyAuditSearchParam param) {
        startPage();
        PageInfo<?> pageInfo = badgeApplyAuditAdminService.listApplyAudits(param);
        return getDataTable(pageInfo);
    }

    @RequiresPermissions("adam:caomei:badgeApplyAudit:list")
    @GetMapping("detail/{applyRecordId}")
    public String detail(@PathVariable("applyRecordId") String applyRecordId, ModelMap mmap) {
        AdamCaomeiBadgeApplyAuditDetailVo detail = badgeApplyAuditAdminService.getApplyAuditDetail(applyRecordId);
        mmap.put("detail", detail);
        return prefix + "/detail";
    }

    @RequiresPermissions("adam:caomei:badgeApplyAudit:edit")
    @Log(title = "草莓护照-补签审核:通过", businessType = BusinessType.UPDATE)
    @PostMapping("pass")
    @ResponseBody
    public AjaxResult pass(@RequestParam("applyRecordId") String applyRecordId) {
        boolean ok = badgeApplyAuditAdminService.passApplyAudit(applyRecordId);
        if (!ok) {
            return error("审核通过失败：申请不存在或当前状态不可操作");
        }
        return success();
    }

    @RequiresPermissions("adam:caomei:badgeApplyAudit:edit")
    @Log(title = "草莓护照-补签审核:驳回", businessType = BusinessType.UPDATE)
    @PostMapping("reject")
    @ResponseBody
    public AjaxResult reject(@RequestParam("applyRecordId") String applyRecordId,
                             @RequestParam("rejectReason") String rejectReason) {
        if (StringUtils.isBlank(rejectReason)) {
            return error("驳回理由不能为空");
        }
        boolean ok = badgeApplyAuditAdminService.rejectApplyAudit(applyRecordId, rejectReason);
        if (!ok) {
            return error("驳回失败：申请不存在或当前状态不可操作");
        }
        return success();
    }
}
