package com.sv.oms.controller;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.oms.controller.OmsController;
import com.sv.entity.MemberMoneyLog;
import com.sv.service.oms.MemberMoneyLogService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 用户金额记录
 *
 * @author yechanglin
 * @since 2018-08-08
 */
@RestController
public class MemberMoneyLogController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(MemberMoneyLogController.class);
	
	@Resource
	private MemberMoneyLogService memberMoneyLogService;

	/**
	 * 分页查询用户金额记录
	 */
	@RequestMapping(value = "/member/money/logs", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination, Integer memberId) {
		return ResponseDTO.ok()
				.setPagination(memberMoneyLogService.findPage(pagination, memberId));
	}

	/**
	 * 查询用户金额记录信息
	 */
	@RequestMapping(value = "/member/money/log/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("memberMoneyLog", memberMoneyLogService.findById(id));
	}

	/**
	 * 保存用户金额记录
	 */
	@RequestMapping(value = "/member/money/log", method = RequestMethod.GET)
	public ResponseDTO save(MemberMoneyLog memberMoneyLog) {
		memberMoneyLogService.save(memberMoneyLog);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除用户金额记录
	 */
	@RequestMapping(value = "/member/money/log/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		memberMoneyLogService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

}
