package com.flossom.system.controller;

import java.util.List;
import java.io.IOException;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.flossom.common.core.domain.entity.CtLeaveMessage;
import com.flossom.common.core.domain.entity.WxUserMember;
import com.flossom.common.core.utils.poi.ExcelUtil;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.core.web.page.TableDataInfo;
import com.flossom.common.log.annotation.Log;
import com.flossom.common.log.enums.BusinessType;
import com.flossom.common.security.annotation.RequiresPermissions;
import com.flossom.system.service.IWxUserMemberService;
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.flossom.system.service.ICtLeaveMessageService;
/**
 * 共创管理-留言管理Controller
 *
 * @author flossom
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/leaveMessage")
public class CtLeaveMessageController extends BaseController
{
    @Autowired
    private ICtLeaveMessageService ctLeaveMessageService;
    @Autowired
    private IWxUserMemberService wxUserMemberService;

    /**
     * 查询共创管理-留言管理列表
     */
    @RequiresPermissions("system:leaveMessage:list")
    @GetMapping("/list")
    public TableDataInfo list(CtLeaveMessage ctLeaveMessage)
    {
        startPage();
//        List<CtLeaveMessage> list = ctLeaveMessageService.selectCtLeaveMessageList(ctLeaveMessage);
        List<CtLeaveMessage> list = ctLeaveMessageService.selectCtLeaveMessageByCondition(ctLeaveMessage);
//        for (CtLeaveMessage leaveMessage: list) {
//            System.out.println("获取到用户id="+leaveMessage.getUserId());
//            if (Objects.nonNull(leaveMessage.getUserId())) {
//                WxUserMember userMember = wxUserMemberService.selectWxUserMemberByIdInit(leaveMessage.getUserId());
//                System.out.println("获取到用户="+userMember);
//                leaveMessage.setWxUserMember(userMember);
//            }
//        }
        return getDataTable(list);
    }

    /**
     * 导出共创管理-留言管理列表
     */
    @RequiresPermissions("system:leaveMessage:export")
    @Log(title = "共创管理-留言管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtLeaveMessage ctLeaveMessage)
    {
        List<CtLeaveMessage> list = ctLeaveMessageService.selectCtLeaveMessageList(ctLeaveMessage);
        ExcelUtil<CtLeaveMessage> util = new ExcelUtil<CtLeaveMessage>(CtLeaveMessage.class);
        util.exportExcel(response, list, "共创管理-留言管理数据");
    }

    /**
     * 获取共创管理-留言管理详细信息
     */
    @RequiresPermissions("system:leaveMessage:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ctLeaveMessageService.selectCtLeaveMessageById(id));
    }

    /**
     * 新增共创管理-留言管理
     */
    @RequiresPermissions("system:leaveMessage:add")
    @Log(title = "共创管理-留言管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtLeaveMessage ctLeaveMessage)
    {
        return toAjax(ctLeaveMessageService.insertCtLeaveMessage(ctLeaveMessage));
    }

    /**
     * 修改共创管理-留言管理
     */
    @RequiresPermissions("system:leaveMessage:edit")
    @Log(title = "共创管理-留言管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtLeaveMessage ctLeaveMessage)
    {
        return toAjax(ctLeaveMessageService.updateCtLeaveMessage(ctLeaveMessage));
    }

    /**
     * 删除共创管理-留言管理
     */
    @RequiresPermissions("system:leaveMessage:remove")
    @Log(title = "共创管理-留言管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ctLeaveMessageService.deleteCtLeaveMessageByIds(ids));
    }
}
