package com.zd.alg.smartlock.controller;

import com.zd.alg.smartlock.domain.SlApplyApproval;
import com.zd.alg.smartlock.service.ISlApplyApprovalService;
import com.zd.common.core.utils.poi.ExcelUtil;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.web.domain.ResultData;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 门锁申请审核Controller
 *
 * @author xxf
 * @date 2022-09-02
 */
@RestController
@Api(tags = "【申请审核】")
@RequestMapping("/approval")
public class SlApplyApprovalController extends BaseController
{
    @Autowired
    private ISlApplyApprovalService slApplyApprovalService;


    /**
     * 查询申请审核列表
     */
    //@PreAuthorize(hasPermi = "laboratory:approval:list")
    @GetMapping("/list")
    @ApiOperation(value = "查询申请审核列表")
    public TableDataInfo<SlApplyApproval> list(SlApplyApproval slApplyApproval)
    {
        startPage();
        List<SlApplyApproval> list = slApplyApprovalService.selectSlApplyApprovalList(slApplyApproval);
        return getDataTable(list);
    }

    /**
     * 导出申请审核列表
     */
    @ApiOperation(value = "导出申请审核列表")
    //@PreAuthorize(hasPermi = "laboratory:approval:export")
    @Log(title = "申请审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlApplyApproval slApplyApproval) throws IOException
    {
        List<SlApplyApproval> list = slApplyApprovalService.selectSlApplyApprovalList(slApplyApproval);
        ExcelUtil<SlApplyApproval> util = new ExcelUtil<SlApplyApproval>(SlApplyApproval.class);
        util.exportExcel(response, list, "申请审核数据");
    }

    /**
     * 获取申请审核详细信息
     */
    @ApiOperation(value = "获取申请审核详细信息")
    //@PreAuthorize(hasPermi = "laboratory:approval:query")
    @GetMapping(value = "/{id}")
    public ResultData<SlApplyApproval> getInfo(@PathVariable("id") Long id)
    {
        return ResultData.success(slApplyApprovalService.selectSlApplyApprovalById(id));
    }

    /**
     * 新增申请审核
     */
    @ApiOperation(value = "新增申请审核")
    //@PreAuthorize(hasPermi = "laboratory:approval:add")
    @Log(title = "申请审核", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody SlApplyApproval slApplyApproval)
    {
        return ResultData.result(slApplyApprovalService.insertSlApplyApproval(slApplyApproval));
    }

    /**
     * 修改申请审核
     */
    @ApiOperation(value = "修改申请审核")
    //@PreAuthorize(hasPermi = "laboratory:approval:edit")
    @Log(title = "申请审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody SlApplyApproval slApplyApproval)
    {
        return  ResultData.result(slApplyApprovalService.updateSlApplyApproval(slApplyApproval));
    }

    /**
     * 删除申请审核
     */
    @ApiOperation(value = "删除申请审核")
    //@PreAuthorize(hasPermi = "laboratory:approval:remove")
    @Log(title = "申请审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids)
    {
        return ResultData.result(slApplyApprovalService.deleteSlApplyApprovalByIds(ids));
    }

    /***
     * 短信审核
     * @param phone 电话
     * @param content 1通过 0拒绝
     * @param lockApplyId
     * @return
     */
    @ApiOperation(value = "门锁短信审核")
    @GetMapping("/sysMsgApprova")
    public AjaxResult sysMsgApprova(String phone, String content, Long lockApplyId)
    {   // msg:异常说明  status:处理状态（ok-成功  error-失败）
        Map<String,Object> map = slApplyApprovalService.sysMsgApprova(phone,content,lockApplyId);
        return AjaxResult.success(map);
    }

}
