package com.nmgs.controller;

import com.alibaba.fastjson.JSONArray;
import com.nmgs.config.ResultData;
import com.nmgs.service.IntegralLevelMessageService;
import com.nmgs.service.IntegralSignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value="signManager")
@Api(tags = "用户签到")
public class IntegralSignController {
    public IntegralSignService integralSignService;
    @Autowired
    public void setIntegralSignService(IntegralSignService integralSignServiceT) {
        this.integralSignService = integralSignServiceT;
    }



    @RequestMapping(value = "signList",
            method = {RequestMethod.POST}
    )
    @ApiOperation(httpMethod="POST",value="查询用户签到信息")
    public ResultData<List> signList(@RequestParam(value = "userId",required = true) String userId,
                                                 @RequestParam(value = "signDate",required = true) String signDate,
                                     @RequestParam(value = "countDay",required = true) String countDay){
        JSONArray integrationList = this.integralSignService.getList(userId, signDate,Integer.parseInt(countDay));
        if(integrationList != null){
            return ResultData.success("查询成功",integrationList,integrationList.size());
        }else{
            return ResultData.fail("查询失败");
        }
    }

    @RequestMapping(value = "sign",
            method = {RequestMethod.POST}
    )
    @ApiOperation(httpMethod="POST",value="用户签到提交")
    public ResultData<List> sign(@RequestParam(value = "userId",required = true) String userId,
                                   @RequestParam(value = "dateTime",required = true) String dateTime){
        int ret = this.integralSignService.commit(userId, dateTime);
        if(ret>0){
            if(ret==1){
                return ResultData.success(1,"签到成功");
            }else if(ret==2){
                return ResultData.success(2,"只能签到今天的日期");
            }else{
                return ResultData.success(3,"签到失败，未知错误");
            }
        }else{
            return ResultData.fail("签到失败");
        }
    }
}
