package com.ruoyi.web.controller.zdsz;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zdsz.domain.ZEngineeringGY;
import com.ruoyi.zdsz.domain.bo.ZEngineeringIndustryBo;
import com.ruoyi.zdsz.domain.bo.ZEngineeringIndustryGYBo;
import com.ruoyi.zdsz.domain.vo.ZEngineeringGYVo;
import com.ruoyi.zdsz.domain.vo.ZEngineeringIndustryTypeVo;
import com.ruoyi.zdsz.domain.vo.ZEngineeringIndustryVo;
import com.ruoyi.zdsz.service.IZEngineeringGYService;
import com.ruoyi.zdsz.service.IZEngineeringIndustryService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 工业工程
 *
 * @author ruoyi
 * @date 2024-01-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zdsz/engineeringGY")
public class ZEngineeringGYController extends BaseController {

    private final IZEngineeringGYService iZEngineeringIndustryService;


    /**
     * 查询工业工程
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:list")
    @GetMapping("/list")
    public TableDataInfo<ZEngineeringGYVo> list(ZEngineeringIndustryGYBo bo, PageQuery pageQuery) {
        return iZEngineeringIndustryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出工业工程列表
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:export")
    @Log(title = "工业工程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZEngineeringIndustryGYBo bo, HttpServletResponse response) {
        List<ZEngineeringGYVo> list = iZEngineeringIndustryService.queryList(bo);
        ExcelUtil.exportExcel(list, "工业工程", ZEngineeringGYVo.class, response);
    }

    /**
     * 获取工业工程详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:query")
    @GetMapping("/{id}")
    public R<ZEngineeringGYVo> getInfo(@NotNull(message = "主键不能为空")@PathVariable String id) {
        return R.ok(iZEngineeringIndustryService.queryById(id));
    }

    /**
     * 新增工业工程
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:add")
    @Log(title = "工业工程", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZEngineeringIndustryGYBo bo) {
        return toAjax(iZEngineeringIndustryService.insertByBo(bo));
    }

    @GetMapping("query/{id}/{type}")
    public R<ZEngineeringGYVo> querys(@NotNull(message = "主键不能为空") @PathVariable String id) {
        return R.ok(iZEngineeringIndustryService.query(id));
    }
    /**
     * 修改工业工程
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:edit")
    @Log(title = "工业工程", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZEngineeringIndustryGYBo bo) {
        return toAjax(iZEngineeringIndustryService.updateByBo(bo));
    }

    /**
     * 删除工业工程
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:remove")
    @Log(title = "工业工程", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")@PathVariable String[] ids) {
        return toAjax(iZEngineeringIndustryService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 工业工程历史
     *
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:query")
    @GetMapping("/{id}/{type}")
    public R<ZEngineeringGYVo> query(@PathVariable String id, @PathVariable String type) {
        return R.ok(iZEngineeringIndustryService.query(id, type));
    }

    /**
     * 工程分类与工程类型查询工业工程
     */
    @GetMapping("/queryByType")
//    @SaCheckPermission("zdsz:engineeringIndustry:type")
    public R<List<?>> queryNameByType(ZEngineeringIndustryGYBo bo) {
        return R.ok(iZEngineeringIndustryService.queryByType(bo));
    }

    /**
     * 工业工程修改工程
     */
    @PutMapping("/updateNodeByBo")
    @Log(title = "工业工程", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    public R<Void> updateNodeByBo(@Validated(EditGroup.class) @RequestBody ZEngineeringIndustryGYBo bo) {
        return toAjax(iZEngineeringIndustryService.updateNodeByBo(bo));
    }

}
