Browse Source

add 资源都可以导出

459242451@qq.com 3 years ago
parent
commit
ac59c5110c

+ 96 - 25
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/ResourceDetailController.java

@@ -4,6 +4,7 @@ import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
 import cn.afterturn.easypoi.excel.entity.ExportParams;
 import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
 import cn.afterturn.easypoi.view.PoiBaseView;
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.annotation.Log;
@@ -20,8 +21,12 @@ import com.ruoyi.system.service.ISysDictTypeService;
 import com.ruoyi.zhdd.domain.Resource;
 import com.ruoyi.zhdd.domain.ResourceDetail;
 import com.ruoyi.zhdd.domain.bo.ResourceDetailBo;
+import com.ruoyi.zhdd.domain.vo.ResourceCarDetailExport;
+import com.ruoyi.zhdd.domain.vo.ResourceCarDetailVo;
 import com.ruoyi.zhdd.domain.vo.ResourceDetailExport;
 import com.ruoyi.zhdd.domain.vo.ResourceDetailVo;
+import com.ruoyi.zhdd.domain.vo.ResourceTeamDetailExport;
+import com.ruoyi.zhdd.domain.vo.ResourceTeamDetailVo;
 import com.ruoyi.zhdd.domain.vo.ResourceVo;
 import com.ruoyi.zhdd.service.IResourceDetailService;
 import com.ruoyi.zhdd.service.IResourceService;
@@ -83,38 +88,104 @@ public class ResourceDetailController extends BaseController {
     @Log(title = "应急资源明细", businessType = BusinessType.EXPORT)
     @GetMapping("/export/{ids}")
     public void export(@PathVariable String[] ids, HttpServletResponse response, HttpServletRequest request, ModelMap modelMap) {
-        List<ResourceDetailVo> list = iResourceDetailService.listVo(Wrappers.<ResourceDetail>lambdaQuery()
-            .in(ResourceDetail::getResourceId, Arrays.asList(ids)).orderByAsc(ResourceDetail::getResourceId));
-        // 查询仓库名称
-        List<Resource> list1 = resourceService.list(Wrappers.<Resource>lambdaQuery().in(Resource::getId, Arrays.asList(ids)));
-        Map<String, Resource> collect = list1.stream().collect(Collectors.toMap(Resource::getId, a -> a));
+        // 物资明细
+        List<ResourceDetailVo> detailList = iResourceDetailService.listVo(Wrappers.<ResourceDetail>lambdaQuery()
+            .in(ResourceDetail::getResourceId, Arrays.asList(ids)));
 
-        Map<String, List<ResourceDetailVo>> collect1 = list.stream().collect(Collectors.groupingBy(ResourceDetailVo::getResourceId));
+        // 查询仓库名称
+        List<Resource> resourceList = resourceService.list(Wrappers.<Resource>lambdaQuery().in(Resource::getId, Arrays.asList(ids)));
+        Map<String, Resource> resourceCollect = resourceList.stream().collect(Collectors.toMap(Resource::getId, a -> a));
 
         // 行业主管单位
         List<SysDictData> zhdd_admin_org = dictTypeService.selectDictDataByType("zhdd_admin_org");
         Map<String, String> adminOrgCollect = zhdd_admin_org.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
 
-        List<ResourceDetailExport> exportList = new ArrayList<>();
-        for (Map.Entry<String, List<ResourceDetailVo>> stringListEntry : collect1.entrySet()) {
-            ResourceDetailExport bean = new ResourceDetailExport();
-            Resource resource = collect.get(stringListEntry.getKey());
-            bean.setAdminOrgName(StrUtil.isNotBlank(resource.getAdminOrgName()) ? adminOrgCollect.get(resource.getAdminOrgName()) : "");
-            bean.setResourceName(resource.getName());
-            bean.setManageUnit(resource.getManageUnit());
-            bean.setContactName(resource.getContactName());
-            bean.setContactPhone(resource.getContactPhone());
-            bean.setAddress(resource.getAddress());
-            bean.setDetail(stringListEntry.getValue());
-            exportList.add(bean);
+        // 根据仓库的类型判断走哪一种导出bean
+        if (resourceList.size() > 0) {
+            Integer resourceType = resourceList.get(0).getResourceType();
+            if (resourceType == 1) {
+                // 应急仓库
+                List<ResourceDetailExport> exportList = new ArrayList<>();
+                Map<String, List<ResourceDetailVo>> detailCollect = detailList.stream().collect(Collectors.groupingBy(ResourceDetailVo::getResourceId));
+                for (Map.Entry<String, List<ResourceDetailVo>> stringListEntry : detailCollect.entrySet()) {
+                    ResourceDetailExport bean = new ResourceDetailExport();
+                    Resource resource = resourceCollect.get(stringListEntry.getKey());
+                    bean.setAdminOrgName(StrUtil.isNotBlank(resource.getAdminOrgName()) ? adminOrgCollect.get(resource.getAdminOrgName()) : "");
+                    bean.setResourceName(resource.getName());
+                    bean.setManageUnit(resource.getManageUnit());
+                    bean.setContactName(resource.getContactName());
+                    bean.setContactPhone(resource.getContactPhone());
+                    bean.setAddress(resource.getAddress());
+                    bean.setDetail(stringListEntry.getValue());
+                    exportList.add(bean);
+                }
+                ExportParams params = new ExportParams("仓库物资明细", "仓库物资", ExcelType.XSSF);
+                params.setFreezeCol(6);
+                modelMap.put(NormalExcelConstants.DATA_LIST, exportList);
+                modelMap.put(NormalExcelConstants.CLASS, ResourceDetailExport.class);
+                modelMap.put(NormalExcelConstants.PARAMS, params);
+                modelMap.put(NormalExcelConstants.FILE_NAME, "仓库物资明细");
+                PoiBaseView.render(modelMap, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
+            } else if (resourceType == 2) {
+                // 应急队伍
+                List<ResourceTeamDetailExport> exportList = new ArrayList<>();
+                List<ResourceTeamDetailVo> teamDetailList = new ArrayList<>();
+                for (ResourceDetailVo resourceDetailVo : detailList) {
+                    ResourceTeamDetailVo resourceTeamDetailVo = new ResourceTeamDetailVo();
+                    BeanUtil.copyProperties(resourceDetailVo, resourceTeamDetailVo);
+                    teamDetailList.add(resourceTeamDetailVo);
+                }
+                Map<String, List<ResourceTeamDetailVo>> detailCollect = teamDetailList.stream().collect(Collectors.groupingBy(ResourceTeamDetailVo::getResourceId));
+                for (Map.Entry<String, List<ResourceTeamDetailVo>> stringListEntry : detailCollect.entrySet()) {
+                    ResourceTeamDetailExport bean = new ResourceTeamDetailExport();
+                    Resource resource = resourceCollect.get(stringListEntry.getKey());
+                    bean.setAdminOrgName(StrUtil.isNotBlank(resource.getAdminOrgName()) ? adminOrgCollect.get(resource.getAdminOrgName()) : "");
+                    bean.setResourceName(resource.getName());
+                    bean.setManageUnit(resource.getManageUnit());
+                    bean.setContactName(resource.getContactName());
+                    bean.setContactPhone(resource.getContactPhone());
+                    bean.setAddress(resource.getAddress());
+                    bean.setDetail(stringListEntry.getValue());
+                    exportList.add(bean);
+                }
+                ExportParams params = new ExportParams("队伍物资明细", "队伍物资", ExcelType.XSSF);
+                params.setFreezeCol(6);
+                modelMap.put(NormalExcelConstants.DATA_LIST, exportList);
+                modelMap.put(NormalExcelConstants.CLASS, ResourceTeamDetailExport.class);
+                modelMap.put(NormalExcelConstants.PARAMS, params);
+                modelMap.put(NormalExcelConstants.FILE_NAME, "队伍物资明细");
+                PoiBaseView.render(modelMap, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
+            } else if (resourceType == 3) {
+                // 应急车船
+                List<ResourceCarDetailExport> exportList = new ArrayList<>();
+                List<ResourceCarDetailVo> carDetailList = new ArrayList<>();
+                for (ResourceDetailVo resourceDetailVo : detailList) {
+                    ResourceCarDetailVo resourceCarDetailVo = new ResourceCarDetailVo();
+                    BeanUtil.copyProperties(resourceDetailVo, resourceCarDetailVo);
+                    carDetailList.add(resourceCarDetailVo);
+                }
+                Map<String, List<ResourceCarDetailVo>> detailCollect = carDetailList.stream().collect(Collectors.groupingBy(ResourceCarDetailVo::getResourceId));
+                for (Map.Entry<String, List<ResourceCarDetailVo>> stringListEntry : detailCollect.entrySet()) {
+                    ResourceCarDetailExport bean = new ResourceCarDetailExport();
+                    Resource resource = resourceCollect.get(stringListEntry.getKey());
+                    bean.setAdminOrgName(StrUtil.isNotBlank(resource.getAdminOrgName()) ? adminOrgCollect.get(resource.getAdminOrgName()) : "");
+                    bean.setManageUnit(resource.getManageUnit());
+                    bean.setContactName(resource.getContactName());
+                    bean.setContactPhone(resource.getContactPhone());
+                    bean.setAddress(resource.getAddress());
+                    bean.setDetail(stringListEntry.getValue());
+                    exportList.add(bean);
+                }
+                ExportParams params = new ExportParams("车船物资明细", "车船物资", ExcelType.XSSF);
+                params.setFreezeCol(5);
+                modelMap.put(NormalExcelConstants.DATA_LIST, exportList);
+                modelMap.put(NormalExcelConstants.CLASS, ResourceCarDetailExport.class);
+                modelMap.put(NormalExcelConstants.PARAMS, params);
+                modelMap.put(NormalExcelConstants.FILE_NAME, "车船物资明细");
+                PoiBaseView.render(modelMap, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
+            }
         }
-        ExportParams params = new ExportParams("仓库物资明细", "仓库物资", ExcelType.XSSF);
-        params.setFreezeCol(5);
-        modelMap.put(NormalExcelConstants.DATA_LIST, exportList);
-        modelMap.put(NormalExcelConstants.CLASS, ResourceDetailExport.class);
-        modelMap.put(NormalExcelConstants.PARAMS, params);
-        modelMap.put(NormalExcelConstants.FILE_NAME, "仓库物资明细");
-        PoiBaseView.render(modelMap, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
+
     }
 
     /**

+ 48 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/vo/ResourceCarDetailExport.java

@@ -0,0 +1,48 @@
+package com.ruoyi.zhdd.domain.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+
+/**
+ * 应急资源明细视图对象 b_resource_detail
+ *
+ * @author xintong
+ * @date 2021-10-27
+ */
+@Data
+@ApiModel("应急车船资源明细导出视图对象")
+public class ResourceCarDetailExport {
+
+    private static final long serialVersionUID = 1L;
+
+    @Excel(name = "行业主管部门 ", needMerge = true, width = 25)
+    private String adminOrgName;
+
+    /**
+     * 资源id
+     */
+    @ApiModelProperty("资源id")
+    private String resourceId;
+
+    @Excel(name = "管理单位", needMerge = true, width = 25)
+    private String manageUnit;
+
+    @Excel(name = "联系人", needMerge = true)
+    private String contactName;
+
+    @Excel(name = "联系电话", needMerge = true, width = 13)
+    private String contactPhone;
+
+    @Excel(name = "地址", width = 15, needMerge = true)
+    private String address;
+
+    @ExcelCollection(name = "明细")
+    private List<ResourceCarDetailVo> detail;
+
+}

+ 38 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/vo/ResourceCarDetailVo.java

@@ -0,0 +1,38 @@
+package com.ruoyi.zhdd.domain.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+
+/**
+ * 应急资源明细视图对象 b_resource_detail
+ *
+ * @author xintong
+ * @date 2021-10-27
+ */
+@Data
+@ApiModel("应急车辆资源明细视图对象")
+public class ResourceCarDetailVo {
+
+    /**
+     * 资源id
+     */
+    @ApiModelProperty("资源id")
+    private String resourceId;
+
+    @Excel(name = "车牌号(船名号)", width = 20)
+    private String name;
+
+    @Excel(name = "类型", width = 20)
+    private String carType;
+
+    @Excel(name = "车船类型", width = 20)
+    private String carDetailType;
+
+    @Excel(name = "限载量", width = 20)
+    private String carLimit;
+
+
+}

+ 54 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/vo/ResourceTeamDetailExport.java

@@ -0,0 +1,54 @@
+package com.ruoyi.zhdd.domain.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+
+/**
+ * 应急资源明细视图对象 b_resource_detail
+ *
+ * @author xintong
+ * @date 2021-10-27
+ */
+@Data
+@ApiModel("应急队伍资源明细导出视图对象")
+public class ResourceTeamDetailExport {
+
+    private static final long serialVersionUID = 1L;
+
+    @Excel(name = "行业主管部门 ", needMerge = true, width = 25)
+    private String adminOrgName;
+
+    /**
+     * 资源id
+     */
+    @ApiModelProperty("资源id")
+    private String resourceId;
+
+    @Excel(name = "管理单位", needMerge = true, width = 25)
+    private String manageUnit;
+
+    @Excel(name = "队伍名称", needMerge = true, width = 25)
+    private String resourceName;
+
+    @Excel(name = "联系人", needMerge = true)
+    private String contactName;
+
+    /**
+     * 联系电话
+     */
+    @Excel(name = "联系电话", needMerge = true, width = 13)
+    private String contactPhone;
+
+    @Excel(name = "地址", width = 15, needMerge = true)
+    private String address;
+
+    @ExcelCollection(name = "明细")
+    private List<ResourceTeamDetailVo> detail;
+
+}

+ 49 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/vo/ResourceTeamDetailVo.java

@@ -0,0 +1,49 @@
+package com.ruoyi.zhdd.domain.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+
+/**
+ * 应急资源明细视图对象 b_resource_detail
+ *
+ * @author xintong
+ * @date 2021-10-27
+ */
+@Data
+@ApiModel("应急队伍明细视图对象")
+public class ResourceTeamDetailVo {
+
+    /**
+     * 资源id
+     */
+    @ApiModelProperty("资源id")
+    private String resourceId;
+
+    @Excel(name = "姓名", width = 20)
+    private String name;
+
+    @Excel(name = "身份证", width = 20)
+    private String idcard;
+
+    @Excel(name = "性别", width = 20)
+    private String sex;
+
+    @Excel(name = "年龄", width = 20)
+    private String age;
+
+    @Excel(name = "出生年月", width = 20)
+    private String birth;
+
+    @Excel(name = "职位", width = 20)
+    private String position;
+
+    @Excel(name = "政治面貌", width = 20)
+    private String political;
+
+    @Excel(name = "联系电话", width = 20)
+    private String contactPhone;
+
+}