package com.fastbee.data.controller.xunjian;

import com.fastbee.common.annotation.Log;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.enums.BusinessType;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.xunjian.domain.XjInspectionRoutes;
import com.fastbee.xunjian.service.IXjInspectionRoutesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * 巡检路线Controller
 *
 * @author kenlixunjian
 * @date 2023-08-04
 */
@RestController
@RequestMapping("/inspection/routes")
public class XjInspectionRoutesController extends BaseController
{
    @Autowired
    private IXjInspectionRoutesService klxjInspectionRoutesService;

    /**
     * 查询巡检路线列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:routes:list')")
    @GetMapping("/list")
    public TableDataInfo list(XjInspectionRoutes klxjInspectionRoutes)
    {
        startPage();
        List<XjInspectionRoutes> list = klxjInspectionRoutesService.selectXjInspectionRoutesList(klxjInspectionRoutes);
        return getDataTable(list);
    }

    /**
     * 导出巡检路线列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:routes:export')")
    @Log(title = "巡检路线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XjInspectionRoutes klxjInspectionRoutes) {
        List<XjInspectionRoutes> list = klxjInspectionRoutesService.selectXjInspectionRoutesList(klxjInspectionRoutes);
        ExcelUtil<XjInspectionRoutes> util = new ExcelUtil<XjInspectionRoutes>(XjInspectionRoutes.class);
        util.exportExcel(response, list, "巡检路线数据");
    }




    /**
     * 获取巡检路线详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:routes:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(klxjInspectionRoutesService.selectXjInspectionRoutesById(id));
    }


    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('inspection:routes:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<XjInspectionRoutes> util = new ExcelUtil<XjInspectionRoutes>(XjInspectionRoutes.class);
        List<XjInspectionRoutes> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = klxjInspectionRoutesService.importData(userList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<XjInspectionRoutes> util = new ExcelUtil<XjInspectionRoutes>(XjInspectionRoutes.class);
        util.importTemplateExcel(response, "巡检对象数据");
    }

    /**
     * 新增巡检路线
     */
    @PreAuthorize("@ss.hasPermi('inspection:routes:add')")
    @Log(title = "巡检路线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XjInspectionRoutes klxjInspectionRoutes) {
        return toAjax(klxjInspectionRoutesService.insertXjInspectionRoutes(klxjInspectionRoutes));
    }

    /**
     * 修改巡检路线
     */
    @PreAuthorize("@ss.hasPermi('inspection:routes:edit')")
    @Log(title = "巡检路线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XjInspectionRoutes klxjInspectionRoutes)
    {
        return toAjax(klxjInspectionRoutesService.updateXjInspectionRoutes(klxjInspectionRoutes));
    }

    /**
     * 删除巡检路线
     */
    @PreAuthorize("@ss.hasPermi('inspection:routes:remove')")
    @Log(title = "巡检路线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(klxjInspectionRoutesService.deleteXjInspectionRoutesByIds(ids));
    }
}
