package com.srs.web.controller.comprehensive;

import com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.page.TableDataInfo;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.comprehensive.domain.SrsComplaint;
import com.srs.comprehensive.service.ISrsComplaintService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 接诉即办Controller
 *
 * @author srs
 * @date 2024-07-18
 */
@RestController
@RequestMapping("/comprehensive/complaint")
@Api(value = "接诉即办", tags = "接诉即办")
public class SrsComplaintController extends BaseController {
    @Autowired
    private ISrsComplaintService srsComplaintService;

    /**
     * 查询【请填写功能名称】列表
     */
//@PreAuthorize("@ss.hasPermi('system:complaint:list')")
@GetMapping("/list")
@ApiOperation("分页查询")
    public TableDataInfo list(SrsComplaint srsComplaint)
    {
        startPage();
        List<SrsComplaint> list = srsComplaintService.selectSrsComplaintList(srsComplaint);

        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:export')")
    @Log(title = "【接诉即办】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出列表")
    public void export(HttpServletResponse response, SrsComplaint srsComplaint)
    {
        List<SrsComplaint> list = srsComplaintService.selectSrsComplaintList(srsComplaint);
        ExcelUtil<SrsComplaint> util = new ExcelUtil<SrsComplaint>(SrsComplaint.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(srsComplaintService.selectSrsComplaintById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:add')")
    @Log(title = "【接诉即办】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增")
    public AjaxResult add(@RequestBody SrsComplaint srsComplaint)
    {
        srsComplaint.setCreateId(getUserId());
        srsComplaint.setCreateTime(new Date());
        srsComplaint.setStatus("0");
        return toAjax(srsComplaintService.insertSrsComplaint(srsComplaint));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:edit')")
    @Log(title = "接诉即办", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改")
    public AjaxResult edit(@RequestBody SrsComplaint srsComplaint)
    {
        return toAjax(srsComplaintService.updateSrsComplaint(srsComplaint));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:remove')")
    @Log(title = "【接诉即办】", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(srsComplaintService.deleteSrsComplaintByIds(ids));
    }
    @PostMapping("/process")
    @ApiOperation("处理")
    public AjaxResult process(@RequestBody SrsComplaint srsComplaint)
    {

        SrsComplaint updateObj = new SrsComplaint();
        updateObj.setId(srsComplaint.getId());
        updateObj.setStatus("1");
        updateObj.setFeedback(srsComplaint.getFeedback());
        //添加反馈图片
        //updateObj.setPhotos(srsComplaint.getPhotos());
        updateObj.setUpdateId(getUserId());
        updateObj.setUpdateTime(new Date());
        return toAjax(srsComplaintService.updateSrsComplaint(updateObj));
    }

}
