package com.yihu.jw.base.endpoint.sync;

import com.yihu.jw.base.service.sync.BaseSyncDataService;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/5/25
 */
@RestController
@RequestMapping(value = BaseRequestMapping.SyncData.PREFIX)
@Api(value = "数据同步", description = "数据同步", tags = {"wlyy基础服务 - 数据同步接口"})
public class BaseSyncDataEndpoint  extends EnvelopRestEndpoint {


    @Autowired
    private BaseSyncDataService baseSyncDataService;




    @Value("${wechat.id}")
    private String wxId;

    @GetMapping(value = BaseRequestMapping.SyncData.findAllSyncData)
    @ApiOperation(value = "获取同步数据列表")
    public PageEnvelop findAllSyncData( @ApiParam(name = "startTime", value = "开始时间", required = false, defaultValue = "")
                                        @RequestParam(value = "startTime",required = false) String startTime,
                                        @ApiParam(name = "endTime", value = "结束时间", required = false, defaultValue = "")
                                        @RequestParam(value = "endTime",required = false) String endTime,
                                       @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
                                           @RequestParam(value = "page") Integer page,
                                       @ApiParam(name = "size", value = "页码", required = true, defaultValue = "10")
                                           @RequestParam(value = "size") Integer size){
        try {

            return   baseSyncDataService.findAllSyncData(startTime,endTime,page,size,wxId);
        }catch (Exception e){
            return PageEnvelop.getError(e.getMessage(),-1);
        }

    }

    @GetMapping(value = BaseRequestMapping.SyncData.syncComplete)
    @ApiOperation(value = "同步数据")
    public MixEnvelop syncComplete(){
        baseSyncDataService.complete(wxId);
        return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_find);
    }


}
