package com.fjhx.controller.water;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.Condition;
import com.fjhx.entity.water.WaterTag;
import com.fjhx.params.JumpVo;
import com.fjhx.params.water.WaterTagVo;
import com.fjhx.service.flow.DeleteTagService;
import com.fjhx.service.water.WaterTagService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标签 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-09-21
 */
@RestController
@RequestMapping("/waterTag")
public class WaterTagController {

    @Autowired
    private WaterTagService waterTagService;

    @Autowired
    private DeleteTagService deleteTagService;

    @PostMapping("/page")
    public R page(@RequestBody Condition condition) {
        Page<Map<String, Object>> result = waterTagService.getPage(condition);
        return R.success(result);
    }

    @PostMapping("/count")
    public R count() {
        Long count = waterTagService.count();
        return R.success(count);
    }

    /**
     * 添加标签
     */
    @PostMapping("/add")
    public R add(@RequestBody WaterTagVo waterTagVo) {
        waterTagService.add(waterTagVo);
        return R.success();
    }

    /**
     * 导入标签
     */
    @PostMapping("/uploadTag")
    public R uploadTag(@RequestParam("file") MultipartFile file, @RequestParam("waterBatchId") Long waterBatchId) {
        waterTagService.uploadTag(file, waterBatchId);
        return R.success();
    }

    /**
     * 打印二维码
     */
    @PostMapping("/printer")
    public R printer(@RequestBody List<Long> tagIdList) {
        waterTagService.printer(tagIdList);
        return R.success();
    }

    /**
     * 绑定rfid
     */
    @PostMapping("/bindingRfid")
    public R bindingRfid(@RequestBody WaterTag waterTag) {
        waterTagService.bindingRfid(waterTag.getId(), waterTag.getRfidCode());
        return R.success();
    }

    /**
     * 删除标签流程
     */
    @PostMapping("/deleteFlowCreate")
    public R deleteFlowCreate(@RequestBody WaterTagVo waterTagVo) {
        deleteTagService.create(waterTagVo.getId());
        return R.success();
    }

    /**
     * 删除标签跳转
     */
    @PostMapping("/deleteFlowJump")
    public R deleteFlowJump(@RequestBody JumpVo jumpVo) {
        deleteTagService.jump(jumpVo);
        return R.success();
    }

    /**
     * 通过二维码获取标签明细
     */
    @PostMapping("/getDetailsByQrCode")
    public R getDetailsByQrCode(@RequestBody WaterTag waterTag) {
        Map<String, Object> result = waterTagService.getDetailsByQrCode(waterTag.getQrCode());
        return R.success(result);
    }

    /**
     * 通过rfid获取标签明细
     */
    @PostMapping("/getDetailsByRfid")
    public R getDetailsByRfid(@RequestBody WaterTag waterTag) {
        Map<String, Object> result = waterTagService.getDetailsByRfid(waterTag.getRfidCode());
        return R.success(result);
    }

}

