package com.dgtly.member.controller;

import com.dgtly.apiframework.util.TokenUtil;
import com.dgtly.common.annotation.ApiNoCheckSign;
import com.dgtly.common.annotation.ApiPassToken;
import com.dgtly.common.core.controller.ApiBaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.core.domain.ParameterObject;
import com.dgtly.common.utils.DateUtils;
import com.dgtly.common.utils.StringUtils;
import com.dgtly.member.domain.MemberFollow;
import com.dgtly.member.service.IMemberFollowService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
  * @descption: 会员关注商户相关API接口
  * @author LiuLingChao
  * @version 1.0
  * @company 神州数码通用软件（洛阳）有限公司
  * @copyright (c) 2019 LuoYang DGT Co'Ltd Inc. All rights reserved.
  * @date 2020-2-27 15:10
  * @since JDK1.8
  */
@RestController
@RequestMapping("/member/follow")
@ApiNoCheckSign/* 不用验证 签名 方法上可用*/
public class MemberFollowApi extends ApiBaseController {

    @Autowired
    private IMemberFollowService iMemberFollowService;
    /**
     * @descption: 网站会员关注添加
     * @param:
     * @return:
     * @auther: LiuLingChao
     * @date: 2020-2-27 15:11
     */
    @ApiOperation(value = "会员关注")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "params" , paramType = "body"),
        @ApiImplicitParam(name = "token" , paramType = "header")
    })
    @PostMapping("/addMemberFollow")
    public Object addMemberFollow(){
        //获取token中用户id
        String userId = TokenUtil.getTokenUserId();
            ParameterObject obj =  getParameterObject();
            MemberFollow memberFollow = obj.parseBean(MemberFollow.class);
            memberFollow.setMemberId(Long.parseLong(userId));
            memberFollow.setFollowDate(DateUtils.getNowDate());
            int flag = iMemberFollowService.insertMemberFollow(memberFollow);
            return toAjax(flag);
    }

    /**
     * @descption: 网站用户取消关注
     * @param: 关注id
     * @return:
     * @auther: LiuLingChao
     * @date: 2020-2-27 15:35
     */
    @ApiOperation(value = "取消关注")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params" , paramType = "body"),
            @ApiImplicitParam(name = "token" , paramType = "header")
    })
    @PostMapping("/cancleMemberFollow")
    public Object cancleMemberFollow(){
        ParameterObject obj =  getParameterObject();
        obj.checkParameterNotNull("companyId");
        //获取token中用户id
        String memberId = TokenUtil.getTokenUserId();
        String companyId = obj.getString("companyId");
        int flag = iMemberFollowService.deleteMemberFollowByCompanyMemberId(memberId,companyId);
        return AjaxResult.success();
    }

    /**
     * @descption: 获取网站会员关注的商户列表
     * @param:
     * @return:
     * @auther: LiuLingChao
     * @date: 2020-2-27 15:57
     */
    @ApiOperation(value = "商户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params" , paramType = "body"),
            @ApiImplicitParam(name = "token" , paramType = "header")
    })
    @PostMapping("/getMemberFollowList")
    public Object getMemberFollowList(){
        String userId = TokenUtil.getTokenUserId();
        ParameterObject obj =  getParameterObject();
        startPage(obj);
        MemberFollow memberFollow = new MemberFollow();
        memberFollow.setMemberId(Long.parseLong(userId));

        List<MemberFollow> memberFollowList = iMemberFollowService.getMemberFollowList(memberFollow);
        return AjaxResult.success(getDataTable(memberFollowList));

    }
}
