package com.yonge.cooleshow.admin.controller;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.toolset.base.page.PageInfo;
import com.yonge.toolset.mybatis.support.PageUtil;

import com.yonge.toolset.base.util.StringUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import com.yonge.cooleshow.biz.dal.vo.AuditReasonVo;
import com.yonge.cooleshow.biz.dal.dto.search.AuditReasonSearch;
import com.yonge.cooleshow.biz.dal.entity.AuditReason;
import com.yonge.cooleshow.biz.dal.service.AuditReasonService;

import java.util.Date;

@RestController
@RequestMapping("/auditReason")
@Api(value = "审核原因表", tags = "审核原因表")
public class AuditReasonController extends BaseController {
	@Autowired
	private SysUserFeignService sysUserFeignService;

    @Autowired
    private AuditReasonService auditReasonService;

	/**
     * 查询单条
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "详情", notes = "传入id")
    public HttpResponseResult<AuditReasonVo> detail(@PathVariable("id") Long id) {
    	return succeed(auditReasonService.detail(id));
	}
    
    /**
     * 查询分页
     */
    @PostMapping("/page")
    @ApiOperation(value = "查询分页", notes = "传入auditReasonSearch")
    public HttpResponseResult<PageInfo<AuditReasonVo>> page(@RequestBody AuditReasonSearch query) {
		IPage<AuditReasonVo> pages = auditReasonService.selectPage(PageUtil.getPage(query), query);
        return succeed(PageUtil.pageInfo(pages));
	}
    
    /**
	 * 新增
	 */
	@PostMapping("/save")
	@ApiOperation(value = "新增", notes = "传入auditReason")
	public HttpResponseResult save(@Valid @RequestBody AuditReason auditReason) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null  || sysUser.getId() == null) {
			return failed("用户信息获取失败");
		}
		auditReason.setCreateBy(sysUser.getId());
		auditReason.setCreateTime(new Date());
		auditReason.setUpdateBy(sysUser.getId());
		auditReason.setUpdateTime(new Date());
    	return status(auditReasonService.save(auditReason));
	}
    
    /**
	 * 修改
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "传入auditReason")
	public HttpResponseResult update(@Valid @RequestBody AuditReason auditReason) {

		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null  || sysUser.getId() == null) {
			return failed("用户信息获取失败");
		}
		auditReason.setUpdateBy(sysUser.getId());
		auditReason.setUpdateTime(new Date());
        return status(auditReasonService.updateById(auditReason));
	}


 	/**
	 * 删除
	 */
	@PostMapping("/remove/{id}")
	@ApiOperation(value = "删除", notes = "传入ids")
	public HttpResponseResult remove(@PathVariable Long id) {

		return status(auditReasonService.del(id));
	}
}