package com.bonus.app.controller;

import com.bonus.app.entity.BoxEntity;
import com.bonus.app.entity.BraceletEntity;
import com.bonus.app.service.BraceletService;
import com.bonus.common.core.utils.BASE64DecodedMultipartFile;
import com.bonus.common.core.utils.UploadCheckUtils;
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.entity.app.AppParamsDto;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 手环管理模块
 * APP
 */
@RestController
@RequestMapping("/bracelet/")
@Slf4j
public class BraceletController extends BaseController {


    @Autowired
    private BraceletService service;

    /**
     * 查询班组
     * 所领取的手环箱
     *
     * @param entity
     * @return
     */
    @GetMapping("getBoxListById")
    @SysLog(title = "手环管理", businessType = OperaType.QUERY, module = "基础管理->手环管理", details = "查询手环列表")
    public AjaxResult getBoxListById(BoxEntity entity) {
        return service.getBoxListById(entity);

    }


    /**
     * 查询相关手环箱
     * 分配信息
     *
     * @param entity
     * @return
     */
    @GetMapping("getBoxInfo")
    @SysLog(title = "手环管理", businessType = OperaType.QUERY, module = "基础管理->手环管理", details = "查询手环列表")
    public AjaxResult getBoxInfo(BoxEntity entity) {
        return service.getBoxInfo(entity);
    }

    /**
     * 发放手环查询接口
     * 分配信息
     *
     * @param entity
     * @return
     */
    @GetMapping("getBoxToUser")
    @SysLog(title = "app->手环管理", businessType = OperaType.QUERY, module = "app->手环管理->手环管理", details = "查看手环发放信息")
    public AjaxResult getBoxToUser(BoxEntity entity) {
        return service.getBoxToUser(entity);
    }

    /**
     * 发放手环查询接口
     * 分配信息
     *
     * @param entity
     * @return
     */
    @PostMapping("sendBoxBracelet")
    @SysLog(title = "app->手环管理", businessType = OperaType.QUERY, module = "app->手环管理->发放手环", details = "发放手环")
    public AjaxResult sendBoxBracelet(@RequestBody BoxEntity entity) {
        return service.sendBoxBracelet(entity);
    }


    /**
     * 归还手环箱查询
     *
     * @param entity
     * @return
     */
    @GetMapping("getBoxBraceletUsed")
    @SysLog(title = "app->手环管理", businessType = OperaType.QUERY, module = "app->手环管理->归还手环", details = "查询手环使用信息")
    public AjaxResult getBoxBraceletUsed(BoxEntity entity) {
        return service.getBoxBraceletUsed(entity);
    }

    /**
     * 归还手环箱查询
     *
     * @param entity
     * @return
     */
    @PostMapping("returnBoxBracelet")
    @SysLog(title = "app->手环管理", businessType = OperaType.QUERY, module = "app->手环管理->归还手环", details = "归还手环")
    public AjaxResult returnBoxBracelet(@RequestBody BoxEntity entity) {
        return service.returnBoxBracelet(entity);
    }

    /**
     * 归还手环箱查询
     *
     * @param
     * @return
     */
    @PostMapping("addLsUser")
    @SysLog(title = "app->手环管理", businessType = OperaType.QUERY, module = "app->手环管理->新增临时人员", details = "新增临时人员")
    public AjaxResult addLsUser(@RequestBody AppParamsDto dto) {
        MultipartFile fileData = BASE64DecodedMultipartFile.base64ToMultipart2(dto.getFile());
        String result = UploadCheckUtils.uploadImgVerify(fileData);
        if (StringUtils.isNotBlank(result)) {
            return AjaxResult.error(result);
        }
        return service.addLsUser(fileData, dto.getParams());
    }
}
