package com.hzs.system.base.controller.api;



import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.system.ext.BdFeedbackExt;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.system.base.service.IBdFeedbackService;
import com.hzs.system.base.vo.FeedbackVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 意见反馈 前端控制器
 * </p>
 *
 * @author hzs
 * @since 2023-02-05
 */
@RestController
@RequestMapping("/api/feedback")
public class ApiFeedbackController extends BaseController {

    @Autowired
    IBdFeedbackService bdFeedbackService;

    /**
     * 添加意见反馈
     *
     * @return
     */
    @PostMapping("save")
    public AjaxResult save(@RequestBody FeedbackVO feedbackVO) {
        Integer type = feedbackVO.getType();
        String idea = feedbackVO.getIdea();
        if (null == type) {
            return AjaxResult.error("请选择反馈类型");
        }
        if (StringUtils.isEmpty(idea)) {
            return AjaxResult.error("请填写反馈内容");
        }
        feedbackVO.setPkMember(SecurityUtils.getUserId());
        feedbackVO.setPkCountry(SecurityUtils.getPkCountry());
        return toAjax(bdFeedbackService.saveFeedback(feedbackVO));
    }


    @GetMapping("index-list")
    public TableDataInfo indexList(Integer isShowDay) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        FeedbackVO feedbackVO = FeedbackVO.builder().pkCountry(pkCountry).isShowDay(isShowDay)
                .pkMember(SecurityUtils.getUserId())
                .build();
        startPage();
        Object[] objects = bdFeedbackService.selectFeedbackList(feedbackVO);
        TableDataInfo tableDataInfo = getDataTable((List<BdFeedbackExt>) objects[0]);
        tableDataInfo.setRows((List<FeedbackVO>) objects[1]);
        return tableDataInfo;
    }


    @GetMapping("index-detail")
    public AjaxResult index(Long pkId) {
        return AjaxResult.success(bdFeedbackService.showFeedbackVOById(pkId));
    }
}
