package org.springblade.modules.member.controller.pc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.member.entity.MemberAccountEntity;
import org.springblade.modules.member.service.IMemberAccountService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 *  控制器
 *
 * @author Chill
 */
@RestController
@AllArgsConstructor
@RequestMapping("/member_account")
@Api(value = "", tags = "")
public class MemberAccountController extends BladeController {

	private final IMemberAccountService memberAccountService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入member_account")
	public R<MemberAccountEntity> detail(MemberAccountEntity member_account) {
		MemberAccountEntity detail = memberAccountService.getOne(Condition.getQueryWrapper(member_account));
		return R.data(detail);
	}

	/**
	 * 分页 代码自定义代号
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入member_account")
	public R<IPage<MemberAccountEntity>> list(MemberAccountEntity member_account, Query query) {
		IPage<MemberAccountEntity> pages = memberAccountService.page(Condition.getPage(query), Condition.getQueryWrapper(member_account));
		return R.data(pages);
	}

	/**
	 * 新增 代码自定义代号
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入member_account")
	public R save(@Valid @RequestBody MemberAccountEntity member_account) {
		return R.status(memberAccountService.save(member_account));
	}

	/**
	 * 修改 代码自定义代号
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入member_account")
	public R update(@Valid @RequestBody MemberAccountEntity member_account) {
		return R.status(memberAccountService.updateById(member_account));
	}

	/**
	 * 新增或修改 代码自定义代号
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入member_account")
	public R submit(@Valid @RequestBody MemberAccountEntity member_account) {
		return R.status(memberAccountService.saveOrUpdate(member_account));
	}


	/**
	 * 删除 代码自定义代号
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(memberAccountService.deleteLogic(Func.toLongList(ids)));
	}

}
