package com.chushang.inspection.work.controller;
import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.log.annotation.SysLog;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.inspection.work.dto.WrkInfoPhoneImportDTO;
import com.chushang.inspection.work.query.WrkInfoQuery;
import com.chushang.inspection.work.service.WrkInfoPhoneService;
import com.chushang.security.annotation.RequiresPermissions;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
* 电话巡检工单信息(wrk_info_phone)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/wrk/info/phone")
@RequiredArgsConstructor
public class WrkInfoPhoneController {

    private final WrkInfoPhoneService infoPhoneService;

    /**
     * 查询工单
     */
    @SysLog(value = "电话工单", businessType = BusinessType.QUERY)
    @GetMapping("/dispatch/page")
    @RequiresPermissions("wrk:phone:page")
    public AjaxResult pageList(@Validated WrkInfoQuery query) {
        return AjaxResult.success(infoPhoneService.pageList(query));
    }

    /**
     * 导入电话工单, 读取之后返回数据
     */
    @SysLog(value = "电话工单read", businessType = BusinessType.IMPORT)
    @PostMapping(value = "/import/read")
    @RequiresPermissions("wrk:phone:import")
    public AjaxResult importRead(@RequestParam("file") MultipartFile file){
        return AjaxResult.success(infoPhoneService.importRead(file));
    }


    /**
     * 导入电话工单, 读取之后返回数据
     */
    @SysLog(value = "电话工单save",businessType = BusinessType.IMPORT)
    @PostMapping(value = "/import/save")
    @RequiresPermissions("wrk:phone:import")
    public AjaxResult importSave(@RequestBody List<WrkInfoPhoneImportDTO> dataList,
                               @RequestParam("taskId") Long taskId,
                               @RequestParam("lowerTaskId") Long lowerTaskId)
    {
        return infoPhoneService.importSave(dataList, taskId, lowerTaskId);
    }

    /**
     * 单条录入
     */
    @SysLog(value = "电话工单", businessType = BusinessType.INSERT)
    @PostMapping(value = "/save")
    @RequiresPermissions("wrk:phone:save")
    public AjaxResult saveInfo(@RequestBody WrkInfoPhoneImportDTO info,
                              @RequestParam("taskId") Long taskId,
                              @RequestParam("lowerTaskId") Long lowerTaskId)
    {
        return AjaxResult.success(infoPhoneService.saveInfo(info,taskId, lowerTaskId));
    }

    /**
     * todo
     * 单条修改
     */
    @SysLog(value = "电话工单", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{wrkId}")
    @RequiresPermissions("wrk:phone:save")
    public AjaxResult delInfo(@RequestBody WrkInfoPhoneImportDTO info,
                              @PathVariable Long wrkId)
    {
        return AjaxResult.success(infoPhoneService.updateInfo(info, wrkId));
    }

    /**
     * 单条删除
     */
    @SysLog(value = "电话工单", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/del/{wrkId}")
    @RequiresPermissions("wrk:phone:save")
    public AjaxResult delInfo(@PathVariable Long wrkId)
    {
        return AjaxResult.success(infoPhoneService.removeById(wrkId));
    }

}
