Browse Source

数据采集 导入

hejizheng 1 year ago
parent
commit
49f15e608b

+ 19 - 20
zhbsq-admin/src/main/java/com/hjy/modlue/gather/CbGatherController.java

@@ -12,13 +12,19 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import com.hjy.common.core.page.TableDataInfo;
 
+import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 数据采集Controller
@@ -47,18 +53,6 @@ public class CbGatherController extends BaseController {
         return AjaxResult.success("查询成功", cbGatherService.queryAll(entity));
     }
 
-
-
-    @ApiOperation("导出数据采集列表")
-    @PreAuthorize("@ss.hasPermi('gather:GATHER:export')")
-    @Log(title = "数据采集", businessType = BusinessType.EXPORT)
-    @PostMapping("/export")
-    public void export(HttpServletResponse response, CbGatherVo entity) {
-        List<CbGatherVo> list = cbGatherService.queryAll(entity);
-        ExcelUtil<CbGatherVo> util = new ExcelUtil<>(CbGatherVo.class);
-        util.exportExcel(response, list, "数据采集数据");
-    }
-
     @ApiOperation("获取可采集的数据")
     @PreAuthorize("@ss.hasPermi('gather:GATHER:collList')")
     @GetMapping(value = "/getInfoByColl/{id}")
@@ -105,17 +99,22 @@ public class CbGatherController extends BaseController {
     @Log(title = "数据审核", businessType = BusinessType.UPDATE)
     @PostMapping("approve")
     public AjaxResult approve(@RequestBody CbGatherVo entity) {
-        entity.setApproveStatus("1");
+        entity.setApproveStatus("2");
         return toAjax(cbGatherService.updateById(entity));
     }
 
-    @ApiOperation("删除数据采集")
-    @PreAuthorize("@ss.hasPermi('gather:GATHER:remove')")
-    @Log(title = "数据采集", businessType = BusinessType.DELETE)
-	@GetMapping("/remove/{ids}")
-    public AjaxResult remove(@PathVariable String[] ids) {
-        return toAjax(cbGatherService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
-    }
 
+    @ApiOperation("下载导入模板")
+    @PreAuthorize("@ss.hasPermi('gather:GATHER:download')")
+    @Log(title = "下载导入模板", businessType = BusinessType.DOWNLOAD)
+    @GetMapping("/download/{id}")
+    public void downloadModlue(HttpServletResponse response,@PathVariable String id) throws IOException {
+        String fileName = "导入模板";
+        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+        response.setCharacterEncoding("utf-8");
+        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName+".xlsx", "UTF-8"));
+        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
 
+        cbGatherService.downloadModlue(response,id);
+    }
 }

+ 28 - 0
zhbsq-admin/src/main/java/com/hjy/modlue/gather/CbGatherWarningController.java

@@ -4,6 +4,8 @@ import com.hjy.common.annotation.Log;
 import com.hjy.common.core.controller.BaseController;
 import com.hjy.common.core.domain.AjaxResult;
 import com.hjy.common.enums.BusinessType;
+import com.hjy.common.utils.DateUtils;
+import com.hjy.common.utils.SecurityUtils;
 import com.hjy.common.utils.poi.ExcelUtil;
 import com.hjy.module.service.gather.ICbGatherWarningService;
 import com.hjy.module.vo.gather.CbGatherWarningVo;
@@ -86,4 +88,30 @@ public class CbGatherWarningController extends BaseController {
     public AjaxResult remove(@PathVariable String[] ids) {
         return toAjax(cbGatherWarningService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
     }
+
+    @ApiOperation("解除预警")
+    @PreAuthorize("@ss.hasPermi('gather:GATHERWARNING:deal')")
+    @Log(title = "解除预警", businessType = BusinessType.OTHER)
+    @GetMapping("/deal/{id}")
+    public AjaxResult deal(@PathVariable String id) {
+        CbGatherWarningVo warning = new CbGatherWarningVo();
+        warning.setId(id);
+        warning.setStatus("1");
+        warning.setDealBy(SecurityUtils.getUsername());
+        warning.setDealTime(DateUtils.getTime());
+        return toAjax(cbGatherWarningService.updateById(warning));
+    }
+
+    @ApiOperation("取消预警")
+    @PreAuthorize("@ss.hasPermi('gather:GATHERWARNING:cancel')")
+    @Log(title = "取消预警", businessType = BusinessType.OTHER)
+    @GetMapping("/cancel/{id}")
+    public AjaxResult cancel(@PathVariable String id) {
+        CbGatherWarningVo warning = new CbGatherWarningVo();
+        warning.setId(id);
+        warning.setStatus("2");
+        warning.setCancelBy(SecurityUtils.getUsername());
+        warning.setCancelTime(DateUtils.getTime());
+        return toAjax(cbGatherWarningService.updateById(warning));
+    }
 }

+ 13 - 0
zhbsq-common/pom.xml

@@ -152,6 +152,19 @@
             <artifactId>lombok</artifactId>
         </dependency>
 
+        <!-- easyexcel -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+            <version>3.1.0</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>poi-ooxml-schemas</artifactId>
+                    <groupId>org.apache.poi</groupId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
 
         <!-- Swagger3依赖 -->
         <dependency>

+ 2 - 1
zhbsq-modlue/src/main/java/com/hjy/module/domain/gether/CbGather.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.hjy.common.annotation.Excel;
+import com.hjy.common.annotation.PageDict;
 import com.hjy.common.annotation.ResVoDict;
 import com.hjy.common.core.domain.BaseEntity;
 import io.swagger.annotations.ApiModelProperty;
@@ -41,7 +42,7 @@ public class CbGather extends BaseEntity {
     /**
      * 部门id
      */
-    @ResVoDict(dicCode = "dept_id", dicText = "dept_name", dictTable = "sys_dept")
+    @PageDict(dicCode = "dept_id", dicText = "dept_name", dictTable = "sys_dept")
     @TableField(fill = FieldFill.INSERT)
     @Excel(name = "部门id")
     private String deptId;

+ 9 - 0
zhbsq-modlue/src/main/java/com/hjy/module/domain/gether/CbGatherWarning.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.hjy.common.annotation.Excel;
+import com.hjy.common.annotation.PageDict;
 import com.hjy.common.core.domain.BaseEntity;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -42,6 +43,7 @@ public class CbGatherWarning extends BaseEntity {
     /**
      * 部门id
      */
+    @PageDict(dicCode = "dept_id", dicText = "dept_name", dictTable = "sys_dept")
     @TableField(fill = FieldFill.INSERT)
     @Excel(name = "部门id")
     private String deptId;
@@ -75,6 +77,13 @@ public class CbGatherWarning extends BaseEntity {
     private BigDecimal errValue;
 
     /**
+     * 状态(0=预警,1=已解除,2已取消)
+     */
+    @ApiModelProperty("状态(0=预警,1=已解除,2已取消)")
+    @Excel(name = "状态(0=预警,1=已解除,2已取消)")
+    private String status;
+
+    /**
      * 处置人
      */
     @ApiModelProperty("处置人")

+ 9 - 0
zhbsq-modlue/src/main/java/com/hjy/module/service/gather/ICbGatherService.java

@@ -5,6 +5,8 @@ import com.hjy.common.core.page.TableDataInfo;
 import com.hjy.module.domain.gether.CbGather;
 import com.hjy.module.vo.gather.CbGatherVo;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -60,4 +62,11 @@ public interface ICbGatherService extends IService<CbGather> {
      * @return
      */
     boolean updateEntity(CbGatherVo entity);
+
+    /**
+     * 下载导入模板
+     * @param response
+     * @param id
+     */
+    void downloadModlue(HttpServletResponse response, String id) throws IOException;
 }

+ 85 - 0
zhbsq-modlue/src/main/java/com/hjy/module/service/gather/impl/CbGatherServiceImpl.java

@@ -1,8 +1,14 @@
 package com.hjy.module.service.gather.impl;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.write.metadata.WriteSheet;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.hjy.common.core.domain.entity.SysDept;
 import com.hjy.common.core.page.TableDataInfo;
+import com.hjy.common.core.text.Convert;
 import com.hjy.common.utils.CommomUtils;
+import com.hjy.common.utils.DictUtils;
 import com.hjy.common.utils.PageUtils;
 import com.hjy.module.domain.gether.CbGather;
 import com.hjy.module.domain.gether.CbGatherFee;
@@ -20,13 +26,20 @@ import com.hjy.module.service.norm.ICbNormService;
 import com.hjy.module.vo.gather.CbGatherFeeVo;
 import com.hjy.module.vo.gather.CbGatherVo;
 import com.hjy.module.vo.gather.CbGatherWarningVo;
+import com.hjy.module.vo.gather.GatherImportVo;
 import com.hjy.module.vo.norm.CbNormFeeVo;
 import com.hjy.module.vo.norm.CbNormVo;
+import com.hjy.system.mapper.SysDeptMapper;
+import com.hjy.system.service.ISysDeptService;
 import org.apache.commons.compress.utils.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -54,6 +67,9 @@ public class CbGatherServiceImpl extends ServiceImpl<CbGatherMapper, CbGather> i
     @Autowired
     private ICbGatherWarningService warningService;
 
+    @Autowired
+    private ISysDeptService sysDeptService;
+
     @Override
     public TableDataInfo<CbGatherVo> queryList(CbGatherVo entity) {
         return PageUtils.buildDataInfo(this.baseMapper.queryList(PageUtils.buildPage(), entity));
@@ -166,6 +182,7 @@ public class CbGatherServiceImpl extends ServiceImpl<CbGatherMapper, CbGather> i
                     warningVo.setGetherId(entity.getId());
                     warningVo.setGetherfeeId(feeVo.getId());
                     warningVo.setErrValue(collValue);
+                    warningVo.setStatus("0");
                     warningService.save(warningVo);
                 }
             }
@@ -184,6 +201,7 @@ public class CbGatherServiceImpl extends ServiceImpl<CbGatherMapper, CbGather> i
                     warningVo.setGetherId(entity.getId());
                     warningVo.setGetherfeeId(feeVo.getId());
                     warningVo.setErrValue(collValue);
+                    warningVo.setStatus("0");
                     warningService.save(warningVo);
                 }
             }
@@ -204,6 +222,73 @@ public class CbGatherServiceImpl extends ServiceImpl<CbGatherMapper, CbGather> i
         return false;
     }
 
+    /**
+     * 下载导入模板
+     * @param response
+     * @param id
+     */
+    @Override
+    public void downloadModlue(HttpServletResponse response, String id) throws IOException {
+        CbGatherVo gatherVo = this.getInfoByColl(id);
+        SysDept dept = sysDeptService.selectDeptById(Convert.toLong(gatherVo.getDeptId()));
+        ServletOutputStream out = response.getOutputStream();
+        ExcelWriter writer = EasyExcel.write(out).build();
+        WriteSheet sheet1 = EasyExcel.writerSheet("sheet1").head(getHead(dept.getDeptName())).build();
+        List<GatherImportVo> importVoList = getImportData(gatherVo);
+        writer.write(importVoList,sheet1);
+        writer.close();
+        out.close();
+    }
+
+    /**
+     * 构造导出数据
+     * @param gatherVo
+     * @return
+     */
+    private List<GatherImportVo> getImportData(CbGatherVo gatherVo) {
+        List<GatherImportVo> resultList = Lists.newArrayList();
+        for (CbGatherFeeVo feeVo:gatherVo.getFeeLists()){
+            GatherImportVo importVo = new GatherImportVo();
+            importVo.setNormName(feeVo.getNormName());
+            importVo.setNormfeeName(feeVo.getNormfeeName());
+            importVo.setUint( DictUtils.getDictLabel("norm_uint",normFeeService.getById(feeVo.getNormfeeId()).getFunit()));
+            importVo.setCollCalue(feeVo.getCollCalue());
+            resultList.add(importVo);
+        }
+        return resultList;
+    }
+
+    /**
+     * excel表态构造
+     * @param lebal
+     * @return
+     */
+    public static List<List<String>> getHead( String lebal) {
+        List<List<String>> list = new ArrayList<List<String>>();
+        for (int i=0 ; i<4;i++){
+            List<String> row = Lists.newArrayList();
+            switch (i){
+                case 0:
+                    row.add("指标分类");
+                    break;
+                case 1:
+                    row.add("指标名称");
+                    break;
+                case 2:
+                    row.add("计量单位");
+                    break;
+                case 3:
+                    row.add(lebal);
+                    break;
+                default:
+                    break;
+            }
+            list.add(row);
+        }
+        return list;
+
+    }
+
 
 
 }

+ 1 - 0
zhbsq-modlue/src/main/java/com/hjy/module/service/wf/impl/WfInstActionTaskServiceImpl.java

@@ -74,6 +74,7 @@ public class WfInstActionTaskServiceImpl extends ServiceImpl<WfInstActionTaskMap
         WorkFlowInterface workFlowInterface = (WorkFlowInterface) SpringUtils.getBean(currentAction.getServiceUrl());
         Object obj = workFlowInterface.getEntity(currentAction.getFromDataId()); // 回调业务接口
         taskVo.setFormobj(obj);
+        taskVo.setInfoUrl(currentAction.getInfoUrl());
         return taskVo;
     }
 

+ 12 - 0
zhbsq-modlue/src/main/java/com/hjy/module/vo/gather/CbGatherWarningVo.java

@@ -1,6 +1,7 @@
 package com.hjy.module.vo.gather;
 
 import com.hjy.module.domain.gether.CbGatherWarning;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.ToString;
@@ -18,4 +19,15 @@ import lombok.experimental.Accessors;
 @EqualsAndHashCode(callSuper = true)
 public class CbGatherWarningVo extends CbGatherWarning {
 
+    /**
+     * 异常项名称
+     */
+    @ApiModelProperty("异常项名称")
+    private String gatherFeeName;
+
+    /**
+     * 异常项类型名称
+     */
+    @ApiModelProperty("异常项类型名称")
+    private String gathernormName;
 }

+ 24 - 0
zhbsq-modlue/src/main/java/com/hjy/module/vo/gather/GatherImportVo.java

@@ -0,0 +1,24 @@
+package com.hjy.module.vo.gather;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.hjy.common.annotation.Excel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class GatherImportVo {
+
+    @ExcelProperty(value = "指标分类")
+    private String normName;
+
+    @ExcelProperty(value = "权重名称")
+    private String normfeeName;
+
+    @ExcelProperty(value = "计量单位")
+    private String uint;
+
+    @ExcelProperty(value = "采集值")
+    private BigDecimal collCalue;
+}

+ 6 - 0
zhbsq-modlue/src/main/java/com/hjy/module/vo/wf/WfInstActionTaskVo.java

@@ -46,6 +46,12 @@ public class WfInstActionTaskVo extends WfInstActionTask {
     private Object formobj;
 
     /**
+     * 前端组件地址
+     */
+    @ApiModelProperty("前端组件地址")
+    private String infoUrl;
+
+    /**
      * 历史节点
      */
     @ApiModelProperty("历史节点")

+ 5 - 0
zhbsq-modlue/src/main/java/com/hjy/module/vo/wf/WfInstActionVo.java

@@ -33,4 +33,9 @@ public class WfInstActionVo extends WfInstAction {
      */
     private String proId;
 
+    /**
+     * 前端页面url
+     */
+    private String infoUrl;
+
 }

+ 9 - 1
zhbsq-modlue/src/main/resources/mapper/gather/CbGatherWarningMapper.xml

@@ -7,6 +7,8 @@
     <sql id="querySql">
         select <include refid="allField"/>
         from CB_GATHER_WARNING A
+        left join cb_gather B ON A.gether_id = B.ID
+        left join cb_gather_fee C ON A.getherfee_id = C.ID
         <include refid="search"/>
     </sql>
 
@@ -60,6 +62,9 @@
         <if test="entity.remark != null and entity.remark != ''">
             and A.REMARK like concat('%', #{entity.remark}, '%')
         </if>
+        <if test="entity.status != null and entity.status != ''">
+            and A.status like concat('%', #{entity.status}, '%')
+        </if>
         order by A.create_time desc
     </select>
 
@@ -84,7 +89,10 @@
         A.DEAL_TIME,
         A.CANCEL_BY,
         A.CANCEL_TIME,
-        A.REMARK
+        A.status,
+        A.REMARK,
+        C.normfee_name as gatherFeeName,
+        C.norm_name as gathernormName
     </sql>
 
     <sql id="search">

+ 2 - 1
zhbsq-modlue/src/main/resources/mapper/wf/WfInstActionMapper.xml

@@ -111,7 +111,8 @@
             A.STATUS,
             C.service_url,
             B.business_id AS fromDataId,
-            B.ID AS proId
+            B.ID AS proId,
+            C.info_url AS infoUrl
     </sql>
 
     <sql id="allField">

+ 0 - 5
zhbsq-system/src/main/java/com/hjy/system/service/impl/SysDictDataServiceImpl.java

@@ -117,7 +117,6 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
         String[] tableAndFields = new String[]{table, text, code};
         SqlUtil.filterContent(tableAndFields,null);
         SqlUtil.specialFilterContentForDictSql(filterSql);
-        keys.add("dfdf");
         return dictDataMapper.queryTableDictByKeysAndFilterSql(table, text, code, filterSql, keys);
     }
 
@@ -129,10 +128,6 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
             List<SysDictModel> dictItemList = dictMap.computeIfAbsent(dict.getDictcode(), i -> new ArrayList<>());
             dictItemList.add(new SysDictModel(dict.getDictcode(),dict.getValue(), dict.getText()));
         }
-        //update-begin-author:taoyan date:2022-7-8 for: 系统字典数据应该包括自定义的java类-枚举
-        // Map<String, List<SysDictModel>> enumRes = ResourceUtil.queryManyDictByKeys(dictCodeList, keys);
-        // dictMap.putAll(enumRes);
-        //update-end-author:taoyan date:2022-7-8 for: 系统字典数据应该包括自定义的java类-枚举
         return dictMap;
     }