package com.ruoyi.web.controller.propertyRepair;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.propertyRepair.PropertyRepair;
import com.ruoyi.system.service.IPropertyRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 物业报修Controller
 *
 * @author boman
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/wuYe/repair")
public class PropertyRepairController extends BaseController {
    @Autowired
    private IPropertyRepairService propertyRepairService;

    /**
     * 查询物业报修列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:repair:list')")
    @GetMapping("/list")
    public TableDataInfo list(PropertyRepair propertyRepair) {
        startPage();
        List<PropertyRepair> list = propertyRepairService.selectPropertyRepairList(propertyRepair);
        return getDataTable(list);
    }

    /**
     * 查询我的物业报修列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:repair:myList')")
    @GetMapping("/myList")
    public TableDataInfo myList(PropertyRepair propertyRepair) {
        propertyRepair.setStaffId(getUserId());
        startPage();
        List<PropertyRepair> list = propertyRepairService.selectPropertyRepairList(propertyRepair);
        return getDataTable(list);
    }

    /**
     * 导出物业报修列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:repair:export')")
    @Log(title = "物业报修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyRepair propertyRepair) {
        List<PropertyRepair> list = propertyRepairService.selectPropertyRepairList(propertyRepair);
        ExcelUtil<PropertyRepair> util = new ExcelUtil<PropertyRepair>(PropertyRepair.class);
        util.exportExcel(response, list, "物业报修数据");
    }

    /**
     * 获取物业报修详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:repair:query')")
    @GetMapping(value = "/{repairId}")
    public AjaxResult getInfo(@PathVariable("repairId") Long repairId) {
        return success(propertyRepairService.selectPropertyRepairByRepairId(repairId));
    }

    /**
     * 新增物业报修
     */
    @PreAuthorize("@ss.hasPermi('wuYe:repair:add')")
    @Log(title = "物业报修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyRepair propertyRepair) {
        return toAjax(propertyRepairService.insertPropertyRepair(propertyRepair));
    }

    /**
     * 修改物业报修
     */
    @PreAuthorize("@ss.hasPermi('wuYe:repair:edit')")
    @Log(title = "物业报修", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody PropertyRepair propertyRepair) {
        return toAjax(propertyRepairService.updatePropertyRepair(propertyRepair));
    }

    /**
     * 删除物业报修
     */
    @PreAuthorize("@ss.hasPermi('wuYe:repair:remove')")
    @Log(title = "物业报修", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{repairIds}")
    public AjaxResult remove(@PathVariable Long[] repairIds) {
        return toAjax(propertyRepairService.deletePropertyRepairByRepairIds(repairIds));
    }

    /**
     * 指派物业报修人员
     */
    @PreAuthorize("@ss.hasPermi('wuYe:repair:assign')")
    @PostMapping("/assign")
    public AjaxResult assign(@RequestBody PropertyRepair propertyRepair) {
        return propertyRepairService.assign(propertyRepair);
    }

    /**
     * 物业保修一周统计（当前时间往前推7天）
     */
    @PreAuthorize("@ss.hasPermi('wuYe:repair:statistics:qx')")
    @GetMapping("/statistics/qx")
    public AjaxResult statisticsQx() {
        return propertyRepairService.statisticsQx();
    }
}
