package com.unis.crk.cplbusiness.controller;

import com.unis.crk.cplbusiness.entity.LiAfterSale;
import com.unis.crk.cplbusiness.entity.LiOrder;
import com.unis.crk.cplbusiness.entity.vo.DataCrkywCplckDefaultVo;
import com.unis.crk.cplbusiness.entity.vo.LiAfterSaleVo;
import com.unis.crk.cplbusiness.entity.vo.LiOrderVo;
import com.unis.crk.cplbusiness.service.ILiAfterSaleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.unis.crk.utils.ResultUtil;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import cn.hutool.json.JSONObject;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ghh
 * @since 2023-01-20
 */
@CrossOrigin
@Api(value = "售后卖家确认收货入库",tags = {"售后卖家确认收货入库"})
@RestController
@RequestMapping("liAfterSale")
public class LiAfterSaleController {

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


    @Autowired
    private ILiAfterSaleService liAfterSaleService;


    /**
     * 根据ID查询数据
     * @param id
     * @return
     */
    @ApiOperation(value="单条数据查询查询", notes="根据ID查询数据")
    @GetMapping("getOne/{id}")
    public ResultUtil getOne(@PathVariable("id") String id){
        LOGGER.info("入参为:{}",id);
        ResultUtil<LiAfterSale> data = new ResultUtil<>();
        if (StringUtils.isEmpty(id)){
            data.failed("传入的主键为空");
            return data;
        }
        data.success(this.liAfterSaleService.getByIdgetSale(id));
        return data;
    }
    /**
     * 分页高级查询
     * @return
     */
    @ApiOperation(value="分页查询", notes="分页高级查询")
    @PostMapping(value="/findPage")
    public ResultUtil findPage(@RequestBody LiAfterSaleVo pageQuery) {
        ResultUtil<IPage<Map<String,Object>>> data = new ResultUtil<>();
        data.success(this.liAfterSaleService.findPageVo(pageQuery));
        return data;
    }

    /**
     * 保存电商退货订单入库
     * @return
     */
    @ApiOperation(value="保存电商退货订单入库", notes="保存电商退货订单入库")
    @PostMapping(value="/save")
    public ResultUtil save(@RequestBody LiAfterSale param) {
        LOGGER.info("入参为:{}", param);
        ResultUtil<Boolean> data = new ResultUtil<>();
        if (ObjectUtils.isEmpty(param)){
            data.failed("所接收对象为null");
            return data;
        }
        JSONObject ret = new JSONObject();
        try {
            ret  = this.liAfterSaleService.saveOrAfter(param);
        } catch (Exception e) {
            e.printStackTrace();
            ret.set("success", false);
            ret.set("msg", e.getMessage());
        }

        if (ret.getBool("success")){
            data.success(ret.getStr("msg"));
        }else {
            data.failed(ret.getStr("msg"));
        }
        return  data;
    }




}

