package com.liangjian.dataplatform.member.controller;

import com.liangjian.dataplatform.member.entity.po.secondary.WeixinUserInfo;
import com.liangjian.dataplatform.member.entity.po.elasticsearch.UserPointLog;
import com.liangjian.dataplatform.member.entity.response.ResultObject;
import com.liangjian.dataplatform.member.entity.vo.request.BirdGirdRequest;
import com.liangjian.dataplatform.member.entity.vo.response.BirdGirdTableResponse2;
import com.liangjian.dataplatform.member.service.IUserPointLogService;
import com.liangjian.dataplatform.member.service.IWeixinUserInfoQueryService;
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.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 黄子奇
 * @Date: 2019/12/6
 */
@RestController
@RequestMapping("/wechatInfo")
@Api(value = "微信用户控制器（积分、成长值信息）", description = "微信用户控制器（积分、成长值信息）")
public class WeixinUserInfoController {
    @Autowired
    private IWeixinUserInfoQueryService iWeixinUserInfoQueryService;

    @Autowired
    private IUserPointLogService iUserPointLogService;

    @PostMapping("/query")
    @ApiOperation("查询微信用户信息")
    public BirdGirdTableResponse2<WeixinUserInfo> query(@ApiParam(value = "birdgrid请求对象", required = true) @RequestBody BirdGirdRequest girdRequest) {
        girdRequest.setPageIndex(girdRequest.getPageIndex() - 1);
        Page<WeixinUserInfo> paged = iWeixinUserInfoQueryService.queryByCondition(girdRequest);
        return new BirdGirdTableResponse2<>(paged.getContent(),paged.getTotalElements());
    }

    @PostMapping("/addPoint")
    @ApiOperation(value = "人为添加积分")
    public ResultObject<Object> addPoint(@ApiParam(value = "积分记录对象", required = true) @RequestBody UserPointLog log) {
        if(iWeixinUserInfoQueryService.update(log)) {
            return ResultObject.success("更改积分记录成功",null);
        } else {
            return ResultObject.error("更改积分记录保存失败");
        }
    }
}
