package com.unis.crk.common.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.unis.crk.basic.entity.Attaches;
import com.unis.crk.common.entity.vo.UpdataLogVo;
import com.unis.crk.common.service.IUpdataLogService;
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-03-17
 */
@CrossOrigin
@Api(value = "上传数据日志",tags = {"上传数据日志"})
@RestController
@RequestMapping("updataLog")
public class UpdataLogController {

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


    @Autowired
    private IUpdataLogService updataLogService;


    /**
     * 根据单位Id查询上传数据
     * @param unitId
     * @return
     */
    @ApiOperation(value="查询", notes="根据单位Id查询上传数据")
    @GetMapping("uploadData/{unitId}")
    public ResultUtil uploadData(@PathVariable("unitId") String unitId){
        LOGGER.info("入参为:{}",unitId);
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        if (StringUtils.isEmpty(unitId)){
            data.failed("传入的主键为空");
            return data;
        }
        data.success(this.updataLogService.uploadData(unitId));
        return data;
    }
    /**
     * 根据单位Id查询上传数据中心数据
     * @param unitId
     * @return
     */
    @ApiOperation(value="查询", notes="根据单位Id查询上传数据中心数据")
    @GetMapping("uploadSjzxData/{unitId}")
    public ResultUtil uploadSjzxData(@PathVariable("unitId") String unitId){
        LOGGER.info("入参为:{}",unitId);
        ResultUtil<JSONObject> data = new ResultUtil<>();
        if (StringUtils.isEmpty(unitId)){
            data.failed("传入的主键为空");
            return data;
        }
        data.success(this.updataLogService.uploadSjzxData(unitId));
        return data;
    }
    /**
     * 根据单位Id查询删除数据中心数据
     * @param unitId
     * @return
     */
    @ApiOperation(value="查询", notes="根据单位Id删除上传数据中心数据")
    @GetMapping("deleteSjzxData/{unitId}")
    public ResultUtil deleteSjzxData(@PathVariable("unitId") String unitId){
        LOGGER.info("入参为:{}",unitId);
        ResultUtil<JSONObject> data = new ResultUtil<>();
        if (StringUtils.isEmpty(unitId)){
            data.failed("传入的主键为空");
            return data;
        }
        data.success(this.updataLogService.deleteSjzxData(unitId));
        return data;
    }
    /**
     * 从ddm取调拔单数据
     * @return
     */
    @ApiOperation(value="查询", notes="从ddm取调拔单数据")
    @GetMapping("downDbDInfo")
    public ResultUtil downDbDInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downDbDInfo());
        return data;
    }
    /**
     * 从ddm取采购单数据
     * @return
     */
    @ApiOperation(value="查询", notes="从ddm取采购单数据")
    @GetMapping("downCgdInfo")
    public ResultUtil downCgdInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downCgdInfo());
        return data;
    }
    /**
     * 从ddm取采购单数据
     * @return
     */
    @ApiOperation(value="查询", notes="从ddm取采购单数据")
    @GetMapping("downXsdInfo")
    public ResultUtil downXsdInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downXsdInfo());
        return data;
    }
    /**
     * 从ddm取销售退换货单数据
     * @return
     */
    @ApiOperation(value="查询", notes="从ddm取销售退换货单数据")
    @GetMapping("downXsThhdInfo")
    public ResultUtil downXsThhdInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downXsThhdInfo());
        return data;
    }
    /**
     * 从dmm采购退换货单数据
     * @return
     */
    @ApiOperation(value="查询", notes="从dmm采购退换货单数据")
    @GetMapping("downCgThhdInfo")
    public ResultUtil downCgThhdInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downCgThhdInfo());
        return data;
    }
    /**
     * 从ddm取商品数据
     * @return
     */
    @ApiOperation(value="查询", notes="从ddm取商品数据")
    @GetMapping("downSpInfo")
    public ResultUtil downSpInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downSpInfo());
        return data;
    }
    /**
     * 接收上传数据
     * @param jsonObject
     * @return
     */
    @ApiOperation(value="接收", notes="接收上传数据")
    @PostMapping("recData")
    public ResultUtil recData(@RequestBody JSONObject jsonObject){
        LOGGER.info("入参为:{}", jsonObject);
        ResultUtil<JSONObject> data = new ResultUtil<>();
        if (ObjectUtils.isEmpty(jsonObject)){
            data.failed("所接收对象为null");
            return data;
        }
        data.success(this.updataLogService.recData(jsonObject));
        return data;
    }

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


    /**
     * 从ddm取货位数据
     * @return
     */
    @ApiOperation(value="从ddm取货位数据", notes="从ddm取货位数据")
    @GetMapping("downDbhwInfo")
    public ResultUtil downDbhwInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downHwInfo());
        return data;
    }

    /**
     * 从ddm取仓房数据
     * @return
     */
    @ApiOperation(value="从ddm取仓房数据", notes="从ddm取仓房数据")
    @GetMapping("downChInfo")
    public ResultUtil downChInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downChInfo());
        return data;
    }


    /**
     * 从ddm取计量单位数据
     * @return
     */
    @ApiOperation(value="从ddm取计量单位数据", notes="从ddm取计量单位数据")
    @GetMapping("downJldwInfo")
    public ResultUtil downJldwInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downJldwInfo());
        return data;
    }

    /**
     * 从ddm取品牌数据
     * @return
     */
    @ApiOperation(value="从ddm取品牌数据", notes="从ddm取品牌数据")
    @GetMapping("downPpInfo")
    public ResultUtil downPpInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downPpInfo());
        return data;
    }


    /**
     * 从ddm取品种数据
     * @return
     */
    @ApiOperation(value="从ddm取品种数据", notes="从ddm取品种数据")
    @GetMapping("downPzInfo")
    public ResultUtil downPzInfo(){
        ResultUtil<com.alibaba.fastjson.JSONObject> data = new ResultUtil<>();
        data.success(this.updataLogService.downPzInfo());
        return data;
    }
}

