package com.bizzan.bitrade.controller.swap;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Sort;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bizzan.bitrade.annotation.AccessLog;
import com.bizzan.bitrade.constant.AdminModule;
import com.bizzan.bitrade.constant.PageModel;
import com.bizzan.bitrade.controller.common.BaseAdminController;
import com.bizzan.bitrade.entity.CloseType;
import com.bizzan.bitrade.entity.CoinThumb;
import com.bizzan.bitrade.entity.ContractCoin;
import com.bizzan.bitrade.entity.Member;
import com.bizzan.bitrade.entity.MemberContractPosition;
import com.bizzan.bitrade.entity.QMember;
import com.bizzan.bitrade.entity.QMemberContractPosition;
import com.bizzan.bitrade.entity.QUserPurse;
import com.bizzan.bitrade.entity.UserPurse;
import com.bizzan.bitrade.model.screen.MemberContractPositionScreen;
import com.bizzan.bitrade.model.screen.TradingAccountScreen;
import com.bizzan.bitrade.model.vo.TradingAccountVo;
import com.bizzan.bitrade.service.ContractOrderEntrustService;
import com.bizzan.bitrade.service.MemberContractPositionService;
import com.bizzan.bitrade.service.MemberService;
import com.bizzan.bitrade.service.MemberWalletService;
import com.bizzan.bitrade.service.RedisLock;
import com.bizzan.bitrade.service.SysConfigService;
import com.bizzan.bitrade.service.UserPurseService;
import com.bizzan.bitrade.util.MessageResult;
import com.bizzan.bitrade.util.PredicateUtils;
import com.bizzan.bitrade.util.RedisManager;
import com.bizzan.bitrade.vo.MemberContractPositionWithCut;
import com.bizzan.bitrade.vo.TradingAccount;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.SubQueryExpression;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.JPAExpressions;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api(description="合约交易账户接口")
@RestController
@RequestMapping("/swap/account")
@Slf4j
public class TradingAccountController extends BaseAdminController {

	@Autowired
	private UserPurseService userPurseService;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    @Autowired
    private MemberService memberService;
    @Autowired
	private SysConfigService sysConfigService;
    @Autowired
    private MemberWalletService memberWalletService;
    @Autowired
    private ContractOrderEntrustService contractOrderEntrustService;
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
	@Autowired
	private RedisLock redisLock;
	@Autowired
	private MemberContractPositionService positionService;
	
	@RequiresPermissions("swap:account:get")
    @GetMapping("get")
    public MessageResult get(Long id) {
		UserPurse userPurse = userPurseService.findOne(id);
		return success(userPurse);
	}
	
	@ApiOperation(value="获取合约交易账户列表", notes="获取合约交易账户列表")
	@RequiresPermissions("swap:account:page-query")
    @PostMapping("page-query")
    @AccessLog(module = AdminModule.CONTRACTOPTION, operation = "合约交易账户列表")
	public MessageResult<Page<TradingAccount>> list(PageModel pageModel,
			TradingAccountScreen screen) {
		String serviceName = "contract-swap-api";
        String marketUrl = "http://" + serviceName + "/swap/symbol-price";

        ParameterizedTypeReference<Map<String, BigDecimal>> typeRef = new ParameterizedTypeReference<Map<String, BigDecimal>>() {};
        ResponseEntity<Map<String, BigDecimal>> responseEntity = restTemplate.exchange(marketUrl, HttpMethod.POST, new HttpEntity<>(null), typeRef);
        Map<String, BigDecimal> currentPriceMap =responseEntity.getBody();
        
        if (pageModel.getDirection() == null && pageModel.getProperty() == null) {
            ArrayList<Sort.Direction> directions = new ArrayList<>();
            directions.add(Sort.Direction.ASC);
            pageModel.setDirection(directions);
            List<String> property = new ArrayList<>();
            property.add("id"); // 默认金额排序
            pageModel.setProperty(property);
        }
        
        Predicate predicate = getPredicate(screen);
        
        Page<UserPurse> all = userPurseService.findAll(predicate, pageModel.getPageable());
        List<UserPurse> userPurseList = all.getContent();
		List<TradingAccount> retList = new ArrayList<TradingAccount>();
		for(UserPurse userPurse: userPurseList) {
			TradingAccount vo = new TradingAccountVo();
			BeanUtils.copyProperties(userPurse, vo);
			vo.setBlastMarginRate(sysConfigService.get().getContractMarginRate());
			//vo.setWalletList(memberContractWalletService.findAllByMemberId(userPurse.getId()));
			vo.setCashBalance(memberWalletService.sumBalanceByMemberId(userPurse.getId()));
			vo.setUsername(memberService.findUserNameById(userPurse.getId()));
			
			
			List<MemberContractPositionWithCut> positionList = new ArrayList<>();
			for(MemberContractPosition postion:userPurse.getCurrentPositionList()) {
				MemberContractPositionWithCut positionWithCut = new MemberContractPositionWithCut();
				BeanUtils.copyProperties(postion, positionWithCut);
				positionList.add(positionWithCut);
			}
			vo.setCurrentPositionWithCutList(positionList);

			vo.setCurrentPriceMap(currentPriceMap);
			
			BigDecimal blastRate = vo.getEstimatedBlastRate();
			
			List<MemberContractPositionWithCut> positions = vo.getCurrentPositionWithCutList();
			
			//List<MemberContractPositionWithCut> positionList = new ArrayList<MemberContractPositionWithCut>();
			for(MemberContractPositionWithCut position: positions) {
				//MemberContractPositionWithCut positionWithCut = new MemberContractPositionWithCut();
				//BeanUtils.copyProperties(position, positionWithCut);
				//positionWithCut.setCutList(contractCoinMatchFactory.getContractCoinMatch(position.getCoin().getSymbol()).findRunningCutOrders(position.getId()));
				position.setCutList(contractOrderEntrustService.queryEntrustCutOrdersByPositionId(position.getId()));
				if(blastRate.doubleValue()==0 || (blastRate.doubleValue() > 1 && blastRate.doubleValue() < 1000))
					position.setEstimatedBlastPrice(BigDecimal.valueOf(-1));
				else {
					if (position.getCurrentPrice()!=null)
						position.setEstimatedBlastPrice(position.getCurrentPrice().multiply(BigDecimal.ONE.subtract(blastRate)));
				}
				if(vo.getCurrentMargin().compareTo(BigDecimal.ZERO)>0)
					position.setMarginRate(vo.getCurrentCapital().multiply(BigDecimal.valueOf(100)).divide(vo.getCurrentMargin(), 2, BigDecimal.ROUND_DOWN));
				//positionList.add(positionWithCut);
			}
			//vo.setPositionsWithCut(positionList);
			
			retList.add(vo);
		}
		Page<TradingAccount> newAll = new PageImpl<TradingAccount>(retList, pageModel.getPageable(), all.getTotalElements());
		
		MessageResult<Page<TradingAccount>> result = MessageResult.success("success");
        result.setData(newAll);
        return result;
	}
	
	private Predicate getPredicate(TradingAccountScreen screen) {
		ArrayList<BooleanExpression> booleanExpressions = new ArrayList<>();
		QUserPurse qUserPurse = QUserPurse.userPurse;
		
        if(screen.getMemberId() != null) {
            booleanExpressions.add(qUserPurse.id.eq(screen.getMemberId()));
        }
        if(StringUtils.isNotEmpty(screen.getUsername())) {
            Member member = memberService.findByUsername(screen.getUsername());
            booleanExpressions.add(qUserPurse.id.eq(member.getId()));
        }
        if(StringUtils.isNotEmpty(screen.getPhone())) {
            Member member = memberService.findByPhone(screen.getPhone());
            booleanExpressions.add(qUserPurse.id.eq(member.getId()));
        }
        if(StringUtils.isNotEmpty(screen.getEmail())) {
            Member member = memberService.findByEmail(screen.getEmail());
            booleanExpressions.add(qUserPurse.id.eq(member.getId()));
        }
        if(screen.getHasPosition()!=null) {
        	if(screen.getHasPosition()==1)
        		booleanExpressions.add(qUserPurse.currentPositionList.size().gt(0));
        	else
        		booleanExpressions.add(qUserPurse.currentPositionList.size().eq(0));
        }
        if(screen.getIsSupervised()!=null) {
        	if(screen.getIsSupervised()==1)
        		booleanExpressions.add(qUserPurse.isSupervised.eq(1));
        	else
        		booleanExpressions.add(qUserPurse.isSupervised.ne(1));
        }
        if(screen.getIsTrader()!=null && screen.getIsTrader()>0) {
        	QMember qMember = QMember.member;
        	SubQueryExpression traderQuery = JPAExpressions.select(qMember.id).from(qMember)
        			.where(qMember.isTrader.gt(0));
        	booleanExpressions.add(qUserPurse.id.in(traderQuery));
        }
        return PredicateUtils.getPredicate(booleanExpressions);
	}
	
	@ApiOperation(value="获取交易员账户列表", notes="获取交易员账户列表")
	@RequiresPermissions("swap:account:page-query")
    @PostMapping("trader-page-query")
    @AccessLog(module = AdminModule.CONTRACTOPTION, operation = "交易员账户列表")
	public MessageResult<Page<TradingAccount>> traderList(PageModel pageModel,
			TradingAccountScreen screen) {
		log.info("【交易员持仓】收到请求 trader-page-query, pageNo={}, pageSize={}, memberId={}, phone={}, email={}, hasPosition={}, isTrader={}",
				pageModel.getPageNo(), pageModel.getPageSize(), screen.getMemberId(), screen.getPhone(), screen.getEmail(), screen.getHasPosition(), screen.getIsTrader());
		String serviceName = "contract-swap-api";
        String marketUrl = "http://" + serviceName + "/swap/symbol-price";

        ParameterizedTypeReference<Map<String, BigDecimal>> typeRef = new ParameterizedTypeReference<Map<String, BigDecimal>>() {};
        ResponseEntity<Map<String, BigDecimal>> responseEntity = restTemplate.exchange(marketUrl, HttpMethod.POST, new HttpEntity<>(null), typeRef);
        Map<String, BigDecimal> currentPriceMap =responseEntity.getBody();
        
        if (pageModel.getDirection() == null && pageModel.getProperty() == null) {
            ArrayList<Sort.Direction> directions = new ArrayList<>();
            directions.add(Sort.Direction.ASC);
            pageModel.setDirection(directions);
            List<String> property = new ArrayList<>();
            property.add("id"); // 默认金额排序
            pageModel.setProperty(property);
        }
        
        Predicate predicate = getPredicate(screen);
        
        Page<UserPurse> all = userPurseService.findAll(predicate, pageModel.getPageable());
        List<UserPurse> userPurseList = all.getContent();
		List<TradingAccount> retList = new ArrayList<TradingAccount>();
		for(UserPurse userPurse: userPurseList) {
			TradingAccount vo = new TradingAccountVo();
			BeanUtils.copyProperties(userPurse, vo);
			vo.setBlastMarginRate(sysConfigService.get().getContractMarginRate());
			//vo.setWalletList(memberContractWalletService.findAllByMemberId(userPurse.getId()));
			vo.setCashBalance(memberWalletService.sumBalanceByMemberId(userPurse.getId()));
			vo.setUsername(memberService.findUserNameById(userPurse.getId()));
			
			
			List<MemberContractPositionWithCut> positionList = new ArrayList<>();
			for(MemberContractPosition postion:userPurse.getCurrentPositionList()) {
				MemberContractPositionWithCut positionWithCut = new MemberContractPositionWithCut();
				BeanUtils.copyProperties(postion, positionWithCut);
				positionList.add(positionWithCut);
			}
			vo.setCurrentPositionWithCutList(positionList);

			vo.setCurrentPriceMap(currentPriceMap);
			
			BigDecimal blastRate = vo.getEstimatedBlastRate();
			
			List<MemberContractPositionWithCut> positions = vo.getCurrentPositionWithCutList();
			
			//List<MemberContractPositionWithCut> positionList = new ArrayList<MemberContractPositionWithCut>();
			for(MemberContractPositionWithCut position: positions) {
				//MemberContractPositionWithCut positionWithCut = new MemberContractPositionWithCut();
				//BeanUtils.copyProperties(position, positionWithCut);
				//positionWithCut.setCutList(contractCoinMatchFactory.getContractCoinMatch(position.getCoin().getSymbol()).findRunningCutOrders(position.getId()));
				position.setCutList(contractOrderEntrustService.queryEntrustCutOrdersByPositionId(position.getId()));
				if(blastRate.doubleValue()==0 || (blastRate.doubleValue() > 1 && blastRate.doubleValue() < 1000))
					position.setEstimatedBlastPrice(BigDecimal.valueOf(-1));
				else {
					if (position.getCurrentPrice()!=null)
						position.setEstimatedBlastPrice(position.getCurrentPrice().multiply(BigDecimal.ONE.subtract(blastRate)));
				}
				if(vo.getCurrentMargin().compareTo(BigDecimal.ZERO)>0)
					position.setMarginRate(vo.getCurrentCapital().multiply(BigDecimal.valueOf(100)).divide(vo.getCurrentMargin(), 2, BigDecimal.ROUND_DOWN));
				
				position.setFollowCount(positionService.countCurrentFollowPositionsByPositionId(position.getId()));
				//positionList.add(positionWithCut);
			}
			//vo.setPositionsWithCut(positionList);
			
			retList.add(vo);
		}
		Page<TradingAccount> newAll = new PageImpl<TradingAccount>(retList, pageModel.getPageable(), all.getTotalElements());
		
		MessageResult<Page<TradingAccount>> result = MessageResult.success("success");
        result.setData(newAll);
        return result;
	}
	
	@ApiOperation(value="设置交易账户是否被监控", notes="设置交易账户是否被监控")
	@ApiImplicitParams(value = {
    		@ApiImplicitParam(name = "id",value = "账户ID",required = true,paramType = "form",dataType = "int"),
    		@ApiImplicitParam(name = "isSupervised",value = "是否被监控 0未监控 1监控",required = true,paramType = "form",dataType = "int")
    })
	@RequiresPermissions("swap:account:update")
	@PostMapping("updateIsSupervised")
    public MessageResult updateIsSupervised(Long id, int isSupervised) {
		userPurseService.updateIsSupervised(id, isSupervised);
		return success();
	}
	
	@ApiOperation(value="刷新用户缓存", notes="刷新用户缓存")
	@ApiImplicitParams(value = {
    		@ApiImplicitParam(name = "id",value = "账户ID",required = true,paramType = "form",dataType = "int")
    })
	@RequiresPermissions("swap:account:update")
	@PostMapping("refresh")
    public MessageResult refreshAccount(Long id) {
		kafkaTemplate.send("trading-account-change", id+"");
		kafkaTemplate.send("follow-account-change", id+"");
		return success();
	}
	
	@ApiOperation(value="发布价格", notes="发布价格")
	@ApiImplicitParams(value = {
    		@ApiImplicitParam(name = "symbol",value = "合约symbol ex:BTC/USDT",required = true,paramType = "form",dataType = "string"),
    		@ApiImplicitParam(name = "price",value = "指定价格",required = true,paramType = "form",dataType = "double")
    })
	@RequiresPermissions("swap:account:update")
	@PostMapping("publishPrice")
    public MessageResult publishPrice(String symbol, BigDecimal price) {
		long time = System.currentTimeMillis()/1000;
		CoinThumb thumb = new CoinThumb();
        thumb.setSymbol(symbol);
        thumb.setOpen(price);
        thumb.setClose(price);
        thumb.setHigh(price);
        thumb.setLow(price);
        thumb.setVolume(BigDecimal.ONE);
        thumb.setTurnover(BigDecimal.ONE);
        //thumb.setTime(time);
        thumb.setChange(thumb.getClose().subtract(thumb.getOpen()));
        
        redisTemplate.convertAndSend("market-contract", JSON.toJSONString(thumb));
		return success();
	}
	
	@ApiOperation(value="交易员平仓", notes="交易员平仓")
	@ApiImplicitParams(value = {
    		@ApiImplicitParam(name = "symbol",value = "合约symbol ex:BTC/USDT",required = true,paramType = "form",dataType = "string"),
    		@ApiImplicitParam(name = "amount",value = "数量",required = true,paramType = "form",dataType = "double"),
    		@ApiImplicitParam(name = "direction",value = "方向 0：买入平空 1：卖出平多",required = true,paramType = "form",dataType = "int")
    })
	@RequiresPermissions("swap:account:update")
	@PostMapping("traderClose")
	@AccessLog(module = AdminModule.CONTRACTOPTION, operation = "交易员平仓")
    public MessageResult traderClose(Long memberId, String symbol, BigDecimal amount, BigDecimal openPrice, BigDecimal closePrice, int direction) {
		if(!redisLock.lockBySeconds("ADMIN_TRADER_CLOSE", 10))
			return this.error("操作太频繁");
		
		if (memberId == null) {
            return error("memberId不能为空");
        }
		if (symbol == null || symbol.equals("")) {
            return error("symbol不能为空");
        }
		if (amount == null) {
            return error("数量不能为空");
        }
		if (openPrice == null) {
            return error("开仓价格不能为空");
        }
		if (closePrice == null) {
            return error("平仓价格不能为空");
        }
		JSONObject obj = new JSONObject();
		obj.put("memberId", memberId);
		obj.put("symbol", symbol);
		obj.put("amount", amount);
		obj.put("openPrice", openPrice);
		obj.put("closePrice", closePrice);
		obj.put("direction", direction);
        
		kafkaTemplate.send("swap-special-trader-order-close", JSON.toJSONString(obj));
		
		return success();
	}
	
	@ApiOperation(value="交易员平仓", notes="交易员平仓")
	@ApiImplicitParams(value = {
    		@ApiImplicitParam(name = "symbol",value = "合约symbol ex:BTC/USDT",required = true,paramType = "form",dataType = "string"),
    		@ApiImplicitParam(name = "amount",value = "数量",required = true,paramType = "form",dataType = "double"),
    		@ApiImplicitParam(name = "direction",value = "方向 0：买入平空 1：卖出平多",required = true,paramType = "form",dataType = "int")
    })
	@RequiresPermissions("swap:account:update")
	@PostMapping("set-back-length")
	@AccessLog(module = AdminModule.CONTRACTOPTION, operation = "交易员平仓")
    public MessageResult setBackLength(int backLength) {
		log.info("【开仓前移】管理后台接收设置请求, backLength={}", backLength);
		JSONObject obj = new JSONObject();
		obj.put("backLength", backLength);
		String message = JSON.toJSONString(obj);
		log.info("【开仓前移】准备发送Kafka消息, topic=swap-inner-trader-set-back-length, message={}", message);
        
		try {
			kafkaTemplate.send("swap-inner-trader-set-back-length", message);
			log.info("【开仓前移】Kafka消息发送成功, backLength={}", backLength);
		} catch (Exception e) {
			log.error("【开仓前移】Kafka消息发送失败, backLength={}, error={}", backLength, e.getMessage(), e);
			return error("发送消息失败：" + e.getMessage());
		}
		
		return success();
	}
	
	@ApiOperation(value="重置交易员状态", notes="重置交易员状态")
	@RequiresPermissions("swap:account:update")
	@PostMapping("traderReset")
    public MessageResult traderReset(Long memberId, String symbol) {
		if(!redisLock.lockBySeconds("ADMIN_TRADER_CLOSE", 10))
			return this.error("操作太频繁");
		if (symbol == null || symbol.equals("")) {
            return error("symbol不能为空");
        }
		if (memberId == null) {
            return error("memberId不能为空");
        }
		
		UserPurse userPurse = userPurseService.findOne(memberId);
		Set<MemberContractPosition> set = userPurse.getCurrentPositionList();
		List<MemberContractPosition> list = new ArrayList<>();
		for(MemberContractPosition position: set) {
			if(position.getCoin().getSymbol().equals(symbol)) {
				list.add(position);
			}
		}
		if (list.size() == 0) {
            return error("当前没有仓位");
        }
		for(MemberContractPosition position : list) {
			position.setCloseType(CloseType.MARKET_CLOSE);
        	kafkaTemplate.send("swap-order-close-all", JSON.toJSONString(position));
        }
		
		JSONObject obj = new JSONObject();
		obj.put("memberId", memberId);
		obj.put("symbol", symbol);
		kafkaTemplate.send("swap-special-trader-reset", JSON.toJSONString(obj));
		
		return success();
	}
	
	@ApiOperation(value="获取合约行情", notes="获取合约行情")
	@RequiresPermissions("swap:account:page-query")
    @PostMapping("swapPrice")
	public MessageResult<Map<String, BigDecimal>> swapPrice() {
		String serviceName = "contract-swap-api";
        String marketUrl = "http://" + serviceName + "/swap/symbol-price";
        
        ParameterizedTypeReference<Map<String, BigDecimal>> typeRef = new ParameterizedTypeReference<Map<String, BigDecimal>>() {};
        ResponseEntity<Map<String, BigDecimal>> responseEntity = restTemplate.exchange(marketUrl, HttpMethod.POST, new HttpEntity<>(null), typeRef);
        Map<String, BigDecimal> currentPriceMap =responseEntity.getBody();
        
        MessageResult<Map<String, BigDecimal>> result = MessageResult.success("success");
        result.setData(currentPriceMap);
        return result;
	}
	
	@ApiOperation(value="获取特级交易员当前仓位", notes="获取特级交易员当前仓位")
	@ApiImplicitParams(value = {
    		@ApiImplicitParam(name = "symbol",value = "合约symbol ex:BTC/USDT",required = true,dataType = "string"),
    		@ApiImplicitParam(name = "memberId",value = "会员ID",required = true,dataType = "int")
    })
	@RequiresPermissions("swap:account:page-query")
    @PostMapping("traderAmount")
	public MessageResult<List<MemberContractPosition>> traderAmount(Long memberId, String symbol) {
		String serviceName = "contract-swap-api";
        String marketUrl = "http://" + serviceName + "/swap/symbol-price";

        ParameterizedTypeReference<Map<String, BigDecimal>> typeRef = new ParameterizedTypeReference<Map<String, BigDecimal>>() {};
        ResponseEntity<Map<String, BigDecimal>> responseEntity = restTemplate.exchange(marketUrl, HttpMethod.POST, new HttpEntity<>(null), typeRef);
        Map<String, BigDecimal> currentPriceMap =responseEntity.getBody();
        
		//Member member = memberService.getSpecialTrader();
		UserPurse userPurse = userPurseService.findOne(memberId);
		Set<MemberContractPosition> set = userPurse.getCurrentPositionList();
		List<MemberContractPosition> list = new ArrayList<>();
		for(MemberContractPosition position: set) {
			if(position.getCoin().getSymbol().equals(symbol)) {
				position.setCurrentPrice(currentPriceMap.get(symbol));
				list.add(position);
			}
		}
		MessageResult<List<MemberContractPosition>> result = MessageResult.success("success");
        result.setData(list);
        return result;
	}
	
	@ApiOperation(value="获取特级交易员列表", notes="获取特级交易员列表")
	@RequiresPermissions("swap:account:page-query")
    @PostMapping("traderList")
	public MessageResult<List<Member>> getSpecialTraderList() {
		List<Member> list = memberService.getSpecialTraders();
		MessageResult<List<Member>> result = MessageResult.success("success");
        result.setData(list);
        return result;
	}
}
