package com.app.controller.platform;

import com.app.annotation.platform.OperationLog;
import com.app.dto.PageResult;
import com.app.dto.Result;
import com.app.dto.SearchDto;
import com.app.dto.platform.AccountDto;
import com.app.dto.platform.ResponseAccountDto;
import com.app.dto.platform.SearchAccountDto;
import com.app.service.platform.auth.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 功能描述：
 * https://www.jianshu.com/p/cf9ad8c3621d
 *
 * @Auther: 梁展鹏
 * @Date: 2018/7/24 11:38
 */
@Api(tags = "账号管理")
@Slf4j
@RestController("PlatformAccountController")
@RequestMapping("/platform/account")
public class AccountController {

    @Resource
    private AccountService accountService;

    /**
     * 查询【账号】列表
     *
     */
    @ApiOperation(value = "查询[账号]列表")
    @PostMapping("/page")
    public ResponseEntity<Result<PageResult<ResponseAccountDto>>> page(@Valid @RequestBody SearchAccountDto params) {
        return new ResponseEntity(new Result<>().ok(accountService.page(params)), HttpStatus.OK);
    }

    /**
     * 保存/更新[账号]
     *
     */
    @OperationLog("更新 - 账号")
    @ApiOperation(value = "保存/更新[账号]")
    @PostMapping("/save-or-update")
    public ResponseEntity<Result> saveOrUpdate(@Valid @RequestBody AccountDto dto) {
        accountService.saveOrUpdate(dto);
        return new ResponseEntity(new Result().ok(), HttpStatus.OK);
    }

    /**
     * 删除【账号】
     */
    @OperationLog("替换删除状态 - 账号")
    @ApiOperation(value = "替换[账号]删除状态")
    @PostMapping("/handle-is-del")
    public ResponseEntity<Result> handleIsDel(@Valid @RequestBody SearchDto searchdto) {
        accountService.handleIsDel(searchdto.getId());
        return new ResponseEntity(new Result().ok(), HttpStatus.OK);
    }

}
