package com.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.response.PageResponse;
import com.ssm.manage.utils.SessionHelp;
import com.ssm.manage.entity.AccountTradeRecord;
import com.ssm.manage.query.AccountTradeRecordRequest;
import com.ssm.manage.response.AccountTradeRecordResponse;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmAccountTradeRecordService;
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;

@Api(value="门店会员账户交易记录controller",tags={"门店会员账户交易记录controller相关接口"})
@RestController
@RequestMapping("/demay/ssm/accountTrade")
@Slf4j
public class SsmAccountTradeRecordController {
    @Autowired
    private SsmAccountTradeRecordService ssmAccountTradeRecordService;

    @ApiOperation(value = "查询门店会员账户交易记录list  会员微信小程序-查询门店会员账户交易记录list",httpMethod = "POST",response = PageResponse.class)
    @RequestMapping("/listByMember")
    public PageResponse listByMember(@RequestBody AccountTradeRecordRequest accountTradeRecordRequest, HttpSession session){
        PageResponse<AccountTradeRecord> pageResponse = new PageResponse<>();
        accountTradeRecordRequest.setStoreId(SessionHelp.getStoreId(session));
        PageInfo<AccountTradeRecord> pageInfo = new PageInfo<>();
        try {
            pageInfo = ssmAccountTradeRecordService.selectPage(accountTradeRecordRequest);
        }catch (Exception e){
            log.error("SsmAccountTradeRecordController.listByMember:",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

    @ApiOperation(value = "查询门店会员账户交易记录list  会员微信小程序-查询门店会员账户交易记录list(新)",httpMethod = "POST",response = PageResponse.class)
    @RequestMapping("/listByMembers")
    public PageResponse listByMembers(@RequestBody AccountTradeRecordRequest accountTradeRecordRequest, HttpSession session){
        PageResponse<AccountTradeRecordResponse> pageResponse = new PageResponse<>();
        accountTradeRecordRequest.setStoreId(SessionHelp.getStoreId(session));
        PageInfo<AccountTradeRecordResponse> pageInfo = new PageInfo<>();
        try {
            pageInfo = ssmAccountTradeRecordService.selectPages(accountTradeRecordRequest);
        }catch (Exception e){
            log.error("SsmAccountTradeRecordController.listByMember:",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

    @ApiOperation(value = "查询门店会员账户交易记录list  会员微信小程序-查询门店会员账户交易记录list(新)",httpMethod = "POST",response = PageResponse.class)
    @RequestMapping("/listByMembersNew")
    public PageResponse listByMembersNew(@RequestBody AccountTradeRecordRequest accountTradeRecordRequest, HttpSession session){
        PageResponse<AccountTradeRecordResponse> pageResponse = new PageResponse<>();
        accountTradeRecordRequest.setStoreId(SessionHelp.getStoreId(session));
        PageInfo<AccountTradeRecordResponse> pageInfo = new PageInfo<>();
        try {
            pageInfo = ssmAccountTradeRecordService.selectPagesNew(accountTradeRecordRequest);
        }catch (Exception e){
            log.error("SsmAccountTradeRecordController.listByMember:",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

    @ApiOperation(value = "修改交易记录的会员名字",httpMethod = "POST",response = PageResponse.class)
    @RequestMapping("/updateMemberName")
    public GenericResponse updateMemberName(@RequestBody AccountTradeRecordRequest accountTradeRecordRequest, HttpSession session){
        GenericResponse genericResponse = new GenericResponse<>();
        try {
             ssmAccountTradeRecordService.updateMemberName(accountTradeRecordRequest);
        }catch (Exception e){
            log.error("SsmAccountTradeRecordController.listByMember:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }


}
