package com.securitycontrol.system.base.controller;

import com.securitycontrol.common.core.web.controller.BaseController;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.common.core.web.page.TableDataInfo;
import com.securitycontrol.common.log.annotation.Log;
import com.securitycontrol.common.log.enums.OperationType;
import com.securitycontrol.entity.system.base.dto.GxPlanDto;
import com.securitycontrol.entity.system.base.dto.ProDto;
import com.securitycontrol.entity.system.base.vo.GxPlanVo;
import com.securitycontrol.entity.system.base.vo.ProVo;
import com.securitycontrol.system.base.service.IProService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author：cwchen
 * @date：2024-03-11-10:05
 * @version：1.0
 * @description：工程管理-web层
 */
@RestController
@RequestMapping("/sys/pro/")
public class ProController extends BaseController {

    @Resource(name = "IProService")
    private IProService service;

    @ApiOperation(value = "获取工程列表")
    @GetMapping("getProLists")
    @Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.QUERY_BUSINESS, details = "查询工程", type = "业务日志")
    public TableDataInfo getProLists(ProDto dto) {
        startPage();
        List<ProVo> list = service.getProLists(dto);
        return getDataTable(list);
    }

    @ApiOperation(value = "新增工程")
    @PostMapping("addPro")
    @Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.ADD_BUSINESS, details = "新增工程", type = "业务日志")
    public AjaxResult addPro(HttpServletRequest request, @RequestParam(value = "file[]", required = false) MultipartFile[] files, @RequestParam(value = "type[]", required = false) int[] types, String params) {
        return service.addOrUpdatePro(files, types, params);
    }

    @ApiOperation(value = "修改工程")
    @PostMapping("editPro")
    @Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.UPDATE_BUSINESS, details = "修改工程", type = "业务日志")
    public AjaxResult editPro(HttpServletRequest request, @RequestParam(value = "file[]", required = false) MultipartFile[] files, @RequestParam(value = "type[]", required = false) int[] types, String params) {
        return service.addOrUpdatePro(files, types, params);
    }

    @ApiOperation(value = "工程详情")
    @GetMapping("getProById")
    public AjaxResult getProById(ProDto dto) {
        return service.getProById(dto);
    }

    @ApiOperation(value = "删除工程")
    @PostMapping("delPro")
    @Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.DELETE_BUSINESS, details = "删除工程", type = "业务日志")
    public AjaxResult delPro(@RequestBody ProDto dto) {
        return service.delPro(dto);
    }


    @ApiOperation(value = "工程图片/平面图预览")
    @GetMapping("viewProFile")
    public AjaxResult viewProFile(ProDto dto) {
        return service.viewProFile(dto);
    }

    @ApiOperation(value = "工程信息导入")
    @PostMapping("importProData")
    @Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.IMPORT_BUSINESS, details = "工程信息导入")
    public AjaxResult importProData(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
        return service.importProData(file, request, response);
    }

    @ApiOperation(value = "工程完工")
    @PostMapping("editProStatus")
    @Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.IMPORT_BUSINESS, details = "工程完工")
    public AjaxResult editProStatus(@RequestBody ProVo vo) {
        return service.editProStatus(vo);
    }

    @ApiOperation(value = "获取工序列表")
    @GetMapping("getGxPlanLists")
    @Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.QUERY_BUSINESS, details = "查询工序计划", type = "业务日志")
    public TableDataInfo getGxPlanLists(GxPlanDto dto) {
        startPage();
        List<GxPlanVo> list = service.getGxPlanLists(dto);
        return getDataTable(list);
    }

    @ApiOperation(value = "新增工序计划")
    @PostMapping("addGxPlan")
    @Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.ADD_BUSINESS, details = "新增工序计划", type = "业务日志")
    public AjaxResult addGxPlan(@RequestBody GxPlanVo vo) {
        return service.addOrUpdateGxPlan(vo);
    }

    @ApiOperation(value = "修改工序计划")
    @PostMapping("editGxPlan")
    @Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.UPDATE_BUSINESS, details = "修改工序计划", type = "业务日志")
    public AjaxResult editGxPlan(@RequestBody GxPlanVo vo) {
        return service.addOrUpdateGxPlan(vo);
    }

    @ApiOperation(value = "工序计划详情")
    @GetMapping("getGxPlanById")
    public AjaxResult getGxPlanById(GxPlanDto dto) {
        return service.getGxPlanById(dto);
    }

    @ApiOperation(value = "删除工序计划")
    @PostMapping("delGxPlanById")
    @Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.DELETE_BUSINESS, details = "删除工序计划", type = "业务日志")
    public AjaxResult delGxPlanById(@RequestBody GxPlanDto dto) {
        return service.delGxPlanById(dto);
    }
}
