package com.ktg.iscs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.pojo.CommonResult;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.iscs.domain.IsJobCard;
import com.ktg.iscs.domain.vo.card.IsJobCardInfoRespVO;
import com.ktg.iscs.domain.vo.card.IsJobCardLoginReqVO;
import com.ktg.iscs.service.IIsJobCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工作卡Controller
 *
 * @author cgj
 * @date 2024-11-12
 */
@Api(tags = "工作卡")
@RestController
@RequestMapping("/iscs/card")
public class IsJobCardController extends BaseController
{
    @Autowired
    private IIsJobCardService isJobCardService;

    /**
     * 查询工作卡分页
     */
    @ApiOperation("查询工作卡-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isJobCard", description = "实体参数")
    })
    // @PreAuthorize("@ss.hasPermi('iscs:card:list')")
    @GetMapping("/getIsJobCardPage")
    public CommonResult<Page<IsJobCard>> getIsJobCardPage(Page<IsJobCard> page, IsJobCard isJobCard)
    {
        Page<IsJobCard> result = isJobCardService.getIsJobCardPage(page, isJobCard);
        return CommonResult.success(result);
    }

    /**
     * 导出工作卡列表
     */
    @ApiOperation("导出工作卡列表")
    @Parameter(name = "isJobCard", description = "实体参数")
    // @PreAuthorize("@ss.hasPermi('iscs:card:export')")
    @Log(title = "工作卡", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsJobCard")
    public void exportIsJobCard(HttpServletResponse response, IsJobCard isJobCard)
    {
        List<IsJobCard> list = isJobCardService.selectIsJobCardList(isJobCard);
        ExcelUtil<IsJobCard> util = new ExcelUtil<IsJobCard>(IsJobCard.class);
        util.exportExcel(response, list, "工作卡数据");
    }

    /**
     * 获取工作卡详细信息
     */
    @ApiOperation("获取工作卡详细信息")
    @Parameter(name = "cardId", description = "cardId")
    // @PreAuthorize("@ss.hasPermi('iscs:card:query')")
    @GetMapping(value = "/selectIsJobCardById")
    public CommonResult<IsJobCard> selectIsJobCardById(Long cardId)
    {
        return CommonResult.success(isJobCardService.selectIsJobCardByCardId(cardId));
    }

    @ApiOperation("获取工作卡详细信息")
    @GetMapping(value = "/selectIsJobCardByLoginUser")
    public CommonResult<IsJobCardInfoRespVO> getCardInfoByLoginUser(HttpServletRequest request) {
        return CommonResult.success(isJobCardService.getCardInfoByLoginUser(request));
    }

    @ApiOperation("获取工作卡详细信息 - cardNfc")
    @GetMapping(value = "/selectIsJobCardByCardNfc")
    public CommonResult<IsJobCard> getCardInfoByCardNfc(@RequestParam("cardNfc") String cardNfc) {
        return CommonResult.success(isJobCardService.getCardInfoByCardNfc(cardNfc));
    }

    /**
     * 新增工作卡
     */
    @ApiOperation("新增工作卡")
    // @PreAuthorize("@ss.hasPermi('iscs:card:add')")
    @Log(title = "工作卡", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsJobCard")
    public CommonResult<Boolean> insertIsJobCard(@RequestBody @Parameter(name = "isJobCard", description = "新增数据类,放到body") IsJobCard isJobCard)
    {
        return CommonResult.success(isJobCardService.insertIsJobCard(isJobCard) == 1);
    }

    /**
     * 修改工作卡
     */
    @ApiOperation("修改工作卡")
    // @PreAuthorize("@ss.hasPermi('iscs:card:edit')")
    @Log(title = "工作卡", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsJobCard")
    public CommonResult<Boolean> updateIsJobCard(@RequestBody @Parameter(name = "isJobCard", description = "修改数据类,放到body") IsJobCard isJobCard)
    {
        return CommonResult.success(isJobCardService.updateIsJobCard(isJobCard) == 1);
    }

    /**
     * 删除工作卡
     */
    @ApiOperation("删除工作卡")
    // @PreAuthorize("@ss.hasPermi('iscs:card:remove')")
    @Log(title = "工作卡", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsJobCardByCardIds")
    public CommonResult<Boolean> deleteIsJobCardByCardIds(String cardIds)
    {
        return CommonResult.success(isJobCardService.deleteIsJobCardByCardIds(cardIds) != 0);
    }

    @ApiOperation("工作卡登录")
    @PostMapping("/login")
    public CommonResult<String> loginByCard(@RequestBody IsJobCardLoginReqVO reqVO) {
        return CommonResult.success(isJobCardService.loginByCard(reqVO));
    }

    @ApiOperation("工作卡登录")
    @PostMapping("/loginByCard")
    public AjaxResult loginByCard1(@RequestBody IsJobCardLoginReqVO reqVO) {
        return isJobCardService.loginByCard1(reqVO);
    }

    @ApiOperation("机柜录入工作卡")
    // @PreAuthorize("@ss.hasPermi('iscs:card:add')")
    @Log(title = "机柜录入工作卡", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsJobCardByCabinet")
    public CommonResult<Boolean> insertIsJobCardByCabinet(@RequestBody @Parameter(name = "isJobCard", description = "新增数据类,放到body") IsJobCard isJobCard)
    {
        return CommonResult.success(isJobCardService.insertIsJobCardByCabinet(isJobCard));
    }

}
