/*
Copyright [2020] [https://www.xiaonuo.vip]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：

1.请不要删除和修改根目录下的LICENSE文件。
2.请不要删除和修改Snowy源码头部的版权声明。
3.请保留源码和相关描述文件的项目出处，作者声明等。
4.分发源码时候，请注明软件出处 https://gitee.com/xiaonuobase/snowy
5.在修改包名，模块名称，项目代码等时，请注明软件出处 https://gitee.com/xiaonuobase/snowy
6.若您的项目无法满足以上几点，可申请商业授权，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package com.huimv.modular.rawdata.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huimv.core.annotion.BusinessLog;
import com.huimv.core.annotion.Permission;
import com.huimv.core.enums.LogAnnotionOpTypeEnum;
import com.huimv.core.factory.PageFactory;
import com.huimv.core.pojo.page.PageResult;
import com.huimv.core.pojo.response.ResponseData;
import com.huimv.core.pojo.response.SuccessResponseData;

import com.huimv.core.util.HttpServletUtil;
import com.huimv.modular.eartagdata.entity.EartagData;
import com.huimv.modular.rawdata.entity.RawData;
import com.huimv.modular.rawdata.mapper.RawDataMapper;
import com.huimv.modular.rawdata.param.RawDataParam;
import com.huimv.modular.rawdata.service.RawDataService;
import com.huimv.modular.utils.util.StringUtilsWork;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 原始数据存储控制器  第三方公司要求从此处读取数据
 *
 * @author yangdi
 * @date 2021-11-09 16:58:43
 */
@RestController
public class RawDataController {

    @Resource
    private RawDataService rawDataService;

    @Resource
    private RawDataMapper rawDataMapper;

    /**
     * 查询原始数据存储
     * @author yangdi
     * @date 2021-11-09 16:58:43
     */
    @GetMapping("/rawData/page")
    public ResponseData page001(RawDataParam rawDataPara) throws ParseException {
        HttpServletRequest request = HttpServletUtil.getRequest();
        //每页条数
        String pageNo = request.getParameter("pageNo");
        String starttime = request.getParameter("startTime");
        String endtime = request.getParameter("endTime");
        System.out.println(pageNo);
        if (StringUtilsWork.isNotBlank(starttime) & StringUtilsWork.isNotBlank(endtime)) {
            LambdaQueryWrapper<RawData> wrapper = Wrappers.lambdaQuery();
            System.out.println(starttime + "***shijian**" + endtime);
            DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date startTime = fmt.parse(starttime);
            Date endTime = fmt.parse(endtime);
            System.out.println("时间传入" + starttime + endtime);
            //过滤时间
            wrapper.between(RawData::getCreateTime, startTime, endTime);
            return ResponseData.success(rawDataMapper.selectList(wrapper));
        }
        //倒序展示数据
        return new SuccessResponseData(rawDataService.pageDesc(rawDataPara) );
    }




/*

    *//**
     * 查询原始数据存储----根据时间查询
     * @author yangdi
     * @date 2021-11-09 16:58:43
     *//*
    @GetMapping("/rawData/findByTime")
    public ResponseData findByTime(@RequestParam Map<String, Object> params ) throws ParseException {
    LambdaQueryWrapper<RawData> wrapper = Wrappers.lambdaQuery();
        String starttime = (String) params.get("startTime");//开始时间
        String endtime = (String) params.get("endTime");//结束时间

            System.out.println(starttime + "***shijian**" + endtime);
            DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date startTime = fmt.parse(starttime);
            Date endTime = fmt.parse(endtime);
            System.out.println("时间传入" + starttime + endtime);
            //过滤时间
            wrapper.between(RawData::getCreateTime, startTime, endTime);
            return   ResponseData.success(rawDataMapper.selectList(wrapper)) ;
    }*/







    /**
     * 添加原始数据存储
     *
     * @author yangdi
     * @date 2021-11-09 16:58:43
     */
    @Permission
    @PostMapping("/rawData/add")
    @BusinessLog(title = "原始数据存储_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(RawDataParam.add.class) RawDataParam rawDataParam) {
            rawDataService.add(rawDataParam);
        return new SuccessResponseData();
    }

    /**
     * 删除原始数据存储，可批量删除
     *
     * @author yangdi
     * @date 2021-11-09 16:58:43
     */
    @Permission
    @PostMapping("/rawData/delete")
    @BusinessLog(title = "原始数据存储_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(RawDataParam.delete.class) List<RawDataParam> rawDataParamList) {
            rawDataService.delete(rawDataParamList);
        return new SuccessResponseData();
    }

    /**
     * 编辑原始数据存储
     *
     * @author yangdi
     * @date 2021-11-09 16:58:43
     */
    @Permission
    @PostMapping("/rawData/edit")
    @BusinessLog(title = "原始数据存储_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(RawDataParam.edit.class) RawDataParam rawDataParam) {
            rawDataService.edit(rawDataParam);
        return new SuccessResponseData();
    }

    /**
     * 查看原始数据存储
     *
     * @author yangdi
     * @date 2021-11-09 16:58:43
     */
    @Permission
    @GetMapping("/rawData/detail")
    @BusinessLog(title = "原始数据存储_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(RawDataParam.detail.class) RawDataParam rawDataParam) {
        return new SuccessResponseData(rawDataService.detail(rawDataParam));
    }

    /**
     * 原始数据存储列表
     *
     * @author yangdi
     * @date 2021-11-09 16:58:43
     */
    @Permission
    @GetMapping("/rawData/list")
    @BusinessLog(title = "原始数据存储_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(RawDataParam rawDataParam) {
        return new SuccessResponseData(rawDataService.list(rawDataParam));
    }

    /**
     * 导出系统用户
     *
     * @author yangdi
     * @date 2021-11-09 16:58:43
     */
    @Permission
    @GetMapping("/rawData/export")
    @BusinessLog(title = "原始数据存储_导出", opType = LogAnnotionOpTypeEnum.EXPORT)
    public void export(RawDataParam rawDataParam) {
        rawDataService.export(rawDataParam);
    }

}
