Browse Source

报表展现 导入

Althars123 2 years ago
parent
commit
a3ec47a5fd

+ 13 - 2
xxgl-admin/src/main/java/com/miaxis/pc/controller/PriceInfoController.java

@@ -51,7 +51,7 @@ public class PriceInfoController extends BaseController{
      */
     @PreAuthorize("@ss.hasPermi('price:info:import')")
     @Log(title = "报价", businessType = BusinessTypeEnum.IMPORT)
-    @GetMapping("/import")
+    @PostMapping("/import")
     @ApiOperation("导入报价列表Excel")
     public Response<String> importPrice(@RequestPart("file")MultipartFile file) throws Exception {
         ExcelUtil<PriceInfo> util = new ExcelUtil<PriceInfo>(PriceInfo.class);
@@ -73,7 +73,18 @@ public class PriceInfoController extends BaseController{
         return util.exportExcel(list, "info");
     }
 
-
+    /**
+     * 查询字段所有枚举值
+     */
+    @PreAuthorize("@ss.hasPermi('price:info:query')")
+    @GetMapping(value = "/field/{name}")
+    @ApiOperation("查询字段所有枚举值")
+    public Response<List<String>> getFieldName(
+            @ApiParam(name = "name", value = "字段名", required = true)
+            @PathVariable("name") String name
+    ){
+        return Response.success(priceInfoService.getListByFieldName(name));
+    }
 
     /**
      * 获取报价详细信息

+ 74 - 35
xxgl-admin/src/main/java/com/miaxis/system/controller/common/CommonController.java

@@ -3,31 +3,30 @@ package com.miaxis.system.controller.common;
 import com.miaxis.common.config.MiaxisConfig;
 import com.miaxis.common.constant.Constants;
 import com.miaxis.common.core.domain.Response;
-import com.miaxis.common.enums.FileUploadTypeEnum;
-import com.miaxis.common.exception.CustomException;
-import com.miaxis.common.utils.EnumUtils;
 import com.miaxis.common.utils.StringUtils;
+import com.miaxis.common.utils.file.FileUploadUtils;
 import com.miaxis.common.utils.file.FileUtils;
-import com.qcloud.cos.COSClient;
+import com.miaxis.framework.config.ServerConfig;
+import com.miaxis.system.dto.common.UploadFileDTO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
-import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 /**
  * 通用请求处理
  *
- * @author miaxis
+ * @author ruoyi
  */
 @RestController
 @Api(tags={"【系统-通用请求处理】"})
@@ -35,7 +34,75 @@ public class CommonController
 {
     private static final Logger log = LoggerFactory.getLogger(CommonController.class);
 
+    @Autowired
+    private ServerConfig serverConfig;
 
+    /**
+     * 通用下载请求
+     *
+     * @param fileName 文件名称
+     * @param delete 是否删除
+     */
+    @GetMapping("common/download")
+    @ApiOperation("通用下载请求")
+    public void fileDownload(
+            @ApiParam(name = "fileName", value = "文件名称")
+            @RequestParam(name = "fileName", required = true) String fileName,
+            @ApiParam(name = "delete", value = "是否删除")
+            @RequestParam(name = "delete", required = true) Boolean delete,
+            HttpServletResponse response,
+            HttpServletRequest request)
+    {
+        try
+        {
+            if (!FileUtils.isValidFilename(fileName))
+            {
+                throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
+            }
+            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
+            String filePath = MiaxisConfig.getDownloadPath() + fileName;
+
+            response.setCharacterEncoding("utf-8");
+            response.setContentType("multipart/form-data");
+            response.setHeader("Content-Disposition",
+                    "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
+            FileUtils.writeBytes(filePath, response.getOutputStream());
+            if (delete)
+            {
+                FileUtils.deleteFile(filePath);
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("下载文件失败", e);
+        }
+    }
+
+    /**
+     * 通用上传请求
+     */
+    @PostMapping("/common/upload")
+    @ApiOperation("通用上传请求")
+    public Response<UploadFileDTO> uploadFile(MultipartFile file) throws Exception
+    {
+        try
+        {
+            // 上传文件路径
+            String filePath = MiaxisConfig.getUploadPath();
+            // 上传并返回新文件名称
+            String fileName = FileUploadUtils.upload(filePath, file);
+            String url = serverConfig.getUrl() + fileName;
+            UploadFileDTO uploadFileDTO = new UploadFileDTO();
+            uploadFileDTO.setFileName(fileName);
+            uploadFileDTO.setUrl(url);
+
+            return Response.success(uploadFileDTO);
+        }
+        catch (Exception e)
+        {
+            return Response.error().setMsg(e.getMessage());
+        }
+    }
 
     /**
      * 本地资源通用下载
@@ -59,32 +126,4 @@ public class CommonController
                 "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName));
         FileUtils.writeBytes(downloadPath, response.getOutputStream());
     }
-
-
-    private Boolean validateFileSuffix(String originalFilenamefile, FileUploadTypeEnum fileUploadTypeEnum) {
-        if (fileUploadTypeEnum == null){
-            throw new CustomException("fileType参数不合法");
-        }
-        if (StringUtils.isEmpty(originalFilenamefile)){
-            throw new CustomException("文件名不合法");
-        }
-        String[] allowSuffixs = fileUploadTypeEnum.getSuffix();
-        for(String suffix : allowSuffixs){
-            String fileSuffix = "."+suffix;
-            if (originalFilenamefile.equals(fileSuffix)){
-                return true;
-            }
-        }
-        return false;
-
-    }
-
-    private FileUploadTypeEnum getPathByType(Integer fileType) {
-        if (fileType == null){
-            throw new CustomException("文件类型不能为空");
-        }
-        return (FileUploadTypeEnum) EnumUtils.getEnumEntityByCode(FileUploadTypeEnum.class, fileType);
-
-    }
-
 }

+ 6 - 2
xxgl-common/src/main/java/com/miaxis/common/utils/poi/ExcelUtil.java

@@ -182,10 +182,10 @@ public class ExcelUtil<T>
                 {
                     // 设置类的私有字段属性可访问.
                     field.setAccessible(true);
-                    Integer column = cellMap.get(attr.name());
+                    Integer column =Integer.valueOf(attr.name());
                     if (column != null)
                     {
-                        fieldsMap.put(column, field);
+                        fieldsMap.put(column-1, field);
                     }
                 }
             }
@@ -207,6 +207,10 @@ public class ExcelUtil<T>
                     if (String.class == fieldType)
                     {
                         String s = Convert.toStr(val);
+                        //如果第一个字段是空的,那么直接返回list
+                        if(entry.getKey() ==0 &&StringUtils.isEmpty(s)){
+                            return list;
+                        }
                         if (StringUtils.endsWith(s, ".0"))
                         {
                             val = StringUtils.substringBefore(s, ".0");

+ 35 - 33
xxgl-service/src/main/java/com/miaxis/price/domain/PriceInfo.java

@@ -30,176 +30,178 @@ public class PriceInfo extends BaseBusinessEntity{
     @ApiModelProperty(value = "主键")
     private Long id;
 
-    /** 品牌 */
-    @Excel(name = "品牌")
-    @TableField("brand")
-    @ApiModelProperty(value = "品牌")
-    private String brand;
+
 
     /** 机组型号 */
-    @Excel(name = "机组型号")
+    @Excel(name = "1")
     @TableField("unit_model")
     @ApiModelProperty(value = "机组型号")
     private String unitModel;
 
     /** 机组功率(kw) */
-    @Excel(name = "机组功率(kw)")
+    @Excel(name = "2")
     @TableField("unit_power_kw")
     @ApiModelProperty(value = "机组功率(kw)")
     private BigDecimal unitPowerKw;
 
     /** 机组功率(kva) */
-    @Excel(name = "机组功率(kva)")
+    @Excel(name = "3")
     @TableField("unit_power_kva")
     @ApiModelProperty(value = "机组功率(kva)")
     private BigDecimal unitPowerKva;
 
     /** 频率(Hz) */
-    @Excel(name = "频率(Hz)")
+    @Excel(name = "4")
     @TableField("rate")
     @ApiModelProperty(value = "频率(Hz)")
     private Integer rate;
 
+    /** 品牌 */
+    @Excel(name = "5")
+    @TableField("brand")
+    @ApiModelProperty(value = "品牌")
+    private String brand;
+
     /** 柴油机型号 */
-    @Excel(name = "柴油机型号")
+    @Excel(name = "6")
     @TableField("diesel_engine_model")
     @ApiModelProperty(value = "柴油机型号")
     private String dieselEngineModel;
 
     /** 转速 */
-    @Excel(name = "转速")
+    @Excel(name = "7")
     @TableField("speed")
     @ApiModelProperty(value = "转速")
     private Integer speed;
 
     /** 动力价格 */
-    @Excel(name = "动力价格")
+    @Excel(name = "8")
     @TableField("power_price")
     @ApiModelProperty(value = "动力价格")
     private BigDecimal powerPrice;
 
     /** 发电机型号 */
-    @Excel(name = "发电机型号")
+    @Excel(name = "9")
     @TableField("generator_model")
     @ApiModelProperty(value = "发电机型号")
     private String generatorModel;
 
     /** 发电机价格 */
-    @Excel(name = "发电机价格")
+    @Excel(name = "10")
     @TableField("generator_price")
     @ApiModelProperty(value = "发电机价格")
     private BigDecimal generatorPrice;
 
     /** 静音机壳价格 */
-    @Excel(name = "静音机壳价格")
+    @Excel(name = "11")
     @TableField("mute_price")
     @ApiModelProperty(value = "静音机壳价格")
     private BigDecimal mutePrice;
 
     /** 开架价格 */
-    @Excel(name = "开架价格")
+    @Excel(name = "12")
     @TableField("open_price")
     @ApiModelProperty(value = "开架价格")
     private BigDecimal openPrice;
 
     /** ATS型号 */
-    @Excel(name = "ATS型号")
+    @Excel(name = "13")
     @TableField("ats_model")
     @ApiModelProperty(value = "ATS型号")
     private String atsModel;
 
     /** ATS价格 */
-    @Excel(name = "ATS价格")
+    @Excel(name = "14")
     @TableField("ats_price")
     @ApiModelProperty(value = "ATS价格")
     private BigDecimal atsPrice;
 
     /** 电瓶型号 */
-    @Excel(name = "电瓶型号")
+    @Excel(name = "15")
     @TableField("battery_model")
     @ApiModelProperty(value = "电瓶型号")
     private String batteryModel;
 
     /** 电瓶价格 */
-    @Excel(name = "电瓶价格")
+    @Excel(name = "16")
     @TableField("battery_price")
     @ApiModelProperty(value = "电瓶价格")
     private BigDecimal batteryPrice;
 
     /** 控制器铭贝 */
-    @Excel(name = "控制器铭贝")
+    @Excel(name = "17")
     @TableField("controller_minbei")
     @ApiModelProperty(value = "控制器铭贝")
     private String controllerMinbei;
 
     /** 控制器价格 */
-    @Excel(name = "控制器价格")
+    @Excel(name = "18")
     @TableField("controller_price")
     @ApiModelProperty(value = "控制器价格")
     private BigDecimal controllerPrice;
 
     /** 合计含税成本(静音) */
-    @Excel(name = "合计含税成本(静音)")
+    @Excel(name = "19")
     @TableField("total_cost_mute")
     @ApiModelProperty(value = "合计含税成本(静音)")
     private BigDecimal totalCostMute;
 
     /** 合计含税成本(开架) */
-    @Excel(name = "合计含税成本(开架)")
+    @Excel(name = "20")
     @TableField("total_cost_open")
     @ApiModelProperty(value = "合计含税成本(开架)")
     private BigDecimal totalCostOpen;
 
     /** 静音尺寸(长) */
-    @Excel(name = "静音尺寸(长)", readConverterExp = "长=")
+    @Excel(name = "21")
     @TableField("mute_long")
     @ApiModelProperty(value = "静音尺寸(长)")
     private BigDecimal muteLong;
 
     /** 静音尺寸(宽) */
-    @Excel(name = "静音尺寸(宽)", readConverterExp = "宽=")
+    @Excel(name = "22")
     @TableField("mute_width")
     @ApiModelProperty(value = "静音尺寸(宽)")
     private BigDecimal muteWidth;
 
     /** 静音尺寸(高) */
-    @Excel(name = "静音尺寸(高)", readConverterExp = "高=")
+    @Excel(name = "23")
     @TableField("mute_high")
     @ApiModelProperty(value = "静音尺寸(高)")
     private BigDecimal muteHigh;
 
     /** 开架尺寸(长) */
-    @Excel(name = "开架尺寸(长)", readConverterExp = "长=")
+    @Excel(name = "24")
     @TableField("open_long")
     @ApiModelProperty(value = "开架尺寸(长)")
     private BigDecimal openLong;
 
     /** 开架尺寸(宽) */
-    @Excel(name = "开架尺寸(宽)", readConverterExp = "宽=")
+    @Excel(name = "25")
     @TableField("open_width")
     @ApiModelProperty(value = "开架尺寸(宽)")
     private BigDecimal openWidth;
 
     /** 开架尺寸(高) */
-    @Excel(name = "开架尺寸(高)", readConverterExp = "高=")
+    @Excel(name = "26")
     @TableField("open_high")
     @ApiModelProperty(value = "开架尺寸(高)")
     private BigDecimal openHigh;
 
     /** CKD尺寸(长) */
-    @Excel(name = "CKD尺寸(长)", readConverterExp = "长=")
+    @Excel(name = "27")
     @TableField("ckd_long")
     @ApiModelProperty(value = "CKD尺寸(长)")
     private BigDecimal ckdLong;
 
     /** CKD尺寸(宽) */
-    @Excel(name = "CKD尺寸(宽)", readConverterExp = "宽=")
+    @Excel(name = "28")
     @TableField("ckd_width")
     @ApiModelProperty(value = "CKD尺寸(宽)")
     private BigDecimal ckdWidth;
 
     /** CKD尺寸(高) */
-    @Excel(name = "CKD尺寸(高)", readConverterExp = "高=")
+    @Excel(name = "29")
     @TableField("ckd_high")
     @ApiModelProperty(value = "CKD尺寸(高)")
     private BigDecimal ckdHigh;

+ 1 - 0
xxgl-service/src/main/java/com/miaxis/price/mapper/PriceInfoMapper.java

@@ -19,4 +19,5 @@ public interface PriceInfoMapper extends BaseMapper<PriceInfo> {
      */
     public List<PriceInfo> selectPriceInfoList(PriceInfo priceInfo);
 
+    List<String> getListByFieldName(String name);
 }

+ 2 - 0
xxgl-service/src/main/java/com/miaxis/price/service/IPriceInfoService.java

@@ -18,4 +18,6 @@ public interface IPriceInfoService extends IService<PriceInfo>{
      * @return 报价集合
      */
     public List<PriceInfo> selectPriceInfoList(PriceInfo priceInfo);
+
+    List<String> getListByFieldName(String name);
 }

+ 6 - 0
xxgl-service/src/main/java/com/miaxis/price/service/impl/PriceInfoServiceImpl.java

@@ -33,4 +33,10 @@ public class PriceInfoServiceImpl extends ServiceImpl<PriceInfoMapper, PriceInfo
     public List<PriceInfo> selectPriceInfoList(PriceInfo priceInfo){
         return priceInfoMapper.selectPriceInfoList(priceInfo);
     }
+
+    @Override
+    public List<String> getListByFieldName(String name) {
+
+        return priceInfoMapper.getListByFieldName(name);
+    }
 }

+ 4 - 0
xxgl-service/src/main/resources/mapper/price/PriceInfoMapper.xml

@@ -77,5 +77,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="ckdHigh != null "> and ckd_high = #{ckdHigh}</if>
         </where>
     </select>
+    <select id="getListByFieldName" resultType="string">
+        select distinct (${fieldName}) as vals from price_info order by ${fieldName}
+
+    </select>
 
 </mapper>