Ver Fonte

项目导出

ljy121 há 1 ano atrás
pai
commit
6185da340c

+ 5 - 0
zjugis-business/pom.xml

@@ -75,6 +75,11 @@
             <version>${revision}</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.zjugis.cloud</groupId>
+            <artifactId>zjugis-spring-boot-starter-excel</artifactId>
+        </dependency>
+
         <!-- Config 配置中心相关 -->
         <dependency>
             <groupId>com.alibaba.cloud</groupId>

+ 64 - 0
zjugis-business/src/main/java/com/zjugis/business/bean/response/ProjectExcelResponse.java

@@ -0,0 +1,64 @@
+package com.zjugis.business.bean.response;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.zjugis.business.excel.ProjectConverter;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+
+/**
+ * @author ljy
+ * @version 1.0
+ * @date 2023/11/23 14:37
+ */
+@Data
+public class ProjectExcelResponse {
+
+    //立项时间
+    @ExcelProperty("立项时间")
+    private LocalDate lxsj;
+    //项目状态 0-立项申请中 1-进行中 2-已结项 3-中止
+    @ExcelProperty(value = "项目状态",converter = ProjectConverter.class)
+    private Integer xmzt;
+    //项目名称
+    @ExcelProperty("项目名称")
+    private String xmmc;
+    //项目编号
+    @ExcelProperty("项目编号")
+    private String xmbh;
+    //行政区代码
+    @ExcelProperty("行政区代码")
+    private String xzqdm;
+    // 行政区名称
+    @ExcelProperty("行政区名称")
+    private String xzqmc;
+    // 项目类型名称
+    @ExcelProperty("项目类型")
+    private String projectTypeName;
+    //行业
+    @ExcelProperty(value = "行业",converter = ProjectConverter.class)
+    private Integer hyId;
+    //预估工期(天)
+    @ExcelProperty("预期工期")
+    private Integer yggq;
+    //验收时间
+    @ExcelProperty("验收时间")
+    private LocalDate yssj;
+    //项目经理名称
+    @ExcelProperty("项目经理")
+    private String xmjl;
+    //责任部门名称
+    @ExcelProperty("责任部门")
+    private String zrbm;
+    //总合同额
+    @ExcelProperty("合同额")
+    private BigDecimal contractAmount;
+    //总成本
+    @ExcelProperty("总成本")
+    private BigDecimal projectCost;
+    //总产值
+    @ExcelProperty("总产值")
+    private BigDecimal outputValue;
+
+}

+ 27 - 0
zjugis-business/src/main/java/com/zjugis/business/controller/ProjectController.java

@@ -7,13 +7,21 @@ import com.zjugis.business.bean.entity.Project;
 import com.zjugis.business.bean.request.ProjectChildRequest;
 import com.zjugis.business.bean.request.ProjectRequest;
 import com.zjugis.business.bean.response.ProjectCalculateResponse;
+import com.zjugis.business.bean.response.ProjectExcelResponse;
 import com.zjugis.business.bean.response.ProjectResponse;
 import com.zjugis.business.service.ProjectService;
 import com.zjugis.framework.common.pojo.CommonResult;
+import com.zjugis.framework.excel.core.util.ExcelUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -95,5 +103,24 @@ public class ProjectController{
     public CommonResult<ProjectCalculateResponse> cost(ProjectDto projectDto) {
         return CommonResult.success(projectService.calculate(projectDto));
     }
+
+    @GetMapping("/export")
+    public void export( ProjectDto projectDto,
+                               HttpServletResponse response) throws IOException {
+        Page<Project> page = projectService.page(new Page<>(projectDto.getPageNo(),-1L),projectDto);
+        List<Project> projects = page.getRecords();
+
+        List<ProjectExcelResponse> excelList = new ArrayList<>(projects.size());
+        projects.forEach(project -> {
+            ProjectExcelResponse projectExcelResponse = new ProjectExcelResponse();
+            BeanUtils.copyProperties(project,projectExcelResponse);
+            excelList.add(projectExcelResponse);
+        });
+        response.setContentType("multipart/form-data");
+        response.setCharacterEncoding(String.valueOf(StandardCharsets.UTF_8));
+        response.setHeader("Content-Disposition",
+                "attachment;filename*=utf-8'zh-cn'" + URLEncoder.encode("项目.xlsx", String.valueOf(StandardCharsets.UTF_8)));
+        ExcelUtils.write(response, "项目.xlsx", "项目列表", ProjectExcelResponse.class, excelList);
+    }
 }
 

+ 0 - 20
zjugis-business/src/main/java/com/zjugis/business/converter/ProjectCostConverter.java

@@ -1,20 +0,0 @@
-package com.zjugis.business.converter;
-
-import com.zjugis.business.bean.dto.ProjectCostDto;
-import com.zjugis.business.bean.entity.ProjectCost;
-
-/**
- * @author ljy
- * @version 1.0
- * @date 2023/11/14 17:59
- */
-public class ProjectCostConverter {
-
-    public ProjectCost toEntity(ProjectCostDto bean) {
-        if ( bean == null ) {
-            return null;
-        }
-        ProjectCost projectCost = new ProjectCost();
-        return projectCost;
-    }
-}

+ 73 - 0
zjugis-business/src/main/java/com/zjugis/business/excel/ProjectConverter.java

@@ -0,0 +1,73 @@
+package com.zjugis.business.excel;
+
+
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.metadata.GlobalConfiguration;
+import com.alibaba.excel.metadata.data.WriteCellData;
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
+import org.apache.commons.lang3.StringUtils;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author ljy
+ * @version 1.0
+ * @date 2023/11/23 15:26
+ */
+public class ProjectConverter implements Converter<Integer> {
+
+
+    private final String[] dictFieldName = {"hyId","xmzt"};
+
+    private final Map<String,Map<Integer,String>> dictMap = new HashMap<>();
+
+    private final Map<Integer,String> hyDict = new HashMap<>();
+
+    private final Map<Integer,String> xmztDict = new HashMap<>();
+
+    public ProjectConverter() {
+        this.hyDict.put(1,"公司内部项目");
+        this.hyDict.put(2,"IT行业");
+        this.hyDict.put(3,"政府行业");
+        this.hyDict.put(4,"其他");
+
+        this.xmztDict.put(0,"立项申请中");
+        this.xmztDict.put(1,"进行中");
+        this.xmztDict.put(2,"已结项");
+        this.xmztDict.put(3,"中止");
+        this.xmztDict.put(4,"已验收");
+
+        dictMap.put("hyId",hyDict);
+        dictMap.put("xmzt",xmztDict);
+
+    }
+
+    @Override
+    public Class<?> supportJavaTypeKey() {
+        return Integer.class;
+    }
+
+    /**
+     * @param value               Java Data.NotNull.
+     * @param contentProperty     Content property.Nullable.
+     * @param globalConfiguration Global configuration.NotNull.
+     */
+    @Override
+    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
+
+        Field field = contentProperty.getField();
+        String fieldName = field.getName();
+        String excelValue;
+        if (StringUtils.equalsAnyIgnoreCase(fieldName,dictFieldName)) {
+            Map<Integer, String> dict = dictMap.get(fieldName);
+            Set<Integer> dictKeys = dict.keySet();
+            excelValue = dictKeys.contains(value) ? dict.get(value) : "";
+        } else {
+            excelValue = String.valueOf(value);
+        }
+        return new WriteCellData<>(excelValue);
+    }
+}

+ 2 - 10
zjugis-business/src/main/java/com/zjugis/business/mybatis/entity/BaseEntity.java

@@ -27,18 +27,10 @@ public class BaseEntity implements Serializable {
      */
     @TableField(fill = FieldFill.INSERT_UPDATE,jdbcType = JdbcType.DATE)
     private LocalDateTime latestModifyTime;
-    /**
-     * 创建者,目前使用 SysUser 的 id 编号
-     *
-     * 使用 String 类型的原因是,未来可能会存在非数值的情况,留好拓展性。
-     */
+
     @TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR)
     private String createWorker;
-    /**
-     * 更新者,目前使用 SysUser 的 id 编号
-     *
-     * 使用 String 类型的原因是,未来可能会存在非数值的情况,留好拓展性。
-     */
+
     @TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.VARCHAR)
     private String latestModifyWorker;
     /**

+ 1 - 1
zjugis-business/src/main/java/com/zjugis/business/service/impl/ProjectServiceImpl.java

@@ -35,7 +35,7 @@ public class ProjectServiceImpl implements ProjectService {
 
     @Override
     public Page<Project> page(Page<Project> page, ProjectDto projectDto) {
-        return  projectMapper.page(page,projectDto);
+        return projectMapper.page(page,projectDto);
     }
 
     @Override

+ 4 - 1
zjugis-business/src/main/resources/mapper/oracle/ProjectMapper.xml

@@ -22,13 +22,16 @@
     <select id="page" resultType="com.zjugis.business.bean.entity.Project">
         SELECT * FROM PROJECT
         <where>
-            ISVALID = 1
+            ISVALID = 1 AND PID IS NULL
             <if test="params != null and params.hyId != null">
                 AND HY_ID = #{params.hyId}
             </if>
             <if test="params != null and params.xzqdm != null and params.xzqdm != ''">
                 AND XZQDM = #{params.xzqdm}
             </if>
+            <if test="params != null and params.projectTypeId != null and params.projectTypeId != ''">
+                AND PROJECT_TYPE_ID = #{params.projectTypeId}
+            </if>
             <if test="params != null and params.xmzt != null">
                 AND XMZT = #{params.xmzt}
             </if>