package com.bjtdba.system.controller;

import com.bjtdba.entity.system.FeedbackCategory;
import com.bjtdba.system.service.FeedbackCategoryService;
import com.bjtdba.system.vo.FeedbackVo;
import com.bjtdba.utils.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 用户反馈分类表(FeedbackCategory)表控制层
 *
 * @author 何海强
 * @since 2022-11-18 11:45:04
 */
@RestController
@RequestMapping("/system_service/feedbackCategory")
public class FeedbackCategoryController {
    /**
     * 服务对象
     */
    @Resource
    private FeedbackCategoryService feedbackCategoryService;

    /**
     * 查询反馈类型
     */


    @GetMapping("/feedback_type_new")
    public Object feedback_type_new(@RequestHeader Map<String,String> Hmap){

        if (!Hmap.containsKey("uid")) {
            return ResponseUtil.fail("uid 参数错误");
        }
        FeedbackCategory feedbackCategory=new FeedbackCategory();
        feedbackCategory.setLevel(1l);
        feedbackCategory.setIsShow(1);

        List<FeedbackCategory> feedbackCategoryList=feedbackCategoryService.quryList(feedbackCategory);
        return ResponseUtil.ok(feedbackCategoryList);
    }

    /**
     * 添加反馈意见
     * @param Hmap
     * @param map
     * @return
     */
    @PostMapping("/feedback")
    public Object feedback(@RequestHeader Map<String,String> Hmap,@RequestBody Map<String,String> map){

        if (!Hmap.containsKey("uid")) {
            return ResponseUtil.fail("uid 参数错误");
        }
        if (!map.containsKey("type")||!map.containsKey("content")||!map.containsKey("images")||!map.containsKey("realname")||!map.containsKey("contact")) {
            return ResponseUtil.fail("参数错误");
        }
        Integer uid=Integer.parseInt(Hmap.get("uid"));
        FeedbackVo feedbackVo=new FeedbackVo();
        feedbackVo.setIs_del(0);
        feedbackVo.setContact(map.get("contact"));
        feedbackVo.setContent(map.get("content"));
        feedbackVo.setCreate_time(new Date());
        feedbackVo.setUid(uid);
        feedbackVo.setImages(map.get("images"));
        feedbackVo.setType(Integer.parseInt(map.get("type")));
        feedbackVo.setRealname(map.get("realname"));
        feedbackCategoryService.insert(feedbackVo);
        return ResponseUtil.ok();
    }

}

