package com.ruoyi.project.training.spec.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.github.stuxuhai.jpinyin.PinyinException;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import com.ruoyi.common.sendEmail.IMailService;
import com.ruoyi.common.thread.Trainning.MeetingInvitationMailThread;
import com.ruoyi.common.thread.Trainning.MonthlyFeedbackMailThread;
import com.ruoyi.project.system.domain.SysMessage;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.service.ISysMessageService;
import com.ruoyi.project.system.service.ISysUserService;
import com.ruoyi.project.training.spec.domain.*;
import com.ruoyi.project.training.spec.domain.vo.TStFeedbackSeasonalVO;
import com.ruoyi.project.training.spec.domain.vo.TStFeedbackVO;
import com.ruoyi.project.training.spec.service.ITStPlanService;
import com.ruoyi.project.training.spec.service.ITStQuestionAnswerService;
import com.ruoyi.project.training.spec.service.ITStSuccessorScoreService;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.training.spec.service.ITStFeedbackService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 专项培训反馈Controller
 *
 * @author ruoyi
 * @date 2022-04-26
 */
@RestController
@RequestMapping("/spec/feedback")
@EnableScheduling
public class TStFeedbackController extends BaseController
{
    @Autowired
    private ISysMessageService sysMessageService;

    @Autowired
    private ITStFeedbackService tStFeedbackService;

    @Autowired
    private ITStPlanService tStPlanService;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private ITStQuestionAnswerService tStQuestionAnswerService;

    @Autowired
    private ITStSuccessorScoreService stSuccessorScoreService;

    @Autowired
    private IMailService mailService;

     /**
     * 保存季度反馈内容
     * @param feedbackSeasonalVO 季度反馈数据传输对象
     * @return
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:edit')")
    @PutMapping("/saveSeasonalFeedback")
    public AjaxResult saveSeasonalFeedback(@RequestBody TStFeedbackSeasonalVO feedbackSeasonalVO) {
        // 反馈id
        Long feedbackId = feedbackSeasonalVO.getFeedbackId();
        // 导师反馈内容
        String mentorFeedback = feedbackSeasonalVO.getMentorFeedback();
        // 问卷内容
        TStQuestionAnswer[] tStQuestionAnswerArray = feedbackSeasonalVO.gettStQuestionAnswerArray();
        // 季度反馈对象
        TStFeedback feedback = new TStFeedback();
        feedback.setId(feedbackId);
        feedback.setMentorFeedback(mentorFeedback);
        // 当前导师评分(14题总分)
        BigDecimal mentorFeedbackScoreSum = new BigDecimal("0.0");
        // 遍历问卷内容数组
        for (int i = 0; i < tStQuestionAnswerArray.length; i++) {
            TStQuestionAnswer answer = new TStQuestionAnswer();
            answer.setFeedbackId(feedbackId);
            answer.setQuestionId(tStQuestionAnswerArray[i].getQuestionId());
            // 根据问题和答案获取TStQuestionAnswer对象
            TStQuestionAnswer result = tStQuestionAnswerService.selectTStQuestionAnswer(answer);
            // TStQuestionAnswer表中不存在记录
            if (result == null) {
                answer.setAnswer(tStQuestionAnswerArray[i].getAnswer());
                // 新增TStQuestionAnswer对象
                tStQuestionAnswerService.insertTStQuestionAnswer(answer);
            } else {
                result.setAnswer(tStQuestionAnswerArray[i].getAnswer());
                // 更新TStQuestionAnswer对象
                tStQuestionAnswerService.updateTStQuestionAnswer(result);
            }
            // 导师评分累计
            switch (tStQuestionAnswerArray[i].getAnswer()) {
                case "1": mentorFeedbackScoreSum = mentorFeedbackScoreSum.add(new BigDecimal("100.0")); break;
                case "2": mentorFeedbackScoreSum = mentorFeedbackScoreSum.add(new BigDecimal("75.0")); break;
                case "3": mentorFeedbackScoreSum = mentorFeedbackScoreSum.add(new BigDecimal("50.0")); break;
                case "4": mentorFeedbackScoreSum = mentorFeedbackScoreSum.add(new BigDecimal("25.0")); break;
            }
        }
        // 当前导师评分(平均分)
        BigDecimal mentorFeedbackScore = mentorFeedbackScoreSum.divide(new BigDecimal("14.0"),1,BigDecimal.ROUND_HALF_UP);
        feedback.setFeedbackScore(mentorFeedbackScore.toString());
        // 保存季度反馈
        tStFeedbackService.updateTStFeedback(feedback);
        // 更新季度平均分
        this.updateSeasonalOverallScore(feedbackId);
        return AjaxResult.success();
    }

    /**
     * 更新季度平均分
     * @param feedbackId 当前节点id
     */
    private void updateSeasonalOverallScore(
            Long feedbackId
    ) {
        TStFeedback feedback = tStFeedbackService.selectTStFeedbackById(feedbackId);    // 当前节点
        TStFeedback parentNode = null;  // 父节点
        if (feedback.getParentId() == null) {   // 当前节点为父节点(本导师)
            // 设置当前节点为父节点
            parentNode = feedback;
        } else {   // 当前节点为子节点(受邀导师)
            // 根据当前节点parentId查询父节点
            parentNode = tStFeedbackService.selectTStFeedbackById(feedback.getParentId());
        }
        TStFeedback queryObj = new TStFeedback();
        queryObj.setParentId(parentNode.getId());
        // 查询子节点
        List<TStFeedback> childNodes = tStFeedbackService.selectTStFeedbackList(queryObj);
        BigDecimal sum = new BigDecimal("0.0");    // 子节点总分
        BigDecimal count = new BigDecimal("0.0");  // 子节点数量
        BigDecimal avg = new BigDecimal("0.0");    // 子节点平均分
        BigDecimal overall = new BigDecimal("0.0");    // 季度平均分
        for (TStFeedback childNode : childNodes) {
            if (childNode.getFeedbackScore()!=null) {
                count = count.add(new BigDecimal("1.0"));
            }
            sum = sum.add(new BigDecimal(childNode.getFeedbackScore()==null?"0.0":childNode.getFeedbackScore()));
        }
        // 计算子节点平均分
        if (!(new BigDecimal("0.0").equals(count))) {
            avg = sum.divide(count,1,BigDecimal.ROUND_HALF_UP);
        }
        // 计算季度平均分
        if (parentNode.getFeedbackScore() == null) { // 父节点没有分数，取子节点分数
            overall = avg;
        } else if (new BigDecimal("0.0").equals(avg)) {  // 子节点没有分数，取父节点分数
            overall = new BigDecimal(parentNode.getFeedbackScore());
        } else {    // 父节点占比60%，子节点平均分占比40%
            overall = (new BigDecimal(parentNode.getFeedbackScore()).multiply(new BigDecimal("0.6")))
                    .add(avg.multiply(new BigDecimal("0.4"))).divide(new BigDecimal("1.0"),1,BigDecimal.ROUND_HALF_UP);
        }
        parentNode.setOverallScore(overall.toString());
        // 更新季度平均分
        tStFeedbackService.updateTStFeedback(parentNode);
        // 更新继任者评分
        this.updateSuccessorScore(parentNode);
        return;
    }

    /**
     * 更新继任者评分
     * @param parentNode TStFeedback表父节点
     */
    private void updateSuccessorScore(TStFeedback parentNode) {
        TStSuccessorScore stSuccessorScore = new TStSuccessorScore();
        stSuccessorScore.setStaffId(parentNode.getSuccessorId());
        // 根据学员id获取继任者评分
        stSuccessorScore = stSuccessorScoreService.selectTStSuccessorScore(stSuccessorScore);
        if (stSuccessorScore != null) { // TStSuccessorScore表中存在记录
            switch (parentNode.getFeedbackSeason()) {   // 设置季度评分
                case "1":   // 第一季度
                    stSuccessorScore.setQuarterOne(parentNode.getOverallScore());
                    break;
                case "2":   // 第二季度
                    stSuccessorScore.setQuarterTwo(parentNode.getOverallScore());
                    break;
                case "3":   // 第三季度
                    stSuccessorScore.setQuarterThree(parentNode.getOverallScore());
                    break;
                case "4":   // 第四季度
                    stSuccessorScore.setQuarterFour(parentNode.getOverallScore());
                    // 总数
                    BigDecimal count = new BigDecimal("0.0");
                    // 总分
                    BigDecimal sum = new BigDecimal("0.0");
                    String quarterOneString = stSuccessorScore.getQuarterOne();
                    String quarterTwoString = stSuccessorScore.getQuarterTwo();
                    String quarterThreeString = stSuccessorScore.getQuarterThree();
                    String quarterFourString = stSuccessorScore.getQuarterFour();
                    if (quarterOneString != null) {
                        count = count.add(new BigDecimal("1.0"));
                        sum = sum.add(new BigDecimal(quarterOneString));
                    }
                    if (quarterTwoString != null) {
                        count = count.add(new BigDecimal("1.0"));
                        sum = sum.add(new BigDecimal(quarterTwoString));
                    }
                    if (quarterThreeString != null) {
                        count = count.add(new BigDecimal("1.0"));
                        sum = sum.add(new BigDecimal(quarterThreeString));
                    }
                    if (quarterFourString != null) {
                        count = count.add(new BigDecimal("1.0"));
                        sum = sum.add(new BigDecimal(quarterFourString));
                    }
                    // 年度评分 = 四季度总分 / 4
                    BigDecimal year = sum.divide(count,1,BigDecimal.ROUND_HALF_UP);
                    stSuccessorScore.setYear(year.toString());
                    break;
            }
            // 更新继任者评分
            stSuccessorScoreService.updateTStSuccessorScore(stSuccessorScore);
        } else {
            stSuccessorScore = new TStSuccessorScore();
            stSuccessorScore.setStaffId(parentNode.getSuccessorId());
            switch (parentNode.getFeedbackSeason()) {   // 设置季度评分
                case "1":   // 第一季度
                    stSuccessorScore.setQuarterOne(parentNode.getOverallScore());
                    break;
                case "2":   // 第二季度
                    stSuccessorScore.setQuarterTwo(parentNode.getOverallScore());
                    break;
                case "3":   // 第三季度
                    stSuccessorScore.setQuarterThree(parentNode.getOverallScore());
                    break;
                case "4":   // 第四季度
                    stSuccessorScore.setQuarterFour(parentNode.getOverallScore());
                    break;
            }
            // 新增继任者评分
            stSuccessorScoreService.insertTStSuccessorScore(stSuccessorScore);
        }
        return;
    }

    /**
     * 导师查询季度反馈列表
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:list')")
    @GetMapping("/list/mentor/season")
    public TableDataInfo listMentorSeason(TStFeedback tStFeedback)
    {
        // 获取当前登录用户
        Long userId = getUserId();
        SysUser sysUser = sysUserService.selectUserById(userId);
        String staffId = sysUser.getStaffId();
        // 设置导师ID为当前登录用户
        tStFeedback.setMentorId(staffId);
        // 设置反馈类型为“季度反馈”
        tStFeedback.setFeedbackType(3L);
        startPage();
        // 查询季度反馈列表
        List<TStFeedback> list = tStFeedbackService.selectTStFeedbackList(tStFeedback);
        // 月季度反馈VO列表
        List<TStFeedbackVO> newList = new ArrayList<>();
        for (TStFeedback feedback : list) {
            feedback.setMentorId(staffId);
            // 查询季度反馈中包含的计划列表
            List<TStPlan> monthlyTStPlanList = tStPlanService.selectSeasonalTStPlanList(feedback);
            // 季度反馈VO
            TStFeedbackVO tStFeedbackVO = new TStFeedbackVO();
            // 复制对象
            tStFeedbackVO.setId(feedback.getId());
            tStFeedbackVO.setFeedbackType(feedback.getFeedbackType());
            tStFeedbackVO.setFeedbackMonth(feedback.getFeedbackMonth());
            tStFeedbackVO.setFeedbackSeason(feedback.getFeedbackSeason());
            tStFeedbackVO.setFeedbackYear(feedback.getFeedbackYear());
            tStFeedbackVO.setMentorId(feedback.getMentorId());
            tStFeedbackVO.setSuccessorId(feedback.getSuccessorId());
            tStFeedbackVO.setParentId(feedback.getParentId());
            tStFeedbackVO.setPlanId(feedback.getPlanId());
            tStFeedbackVO.setSuccessorFeedback(feedback.getSuccessorFeedback());
            tStFeedbackVO.setMentorFeedback(feedback.getMentorFeedback());
            tStFeedbackVO.setFeedbackScore(feedback.getFeedbackScore());
            tStFeedbackVO.setFeedbackStatus(feedback.getFeedbackStatus());
            tStFeedbackVO.setMeetingDate(feedback.getMeetingDate());
            // 设置季度培训计划清单
            tStFeedbackVO.setPlanList(monthlyTStPlanList);
            newList.add(tStFeedbackVO);
        }
        return getDataTable(newList);
    }

    /**
     * 学员查询季度反馈列表
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:list')")
    @GetMapping("/list/successor/season")
    public TableDataInfo listSuccessorSeason(TStFeedback tStFeedback)
    {
        // 获取当前登录用户
        Long userId = getUserId();
        SysUser sysUser = sysUserService.selectUserById(userId);
        String staffId = sysUser.getStaffId();
        // 设置学员ID为当前登录用户
        tStFeedback.setSuccessorId(staffId);
        // 设置反馈类型为“月度反馈”
        tStFeedback.setFeedbackType(3L);
        startPage();
        // 查询jid季度反馈列表
        List<TStFeedback> list = tStFeedbackService.selectTStFeedbackList(tStFeedback);
        // 季度反馈VO列表
        List<TStFeedbackVO> newList = new ArrayList<>();
        for (TStFeedback feedback : list) {
            feedback.setSuccessorId(staffId);
            // 查询季度反馈中包含的计划列表
            List<TStPlan> monthlyTStPlanList = tStPlanService.selectSeasonalTStPlanList(feedback);
            // 季度反馈VO
            TStFeedbackVO tStFeedbackVO = new TStFeedbackVO();
            // 复制对象
            tStFeedbackVO.setId(feedback.getId());
            tStFeedbackVO.setFeedbackType(feedback.getFeedbackType());
            tStFeedbackVO.setFeedbackMonth(feedback.getFeedbackMonth());
            tStFeedbackVO.setFeedbackSeason(feedback.getFeedbackSeason());
            tStFeedbackVO.setFeedbackYear(feedback.getFeedbackYear());
            tStFeedbackVO.setMentorId(feedback.getMentorId());
            tStFeedbackVO.setSuccessorId(feedback.getSuccessorId());
            tStFeedbackVO.setParentId(feedback.getParentId());
            tStFeedbackVO.setPlanId(feedback.getPlanId());
            tStFeedbackVO.setSuccessorFeedback(feedback.getSuccessorFeedback());
            tStFeedbackVO.setMentorFeedback(feedback.getMentorFeedback());
            tStFeedbackVO.setFeedbackScore(feedback.getFeedbackScore());
            tStFeedbackVO.setFeedbackStatus(feedback.getFeedbackStatus());
            tStFeedbackVO.setMeetingDate(feedback.getMeetingDate());
            // 设置季度培训计划清单
            tStFeedbackVO.setPlanList(monthlyTStPlanList);
            newList.add(tStFeedbackVO);
        }
        System.out.println(newList);
        return getDataTable(newList);
    }

    /**
     * 导师查询月度反馈列表
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:list')")
    @GetMapping("/list/mentor/month")
    public TableDataInfo listMentorMonth(TStFeedback tStFeedback)
    {
        // 获取当前登录用户
        Long userId = getUserId();
        SysUser sysUser = sysUserService.selectUserById(userId);
        String staffId = sysUser.getStaffId();
        // 设置导师ID为当前登录用户
        tStFeedback.setMentorId(staffId);
        // 设置反馈类型为“月度反馈”
        tStFeedback.setFeedbackType(2L);
        startPage();
        // 查询月度反馈列表
        List<TStFeedback> list = tStFeedbackService.selectTStFeedbackList(tStFeedback);
        // 月度反馈VO列表
        List<TStFeedbackVO> newList = new ArrayList<>();
        for (TStFeedback feedback : list) {
            feedback.setMentorId(staffId);
            // 查询月度反馈中包含的计划列表
            List<TStPlan> monthlyTStPlanList = tStPlanService.selectMonthlyTStPlanList(feedback);
            // 月度反馈VO
            TStFeedbackVO tStFeedbackVO = new TStFeedbackVO();
            // 复制对象
            tStFeedbackVO.setId(feedback.getId());
            tStFeedbackVO.setFeedbackType(feedback.getFeedbackType());
            tStFeedbackVO.setFeedbackMonth(feedback.getFeedbackMonth());
            tStFeedbackVO.setFeedbackSeason(feedback.getFeedbackSeason());
            tStFeedbackVO.setFeedbackYear(feedback.getFeedbackYear());
            tStFeedbackVO.setMentorId(feedback.getMentorId());
            tStFeedbackVO.setSuccessorId(feedback.getSuccessorId());
            tStFeedbackVO.setParentId(feedback.getParentId());
            tStFeedbackVO.setPlanId(feedback.getPlanId());
            tStFeedbackVO.setSuccessorFeedback(feedback.getSuccessorFeedback());
            tStFeedbackVO.setMentorFeedback(feedback.getMentorFeedback());
            tStFeedbackVO.setFeedbackScore(feedback.getFeedbackScore());
            tStFeedbackVO.setFeedbackStatus(feedback.getFeedbackStatus());
            tStFeedbackVO.setMeetingDate(feedback.getMeetingDate());
            // 设置月度培训计划清单
            tStFeedbackVO.setPlanList(monthlyTStPlanList);
            newList.add(tStFeedbackVO);
        }
        return getDataTable(newList);
    }

    /**
     * 学员查询月度反馈列表
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:list')")
    @GetMapping("/list/successor/month")
    public TableDataInfo listSuccessorMonth(TStFeedback tStFeedback)
    {
        // 获取当前登录用户
        Long userId = getUserId();
        SysUser sysUser = sysUserService.selectUserById(userId);
        String staffId = sysUser.getStaffId();
        // 设置学员ID为当前登录用户
        tStFeedback.setSuccessorId(staffId);
        // 设置反馈类型为“月度反馈”
        tStFeedback.setFeedbackType(2L);
        startPage();
        // 查询月度反馈列表
        List<TStFeedback> list = tStFeedbackService.selectTStFeedbackList(tStFeedback);
        // 月度反馈VO列表
        List<TStFeedbackVO> newList = new ArrayList<>();
        for (TStFeedback feedback : list) {
            feedback.setSuccessorId(staffId);
            // 查询月度反馈中包含的计划列表
            List<TStPlan> monthlyTStPlanList = tStPlanService.selectMonthlyTStPlanList(feedback);
            // 月度反馈VO
            TStFeedbackVO tStFeedbackVO = new TStFeedbackVO();
            // 复制对象
            tStFeedbackVO.setId(feedback.getId());
            tStFeedbackVO.setFeedbackType(feedback.getFeedbackType());
            tStFeedbackVO.setFeedbackMonth(feedback.getFeedbackMonth());
            tStFeedbackVO.setFeedbackSeason(feedback.getFeedbackSeason());
            tStFeedbackVO.setFeedbackYear(feedback.getFeedbackYear());
            tStFeedbackVO.setMentorId(feedback.getMentorId());
            tStFeedbackVO.setSuccessorId(feedback.getSuccessorId());
            tStFeedbackVO.setParentId(feedback.getParentId());
            tStFeedbackVO.setPlanId(feedback.getPlanId());
            tStFeedbackVO.setSuccessorFeedback(feedback.getSuccessorFeedback());
            tStFeedbackVO.setMentorFeedback(feedback.getMentorFeedback());
            tStFeedbackVO.setFeedbackScore(feedback.getFeedbackScore());
            tStFeedbackVO.setFeedbackStatus(feedback.getFeedbackStatus());
            tStFeedbackVO.setMeetingDate(feedback.getMeetingDate());
            // 设置月度培训计划清单
            tStFeedbackVO.setPlanList(monthlyTStPlanList);
            newList.add(tStFeedbackVO);
        }
        return getDataTable(newList);
    }

    /**
     * 查询当前用户作为受邀导师的学员列表
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:list')")
    @GetMapping("/listInvitedSuccessor")
    public AjaxResult listInvitedSuccessor(TStFeedback tStFeedback)
    {
        // 获取当前登录用户
        Long userId = getUserId();
        SysUser sysUser = sysUserService.selectUserById(userId);
        String staffId = sysUser.getStaffId();
        tStFeedback.setMentorId(staffId);
        List<TStFeedback> list = tStFeedbackService.selectInvitedSuccessorList(tStFeedback);
        return AjaxResult.success(list);
    }

    /**
     * 查询专项培训反馈列表
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo list(TStFeedback tStFeedback)
    {
        startPage();
        List<TStFeedback> list = tStFeedbackService.selectTStFeedbackList(tStFeedback);
        return getDataTable(list);
    }

    /**
     * 导出专项培训反馈列表
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:export')")
    @Log(title = "专项培训反馈", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TStFeedback tStFeedback)
    {
        List<TStFeedback> list = tStFeedbackService.selectTStFeedbackList(tStFeedback);
        ExcelUtil<TStFeedback> util = new ExcelUtil<TStFeedback>(TStFeedback.class);
        return util.exportExcel(list, "feedback");
    }

    /**
     * 获取专项培训反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:query')")
    @GetMapping(value = "/getInfoByParams")
    public AjaxResult getInfoByParams(TStFeedback tStFeedback)
    {
        return AjaxResult.success(tStFeedbackService.selectTStFeedbackByParams(tStFeedback));
    }

    /**
     * 获取专项培训反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:query')")
    @GetMapping(value = "/getInfoByPlanId/{planId}")
    public AjaxResult getInfoByPlanId(@PathVariable("planId") Long planId)
    {
        return AjaxResult.success(tStFeedbackService.selectTStFeedbackByPlanId(planId));
    }

    /**
     * 获取专项培训反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tStFeedbackService.selectTStFeedbackById(id));
    }

    /**
     * 新增专项培训反馈
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:add')")
    @Log(title = "专项培训反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TStFeedback tStFeedback) throws PinyinException {
        // 新增受邀导师反馈记录
        if (tStFeedback.getParentId() != null) {
            // 根据学员staffId获取用户对象
            SysUser successor = sysUserService.selectUserByStaffId(tStFeedback.getSuccessorId());
            String successorName = successor.getNickName();
            String successorNameEN = PinyinHelper.convertToPinyinString(successorName, " ", PinyinFormat.WITHOUT_TONE);
            String feedbackYear = tStFeedback.getFeedbackYear();
            String feedbackSeason = tStFeedback.getFeedbackSeason();
            // 根据导师staffId获取用户对象
            SysUser mentor = sysUserService.selectUserByStaffId(tStFeedback.getMentorId());
            String email = mentor.getEmail();
            String mentorName = mentor.getNickName();
            String mentorNameEN = PinyinHelper.convertToPinyinString(mentorName, " ", PinyinFormat.WITHOUT_TONE);
            Date meetingDate = tStFeedbackService.selectTStFeedbackById(tStFeedback.getParentId()).getMeetingDate();
            String meetingDateString = "20" + (meetingDate.getYear() + "年" + (meetingDate.getMonth() + 1 + "月") + meetingDate.getDate() + "日").substring(1);
            // 系统通知
            SysMessage message = new SysMessage();
            message.setUserId(mentor.getUserId());
            message.setMsgTitle("您有一条系统消息");
            message.setMsgContent("您有一条季度汇报消息待查看");
            // 邮件通知导师
            MeetingInvitationMailThread meetingInvitationMailThread = new MeetingInvitationMailThread(
                    mailService, email, successorName, successorNameEN, mentorName, mentorNameEN,
                    feedbackYear, feedbackSeason, meetingDateString, sysMessageService, message);
            Thread thread = new Thread(meetingInvitationMailThread);
            thread.start();
        }
        return toAjax(tStFeedbackService.insertTStFeedback(tStFeedback));
    }

    /**
     * 修改专项培训反馈
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:edit')")
    @Log(title = "专项培训反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TStFeedback tStFeedback) throws PinyinException {
        TStFeedback feedback = tStFeedbackService.selectTStFeedbackById(tStFeedback.getId());
        Long feedbackType = feedback.getFeedbackType();
        if (feedbackType != null) {
            // 反馈类型为月度反馈
            if (feedback.getFeedbackType() == 2) {
                // 根据学员staffId获取用户对象
                SysUser successor = sysUserService.selectUserByStaffId(feedback.getSuccessorId());
                String email = successor.getEmail();
                String successorName = successor.getNickName();
                String successorNameEN = PinyinHelper.convertToPinyinString(successorName, " ", PinyinFormat.WITHOUT_TONE);
                String feedbackYear = feedback.getFeedbackYear();
                String feedbackMonth = feedback.getFeedbackMonth();
                // 根据导师staffId获取用户对象
                SysUser mentor = sysUserService.selectUserByStaffId(feedback.getMentorId());
                String mentorName = mentor.getNickName();
                String mentorNameEN = PinyinHelper.convertToPinyinString(mentorName, " ", PinyinFormat.WITHOUT_TONE);
                // 系统通知
                SysMessage message = new SysMessage();
                message.setUserId(successor.getUserId());
                message.setMsgTitle("您有一条系统消息");
                message.setMsgContent("您有一条月度反馈消息待查看");
                // 邮件通知学员
                MonthlyFeedbackMailThread monthlyFeedbackMailThread = new MonthlyFeedbackMailThread(
                        mailService, email, successorName, successorNameEN, mentorName, mentorNameEN,
                        feedbackYear, feedbackMonth, sysMessageService, message);
                Thread thread = new Thread(monthlyFeedbackMailThread);
                thread.start();
            }
        }
        return toAjax(tStFeedbackService.updateTStFeedback(tStFeedback));
    }

    /**
     * 删除专项培训反馈
     */
    @PreAuthorize("@ss.hasPermi('spec:feedback:remove')")
    @Log(title = "专项培训反馈", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tStFeedbackService.deleteTStFeedbackByIds(ids));
    }
}
