package com.yonge.cooleshow.student.controller;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.entity.Student;
import com.yonge.cooleshow.biz.dal.entity.SysSuggestion;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.service.StudentService;
import com.yonge.cooleshow.biz.dal.service.SysSuggestionService;
import com.yonge.cooleshow.common.controller.BaseController;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "意见反馈")
@RestController
@RequestMapping("${app-config.url.student:}")
public class SysSuggestionController extends BaseController {

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

    @Autowired
    private StudentService studentService;

    @ApiOperation(value = "新增")
    @RequestMapping("sysSuggestion/add")
    public Object add(SysSuggestion sysSuggestion) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        sysSuggestion.setUserId(sysUser.getId());
        sysSuggestion.setClientType("STUDENT");
        if(StringUtils.isEmpty(sysSuggestion.getMobileNo())){
            sysSuggestion.setMobileNo(sysUser.getPhone());
        }
        // 查询学生是否是机构学生 机构学生设置来源为机构
        Student student = studentService.getById(sysUser.getId());
        if (student.getTenantId() !=null && student.getTenantId() != -1) {
            sysSuggestion.setClientType(ClientEnum.TENANT_STUDENT.getCode());
        }

        sysSuggestionService.insert(sysSuggestion);
        return succeed();
    }

}
