package com.yonge.cooleshow.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.entity.SysSuggestion;
import com.yonge.cooleshow.biz.dal.queryInfo.SysSuggestionQueryInfo;
import com.yonge.cooleshow.biz.dal.service.SysSuggestionService;
import com.yonge.cooleshow.common.controller.BaseController;

@Api(tags = "意见反馈")
@RestController
public class SysSuggestionController extends BaseController {

    @Autowired
    private SysSuggestionService sysSuggestionService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "新增")
    @RequestMapping("sysSuggestion/add")
    @PreAuthorize("@pcs.hasPermissions('sysSuggestion/add')")
    public Object add(SysSuggestion sysSuggestion) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        sysSuggestion.setUserId(sysUser.getId().longValue());
        sysSuggestion.setClientType("TEACHER");
        if(StringUtils.isEmpty(sysSuggestion.getMobileNo())){
            sysSuggestion.setMobileNo(sysUser.getPhone());
        }
        sysSuggestionService.insert(sysSuggestion);
        return succeed();
    }

    @ApiOperation(value = "删除")
    @RequestMapping("sysSuggestion/del")
    @PreAuthorize("@pcs.hasPermissions('sysSuggestion/del')")
    public Object del(Long id) {
        sysSuggestionService.delete(id);
        return succeed();
    }

    @ApiOperation(value = "分页查询")
    @RequestMapping("sysSuggestion/queryPage")
    @PreAuthorize("@pcs.hasPermissions('sysSuggestion/queryPage')")
    public Object queryPage(SysSuggestionQueryInfo queryInfo) {
        return succeed(sysSuggestionService.queryPage(queryInfo));
    }

}
