package com.unis.module.coding.controller.admin.kshzs;

import com.unis.framework.common.pojo.CommonResult;
import com.unis.framework.common.pojo.PageResult;
import com.unis.module.coding.controller.admin.kshzs.vo.kqxxVo;
import com.unis.module.coding.controller.admin.kshzs.vo.*;
import com.unis.module.coding.service.kshzs.KshzsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @Author: Insight
 * @Description: TODO
 * @Date: 2025/2/11 10:15
 * @Version: 1.0
 */
@Tag(name = "可视化展示")
@RestController
@RequestMapping("/kshzs/zsxx")
@Validated
public class KshzsController {

    @Resource
    private KshzsService kshzsService;

    @PostMapping("/selectKqmcList")
    @Operation(summary = "库区名称搜索")
    public CommonResult<List<kqxxVo>> selectKqmcList(@Valid @RequestBody paramVo paramVo) {
        List<kqxxVo> dataObj = kshzsService.selectKqmcList(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectMapList")
    @Operation(summary = "地图数据展示")
    public CommonResult<Map<String,Object>> selectMapList(@Valid @RequestBody paramVo paramVo) {
        Map<String,Object> dataObj = kshzsService.selectMapList(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectFrameList")
    @Operation(summary = "地图数据--悬浮框")
    public CommonResult<totalVo> selectFrameList(@Valid @RequestBody paramVo paramVo) {
        totalVo dataObj = kshzsService.selectFrameList(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectPieChart")
    @Operation(summary = "品质机构、收货年份饼图")
    public CommonResult<List<Map<String, Object>>> selectPieChart(@Valid @RequestBody paramVo paramVo) {
        List<Map<String, Object>> dataObj = kshzsService.selectPieChart(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectCxxList")
    @Operation(summary = "仓房信息列表")
    public CommonResult<List<cfxxVo>> selectCxxList(@Valid @RequestBody paramVo paramVo) {
        List<cfxxVo> dataObj = kshzsService.selectCxxList(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/queryKqInfo")
    @Operation(summary = "库区基本信息")
    public CommonResult<kqxxVo> queryKqInfo(@Valid @RequestBody paramVo paramVo) {
        kqxxVo dataObj = kshzsService.queryKqInfo(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectCwxxList")
    @Operation(summary = "财务信息列表")
    public CommonResult<List<cwxxVo>> selectCwxxList(@Valid @RequestBody paramVo paramVo) {
        List<cwxxVo> dataObj = kshzsService.selectCwxxList(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectCfInfo")
    @Operation(summary = "仓房信息")
    public CommonResult<cfxxVo> selectCfInfo(@Valid @RequestBody paramVo paramVo) {
        cfxxVo dataObj = kshzsService.selectCfInfo(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectHwkInfo")
    @Operation(summary = "货位卡信息")
    public CommonResult<hwkVo> selectHwkInfo(@Valid @RequestBody paramVo paramVo) {
        hwkVo dataObj = kshzsService.selectHwkInfo(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectCrkList")
    @Operation(summary = "出入库信息")
    public CommonResult<PageResult<crkVo>> selectCrkList(@Valid @RequestBody pageParamVo paramVo) {
        PageResult<crkVo> dataObj = kshzsService.selectCrkList(paramVo);
        if (dataObj.getList() != null || dataObj.getList().size() > 0) {
            for (crkVo crkVo : dataObj.getList()){
               if(crkVo.getCrklx() == 0){
                   crkVo.setYwrq(crkVo.getCmsj().toString().substring(0,10));
               }else{
                   crkVo.setYwrq(crkVo.getRmsj().toString().substring(0,10));
               }
            }
        }
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectZjList")
    @Operation(summary = "质检信息")
    public CommonResult<PageResult<zjxxVo>> selectZjList(@Valid @RequestBody pageParamVo paramVo) {
        PageResult<zjxxVo> dataObj = kshzsService.selectZjList(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectLqjcList")
    @Operation(summary = "粮情检测")
    public CommonResult<List<lqjcVo>> selectLqjcList(@Valid @RequestBody paramVo paramVo) {
        List<lqjcVo> dataObj = kshzsService.selectLqjcList(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectSydList")
    @Operation(summary = "损益单")
    public CommonResult<PageResult<sydVo>> selectSydList(@Valid @RequestBody pageParamVo paramVo) {
        PageResult<sydVo> dataObj = kshzsService.selectSydList(paramVo);
        return CommonResult.success(dataObj);
    }

    @PostMapping("/selectSpList")
    @Operation(summary = "视频列表")
    public CommonResult<List<Map<String, Object>>> selectSpList(@Valid @RequestBody paramVo paramVo) {
        List<Map<String, Object>> dataObj = kshzsService.selectSpList(paramVo);
        return CommonResult.success(dataObj);
    }

}
