package com.ruoyi.web.controller.zdsz;

import cn.dev33.satoken.annotation.SaCheckPermission;
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.ZEngineeringCivil;
import com.ruoyi.zdsz.domain.bo.*;
import com.ruoyi.zdsz.domain.vo.*;
import com.ruoyi.zdsz.service.IZEngineeringCivilService;
import com.ruoyi.zdsz.service.IZEngineeringReviewService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 民用工程
 *
 * @author ruoyi
 * @date 2023-12-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zdsz/engineeringCivil")
public class ZEngineeringCivilController extends BaseController {

    private final IZEngineeringCivilService iZEngineeringCivilService;
    @Resource
    private IZEngineeringReviewService izEngineeringReviewService;


    /**
     * 根据某个行政区下所有小区进行施工统计（柱状图）
     */
    @GetMapping("selectByDistrictStatistics")
    public R<Map<String, List<?>>> selectByDistrictStatistics(String district) {
        return R.ok(iZEngineeringCivilService.selectByDistrictStatistics(district));
    }

    /**
     * 查询民用工程列表
     */
    //    @SaCheckPermission("zdsz:engineeringCivil:list")
    @GetMapping("/list")
    public TableDataInfo<ZEngineeringCivilVo> list(ZEngineeringCivilBo bo, PageQuery pageQuery) {
        return iZEngineeringCivilService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出民用工程列表
     */
    //    @SaCheckPermission("zdsz:engineeringCivil:export")
    @Log(title = "民用工程导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZEngineeringCivilBo bo, PageQuery pageQuery, HttpServletResponse response) {
        if ("indoor_engin".equals(bo.getEnginClassification())) {
            List<ZEngineeringCivilExportVos> zEngineeringCivilExportVos = iZEngineeringCivilService.exportList(bo);
            ExcelUtil.exportTemplate(Collections.singletonList(zEngineeringCivilExportVos), "民用工程-室内", "excel/civilExcel.xlsx", response);
        }else if ("courtyard".equals(bo.getEnginClassification())) {
            // 庭院
            List<ZEngineeringCivilExportVos> zEngineeringCivilExportVos = iZEngineeringCivilService.exportCcourtyardList(bo);
            ExcelUtil.exportTemplate(Collections.singletonList(zEngineeringCivilExportVos), "民用工程-庭院", "excel/CivilCourtyardExcel.xlsx", response);
        }else if ("overhead".equals(bo.getEnginClassification())) {
            // 架空
            List<ZEngineeringCivilExportVos> zEngineeringCivilExportVos = iZEngineeringCivilService.exportOverheadList(bo);
            ExcelUtil.exportTemplate(Collections.singletonList(zEngineeringCivilExportVos), "民用工程-架空", "excel/CivilOverheadExcel.xlsx", response);
        }else if ("bottom_leg".equals(bo.getEnginClassification())) {
            // 低腿
            List<ZEngineeringCivilExportVos> zEngineeringCivilExportVos = iZEngineeringCivilService.exportBottomLegList(bo);
            ExcelUtil.exportTemplate(Collections.singletonList(zEngineeringCivilExportVos), "民用工程-底腿", "excel/CivilBottLegExcel.xlsx", response);
        }
    }

    /**
     * 导出民用工程列表
     */
    //    @SaCheckPermission("zdsz:engineeringCivil:export")
    @Log(title = "民用工程导出带进度颜色", businessType = BusinessType.EXPORT)
    @PostMapping("/exportColor")
    public void exportColor(ZEngineeringCivilBo bo, PageQuery pageQuery, HttpServletResponse response) {
//            List<ZEngineeringCivilExportVos> zEngineeringCivilExportVos = iZEngineeringCivilService.exportList(bo);
            List<ZEngineeringCivilVo> zEngineeringCivilExportVos = iZEngineeringCivilService.queryAllList(bo);
            ExcelUtil.exportTemplate(Collections.singletonList(zEngineeringCivilExportVos), "民用工程-室内", "excel/civilExcelColor.xlsx", response);
    }

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

    /**
     * 获取民用工程详细信息
     */
    //    @SaCheckPermission("zdsz:engineeringCivil:query")
    @PostMapping("/query")
    public R<ZEngineeringCivilVo> query(@RequestBody ZEngineeringCivilBo zEngineeringCivilBo) {
        return R.ok(iZEngineeringCivilService.queryByEntityBo(zEngineeringCivilBo));
    }


    /**
     * 可视化进度点击房间查历史
     */
    //    @SaCheckPermission("zdsz:engineeringCivil:query")
    @PostMapping("/queryProcess")
    public R<ZEngineeringCivilVo> queryProcess(@RequestBody Map<String, String> params) {
        ZEngineeringCivilVo vo = iZEngineeringCivilService.queryProcess(params);
        return R.ok(vo);
    }

    /**
     * 获取民用工程节点信息
     *
     * @param id 主键
     */
    //    @SaCheckPermission("zdsz:engineeringCivil:query")
    @GetMapping("/{id}/{type}")
    public R<ZEngineeringCivilVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String id, @NotNull(message = "节点类型不能为空") @PathVariable String type) {
        return R.ok(iZEngineeringCivilService.query(id, type));
    }

    /**
     * 新增民用工程
     */

    @Log(title = "民用工程", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    //    @SaCheckPermission("zdsz:engineeringCivil:add")
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZEngineeringCivilBo bo) {
        return toAjax(iZEngineeringCivilService.insertByBo(bo));
    }

    /**
     * 修改民用工程
     */
    //    @SaCheckPermission("zdsz:engineeringCivil:edit")
    @Log(title = "民用工程", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZEngineeringCivilBo bo) {
        return toAjax(iZEngineeringCivilService.updateByBo(bo));
    }

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

    // @SaCheckPermission("zdsz:engineeringCivil:remove")
    @Log(title = "民用工程", businessType = BusinessType.OTHER)
    @PostMapping("/getObtainRoomcCompletionInformationList")
    public R getObtainRoomcCompletionInformationList(@RequestBody ZEngineeringCivilBo zEngineeringCivilBo) {
        return R.ok(iZEngineeringCivilService.getObtainRoomcCompletionInformationList(zEngineeringCivilBo));
    }

    //    @SaCheckPermission("zdsz:engineeringCivil:export")
    @Log(title = "民用工程", businessType = BusinessType.EXPORT)
    @PostMapping("/getAreaCompletionInformationListexport")
    public void getAreaCompletionInformationListexport(ZEngineeringCivilBo bo, HttpServletResponse response) {
        List<areaStatusVo> list = iZEngineeringCivilService.getAreaCompletionInformationList2(bo);
        ExcelUtil.exportExcel(list, "进度统计", areaStatusVo.class, response);
    }

    // @SaCheckPermission("zdsz:engineeringCivil:remove")
    @Log(title = "民用工程", businessType = BusinessType.DELETE)
    @GetMapping("/getAreaCompletionInformationList")
    public TableDataInfo getAreaCompletionInformationList(ZEngineeringCivilBo bo, PageQuery pageQuery) {
        return iZEngineeringCivilService.getAreaCompletionInformationList(bo, pageQuery);
    }

    @Log(title = "民用工程", businessType = BusinessType.DELETE)
    @GetMapping("/getsumStatus")
    public R<?> getsumStatus(ZEngineeringCivilBo bo) {
        return R.ok(iZEngineeringCivilService.getsumStatus(bo));
    }

    /**
     * 批量审核
     *
     * @param bo
     * @return
     */
    @Log(title = "民用工程", businessType = BusinessType.OTHER)
    @PostMapping("/batchReview")
    public R BatchReview(@RequestBody ZEngineeringCivilBo bo, @RequestBody ZEngineeringNodeBo zEngineeringNodeBo) {
        return R.ok(iZEngineeringCivilService.batchReview(bo, zEngineeringNodeBo));
    }

    /**
     * 审核
     *
     * @return
     */
    @Log(title = "通用审核", businessType = BusinessType.OTHER)
    @PostMapping("/Review")
    public R Review(@RequestBody ZEngineeringReviewBo zEngineeringReviewBo) {
        return R.ok(izEngineeringReviewService.insert(zEngineeringReviewBo));
    }

    /**
     * 民用审核
     *
     * @param zEngineeringReviewBo
     * @return
     */
    @Log(title = "民用工程", businessType = BusinessType.OTHER)
    @PostMapping("/CivilReview")
    public R Civilinsert(@RequestBody ZEngineeringReviewBo zEngineeringReviewBo, @RequestBody infoIdList infoIdList) {
        return R.ok(iZEngineeringCivilService.Civilinsert(zEngineeringReviewBo, infoIdList));
    }
    @Log(title = "工程审核", businessType = BusinessType.OTHER)
    @PostMapping("/insertReview")
    public R insertReview(@RequestBody ZEngineeringReviewBo zEngineeringReviewBo, @RequestBody infoIdList infoIdList) {
        return R.ok(iZEngineeringCivilService.insertReview(zEngineeringReviewBo, infoIdList));
    }

    /**
     * 民用获取各个节点状态
     *
     * @return
     */
    @Log(title = "民用工程", businessType = BusinessType.OTHER)
    @PostMapping("/getRivewStatus/{Id}")
    public R getRivewStatus(@PathVariable("Id") String Id) {
        return R.ok(iZEngineeringCivilService.getRivewStatus(Id));
    }

    @Log(title = "民用工程", businessType = BusinessType.OTHER)
    @PostMapping("/batchNode")
    public R batchNode(@RequestBody ZEngineeringCivilBo bo) {
        return R.ok(iZEngineeringCivilService.batchNode(bo));
    }
}
