package com.ssm.controller;

import com.ssm.manage.response.GenericResponse;

import com.ssm.manage.utils.SessionHelp;
import com.ssm.manage.entity.MemberCs;
import com.ssm.manage.entity.SmsException;
import com.ssm.manage.query.MemberCsRequest;
import com.ssm.manage.response.ResponseCode;

import com.ssm.manage.service.SsmMemberCsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;


@Api(value="门店会员评价controller",tags={"门店会员评价controller相关接口"})
@RestController
@RequestMapping("/demay/ssm/memberCs")
@Slf4j
public class SsmMemberCsController {
    @Autowired
    private SsmMemberCsService ssmMemberCsService;

    @ApiOperation(value = "查询门店会员评价记录list  会员微信小程序-查询门店会员账户交易记录list",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/selectRecentRecord")
    public GenericResponse selectRecentRecord(@RequestBody MemberCsRequest memberCsRequest, HttpSession session){
        GenericResponse<MemberCs> genericResponse = new GenericResponse<>();
        memberCsRequest.setStoreId(SessionHelp.getStoreId(session));
        List<MemberCs> lists = new ArrayList<>();
        try {
            lists = ssmMemberCsService.selectRecentRecord(memberCsRequest);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmMemberCsController.selectRecentRecord:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        genericResponse.setRows(lists);
        return genericResponse;
    }

    @ApiOperation(value = "门店会员评价  会员微信小程序-门店会员评价",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/appraise")
    public GenericResponse appraise(@RequestBody MemberCsRequest memberCsRequest){
        GenericResponse<MemberCs> genericResponse = new GenericResponse<>();
        int i = 0;
        try {
            i = ssmMemberCsService.appraise(memberCsRequest);
        }catch (Exception e){
            log.error("SsmMemberCsController.appraise:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }
}
