package com.ruoyi.web.controller.zdsz;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
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.StringUtils;
import com.ruoyi.common.utils.file.FolderToZipUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zdsz.domain.bo.ZEngineeringIndustryBo;
import com.ruoyi.zdsz.domain.vo.ZEngineeringIndustryTypeVo;
import com.ruoyi.zdsz.domain.vo.ZEngineeringIndustryVo;
import com.ruoyi.zdsz.mapper.ZEngineeringCivilMapper;
import com.ruoyi.zdsz.service.IZEngineeringIndustryService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.io.File;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * 工业工程|市政工程
 *
 * @author ruoyi
 * @date 2024-01-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zdsz/engineeringIndustry")
public class ZEngineeringIndustryController extends BaseController {

    private final IZEngineeringIndustryService iZEngineeringIndustryService;

    @GetMapping("getByUserList")
    public R<?> getByUserList(String type,String enginName,String enginType,String enginProcedure,String enginStatus,PageQuery pageQuery,String nodeType,String createBy,String enginClassification){
        return R.ok(iZEngineeringIndustryService.getByUserList(type,enginName,enginType,enginProcedure,enginStatus, pageQuery,nodeType,createBy,enginClassification));
    }

    @GetMapping("/getByUserListAndDicts/{dictType}")
    public R<?> getByUserListAndDicts(@PathVariable String dictType){
        return R.ok(iZEngineeringIndustryService.getByUserListAndDicts(dictType));
    }

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

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

    /**
     * 获取市政工程详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:query")
    @GetMapping("/{id}")
    public R<ZEngineeringIndustryVo> 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 ZEngineeringIndustryBo bo) {
        return toAjax(iZEngineeringIndustryService.insertByBo(bo));
    }

    @GetMapping("query/{id}/{type}")
    public R<ZEngineeringIndustryVo> 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 ZEngineeringIndustryBo 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<ZEngineeringIndustryVo> query(@PathVariable String id, @PathVariable String type) {
        return R.ok(iZEngineeringIndustryService.query(id, type));
    }

    /**
     * 工程分类查询市政工程
     */
    @GetMapping("/queryNameByType")
//    @SaCheckPermission("zdsz:engineeringIndustry:type")
    public R<List<ZEngineeringIndustryTypeVo>> queryNameByType(ZEngineeringIndustryBo bo) {
        return R.ok(iZEngineeringIndustryService.queryNameByType(bo));
    }

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

}
