package com.unis.crk.cplbusiness.controller;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.unis.crk.cplbusiness.entity.DataCrkywCplrkDefault;
import com.unis.crk.cplbusiness.entity.OllectionReview;
import com.unis.crk.cplbusiness.entity.SettlementManagement;
import com.unis.crk.cplbusiness.entity.vo.SettlementManagementVo;
import com.unis.crk.cplbusiness.service.IDataCrkywCplrkDefaultService;
import com.unis.crk.cplbusiness.service.ISettlementManagementService;
import com.unis.crk.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * <p>
 * 结算管理 前端控制器
 * </p>
 *
 * @author TangSong
 * @since 2022-05-23
 */
@CrossOrigin
@Api(value = "结算管理",tags = {"结算管理"})
@RestController
@RequestMapping("settlementManagement")
public class SettlementManagementController {

    private final static Logger LOGGER = LoggerFactory.getLogger(SettlementManagementController.class);


    @Autowired
    private ISettlementManagementService settlementManagementService;

    /**
     * 根据ID查询数据
     * @param id
     * @return
     */
    @ApiOperation(value="查询", notes="根据ID查询数据")
    @GetMapping("getOne/{id}")
    public ResultUtil getOne(@PathVariable("id") String id){
        LOGGER.info("入参为:{}",id);
        ResultUtil<SettlementManagement> data = new ResultUtil<>();
        if (StringUtils.isEmpty(id)){
            data.failed("传入的主键为空");
            return data;
        }
        data.success(this.settlementManagementService.getOneData(id));
        return data;
    }


    /**
         * 分页高级查询
         * @return
         */
    @ApiOperation(value="查询", notes="分页高级查询")
    @PostMapping(value="/findPage")
    public ResultUtil findPage(@RequestBody SettlementManagementVo pageQuery) {
        ResultUtil<IPage<Map<String,Object>>> data = new ResultUtil<>();
        data.success(this.settlementManagementService.findPageVo(pageQuery));
        return data;
    }

    /**
     * 修改状态一条数据
     * @param param
     * @return
     */
    @ApiOperation(value="审核", notes="审核")
    @PatchMapping("edit")
    public ResultUtil edit(@RequestBody SettlementManagement param){
        LOGGER.info("入参为:{}", param);
        ResultUtil<Boolean> data = new ResultUtil<>();
        if (ObjectUtils.isEmpty(param)){
            data.failed("所接收对象为null");
            return data;
        }
        JSONObject ret  = this.settlementManagementService.update(param);
        if (ret.getBool("success")){
            data.success(ret.getStr("msg"));
        }else {
            data.failed(ret.getStr("msg"));
        }

        return data;
    }





}

