package com.ktg.iscs.controller;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.enums.BusinessType;
import com.ktg.common.pojo.CommonResult;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.iscs.domain.IsWorkstation;
import com.ktg.iscs.service.IIsUserWorkstationService;
import com.ktg.iscs.service.IIsWorkstationService;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * mars岗位Controller
 *
 * @author cgj
 * @date 2024-12-16
 */
@Api(tags = "mars岗位")
@RestController
@RequestMapping("/iscs/workstation")
public class IsWorkstationController extends BaseController {
    @Autowired
    private IIsWorkstationService isWorkstationService;
    @Autowired
    private IIsUserWorkstationService iIsUserWorkstationService;

    /**
     * 查询mars岗位分页
     */
    @ApiOperation("查询mars岗位-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isWorkstation", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:workstation:list')")
    @GetMapping("/getIsWorkstationPage")
    public CommonResult<Page<IsWorkstation>> getIsWorkstationPage(IsWorkstation isWorkstation, Page<IsWorkstation> page) {
        Page<IsWorkstation> result = isWorkstationService.getIsWorkstationPage(isWorkstation, page);
        return CommonResult.success(result);
    }

    /**
     * 导出mars岗位列表
     */
    @ApiOperation("导出mars岗位列表")
    @Parameter(name = "isWorkstation", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:workstation:export')")
    @Log(title = "mars岗位", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsWorkstation")
    public void exportIsWorkstation(HttpServletResponse response, IsWorkstation isWorkstation) {
        List<IsWorkstation> list = isWorkstationService.selectIsWorkstationList(isWorkstation);
        ExcelUtil<IsWorkstation> util = new ExcelUtil<IsWorkstation>(IsWorkstation.class);
        util.exportExcel(response, list, "mars岗位数据");
    }

    /**
     * 获取mars岗位详细信息
     */
    @ApiOperation("获取mars岗位详细信息")
    @Parameter(name = "workstationId", description = "workstationId")
    @PreAuthorize("@ss.hasPermi('iscs:workstation:query')")
    @GetMapping(value = "/selectIsWorkstationById")
    public CommonResult<IsWorkstation> selectIsWorkstationById(Long workstationId) {
        return CommonResult.success(isWorkstationService.selectIsWorkstationByWorkstationId(workstationId));
    }

    /**
     * 新增mars岗位
     */
    @ApiOperation("新增mars岗位")
    @PreAuthorize("@ss.hasPermi('iscs:workstation:add')")
    @Log(title = "mars岗位", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsWorkstation")
    public CommonResult<Boolean> insertIsWorkstation(@RequestBody @Parameter(name = "isWorkstation", description = "新增数据类,放到body") IsWorkstation isWorkstation) {
        return CommonResult.success(isWorkstationService.insertIsWorkstation(isWorkstation) == 1);
    }

    /**
     * 修改mars岗位
     */
    @ApiOperation("修改mars岗位")
    @PreAuthorize("@ss.hasPermi('iscs:workstation:edit')")
    @Log(title = "mars岗位", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsWorkstation")
    public CommonResult<Boolean> updateIsWorkstation(@RequestBody @Parameter(name = "isWorkstation", description = "修改数据类,放到body") IsWorkstation isWorkstation) {
        return CommonResult.success(isWorkstationService.updateIsWorkstation(isWorkstation) == 1);
    }

    @ApiOperation("修改mars岗位状态")
    @Log(title = "mars岗位", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsWorkstationStatus")
    public CommonResult<Boolean> updateIsWorkstationStatus(@RequestBody @Parameter(name = "isWorkstation", description = "修改数据类,放到body") IsWorkstation isWorkstation) {
        Assert.notNull(isWorkstation.getWorkstationId(), "id不可为空！");
        Assert.notBlank(isWorkstation.getStatus(), "状态不可为空！");
        return CommonResult.success(isWorkstationService.update(Wrappers.<IsWorkstation>lambdaUpdate()
                .eq(IsWorkstation::getWorkstationId, isWorkstation.getWorkstationId())
                .set(IsWorkstation::getStatus, isWorkstation.getStatus())));
    }

    /**
     * 删除mars岗位
     */
    @ApiOperation("删除mars岗位")
    @PreAuthorize("@ss.hasPermi('iscs:workstation:remove')")
    @Log(title = "mars岗位", businessType = BusinessType.DELETE)
    @PostMapping("/deleteIsWorkstationByWorkstationIds")
    public CommonResult<Boolean> deleteIsWorkstationByWorkstationIds(String workstationIds) {
        return CommonResult.success(isWorkstationService.deleteIsWorkstationByWorkstationIds(workstationIds) != 0);
    }
}
