瀏覽代碼

建筑用能模块:用电集抄接口优化,与数据库数据对接 用电集抄数据导出

sl 1 年之前
父節點
當前提交
791fdc7c3d

+ 26 - 0
module_ems/src/main/java/org/jeecg/modules/dataElectricity/controller/DataElectricityController.java

@@ -13,6 +13,7 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.dataElectricity.entity.DataElectricity;
+import org.jeecg.modules.dataElectricity.entity.DataElectricitySta;
 import org.jeecg.modules.dataElectricity.service.IDataElectricityService;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -26,6 +27,7 @@ import org.jeecgframework.poi.excel.entity.ExportParams;
 import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecgframework.poi.util.ExcelUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -174,4 +176,28 @@ public class DataElectricityController extends JeecgController<DataElectricity,
         return super.importExcel(request, response, DataElectricity.class);
     }
 
+	 /**
+	  * 用电集抄
+	  */
+	 @ApiOperation("用电集抄")
+//	 @PreAuthorize("@ss.hasPermi('ems:emselectricity:list')")
+	 @GetMapping("/liststa")
+	 public Result<Object> liststa(DataElectricity emsElectricity) {
+		 System.out.println(emsElectricity);
+		 List<DataElectricitySta> list = dataElectricityService.selectEmsElecSta(emsElectricity);
+		 return Result.OK(list);
+	 }
+
+	 /**
+	  * 导出用电集抄
+	  */
+	 @ApiOperation("导出用电集抄")
+//	 @PreAuthorize("@ss.hasPermi('ems:emselectricity:export')")
+//	 @Log(title = "用电集抄", businessType = BusinessType.EXPORT)
+	 @RequestMapping(value = "/exportsta")
+	 public ModelAndView exportsta(HttpServletRequest request, DataElectricity dataElectricity) {
+		 System.out.println(dataElectricity);
+		 return dataElectricityService.exportsta(request, DataElectricitySta.class, "用电集抄数据", dataElectricity);
+	 }
+
 }

+ 17 - 0
module_ems/src/main/java/org/jeecg/modules/dataElectricity/entity/DataElectricity.java

@@ -4,6 +4,9 @@ import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.util.Date;
 import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
@@ -134,4 +137,18 @@ public class DataElectricity implements Serializable {
 	@Excel(name = "附加电费", width = 15)
     @ApiModelProperty(value = "附加电费")
     private java.lang.Double addamount;
+
+
+    /** 设备编号 */
+    @Excel(name = "设备编号")
+    private String equipmentcode;
+    /** 电费(元) */
+    @Excel(name = "电费(元)")
+    private Double electricityvalue;
+    /** 开始示数 */
+    private Double beginvalue;
+    /** 结束示数 */
+    private Double endvalue;
+
+    private Map<String, Object> params;
 }

+ 46 - 0
module_ems/src/main/java/org/jeecg/modules/dataElectricity/entity/DataElectricitySta.java

@@ -0,0 +1,46 @@
+package org.jeecg.modules.dataElectricity.entity;
+
+import lombok.Data;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.io.Serializable;
+
+/**
+ * ClassName: EmsElectricitySta
+ * Package: org.jeecg.modules.dataElectricity.entity
+ * Description:
+ *
+ * @Author sl
+ * @Create 2024/2/22 16:23
+ * @Version 1.0
+ */
+@Data
+public class DataElectricitySta implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /** 设备/回路名称 */
+    @Excel(name = "设备名称")
+    private String equipmentname;
+
+    /** 设备/回路编号 */
+    @Excel(name = "设备编号")
+    private String equipmentcode;
+
+    /** 开始示数 */
+    @Excel(name = "开始示数")
+    private Double beginvalue;
+
+    /** 结束示数 */
+    @Excel(name = "结束示数")
+    private Double endvalue;
+
+    /** 用电量(kWh) */
+    @Excel(name = "用电量(kWh)")
+    private Double tagvalue;
+
+    /** 电费(元) */
+    @Excel(name = "电费(元)")
+    private Double electricityvalue;
+
+}

+ 8 - 0
module_ems/src/main/java/org/jeecg/modules/dataElectricity/mapper/DataElectricityMapper.java

@@ -23,4 +23,12 @@ public interface DataElectricityMapper extends BaseMapper<DataElectricity> {
      * @return 分时电量集合
      */
     public List<DataElectricity> selectElectricityByDay(DataElectricity electricity);
+
+    /**
+     * 用电集抄
+     *
+     * @param emsElectricity 分时电量
+     * @return 分时电量集合
+     */
+    public List<DataElectricity> selectEmsElecSta(DataElectricity emsElectricity);
 }

+ 28 - 0
module_ems/src/main/java/org/jeecg/modules/dataElectricity/mapper/xml/DataElectricityMapper.xml

@@ -33,4 +33,32 @@
         order by id asc
     </select>
 
+    <select id="selectEmsElecSta" parameterType="org.jeecg.modules.dataElectricity.entity.DataElectricity" resultMap="DataElectricityResult">
+        SELECT a.equipmentid,e.equipmentname,e.equipmentcode,b.tagvalue as beginvalue,c.tagvalue as endvalue,c.tagvalue-b.tagvalue as tagvalue
+        FROM tpm_equipment_status as a
+                 left join tpm_equipment as e
+                           on a.equipmentid=e.id
+                 left join (
+            select z.equipmentid,z.tagvalue
+            from (
+                     select equipmentid,tagvalue,
+                            row_number() over(partition by equipmentid order by logtime asc) mm
+                     from ems_data_electricity
+                     where logtime &gt;= #{params.beginTime} and logtime &lt;= #{params.endTime}
+                 ) as z
+            where mm=1
+        ) as b on a.equipmentid=b.equipmentid
+                 left join (
+            select y.equipmentid,y.tagvalue
+            from (
+                     select equipmentid,tagvalue,
+                            row_number() over(partition by equipmentid order by logtime desc) mm
+                     from ems_data_electricity
+                     where logtime &gt;= #{params.beginTime} and logtime &lt;= #{params.endTime}
+                 ) as y
+            where mm=1
+        ) as c
+                           on a.equipmentid=c.equipmentid
+    </select>
+
 </mapper>

+ 18 - 0
module_ems/src/main/java/org/jeecg/modules/dataElectricity/service/IDataElectricityService.java

@@ -2,6 +2,11 @@ package org.jeecg.modules.dataElectricity.service;
 
 import org.jeecg.modules.dataElectricity.entity.DataElectricity;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.dataElectricity.entity.DataElectricitySta;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
 
 /**
  * @Description: ems_data_electricity
@@ -11,4 +16,17 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IDataElectricityService extends IService<DataElectricity> {
 
+    /**
+     * 用电集抄
+     *
+     * @param emsElectricity 分时电量
+     * @return 分时电量
+     */
+    public List<DataElectricitySta> selectEmsElecSta(DataElectricity emsElectricity);
+
+    /**
+     * 导出用电集抄
+     */
+    public ModelAndView exportsta(HttpServletRequest request, Class<DataElectricitySta> clazz, String title, DataElectricity dataElectricity);
+
 }

+ 77 - 0
module_ems/src/main/java/org/jeecg/modules/dataElectricity/service/impl/DataElectricityServiceImpl.java

@@ -1,11 +1,25 @@
 package org.jeecg.modules.dataElectricity.service.impl;
 
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.dataElectricity.entity.DataElectricity;
+import org.jeecg.modules.dataElectricity.entity.DataElectricitySta;
 import org.jeecg.modules.dataElectricity.mapper.DataElectricityMapper;
 import org.jeecg.modules.dataElectricity.service.IDataElectricityService;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: ems_data_electricity
@@ -16,4 +30,67 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 @Service
 public class DataElectricityServiceImpl extends ServiceImpl<DataElectricityMapper, DataElectricity> implements IDataElectricityService {
 
+    @Autowired
+    private DataElectricityMapper dataElectricityMapper;
+
+    /**
+     * 用电集抄
+     *
+     * @param emsElectricity 分时电量
+     * @return 分时电量
+     */
+    @Override
+    public List<DataElectricitySta> selectEmsElecSta(DataElectricity emsElectricity)
+    {
+        List<DataElectricity> tempList = dataElectricityMapper.selectEmsElecSta(emsElectricity);
+        List<DataElectricitySta> elecList = new ArrayList<>();
+
+        // 将信息转换一下
+        if (tempList != null && tempList.size() > 0) {
+            for (DataElectricity elec : tempList) {
+                if (elec == null) {
+                    continue;
+                }
+                DataElectricitySta sta = new DataElectricitySta();
+                sta.setEquipmentname(elec.getEquipmentname());
+                sta.setEquipmentcode(elec.getEquipmentcode());
+                sta.setBeginvalue(elec.getBeginvalue());
+                sta.setEndvalue(elec.getEndvalue());
+                sta.setTagvalue(elec.getTagvalue());
+                sta.setElectricityvalue(elec.getElectricityvalue());
+
+                elecList.add(sta);
+            }
+        }
+
+        return elecList;
+    }
+
+
+    /**
+     * 导出用电集抄
+     */
+    @Override
+    public ModelAndView exportsta(HttpServletRequest request, Class<DataElectricitySta> clazz, String title, DataElectricity dataElectricity) {
+//        System.out.println("进入服务层");
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        //1.根据传送的时间找出用电集抄记录
+        List<DataElectricitySta> dataElectricityStaList = selectEmsElecSta(dataElectricity);
+        System.out.println(dataElectricityStaList);
+
+        // 2. AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        //此处设置的filename无效 ,前端会重更新设置一下
+        mv.addObject(NormalExcelConstants.FILE_NAME, title);
+        mv.addObject(NormalExcelConstants.CLASS, clazz);
+        //update-begin--Author:liusq  Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
+        ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
+//        exportParams.setImageBasePath(upLoadPath);
+        //update-end--Author:liusq  Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
+        mv.addObject(NormalExcelConstants.PARAMS, exportParams);
+        mv.addObject(NormalExcelConstants.DATA_LIST, dataElectricityStaList);
+        return mv;
+    }
+
+
 }