package com.bonus.material.basic.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.basic.domain.BmQrBoxInfo;
import com.bonus.material.basic.domain.dto.BoxBindWarehouseDto;
import com.bonus.material.basic.service.BmQrBoxService;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.material.ma.domain.Machine;
import com.bonus.material.ma.domain.TypeKeeper;
import com.bonus.material.ma.service.ITypeKeeperService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author  ma_sh
 * @create 2024/12/11 17:25
 */
@Api(tags = "二维码标准箱管理接口")
@Validated
@RestController
@RequestMapping("/bm_qrcode_box")
public class BmQrBoxController extends BaseController {

    @Resource
    private BmQrBoxService qrBoxService;

    @Resource
    private ITypeKeeperService typeKeeperService;

    /**
     * 查询二维码管理列表
     */
    @ApiOperation(value = "查询二维码标准箱管理列表")
    //@RequiresPermissions("basic:qrBox:list")
    @GetMapping("/list")
    public AjaxResult list(BmQrBoxInfo bmQrBoxInfo) {
        startPage();
        List<BmQrBoxInfo> list = qrBoxService.selectBmQrBoxInfoList(bmQrBoxInfo);
        return AjaxResult.success(getDataTable(list));
    }

    /**
     * 查询二维码标准箱绑定详情列表
     */
    @ApiOperation(value = "查询二维码标准箱绑定详情列表")
    //@RequiresPermissions("basic:qrBox:list")
    @GetMapping("/getList")
    public TableDataInfo getList(BmQrBoxInfo bmQrBoxInfo) {
        startPage();
        List<BmQrBoxInfo> list = qrBoxService.getList(bmQrBoxInfo);
        return getDataTable(list);
    }

    /**
     * APP -- 查询二维码标准箱绑定列表 -- 不分页
     * @param
     */
    @ApiOperation(value = "APP -- 查询二维码标准箱绑定列表")
    //@RequiresPermissions("basic:qrBox:list")
    @GetMapping("/app_box_bind_list")
    public AjaxResult getBoxBindList(BmQrBoxInfo bean) {
        return AjaxResult.success(getDataTable(qrBoxService.getBoxBindList(bean)));
    }

    /**
     * 新增二维码标准箱管理
     */
    @ApiOperation(value = "新增二维码标准箱管理")
    //@PreventRepeatSubmit
    //@RequiresPermissions("basic:qrBox:add")
    @SysLog(title = "二维码标准箱管理", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增二维码标准箱管理")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BmQrBoxInfo bmQrBoxInfo)
    {
        return qrBoxService.insertBmQrcodeInfo(bmQrBoxInfo);
    }

    /**
     * 修改二维码标准箱管理
     */
    @ApiOperation(value = "修改二维码标准箱管理")
    @PreventRepeatSubmit
    //@RequiresPermissions("basic:qrBox:edit")
    @SysLog(title = "二维码标准箱管理", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改二维码标准箱")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BmQrBoxInfo bmQrBoxInfo) {
        return qrBoxService.updateBmQrcodeInfo(bmQrBoxInfo);
    }

    /**
     * APP -- 扫码创建标准箱
     */
    @ApiOperation(value = "APP -- 扫码创建标准箱")
    @PreventRepeatSubmit
    //@RequiresPermissions("basic:qrBox:edit")
    @SysLog(title = "APP-二维码标准箱管理", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->APP扫码创建标准箱")
    @PostMapping("/app_create")
    public AjaxResult appCreate(@RequestBody @NotNull(message = "参数不能为空") BmQrBoxInfo bmQrBoxInfo) {
        return qrBoxService.updateBmQrcodeInfoByCode(bmQrBoxInfo);
    }

    /**
     * 二维码管理 -- 扫码获取绑定物资信息
     */
    @ApiOperation(value = "二维码管理 -- 扫码获取绑定物资信息")
    @GetMapping("/get_ma_info_by_qrcode")
    public AjaxResult appCreateByCode(@RequestParam(value = "qrCode") String qrCode) {
        return qrBoxService.getMaInfoByQrCode(qrCode);
    }

    /**
     * APP -- 新购入库扫码 -- BoxCode查询标准箱信息
     */
    @ApiOperation(value = "APP -- 新购入库扫码 -- BoxCode查询标准箱信息")
    @SysLog(title = "APP-二维码标准箱管理", businessType = OperaType.QUERY, logType = 1,module = "仓储管理->BoxCode查询标准箱信息")
    @GetMapping("/get_info_bind_by_code")
    public AjaxResult getBoxInfoBindListByCode(@NotNull(message = "参数不能为空") BmQrBoxInfo bmQrBoxInfo) {
        return qrBoxService.getBoxInfoBindListByCode(bmQrBoxInfo);
    }

    /**
     * app出库查询标准箱绑定详情
     * @param bmQrBoxInfo
     * @return
     */
    @GetMapping("/get_box_bind_by_code")
    public AjaxResult getBoxBindListByCode(@NotNull(message = "参数不能为空") BmQrBoxInfo bmQrBoxInfo) {
        return qrBoxService.getBoxBindListByCode(bmQrBoxInfo);
    }

    /**
     * APP -- 修饰入库 -- 扫码获取绑定物资信息
     * @param bmQrBoxInfo
     * @return
     */
    @GetMapping("/getBoxCodeList")
    public AjaxResult getBoxCodeList(@NotNull(message = "参数不能为空") BmQrBoxInfo bmQrBoxInfo) {
        return qrBoxService.getBoxCodeList(bmQrBoxInfo);
    }

    /**
     * APP -- 新购入库 -- 确认入库标准箱
     */
    @ApiOperation(value = "APP -- 新购入库 -- 确认入库标准箱")
    @PreventRepeatSubmit
    //@RequiresPermissions("basic:qrBox:edit")
    @SysLog(title = "APP-二维码标准箱管理", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->APP扫码创建标准箱")
    @PostMapping("/app_warehouse")
    public AjaxResult appWarehouse(@RequestBody @NotNull(message = "参数不能为空") BoxBindWarehouseDto boxBindWarehouseDto) {
        return qrBoxService.appWarehouse(boxBindWarehouseDto);
    }



    /**
     * APP -- 新购入库 -- 确认入库标准箱
     */
    @ApiOperation(value = "APP -- 新购入库 -- 标准箱直接扫描入库")

    //@RequiresPermissions("basic:qrBox:edit")
    @SysLog(title = "APP-二维码标准箱入库", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->APP扫码创建标准箱")
    @PostMapping("/app_box_input")
    public AjaxResult appBoxInput(@RequestBody @NotNull(message = "参数不能为空") BoxBindWarehouseDto boxBindWarehouseDto) {
        return qrBoxService.appBoxInput(boxBindWarehouseDto);
    }


    /**
     * APP -- 扫码绑定机具
     */
    @ApiOperation(value = "APP -- 扫码绑定机具")
//    @PreventRepeatSubmit
    //@RequiresPermissions("basic:qrBox:edit")
    @SysLog(title = "APP-二维码标准箱管理", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->APP扫码绑定机具")
    @PostMapping("/app_bind_ma")
    public AjaxResult addQrcodeBoxBind(@RequestBody @NotNull(message = "参数不能为空") BmQrBoxInfo bmQrBoxInfo) {
        return qrBoxService.addQrcodeBoxBind(bmQrBoxInfo);
    }

    /**
     * APP -- 标准箱移交
     */
    @ApiOperation(value = "APP -- 标准箱移交")
    @PreventRepeatSubmit
    @PostMapping("/app_transfer")
    public AjaxResult appTransfer(@RequestBody @NotNull @Valid BmQrBoxInfo bmQrBoxInfo) {
        return qrBoxService.appTransfer(bmQrBoxInfo);
    }

    /**
     * APP -- 标准箱移交驳回
     */
    @ApiOperation(value = "APP -- 标准箱移交驳回")
    @PreventRepeatSubmit
    @PostMapping("/app_transfer_reject")
    public AjaxResult appTransferReject(@RequestBody @NotNull @Valid BmQrBoxInfo bmQrBoxInfo) {
        return qrBoxService.appTransferReject(bmQrBoxInfo);
    }

    /**
     * APP -- 标准箱接收
     */
    @ApiOperation(value = "APP -- 标准箱接收")
    @PreventRepeatSubmit
    @PostMapping("/app_receive")
    public AjaxResult appReceive(@RequestBody @NotNull @Valid BmQrBoxInfo bmQrBoxInfo) {
        return qrBoxService.appReceive(bmQrBoxInfo);
    }

    /**
     * 解绑二维码标准箱
     */
    @ApiOperation(value = "解绑二维码标准箱")
    @PreventRepeatSubmit
    @SysLog(title = "APP--二维码标准箱管理", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->解绑二维码标准箱")
    @PostMapping("/unbind")
    public AjaxResult unBindQrcodeBox(@RequestBody BmQrBoxInfo bmQrBoxInfo) {
       return qrBoxService.unBindQrcodeBox(bmQrBoxInfo);
    }

    @ApiOperation(value = "查询移交库管员列表")
    @GetMapping("/app_transfer_keeps")
    public AjaxResult getTransferUserList(BmQrBoxInfo bmQrBoxInfo) {
        return AjaxResult.success(typeKeeperService.selectTypeKeeperListAndUserName(new TypeKeeper(bmQrBoxInfo.getMaTypeId(), null)));
    }

    /**
     * 删除二维码标准箱
     */
    @ApiOperation(value = "删除二维码标准箱")
    @PreventRepeatSubmit
    //@RequiresPermissions("basic:info:remove")
    @SysLog(title = "二维码标准箱管理", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除二维码标准箱")
    @PostMapping("/deleteById")
    public AjaxResult deleteById(@RequestBody BmQrBoxInfo bmQrBoxInfo)
    {
        return qrBoxService.deleteById(bmQrBoxInfo);
    }

    /**
     * 下载二维码标准箱
     */
    @ApiOperation(value = "下载二维码标准箱")
    @PreventRepeatSubmit
    //@RequiresPermissions("basic:qrBox:download")
    @PostMapping("/download")
    public void download(@RequestBody BmQrBoxInfo bmQrBoxInfo, HttpServletResponse response)
    {
        qrBoxService.download(bmQrBoxInfo, response);
    }

    /**
     * 标准箱信息查询
     * @param info
     * @return
     */
    @ApiOperation(value = "标准箱信息查询")
    @GetMapping("/getBoxInfo")
    public AjaxResult getBoxInfo(BoxBindWarehouseDto info) {
        try {
            return qrBoxService.getBoxInfo(info);
        } catch (Exception e) {
            return AjaxResult.error("查询失败，请联系管理员");
        }
    }

    /**
     * 标准箱信息详情查询
     * @param info
     * @return
     */
    @ApiOperation(value = "标准箱信息详情查询")
    @GetMapping("/getBoxDetails")
    public AjaxResult getBoxDetails(BoxBindWarehouseDto info) {
        try {
            return qrBoxService.getBoxDetails(info);
        } catch (Exception e) {
            return AjaxResult.error("查询失败，请联系管理员");
        }
    }

    /**
     * 根据编码查询信息
     * @param info
     * @return
     */
    @ApiOperation(value = "根据编码查询信息")
    @GetMapping("/getMaCodeList")
    public AjaxResult getMaCodeList(BmQrBoxInfo info) {
        try {
            return qrBoxService.getMaCodeList(info);
        } catch (Exception e) {
            return AjaxResult.error("查询失败，请联系管理员");
        }
    }

    /**
     * APP -- 编码绑定标准箱
     * @param machine
     * @return
     */
    @ApiOperation(value = "APP -- 编码绑定标准箱")
    @PostMapping("/app_code_bind")
    public AjaxResult addMaCodeBoxBind(@RequestBody @NotNull(message = "参数不能为空") Machine machine) {
        return qrBoxService.addMaCodeBoxBind(machine);
    }

    /**
     * APP -- 查询新信息采集二维码标准箱绑定列表
     * @param bean
     * @return
     */
    @ApiOperation(value = "APP -- 查询新信息采集二维码标准箱绑定列表")
    @GetMapping("/app_box_bind_wsList")
    public AjaxResult getBoxBindWsList(BmQrBoxInfo bean) {
        return AjaxResult.success(getDataTable(qrBoxService.getBoxBindWsList(bean)));
    }
}
