wukai 1 жил өмнө
parent
commit
3354c97322
28 өөрчлөгдсөн 1722 нэмэгдсэн , 382 устгасан
  1. 38 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/controller/DataController.java
  2. 127 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/controller/TwinCalcHourEnergyController.java
  3. 21 33
      ruoyi-admin/src/main/java/com/ruoyi/biz/controller/TwinWorkshopController.java
  4. 127 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/controller/TwinWorkshopEnergyController.java
  5. 58 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/domain/TwinCalcHourEnergy.java
  6. 23 49
      ruoyi-admin/src/main/java/com/ruoyi/biz/domain/TwinWorkshop.java
  7. 31 80
      ruoyi-admin/src/main/java/com/ruoyi/biz/domain/TwinWorkshopEnergy.java
  8. 61 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/mapper/TwinCalcHourEnergyMapper.java
  9. 61 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/mapper/TwinWorkshopEnergyMapper.java
  10. 22 13
      ruoyi-admin/src/main/java/com/ruoyi/biz/mapper/TwinWorkshopMapper.java
  11. 12 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/service/ITaskService.java
  12. 61 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/service/ITwinCalcHourEnergyService.java
  13. 61 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/service/ITwinWorkshopEnergyService.java
  14. 0 3
      ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/ApiServiceImpl.java
  15. 64 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TaskServiceImpl.java
  16. 94 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TwinCalcHourEnergyServiceImpl.java
  17. 94 0
      ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TwinWorkshopEnergyServiceImpl.java
  18. 51 41
      ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TwinWorkshopServiceImpl.java
  19. 77 0
      ruoyi-admin/src/main/resources/mapper/biz/TwinCalcHourEnergyMapper.xml
  20. 87 0
      ruoyi-admin/src/main/resources/mapper/biz/TwinWorkshopEnergyMapper.xml
  21. 41 22
      ruoyi-admin/src/main/resources/mapper/biz/TwinWorkshopMapper.xml
  22. 66 0
      ruoyi-admin/src/main/resources/templates/biz/calcEnergy/add.html
  23. 114 0
      ruoyi-admin/src/main/resources/templates/biz/calcEnergy/calcEnergy.html
  24. 67 0
      ruoyi-admin/src/main/resources/templates/biz/calcEnergy/edit.html
  25. 36 0
      ruoyi-admin/src/main/resources/templates/biz/data/data.html
  26. 82 69
      ruoyi-admin/src/main/resources/templates/biz/workshop/add.html
  27. 119 72
      ruoyi-admin/src/main/resources/templates/biz/workshop/edit.html
  28. 27 0
      ruoyi-admin/src/test/java/com/jjt/CalcEnergyTest.java

+ 38 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/controller/DataController.java

@@ -99,4 +99,42 @@ public class DataController extends BaseController {
         } while (!sld.isAfter(eld));
         return success();
     }
+
+    @GetMapping("/bl4")
+    @ResponseBody
+    public AjaxResult bl4(String sd, String ed) {
+        LocalDate sld = LocalDate.parse(sd);
+        LocalDate eld = LocalDate.parse(ed);
+        do {
+            for (int i = 0; i < 24; i++) {
+                //先删除数据,再进行
+                LocalDateTime start = LocalDateTime.of(sld, LocalTime.MIN).plusHours(i);
+                String date = start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+                LocalDateTime edt = start.plusHours(1);
+                String sql = "DELETE FROM TWIN_CALC_HOUR_ENERGY WHERE DATA_DATE=? AND HOUR=?";
+                jdbcTemplate.update(sql, date, i);
+                taskService.calcEnergy(start, edt);
+            }
+            sld = sld.plusDays(1);
+        } while (!sld.isAfter(eld));
+        return success();
+    }
+
+    @GetMapping("/bl5")
+    @ResponseBody
+    public AjaxResult bl5(String date, int sp, int ep) {
+        LocalDate localDate = LocalDate.parse(date);
+        LocalDateTime ldt = LocalDateTime.of(localDate, LocalTime.MIN);
+        for (; sp <= ep; sp++) {
+            //先删除数据,再进行
+            LocalDateTime start = ldt.plusHours(sp).minusHours(1);
+            LocalDateTime end = start.plusHours(1);
+            String sql = "DELETE FROM TWIN_CALC_HOUR_ENERGY WHERE DATA_DATE=? AND HOUR=?";
+            jdbcTemplate.update(sql, date, sp);
+            taskService.calcEnergy(start, end);
+        }
+        return success();
+    }
+
+
 }

+ 127 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/controller/TwinCalcHourEnergyController.java

@@ -0,0 +1,127 @@
+package com.ruoyi.biz.controller;
+
+import java.util.List;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.biz.domain.TwinCalcHourEnergy;
+import com.ruoyi.biz.service.ITwinCalcHourEnergyService;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+
+/**
+ * 能源1小时统计数据Controller
+ * 
+ * @author ruoyi
+ * @date 2024-12-24
+ */
+@Controller
+@RequestMapping("/biz/calcEnergy")
+public class TwinCalcHourEnergyController extends BaseController
+{
+    private String prefix = "biz/calcEnergy";
+
+    @Autowired
+    private ITwinCalcHourEnergyService twinCalcHourEnergyService;
+
+    @RequiresPermissions("biz:calcEnergy:view")
+    @GetMapping()
+    public String calcEnergy()
+    {
+        return prefix + "/calcEnergy";
+    }
+
+    /**
+     * 查询能源1小时统计数据列表
+     */
+    @RequiresPermissions("biz:calcEnergy:list")
+    @PostMapping("/list")
+    @ResponseBody
+    public TableDataInfo list(TwinCalcHourEnergy twinCalcHourEnergy)
+    {
+        startPage();
+        List<TwinCalcHourEnergy> list = twinCalcHourEnergyService.selectTwinCalcHourEnergyList(twinCalcHourEnergy);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出能源1小时统计数据列表
+     */
+    @RequiresPermissions("biz:calcEnergy:export")
+    @Log(title = "能源1小时统计数据", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    @ResponseBody
+    public AjaxResult export(TwinCalcHourEnergy twinCalcHourEnergy)
+    {
+        List<TwinCalcHourEnergy> list = twinCalcHourEnergyService.selectTwinCalcHourEnergyList(twinCalcHourEnergy);
+        ExcelUtil<TwinCalcHourEnergy> util = new ExcelUtil<TwinCalcHourEnergy>(TwinCalcHourEnergy.class);
+        return util.exportExcel(list, "能源1小时统计数据数据");
+    }
+
+    /**
+     * 新增能源1小时统计数据
+     */
+    @GetMapping("/add")
+    public String add()
+    {
+        return prefix + "/add";
+    }
+
+    /**
+     * 新增保存能源1小时统计数据
+     */
+    @RequiresPermissions("biz:calcEnergy:add")
+    @Log(title = "能源1小时统计数据", businessType = BusinessType.INSERT)
+    @PostMapping("/add")
+    @ResponseBody
+    public AjaxResult addSave(TwinCalcHourEnergy twinCalcHourEnergy)
+    {
+        return toAjax(twinCalcHourEnergyService.insertTwinCalcHourEnergy(twinCalcHourEnergy));
+    }
+
+    /**
+     * 修改能源1小时统计数据
+     */
+    @RequiresPermissions("biz:calcEnergy:edit")
+    @GetMapping("/edit/{autoId}")
+    public String edit(@PathVariable("autoId") Long autoId, ModelMap mmap)
+    {
+        TwinCalcHourEnergy twinCalcHourEnergy = twinCalcHourEnergyService.selectTwinCalcHourEnergyByAutoId(autoId);
+        mmap.put("twinCalcHourEnergy", twinCalcHourEnergy);
+        return prefix + "/edit";
+    }
+
+    /**
+     * 修改保存能源1小时统计数据
+     */
+    @RequiresPermissions("biz:calcEnergy:edit")
+    @Log(title = "能源1小时统计数据", businessType = BusinessType.UPDATE)
+    @PostMapping("/edit")
+    @ResponseBody
+    public AjaxResult editSave(TwinCalcHourEnergy twinCalcHourEnergy)
+    {
+        return toAjax(twinCalcHourEnergyService.updateTwinCalcHourEnergy(twinCalcHourEnergy));
+    }
+
+    /**
+     * 删除能源1小时统计数据
+     */
+    @RequiresPermissions("biz:calcEnergy:remove")
+    @Log(title = "能源1小时统计数据", businessType = BusinessType.DELETE)
+    @PostMapping( "/remove")
+    @ResponseBody
+    public AjaxResult remove(String ids)
+    {
+        return toAjax(twinCalcHourEnergyService.deleteTwinCalcHourEnergyByAutoIds(ids));
+    }
+}

+ 21 - 33
ruoyi-admin/src/main/java/com/ruoyi/biz/controller/TwinWorkshopController.java

@@ -1,34 +1,30 @@
 package com.ruoyi.biz.controller;
 
-import java.util.List;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import com.ruoyi.common.annotation.Log;
-import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.biz.domain.TwinWorkshop;
 import com.ruoyi.biz.service.ITwinWorkshopService;
+import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
 
 /**
  * 车间管理Controller
- * 
+ *
  * @author ruoyi
  * @date 2024-12-23
  */
 @Controller
 @RequestMapping("/biz/workshop")
-public class TwinWorkshopController extends BaseController
-{
+public class TwinWorkshopController extends BaseController {
     private String prefix = "biz/workshop";
 
     @Autowired
@@ -36,8 +32,7 @@ public class TwinWorkshopController extends BaseController
 
     @RequiresPermissions("biz:workshop:view")
     @GetMapping()
-    public String workshop()
-    {
+    public String workshop() {
         return prefix + "/workshop";
     }
 
@@ -47,8 +42,7 @@ public class TwinWorkshopController extends BaseController
     @RequiresPermissions("biz:workshop:list")
     @PostMapping("/list")
     @ResponseBody
-    public TableDataInfo list(TwinWorkshop twinWorkshop)
-    {
+    public TableDataInfo list(TwinWorkshop twinWorkshop) {
         startPage();
         List<TwinWorkshop> list = twinWorkshopService.selectTwinWorkshopList(twinWorkshop);
         return getDataTable(list);
@@ -61,8 +55,7 @@ public class TwinWorkshopController extends BaseController
     @Log(title = "车间管理", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     @ResponseBody
-    public AjaxResult export(TwinWorkshop twinWorkshop)
-    {
+    public AjaxResult export(TwinWorkshop twinWorkshop) {
         List<TwinWorkshop> list = twinWorkshopService.selectTwinWorkshopList(twinWorkshop);
         ExcelUtil<TwinWorkshop> util = new ExcelUtil<TwinWorkshop>(TwinWorkshop.class);
         return util.exportExcel(list, "车间管理数据");
@@ -72,8 +65,7 @@ public class TwinWorkshopController extends BaseController
      * 新增车间管理
      */
     @GetMapping("/add")
-    public String add()
-    {
+    public String add() {
         return prefix + "/add";
     }
 
@@ -84,8 +76,7 @@ public class TwinWorkshopController extends BaseController
     @Log(title = "车间管理", businessType = BusinessType.INSERT)
     @PostMapping("/add")
     @ResponseBody
-    public AjaxResult addSave(TwinWorkshop twinWorkshop)
-    {
+    public AjaxResult addSave(TwinWorkshop twinWorkshop) {
         return toAjax(twinWorkshopService.insertTwinWorkshop(twinWorkshop));
     }
 
@@ -94,8 +85,7 @@ public class TwinWorkshopController extends BaseController
      */
     @RequiresPermissions("biz:workshop:edit")
     @GetMapping("/edit/{wsId}")
-    public String edit(@PathVariable("wsId") Long wsId, ModelMap mmap)
-    {
+    public String edit(@PathVariable("wsId") Long wsId, ModelMap mmap) {
         TwinWorkshop twinWorkshop = twinWorkshopService.selectTwinWorkshopByWsId(wsId);
         mmap.put("twinWorkshop", twinWorkshop);
         return prefix + "/edit";
@@ -108,8 +98,7 @@ public class TwinWorkshopController extends BaseController
     @Log(title = "车间管理", businessType = BusinessType.UPDATE)
     @PostMapping("/edit")
     @ResponseBody
-    public AjaxResult editSave(TwinWorkshop twinWorkshop)
-    {
+    public AjaxResult editSave(TwinWorkshop twinWorkshop) {
         return toAjax(twinWorkshopService.updateTwinWorkshop(twinWorkshop));
     }
 
@@ -118,10 +107,9 @@ public class TwinWorkshopController extends BaseController
      */
     @RequiresPermissions("biz:workshop:remove")
     @Log(title = "车间管理", businessType = BusinessType.DELETE)
-    @PostMapping( "/remove")
+    @PostMapping("/remove")
     @ResponseBody
-    public AjaxResult remove(String ids)
-    {
+    public AjaxResult remove(String ids) {
         return toAjax(twinWorkshopService.deleteTwinWorkshopByWsIds(ids));
     }
 }

+ 127 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/controller/TwinWorkshopEnergyController.java

@@ -0,0 +1,127 @@
+package com.ruoyi.biz.controller;
+
+import java.util.List;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.biz.domain.TwinWorkshopEnergy;
+import com.ruoyi.biz.service.ITwinWorkshopEnergyService;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+
+/**
+ * 车间能源管理Controller
+ * 
+ * @author ruoyi
+ * @date 2024-12-24
+ */
+@Controller
+@RequestMapping("/biz/energy")
+public class TwinWorkshopEnergyController extends BaseController
+{
+    private String prefix = "biz/energy";
+
+    @Autowired
+    private ITwinWorkshopEnergyService twinWorkshopEnergyService;
+
+    @RequiresPermissions("biz:energy:view")
+    @GetMapping()
+    public String energy()
+    {
+        return prefix + "/energy";
+    }
+
+    /**
+     * 查询车间能源管理列表
+     */
+    @RequiresPermissions("biz:energy:list")
+    @PostMapping("/list")
+    @ResponseBody
+    public TableDataInfo list(TwinWorkshopEnergy twinWorkshopEnergy)
+    {
+        startPage();
+        List<TwinWorkshopEnergy> list = twinWorkshopEnergyService.selectTwinWorkshopEnergyList(twinWorkshopEnergy);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出车间能源管理列表
+     */
+    @RequiresPermissions("biz:energy:export")
+    @Log(title = "车间能源管理", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    @ResponseBody
+    public AjaxResult export(TwinWorkshopEnergy twinWorkshopEnergy)
+    {
+        List<TwinWorkshopEnergy> list = twinWorkshopEnergyService.selectTwinWorkshopEnergyList(twinWorkshopEnergy);
+        ExcelUtil<TwinWorkshopEnergy> util = new ExcelUtil<TwinWorkshopEnergy>(TwinWorkshopEnergy.class);
+        return util.exportExcel(list, "车间能源管理数据");
+    }
+
+    /**
+     * 新增车间能源管理
+     */
+    @GetMapping("/add")
+    public String add()
+    {
+        return prefix + "/add";
+    }
+
+    /**
+     * 新增保存车间能源管理
+     */
+    @RequiresPermissions("biz:energy:add")
+    @Log(title = "车间能源管理", businessType = BusinessType.INSERT)
+    @PostMapping("/add")
+    @ResponseBody
+    public AjaxResult addSave(TwinWorkshopEnergy twinWorkshopEnergy)
+    {
+        return toAjax(twinWorkshopEnergyService.insertTwinWorkshopEnergy(twinWorkshopEnergy));
+    }
+
+    /**
+     * 修改车间能源管理
+     */
+    @RequiresPermissions("biz:energy:edit")
+    @GetMapping("/edit/{energyId}")
+    public String edit(@PathVariable("energyId") Long energyId, ModelMap mmap)
+    {
+        TwinWorkshopEnergy twinWorkshopEnergy = twinWorkshopEnergyService.selectTwinWorkshopEnergyByEnergyId(energyId);
+        mmap.put("twinWorkshopEnergy", twinWorkshopEnergy);
+        return prefix + "/edit";
+    }
+
+    /**
+     * 修改保存车间能源管理
+     */
+    @RequiresPermissions("biz:energy:edit")
+    @Log(title = "车间能源管理", businessType = BusinessType.UPDATE)
+    @PostMapping("/edit")
+    @ResponseBody
+    public AjaxResult editSave(TwinWorkshopEnergy twinWorkshopEnergy)
+    {
+        return toAjax(twinWorkshopEnergyService.updateTwinWorkshopEnergy(twinWorkshopEnergy));
+    }
+
+    /**
+     * 删除车间能源管理
+     */
+    @RequiresPermissions("biz:energy:remove")
+    @Log(title = "车间能源管理", businessType = BusinessType.DELETE)
+    @PostMapping( "/remove")
+    @ResponseBody
+    public AjaxResult remove(String ids)
+    {
+        return toAjax(twinWorkshopEnergyService.deleteTwinWorkshopEnergyByEnergyIds(ids));
+    }
+}

+ 58 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/domain/TwinCalcHourEnergy.java

@@ -0,0 +1,58 @@
+package com.ruoyi.biz.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 能源1小时统计数据对象 twin_calc_hour_energy
+ *
+ * @author ruoyi
+ * @date 2024-12-24
+ */
+@ApiModel(value = "ITwinCalcHourEnergy", description = "能源1小时统计数据")
+@Data
+public class TwinCalcHourEnergy extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * ID
+     */
+    private Long autoId;
+
+    /**
+     * 日期
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @Excel(name = "日期", width = 30, dateFormat = "yyyy-MM-dd")
+    @ApiModelProperty("日期")
+    private Date dataDate;
+
+    /**
+     * 小时;0-23
+     */
+    @Excel(name = "小时;0-23")
+    @ApiModelProperty("小时;0-23")
+    private Integer hour;
+
+    /**
+     * 设备ID
+     */
+    @Excel(name = "设备ID")
+    @ApiModelProperty("设备ID")
+    private Long energyId;
+
+    /**
+     * 统计数据
+     */
+    @Excel(name = "统计数据")
+    @ApiModelProperty("统计数据")
+    private BigDecimal dataValue;
+
+}

+ 23 - 49
ruoyi-admin/src/main/java/com/ruoyi/biz/domain/TwinWorkshop.java

@@ -1,71 +1,45 @@
 package com.ruoyi.biz.domain;
 
-import java.util.List;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
 import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
-import com.ruoyi.common.core.domain.BaseEntity;
+import lombok.Data;
+
+import java.util.List;
 
 /**
  * 车间管理对象 twin_workshop
  *
  * @author ruoyi
- * @date 2024-12-23
+ * @date 2024-12-24
  */
 @ApiModel(value = "ITwinWorkshop", description = "车间管理")
-public class TwinWorkshop extends BaseEntity
-{
+@Data
+public class TwinWorkshop extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
-    /** 车间ID */
+    /**
+     * 车间ID
+     */
     private Long wsId;
 
-    /** 车间名称 */
+    /**
+     * 车间编码
+     */
+    @Excel(name = "车间编码")
+    @ApiModelProperty("车间编码")
+    private String wsCode;
+
+    /**
+     * 车间名称
+     */
     @Excel(name = "车间名称")
     @ApiModelProperty("车间名称")
     private String wsName;
 
-    /** 车间能源管理信息 */
+    /**
+     * 车间能源管理信息
+     */
     private List<TwinWorkshopEnergy> twinWorkshopEnergyList;
-
-    public void setWsId(Long wsId)
-    {
-        this.wsId = wsId;
-    }
-
-    public Long getWsId()
-    {
-        return wsId;
-    }
-    public void setWsName(String wsName)
-    {
-        this.wsName = wsName;
-    }
-
-    public String getWsName()
-    {
-        return wsName;
-    }
-
-    public List<TwinWorkshopEnergy> getTwinWorkshopEnergyList()
-    {
-        return twinWorkshopEnergyList;
-    }
-
-    public void setTwinWorkshopEnergyList(List<TwinWorkshopEnergy> twinWorkshopEnergyList)
-    {
-        this.twinWorkshopEnergyList = twinWorkshopEnergyList;
-    }
-
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("wsId", getWsId())
-            .append("wsName", getWsName())
-            .append("remark", getRemark())
-            .append("twinWorkshopEnergyList", getTwinWorkshopEnergyList())
-            .toString();
-    }
 }

+ 31 - 80
ruoyi-admin/src/main/java/com/ruoyi/biz/domain/TwinWorkshopEnergy.java

@@ -1,108 +1,59 @@
 package com.ruoyi.biz.domain;
 
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
 import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.BaseEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
 
 /**
  * 车间能源管理对象 twin_workshop_energy
- * 
+ *
  * @author ruoyi
  * @date 2024-12-23
  */
-public class TwinWorkshopEnergy extends BaseEntity
-{
+@Data
+public class TwinWorkshopEnergy extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
-    /** 能源ID */
+    /**
+     * 能源ID
+     */
     private Long energyId;
 
-    /** 车间ID */
+    /**
+     * 车间ID
+     */
     @Excel(name = "车间ID")
     private Long wsId;
 
-    /** 能源设备名称 */
+    /**
+     * 能源设备名称
+     */
     @Excel(name = "能源设备名称")
     private String energyName;
 
-    /** 能源设备类型 */
+    /**
+     * 能源设备类型
+     */
     @Excel(name = "能源设备类型")
     private String energyType;
 
-    /** 能源设备路径 */
+    /**
+     * 能源设备路径
+     */
     @Excel(name = "能源设备路径")
     private String energyPath;
-
-    /** 字段编码 */
+    /**
+     * 计算系数
+     */
+    @Excel(name = "计算系数")
+    @ApiModelProperty("计算系数")
+    private BigDecimal coefficient;
+    /**
+     * 字段编码
+     */
     @Excel(name = "字段编码")
     private String energyCode;
-
-    public void setEnergyId(Long energyId) 
-    {
-        this.energyId = energyId;
-    }
-
-    public Long getEnergyId() 
-    {
-        return energyId;
-    }
-    public void setWsId(Long wsId) 
-    {
-        this.wsId = wsId;
-    }
-
-    public Long getWsId() 
-    {
-        return wsId;
-    }
-    public void setEnergyName(String energyName) 
-    {
-        this.energyName = energyName;
-    }
-
-    public String getEnergyName() 
-    {
-        return energyName;
-    }
-    public void setEnergyType(String energyType) 
-    {
-        this.energyType = energyType;
-    }
-
-    public String getEnergyType() 
-    {
-        return energyType;
-    }
-    public void setEnergyPath(String energyPath) 
-    {
-        this.energyPath = energyPath;
-    }
-
-    public String getEnergyPath() 
-    {
-        return energyPath;
-    }
-    public void setEnergyCode(String energyCode) 
-    {
-        this.energyCode = energyCode;
-    }
-
-    public String getEnergyCode() 
-    {
-        return energyCode;
-    }
-
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("energyId", getEnergyId())
-            .append("wsId", getWsId())
-            .append("energyName", getEnergyName())
-            .append("energyType", getEnergyType())
-            .append("energyPath", getEnergyPath())
-            .append("energyCode", getEnergyCode())
-            .append("remark", getRemark())
-            .toString();
-    }
 }

+ 61 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/mapper/TwinCalcHourEnergyMapper.java

@@ -0,0 +1,61 @@
+package com.ruoyi.biz.mapper;
+
+import java.util.List;
+import com.ruoyi.biz.domain.TwinCalcHourEnergy;
+
+/**
+ * 能源1小时统计数据Mapper接口
+ * 
+ * @author ruoyi
+ * @date 2024-12-24
+ */
+public interface TwinCalcHourEnergyMapper 
+{
+    /**
+     * 查询能源1小时统计数据
+     * 
+     * @param autoId 能源1小时统计数据主键
+     * @return 能源1小时统计数据
+     */
+    public TwinCalcHourEnergy selectTwinCalcHourEnergyByAutoId(Long autoId);
+
+    /**
+     * 查询能源1小时统计数据列表
+     * 
+     * @param twinCalcHourEnergy 能源1小时统计数据
+     * @return 能源1小时统计数据集合
+     */
+    public List<TwinCalcHourEnergy> selectTwinCalcHourEnergyList(TwinCalcHourEnergy twinCalcHourEnergy);
+
+    /**
+     * 新增能源1小时统计数据
+     * 
+     * @param twinCalcHourEnergy 能源1小时统计数据
+     * @return 结果
+     */
+    public int insertTwinCalcHourEnergy(TwinCalcHourEnergy twinCalcHourEnergy);
+
+    /**
+     * 修改能源1小时统计数据
+     * 
+     * @param twinCalcHourEnergy 能源1小时统计数据
+     * @return 结果
+     */
+    public int updateTwinCalcHourEnergy(TwinCalcHourEnergy twinCalcHourEnergy);
+
+    /**
+     * 删除能源1小时统计数据
+     * 
+     * @param autoId 能源1小时统计数据主键
+     * @return 结果
+     */
+    public int deleteTwinCalcHourEnergyByAutoId(Long autoId);
+
+    /**
+     * 批量删除能源1小时统计数据
+     * 
+     * @param autoIds 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteTwinCalcHourEnergyByAutoIds(String[] autoIds);
+}

+ 61 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/mapper/TwinWorkshopEnergyMapper.java

@@ -0,0 +1,61 @@
+package com.ruoyi.biz.mapper;
+
+import java.util.List;
+import com.ruoyi.biz.domain.TwinWorkshopEnergy;
+
+/**
+ * 车间能源管理Mapper接口
+ * 
+ * @author ruoyi
+ * @date 2024-12-24
+ */
+public interface TwinWorkshopEnergyMapper 
+{
+    /**
+     * 查询车间能源管理
+     * 
+     * @param energyId 车间能源管理主键
+     * @return 车间能源管理
+     */
+    public TwinWorkshopEnergy selectTwinWorkshopEnergyByEnergyId(Long energyId);
+
+    /**
+     * 查询车间能源管理列表
+     * 
+     * @param twinWorkshopEnergy 车间能源管理
+     * @return 车间能源管理集合
+     */
+    public List<TwinWorkshopEnergy> selectTwinWorkshopEnergyList(TwinWorkshopEnergy twinWorkshopEnergy);
+
+    /**
+     * 新增车间能源管理
+     * 
+     * @param twinWorkshopEnergy 车间能源管理
+     * @return 结果
+     */
+    public int insertTwinWorkshopEnergy(TwinWorkshopEnergy twinWorkshopEnergy);
+
+    /**
+     * 修改车间能源管理
+     * 
+     * @param twinWorkshopEnergy 车间能源管理
+     * @return 结果
+     */
+    public int updateTwinWorkshopEnergy(TwinWorkshopEnergy twinWorkshopEnergy);
+
+    /**
+     * 删除车间能源管理
+     * 
+     * @param energyId 车间能源管理主键
+     * @return 结果
+     */
+    public int deleteTwinWorkshopEnergyByEnergyId(Long energyId);
+
+    /**
+     * 批量删除车间能源管理
+     * 
+     * @param energyIds 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteTwinWorkshopEnergyByEnergyIds(String[] energyIds);
+}

+ 22 - 13
ruoyi-admin/src/main/java/com/ruoyi/biz/mapper/TwinWorkshopMapper.java

@@ -6,15 +6,15 @@ import com.ruoyi.biz.domain.TwinWorkshopEnergy;
 
 /**
  * 车间管理Mapper接口
- * 
+ *
  * @author ruoyi
  * @date 2024-12-23
  */
-public interface TwinWorkshopMapper 
+public interface TwinWorkshopMapper
 {
     /**
      * 查询车间管理
-     * 
+     *
      * @param wsId 车间管理主键
      * @return 车间管理
      */
@@ -22,7 +22,7 @@ public interface TwinWorkshopMapper
 
     /**
      * 查询车间管理列表
-     * 
+     *
      * @param twinWorkshop 车间管理
      * @return 车间管理集合
      */
@@ -30,7 +30,7 @@ public interface TwinWorkshopMapper
 
     /**
      * 新增车间管理
-     * 
+     *
      * @param twinWorkshop 车间管理
      * @return 结果
      */
@@ -38,7 +38,7 @@ public interface TwinWorkshopMapper
 
     /**
      * 修改车间管理
-     * 
+     *
      * @param twinWorkshop 车间管理
      * @return 结果
      */
@@ -46,7 +46,7 @@ public interface TwinWorkshopMapper
 
     /**
      * 删除车间管理
-     * 
+     *
      * @param wsId 车间管理主键
      * @return 结果
      */
@@ -54,7 +54,7 @@ public interface TwinWorkshopMapper
 
     /**
      * 批量删除车间管理
-     * 
+     *
      * @param wsIds 需要删除的数据主键集合
      * @return 结果
      */
@@ -62,26 +62,35 @@ public interface TwinWorkshopMapper
 
     /**
      * 批量删除车间能源管理
-     * 
+     *
      * @param wsIds 需要删除的数据主键集合
      * @return 结果
      */
     public int deleteTwinWorkshopEnergyByWsIds(String[] wsIds);
-    
+
     /**
      * 批量新增车间能源管理
-     * 
+     *
      * @param twinWorkshopEnergyList 车间能源管理列表
      * @return 结果
      */
     public int batchTwinWorkshopEnergy(List<TwinWorkshopEnergy> twinWorkshopEnergyList);
-    
+
 
     /**
      * 通过车间管理主键删除车间能源管理信息
-     * 
+     *
      * @param wsId 车间管理ID
      * @return 结果
      */
     public int deleteTwinWorkshopEnergyByWsId(Long wsId);
+
+    /**
+     * 修改车间能源管理
+     *
+     * @param twinWorkshopEnergy 车间能源管理
+     * @return 结果
+     */
+    public int updateTwinWorkshopEnergy(TwinWorkshopEnergy twinWorkshopEnergy);
+
 }

+ 12 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/service/ITaskService.java

@@ -19,6 +19,10 @@ public interface ITaskService {
      */
     void calcLastHour();
 
+    /**
+     * 统计上一个时段的能源
+     */
+    void calcLastEnergy();
 
     /**
      * 统计昨日数据
@@ -51,6 +55,7 @@ public interface ITaskService {
      * @param period 时段
      */
     void calc(String date, int period);
+
     /**
      * 按设备循环计算
      *
@@ -58,4 +63,11 @@ public interface ITaskService {
      * @param end   结束时间戳
      */
     void calc4device(LocalDateTime start, LocalDateTime end);
+    /**
+     * 统计指定日期指定时段能耗数据
+     *
+     * @param start 开始时间戳
+     * @param end   结束时间戳
+     */
+    void calcEnergy(LocalDateTime start, LocalDateTime end);
 }

+ 61 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/service/ITwinCalcHourEnergyService.java

@@ -0,0 +1,61 @@
+package com.ruoyi.biz.service;
+
+import java.util.List;
+import com.ruoyi.biz.domain.TwinCalcHourEnergy;
+
+/**
+ * 能源1小时统计数据Service接口
+ * 
+ * @author ruoyi
+ * @date 2024-12-24
+ */
+public interface ITwinCalcHourEnergyService 
+{
+    /**
+     * 查询能源1小时统计数据
+     * 
+     * @param autoId 能源1小时统计数据主键
+     * @return 能源1小时统计数据
+     */
+    public TwinCalcHourEnergy selectTwinCalcHourEnergyByAutoId(Long autoId);
+
+    /**
+     * 查询能源1小时统计数据列表
+     * 
+     * @param twinCalcHourEnergy 能源1小时统计数据
+     * @return 能源1小时统计数据集合
+     */
+    public List<TwinCalcHourEnergy> selectTwinCalcHourEnergyList(TwinCalcHourEnergy twinCalcHourEnergy);
+
+    /**
+     * 新增能源1小时统计数据
+     * 
+     * @param twinCalcHourEnergy 能源1小时统计数据
+     * @return 结果
+     */
+    public int insertTwinCalcHourEnergy(TwinCalcHourEnergy twinCalcHourEnergy);
+
+    /**
+     * 修改能源1小时统计数据
+     * 
+     * @param twinCalcHourEnergy 能源1小时统计数据
+     * @return 结果
+     */
+    public int updateTwinCalcHourEnergy(TwinCalcHourEnergy twinCalcHourEnergy);
+
+    /**
+     * 批量删除能源1小时统计数据
+     * 
+     * @param autoIds 需要删除的能源1小时统计数据主键集合
+     * @return 结果
+     */
+    public int deleteTwinCalcHourEnergyByAutoIds(String autoIds);
+
+    /**
+     * 删除能源1小时统计数据信息
+     * 
+     * @param autoId 能源1小时统计数据主键
+     * @return 结果
+     */
+    public int deleteTwinCalcHourEnergyByAutoId(Long autoId);
+}

+ 61 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/service/ITwinWorkshopEnergyService.java

@@ -0,0 +1,61 @@
+package com.ruoyi.biz.service;
+
+import java.util.List;
+import com.ruoyi.biz.domain.TwinWorkshopEnergy;
+
+/**
+ * 车间能源管理Service接口
+ * 
+ * @author ruoyi
+ * @date 2024-12-24
+ */
+public interface ITwinWorkshopEnergyService 
+{
+    /**
+     * 查询车间能源管理
+     * 
+     * @param energyId 车间能源管理主键
+     * @return 车间能源管理
+     */
+    public TwinWorkshopEnergy selectTwinWorkshopEnergyByEnergyId(Long energyId);
+
+    /**
+     * 查询车间能源管理列表
+     * 
+     * @param twinWorkshopEnergy 车间能源管理
+     * @return 车间能源管理集合
+     */
+    public List<TwinWorkshopEnergy> selectTwinWorkshopEnergyList(TwinWorkshopEnergy twinWorkshopEnergy);
+
+    /**
+     * 新增车间能源管理
+     * 
+     * @param twinWorkshopEnergy 车间能源管理
+     * @return 结果
+     */
+    public int insertTwinWorkshopEnergy(TwinWorkshopEnergy twinWorkshopEnergy);
+
+    /**
+     * 修改车间能源管理
+     * 
+     * @param twinWorkshopEnergy 车间能源管理
+     * @return 结果
+     */
+    public int updateTwinWorkshopEnergy(TwinWorkshopEnergy twinWorkshopEnergy);
+
+    /**
+     * 批量删除车间能源管理
+     * 
+     * @param energyIds 需要删除的车间能源管理主键集合
+     * @return 结果
+     */
+    public int deleteTwinWorkshopEnergyByEnergyIds(String energyIds);
+
+    /**
+     * 删除车间能源管理信息
+     * 
+     * @param energyId 车间能源管理主键
+     * @return 结果
+     */
+    public int deleteTwinWorkshopEnergyByEnergyId(Long energyId);
+}

+ 0 - 3
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/ApiServiceImpl.java

@@ -95,9 +95,6 @@ public class ApiServiceImpl implements IApiService {
         CacheUtils.put(Constants.IOT_TOKEN, Constants.INDEX_CALC, indexData);
     }
 
-    @Resource
-    private ITwinDeviceSpecService specService;
-
     /**
      * 首页告警数据
      */

+ 64 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TaskServiceImpl.java

@@ -1,6 +1,9 @@
 package com.ruoyi.biz.service.impl;
 
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
 import com.ruoyi.biz.domain.*;
+import com.ruoyi.biz.mapper.TwinCalcHourEnergyMapper;
 import com.ruoyi.biz.mapper.TwinCalcHourSpecMapper;
 import com.ruoyi.biz.service.*;
 import com.ruoyi.biz.tools.Tools;
@@ -13,6 +16,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -53,6 +57,8 @@ public class TaskServiceImpl implements ITaskService {
     private ITwinCalcHourService hourService;
     @Resource
     private SqlSessionFactory factory;
+    @Resource
+    private ITwinWorkshopService workshopService;
 
     /**
      * 从数据库最后一个时间段统计至当前的上一个偶数时间点
@@ -95,6 +101,63 @@ public class TaskServiceImpl implements ITaskService {
     }
 
     /**
+     * 统计指定日期指定时段能耗数据
+     *
+     * @param start 开始时间戳
+     * @param end   结束时间戳
+     */
+    @Override
+    public void calcEnergy(LocalDateTime start, LocalDateTime end) {
+        Date date = Date.from(start.toLocalDate().atStartOfDay(ZoneOffset.of("+8")).toInstant());
+        int period = start.getHour();
+        Long startTime = start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        Long endTime = end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        String baseSql = "select %s from %s where time>%s and time <=%s";
+        TwinWorkshop ws = workshopService.selectTwinWorkshopByWsId(1L);
+        List<TwinWorkshopEnergy> energyList = ws.getTwinWorkshopEnergyList();
+        List<TwinCalcHourEnergy> list = new ArrayList<>();
+        iotService.getToken();
+        for (TwinWorkshopEnergy energy : energyList) {
+            String sql = String.format(baseSql, energy.getEnergyCode(), energy.getEnergyPath(), startTime, endTime);
+            JSONObject jsonObject = iotService.query(sql);
+            JSONObject data = jsonObject.getJSONObject("data");
+            JSONArray values = data.getJSONArray("values");
+            JSONArray first = values.getJSONArray(0);
+            JSONArray last = values.getJSONArray(values.size() - 1);
+            int res = last.getInt(0) - first.getInt(0);
+            TwinCalcHourEnergy calcEnergy = new TwinCalcHourEnergy();
+            calcEnergy.setEnergyId(energy.getEnergyId());
+            BigDecimal dataV = BigDecimal.valueOf(res).multiply(energy.getCoefficient());
+            calcEnergy.setDataValue(dataV);
+            calcEnergy.setDataDate(date);
+            calcEnergy.setHour(period);
+            list.add(calcEnergy);
+        }
+        if (list.size() > 0) {
+            try (SqlSession sqlSession = factory.openSession(ExecutorType.BATCH, false)) {
+                TwinCalcHourEnergyMapper mapper = sqlSession.getMapper(TwinCalcHourEnergyMapper.class);
+                list.forEach(mapper::insertTwinCalcHourEnergy);
+                sqlSession.commit();
+            }
+        }
+    }
+
+    /**
+     * 统计上一个时段的能源
+     */
+    @Override
+    public void calcLastEnergy() {
+        LocalDateTime ldt = Tools.currWholeTime();
+        //上一个小时
+        ldt = ldt.minusHours(1);
+        //这里不需要向前取一秒了
+        LocalDateTime start = ldt;
+        LocalDateTime end = ldt.plusHours(1);
+        calcEnergy(start, end);
+
+    }
+
+    /**
      * 统计昨日数据
      */
     @Override
@@ -204,6 +267,7 @@ public class TaskServiceImpl implements ITaskService {
 
     }
 
+
     /**
      * 执行数据获取操作
      *

+ 94 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TwinCalcHourEnergyServiceImpl.java

@@ -0,0 +1,94 @@
+package com.ruoyi.biz.service.impl;
+
+import java.util.List;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.biz.mapper.TwinCalcHourEnergyMapper;
+import com.ruoyi.biz.domain.TwinCalcHourEnergy;
+import com.ruoyi.biz.service.ITwinCalcHourEnergyService;
+import com.ruoyi.common.core.text.Convert;
+
+/**
+ * 能源1小时统计数据Service业务层处理
+ * 
+ * @author ruoyi
+ * @date 2024-12-24
+ */
+@Service
+public class TwinCalcHourEnergyServiceImpl implements ITwinCalcHourEnergyService 
+{
+    @Autowired
+    private TwinCalcHourEnergyMapper twinCalcHourEnergyMapper;
+
+    /**
+     * 查询能源1小时统计数据
+     * 
+     * @param autoId 能源1小时统计数据主键
+     * @return 能源1小时统计数据
+     */
+    @Override
+    public TwinCalcHourEnergy selectTwinCalcHourEnergyByAutoId(Long autoId)
+    {
+        return twinCalcHourEnergyMapper.selectTwinCalcHourEnergyByAutoId(autoId);
+    }
+
+    /**
+     * 查询能源1小时统计数据列表
+     * 
+     * @param twinCalcHourEnergy 能源1小时统计数据
+     * @return 能源1小时统计数据
+     */
+    @Override
+    public List<TwinCalcHourEnergy> selectTwinCalcHourEnergyList(TwinCalcHourEnergy twinCalcHourEnergy)
+    {
+        return twinCalcHourEnergyMapper.selectTwinCalcHourEnergyList(twinCalcHourEnergy);
+    }
+
+    /**
+     * 新增能源1小时统计数据
+     * 
+     * @param twinCalcHourEnergy 能源1小时统计数据
+     * @return 结果
+     */
+    @Override
+    public int insertTwinCalcHourEnergy(TwinCalcHourEnergy twinCalcHourEnergy)
+    {
+        return twinCalcHourEnergyMapper.insertTwinCalcHourEnergy(twinCalcHourEnergy);
+    }
+
+    /**
+     * 修改能源1小时统计数据
+     * 
+     * @param twinCalcHourEnergy 能源1小时统计数据
+     * @return 结果
+     */
+    @Override
+    public int updateTwinCalcHourEnergy(TwinCalcHourEnergy twinCalcHourEnergy)
+    {
+        return twinCalcHourEnergyMapper.updateTwinCalcHourEnergy(twinCalcHourEnergy);
+    }
+
+    /**
+     * 批量删除能源1小时统计数据
+     * 
+     * @param autoIds 需要删除的能源1小时统计数据主键
+     * @return 结果
+     */
+    @Override
+    public int deleteTwinCalcHourEnergyByAutoIds(String autoIds)
+    {
+        return twinCalcHourEnergyMapper.deleteTwinCalcHourEnergyByAutoIds(Convert.toStrArray(autoIds));
+    }
+
+    /**
+     * 删除能源1小时统计数据信息
+     * 
+     * @param autoId 能源1小时统计数据主键
+     * @return 结果
+     */
+    @Override
+    public int deleteTwinCalcHourEnergyByAutoId(Long autoId)
+    {
+        return twinCalcHourEnergyMapper.deleteTwinCalcHourEnergyByAutoId(autoId);
+    }
+}

+ 94 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TwinWorkshopEnergyServiceImpl.java

@@ -0,0 +1,94 @@
+package com.ruoyi.biz.service.impl;
+
+import java.util.List;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.biz.mapper.TwinWorkshopEnergyMapper;
+import com.ruoyi.biz.domain.TwinWorkshopEnergy;
+import com.ruoyi.biz.service.ITwinWorkshopEnergyService;
+import com.ruoyi.common.core.text.Convert;
+
+/**
+ * 车间能源管理Service业务层处理
+ * 
+ * @author ruoyi
+ * @date 2024-12-24
+ */
+@Service
+public class TwinWorkshopEnergyServiceImpl implements ITwinWorkshopEnergyService 
+{
+    @Autowired
+    private TwinWorkshopEnergyMapper twinWorkshopEnergyMapper;
+
+    /**
+     * 查询车间能源管理
+     * 
+     * @param energyId 车间能源管理主键
+     * @return 车间能源管理
+     */
+    @Override
+    public TwinWorkshopEnergy selectTwinWorkshopEnergyByEnergyId(Long energyId)
+    {
+        return twinWorkshopEnergyMapper.selectTwinWorkshopEnergyByEnergyId(energyId);
+    }
+
+    /**
+     * 查询车间能源管理列表
+     * 
+     * @param twinWorkshopEnergy 车间能源管理
+     * @return 车间能源管理
+     */
+    @Override
+    public List<TwinWorkshopEnergy> selectTwinWorkshopEnergyList(TwinWorkshopEnergy twinWorkshopEnergy)
+    {
+        return twinWorkshopEnergyMapper.selectTwinWorkshopEnergyList(twinWorkshopEnergy);
+    }
+
+    /**
+     * 新增车间能源管理
+     * 
+     * @param twinWorkshopEnergy 车间能源管理
+     * @return 结果
+     */
+    @Override
+    public int insertTwinWorkshopEnergy(TwinWorkshopEnergy twinWorkshopEnergy)
+    {
+        return twinWorkshopEnergyMapper.insertTwinWorkshopEnergy(twinWorkshopEnergy);
+    }
+
+    /**
+     * 修改车间能源管理
+     * 
+     * @param twinWorkshopEnergy 车间能源管理
+     * @return 结果
+     */
+    @Override
+    public int updateTwinWorkshopEnergy(TwinWorkshopEnergy twinWorkshopEnergy)
+    {
+        return twinWorkshopEnergyMapper.updateTwinWorkshopEnergy(twinWorkshopEnergy);
+    }
+
+    /**
+     * 批量删除车间能源管理
+     * 
+     * @param energyIds 需要删除的车间能源管理主键
+     * @return 结果
+     */
+    @Override
+    public int deleteTwinWorkshopEnergyByEnergyIds(String energyIds)
+    {
+        return twinWorkshopEnergyMapper.deleteTwinWorkshopEnergyByEnergyIds(Convert.toStrArray(energyIds));
+    }
+
+    /**
+     * 删除车间能源管理信息
+     * 
+     * @param energyId 车间能源管理主键
+     * @return 结果
+     */
+    @Override
+    public int deleteTwinWorkshopEnergyByEnergyId(Long energyId)
+    {
+        return twinWorkshopEnergyMapper.deleteTwinWorkshopEnergyByEnergyId(energyId);
+    }
+}

+ 51 - 41
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TwinWorkshopServiceImpl.java

@@ -1,63 +1,63 @@
 package com.ruoyi.biz.service.impl;
 
-import java.util.List;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import java.util.ArrayList;
-import com.ruoyi.common.utils.StringUtils;
-import org.springframework.transaction.annotation.Transactional;
+import com.ruoyi.biz.domain.TwinWorkshop;
 import com.ruoyi.biz.domain.TwinWorkshopEnergy;
+import com.ruoyi.biz.mapper.TwinWorkshopEnergyMapper;
 import com.ruoyi.biz.mapper.TwinWorkshopMapper;
-import com.ruoyi.biz.domain.TwinWorkshop;
 import com.ruoyi.biz.service.ITwinWorkshopService;
 import com.ruoyi.common.core.text.Convert;
+import com.ruoyi.common.utils.StringUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * 车间管理Service业务层处理
- * 
+ *
  * @author ruoyi
  * @date 2024-12-23
  */
 @Service
-public class TwinWorkshopServiceImpl implements ITwinWorkshopService 
-{
-    @Autowired
+public class TwinWorkshopServiceImpl implements ITwinWorkshopService {
+    @Resource
     private TwinWorkshopMapper twinWorkshopMapper;
+    @Resource
+    private TwinWorkshopEnergyMapper energyMapper;
 
     /**
      * 查询车间管理
-     * 
+     *
      * @param wsId 车间管理主键
      * @return 车间管理
      */
     @Override
-    public TwinWorkshop selectTwinWorkshopByWsId(Long wsId)
-    {
+    public TwinWorkshop selectTwinWorkshopByWsId(Long wsId) {
         return twinWorkshopMapper.selectTwinWorkshopByWsId(wsId);
     }
 
     /**
      * 查询车间管理列表
-     * 
+     *
      * @param twinWorkshop 车间管理
      * @return 车间管理
      */
     @Override
-    public List<TwinWorkshop> selectTwinWorkshopList(TwinWorkshop twinWorkshop)
-    {
+    public List<TwinWorkshop> selectTwinWorkshopList(TwinWorkshop twinWorkshop) {
         return twinWorkshopMapper.selectTwinWorkshopList(twinWorkshop);
     }
 
     /**
      * 新增车间管理
-     * 
+     *
      * @param twinWorkshop 车间管理
      * @return 结果
      */
     @Transactional
     @Override
-    public int insertTwinWorkshop(TwinWorkshop twinWorkshop)
-    {
+    public int insertTwinWorkshop(TwinWorkshop twinWorkshop) {
         int rows = twinWorkshopMapper.insertTwinWorkshop(twinWorkshop);
         insertTwinWorkshopEnergy(twinWorkshop);
         return rows;
@@ -65,68 +65,78 @@ public class TwinWorkshopServiceImpl implements ITwinWorkshopService
 
     /**
      * 修改车间管理
-     * 
+     *
      * @param twinWorkshop 车间管理
      * @return 结果
      */
     @Transactional
     @Override
-    public int updateTwinWorkshop(TwinWorkshop twinWorkshop)
-    {
-        twinWorkshopMapper.deleteTwinWorkshopEnergyByWsId(twinWorkshop.getWsId());
+    public int updateTwinWorkshop(TwinWorkshop twinWorkshop) {
+//        twinWorkshopMapper.deleteTwinWorkshopEnergyByWsId(twinWorkshop.getWsId());
         insertTwinWorkshopEnergy(twinWorkshop);
         return twinWorkshopMapper.updateTwinWorkshop(twinWorkshop);
     }
 
     /**
      * 批量删除车间管理
-     * 
+     *
      * @param wsIds 需要删除的车间管理主键
      * @return 结果
      */
     @Transactional
     @Override
-    public int deleteTwinWorkshopByWsIds(String wsIds)
-    {
+    public int deleteTwinWorkshopByWsIds(String wsIds) {
         twinWorkshopMapper.deleteTwinWorkshopEnergyByWsIds(Convert.toStrArray(wsIds));
         return twinWorkshopMapper.deleteTwinWorkshopByWsIds(Convert.toStrArray(wsIds));
     }
 
     /**
      * 删除车间管理信息
-     * 
+     *
      * @param wsId 车间管理主键
      * @return 结果
      */
     @Transactional
     @Override
-    public int deleteTwinWorkshopByWsId(Long wsId)
-    {
+    public int deleteTwinWorkshopByWsId(Long wsId) {
         twinWorkshopMapper.deleteTwinWorkshopEnergyByWsId(wsId);
         return twinWorkshopMapper.deleteTwinWorkshopByWsId(wsId);
     }
 
     /**
      * 新增车间能源管理信息
-     * 
+     *
      * @param twinWorkshop 车间管理对象
      */
-    public void insertTwinWorkshopEnergy(TwinWorkshop twinWorkshop)
-    {
+    public void insertTwinWorkshopEnergy(TwinWorkshop twinWorkshop) {
+        TwinWorkshop old = selectTwinWorkshopByWsId(twinWorkshop.getWsId());
+        List<TwinWorkshopEnergy> oldList = old.getTwinWorkshopEnergyList();
+        List<TwinWorkshopEnergy> insertList = new ArrayList<>();
+        List<TwinWorkshopEnergy> updateList = new ArrayList<>();
         List<TwinWorkshopEnergy> twinWorkshopEnergyList = twinWorkshop.getTwinWorkshopEnergyList();
         Long wsId = twinWorkshop.getWsId();
-        if (StringUtils.isNotNull(twinWorkshopEnergyList))
-        {
+        if (StringUtils.isNotNull(twinWorkshopEnergyList)) {
             List<TwinWorkshopEnergy> list = new ArrayList<TwinWorkshopEnergy>();
-            for (TwinWorkshopEnergy twinWorkshopEnergy : twinWorkshopEnergyList)
-            {
+            for (TwinWorkshopEnergy twinWorkshopEnergy : twinWorkshopEnergyList) {
                 twinWorkshopEnergy.setWsId(wsId);
-                list.add(twinWorkshopEnergy);
+                if (twinWorkshopEnergy.getEnergyId() != null) {
+                    updateList.add(twinWorkshopEnergy);
+                } else {
+                    insertList.add(twinWorkshopEnergy);
+                }
+            }
+            if (insertList.size() > 0) {
+                for (TwinWorkshopEnergy twinWorkshopEnergy : insertList) {
+                    energyMapper.insertTwinWorkshopEnergy(twinWorkshopEnergy);
+                }
             }
-            if (list.size() > 0)
-            {
-                twinWorkshopMapper.batchTwinWorkshopEnergy(list);
+
+            if (updateList.size() > 0) {
+                for (TwinWorkshopEnergy twinWorkshopEnergy : updateList) {
+                    energyMapper.updateTwinWorkshopEnergy(twinWorkshopEnergy);
+                }
             }
+
         }
     }
 }

+ 77 - 0
ruoyi-admin/src/main/resources/mapper/biz/TwinCalcHourEnergyMapper.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.biz.mapper.TwinCalcHourEnergyMapper">
+    
+    <resultMap type="TwinCalcHourEnergy" id="TwinCalcHourEnergyResult">
+        <result property="autoId"    column="AUTO_ID"    />
+        <result property="dataDate"    column="DATA_DATE"    />
+        <result property="hour"    column="HOUR"    />
+        <result property="energyId"    column="ENERGY_ID"    />
+        <result property="dataValue"    column="DATA_VALUE"    />
+        <result property="remark"    column="REMARK"    />
+    </resultMap>
+
+    <sql id="selectTwinCalcHourEnergyVo">
+        select AUTO_ID, DATA_DATE, HOUR, ENERGY_ID, DATA_VALUE, REMARK from twin_calc_hour_energy
+    </sql>
+
+    <select id="selectTwinCalcHourEnergyList" parameterType="TwinCalcHourEnergy" resultMap="TwinCalcHourEnergyResult">
+        <include refid="selectTwinCalcHourEnergyVo"/>
+        <where>  
+            <if test="dataDate != null "> and DATA_DATE = #{dataDate}</if>
+            <if test="hour != null "> and HOUR = #{hour}</if>
+            <if test="energyId != null "> and ENERGY_ID = #{energyId}</if>
+            <if test="dataValue != null "> and DATA_VALUE = #{dataValue}</if>
+            <if test="remark != null  and remark != ''"> and REMARK = #{remark}</if>
+        </where>
+    </select>
+    
+    <select id="selectTwinCalcHourEnergyByAutoId" parameterType="Long" resultMap="TwinCalcHourEnergyResult">
+        <include refid="selectTwinCalcHourEnergyVo"/>
+        where AUTO_ID = #{autoId}
+    </select>
+        
+    <insert id="insertTwinCalcHourEnergy" parameterType="TwinCalcHourEnergy" useGeneratedKeys="true" keyProperty="autoId">
+        insert into twin_calc_hour_energy
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="dataDate != null">DATA_DATE,</if>
+            <if test="hour != null">HOUR,</if>
+            <if test="energyId != null">ENERGY_ID,</if>
+            <if test="dataValue != null">DATA_VALUE,</if>
+            <if test="remark != null">REMARK,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="dataDate != null">#{dataDate},</if>
+            <if test="hour != null">#{hour},</if>
+            <if test="energyId != null">#{energyId},</if>
+            <if test="dataValue != null">#{dataValue},</if>
+            <if test="remark != null">#{remark},</if>
+         </trim>
+    </insert>
+
+    <update id="updateTwinCalcHourEnergy" parameterType="TwinCalcHourEnergy">
+        update twin_calc_hour_energy
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="dataDate != null">DATA_DATE = #{dataDate},</if>
+            <if test="hour != null">HOUR = #{hour},</if>
+            <if test="energyId != null">ENERGY_ID = #{energyId},</if>
+            <if test="dataValue != null">DATA_VALUE = #{dataValue},</if>
+            <if test="remark != null">REMARK = #{remark},</if>
+        </trim>
+        where AUTO_ID = #{autoId}
+    </update>
+
+    <delete id="deleteTwinCalcHourEnergyByAutoId" parameterType="Long">
+        delete from twin_calc_hour_energy where AUTO_ID = #{autoId}
+    </delete>
+
+    <delete id="deleteTwinCalcHourEnergyByAutoIds" parameterType="String">
+        delete from twin_calc_hour_energy where AUTO_ID in 
+        <foreach item="autoId" collection="array" open="(" separator="," close=")">
+            #{autoId}
+        </foreach>
+    </delete>
+
+</mapper>

+ 87 - 0
ruoyi-admin/src/main/resources/mapper/biz/TwinWorkshopEnergyMapper.xml

@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.biz.mapper.TwinWorkshopEnergyMapper">
+
+    <resultMap type="TwinWorkshopEnergy" id="TwinWorkshopEnergyResult">
+        <result property="energyId"    column="ENERGY_ID"    />
+        <result property="wsId"    column="WS_ID"    />
+        <result property="energyName"    column="ENERGY_NAME"    />
+        <result property="energyType"    column="ENERGY_TYPE"    />
+        <result property="energyPath"    column="ENERGY_PATH"    />
+        <result property="energyCode"    column="ENERGY_CODE"    />
+        <result property="coefficient"    column="COEFFICIENT"    />
+        <result property="remark"    column="REMARK"    />
+    </resultMap>
+
+    <sql id="selectTwinWorkshopEnergyVo">
+        select ENERGY_ID, WS_ID, ENERGY_NAME, ENERGY_TYPE, ENERGY_PATH, ENERGY_CODE, COEFFICIENT, REMARK from twin_workshop_energy
+    </sql>
+
+    <select id="selectTwinWorkshopEnergyList" parameterType="TwinWorkshopEnergy" resultMap="TwinWorkshopEnergyResult">
+        <include refid="selectTwinWorkshopEnergyVo"/>
+        <where>
+            <if test="wsId != null "> and WS_ID = #{wsId}</if>
+            <if test="energyName != null  and energyName != ''"> and ENERGY_NAME like concat('%', #{energyName}, '%')</if>
+            <if test="energyType != null  and energyType != ''"> and ENERGY_TYPE = #{energyType}</if>
+            <if test="energyPath != null  and energyPath != ''"> and ENERGY_PATH = #{energyPath}</if>
+            <if test="energyCode != null  and energyCode != ''"> and ENERGY_CODE = #{energyCode}</if>
+            <if test="coefficient != null "> and COEFFICIENT = #{coefficient}</if>
+            <if test="remark != null  and remark != ''"> and REMARK = #{remark}</if>
+        </where>
+    </select>
+
+    <select id="selectTwinWorkshopEnergyByEnergyId" parameterType="Long" resultMap="TwinWorkshopEnergyResult">
+        <include refid="selectTwinWorkshopEnergyVo"/>
+        where ENERGY_ID = #{energyId}
+    </select>
+
+    <insert id="insertTwinWorkshopEnergy" parameterType="TwinWorkshopEnergy" useGeneratedKeys="true" keyProperty="energyId">
+        insert into twin_workshop_energy
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="wsId != null">WS_ID,</if>
+            <if test="energyName != null">ENERGY_NAME,</if>
+            <if test="energyType != null">ENERGY_TYPE,</if>
+            <if test="energyPath != null">ENERGY_PATH,</if>
+            <if test="energyCode != null">ENERGY_CODE,</if>
+            <if test="coefficient != null">COEFFICIENT,</if>
+            <if test="remark != null">REMARK,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="wsId != null">#{wsId},</if>
+            <if test="energyName != null">#{energyName},</if>
+            <if test="energyType != null">#{energyType},</if>
+            <if test="energyPath != null">#{energyPath},</if>
+            <if test="energyCode != null">#{energyCode},</if>
+            <if test="coefficient != null">#{coefficient},</if>
+            <if test="remark != null">#{remark},</if>
+        </trim>
+    </insert>
+
+    <update id="updateTwinWorkshopEnergy" parameterType="TwinWorkshopEnergy">
+        update twin_workshop_energy
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="wsId != null">WS_ID = #{wsId},</if>
+            <if test="energyName != null">ENERGY_NAME = #{energyName},</if>
+            <if test="energyType != null">ENERGY_TYPE = #{energyType},</if>
+            <if test="energyPath != null">ENERGY_PATH = #{energyPath},</if>
+            <if test="energyCode != null">ENERGY_CODE = #{energyCode},</if>
+            <if test="coefficient != null">COEFFICIENT = #{coefficient},</if>
+            <if test="remark != null">REMARK = #{remark},</if>
+        </trim>
+        where ENERGY_ID = #{energyId}
+    </update>
+
+    <delete id="deleteTwinWorkshopEnergyByEnergyId" parameterType="Long">
+        delete from twin_workshop_energy where ENERGY_ID = #{energyId}
+    </delete>
+
+    <delete id="deleteTwinWorkshopEnergyByEnergyIds" parameterType="String">
+        delete from twin_workshop_energy where ENERGY_ID in
+        <foreach item="energyId" collection="array" open="(" separator="," close=")">
+            #{energyId}
+        </foreach>
+    </delete>
+
+</mapper>

+ 41 - 22
ruoyi-admin/src/main/resources/mapper/biz/TwinWorkshopMapper.xml

@@ -1,11 +1,12 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.biz.mapper.TwinWorkshopMapper">
-    
+
     <resultMap type="TwinWorkshop" id="TwinWorkshopResult">
         <result property="wsId"    column="WS_ID"    />
+        <result property="wsCode"    column="WS_CODE"    />
         <result property="wsName"    column="WS_NAME"    />
         <result property="remark"    column="REMARK"    />
     </resultMap>
@@ -21,63 +22,81 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="energyType"    column="sub_ENERGY_TYPE"    />
         <result property="energyPath"    column="sub_ENERGY_PATH"    />
         <result property="energyCode"    column="sub_ENERGY_CODE"    />
+        <result property="coefficient"    column="sub_COEFFICIENT"    />
         <result property="remark"    column="sub_REMARK"    />
     </resultMap>
 
     <sql id="selectTwinWorkshopVo">
-        select WS_ID, WS_NAME, REMARK from twin_workshop
+        select WS_ID, WS_CODE, WS_NAME, REMARK from twin_workshop
     </sql>
 
     <select id="selectTwinWorkshopList" parameterType="TwinWorkshop" resultMap="TwinWorkshopResult">
         <include refid="selectTwinWorkshopVo"/>
-        <where>  
+        <where>
+            <if test="wsCode != null  and wsCode != ''"> and WS_CODE = #{wsCode}</if>
             <if test="wsName != null  and wsName != ''"> and WS_NAME like concat('%', #{wsName}, '%')</if>
             <if test="remark != null  and remark != ''"> and REMARK = #{remark}</if>
         </where>
     </select>
-    
+
     <select id="selectTwinWorkshopByWsId" parameterType="Long" resultMap="TwinWorkshopTwinWorkshopEnergyResult">
-        select a.WS_ID, a.WS_NAME, a.REMARK,
- b.ENERGY_ID as sub_ENERGY_ID, b.WS_ID as sub_WS_ID, b.ENERGY_NAME as sub_ENERGY_NAME, b.ENERGY_TYPE as sub_ENERGY_TYPE, b.ENERGY_PATH as sub_ENERGY_PATH, b.ENERGY_CODE as sub_ENERGY_CODE, b.REMARK as sub_REMARK
+        select a.WS_ID, a.WS_CODE, a.WS_NAME, a.REMARK,
+               b.ENERGY_ID as sub_ENERGY_ID, b.WS_ID as sub_WS_ID, b.ENERGY_NAME as sub_ENERGY_NAME, b.ENERGY_TYPE as sub_ENERGY_TYPE, b.ENERGY_PATH as sub_ENERGY_PATH,b.COEFFICIENT as sub_COEFFICIENT,b.ENERGY_CODE as sub_ENERGY_CODE, b.REMARK as sub_REMARK
         from twin_workshop a
-        left join twin_workshop_energy b on b.WS_ID = a.WS_ID
+                 left join twin_workshop_energy b on b.WS_ID = a.WS_ID
         where a.WS_ID = #{wsId}
     </select>
-        
+
     <insert id="insertTwinWorkshop" parameterType="TwinWorkshop" useGeneratedKeys="true" keyProperty="wsId">
         insert into twin_workshop
         <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="wsName != null">WS_NAME,</if>
+            <if test="wsCode != null and wsCode != ''">WS_CODE,</if>
+            <if test="wsName != null and wsName != ''">WS_NAME,</if>
             <if test="remark != null">REMARK,</if>
-         </trim>
+        </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="wsName != null">#{wsName},</if>
+            <if test="wsCode != null and wsCode != ''">#{wsCode},</if>
+            <if test="wsName != null and wsName != ''">#{wsName},</if>
             <if test="remark != null">#{remark},</if>
-         </trim>
+        </trim>
     </insert>
 
     <update id="updateTwinWorkshop" parameterType="TwinWorkshop">
         update twin_workshop
         <trim prefix="SET" suffixOverrides=",">
-            <if test="wsName != null">WS_NAME = #{wsName},</if>
+            <if test="wsCode != null and wsCode != ''">WS_CODE = #{wsCode},</if>
+            <if test="wsName != null and wsName != ''">WS_NAME = #{wsName},</if>
             <if test="remark != null">REMARK = #{remark},</if>
         </trim>
         where WS_ID = #{wsId}
     </update>
+    <update id="updateTwinWorkshopEnergy" parameterType="TwinWorkshopEnergy">
+        update twin_workshop_energy
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="wsId != null">WS_ID = #{wsId},</if>
+            <if test="energyName != null">ENERGY_NAME = #{energyName},</if>
+            <if test="energyType != null">ENERGY_TYPE = #{energyType},</if>
+            <if test="energyPath != null">ENERGY_PATH = #{energyPath},</if>
+            <if test="energyCode != null">ENERGY_CODE = #{energyCode},</if>
+            <if test="coefficient != null">COEFFICIENT = #{coefficient},</if>
+            <if test="remark != null">REMARK = #{remark},</if>
+        </trim>
+        where ENERGY_ID = #{energyId}
+    </update>
 
     <delete id="deleteTwinWorkshopByWsId" parameterType="Long">
         delete from twin_workshop where WS_ID = #{wsId}
     </delete>
 
     <delete id="deleteTwinWorkshopByWsIds" parameterType="String">
-        delete from twin_workshop where WS_ID in 
+        delete from twin_workshop where WS_ID in
         <foreach item="wsId" collection="array" open="(" separator="," close=")">
             #{wsId}
         </foreach>
     </delete>
-    
+
     <delete id="deleteTwinWorkshopEnergyByWsIds" parameterType="String">
-        delete from twin_workshop_energy where WS_ID in 
+        delete from twin_workshop_energy where WS_ID in
         <foreach item="wsId" collection="array" open="(" separator="," close=")">
             #{wsId}
         </foreach>
@@ -88,10 +107,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <insert id="batchTwinWorkshopEnergy">
-        insert into twin_workshop_energy( ENERGY_ID, WS_ID, ENERGY_NAME, ENERGY_TYPE, ENERGY_PATH, ENERGY_CODE, REMARK) values
-		<foreach item="item" index="index" collection="list" separator=",">
-            ( #{item.energyId}, #{item.wsId}, #{item.energyName}, #{item.energyType}, #{item.energyPath}, #{item.energyCode}, #{item.remark})
+        insert into twin_workshop_energy( ENERGY_ID, WS_ID, ENERGY_NAME, ENERGY_TYPE, ENERGY_PATH,COEFFICIENT, ENERGY_CODE, REMARK) values
+        <foreach item="item" index="index" collection="list" separator=",">
+            ( #{item.energyId}, #{item.wsId}, #{item.energyName}, #{item.energyType}, #{item.energyPath}, #{item.coefficient}, #{item.energyCode}, #{item.remark})
         </foreach>
     </insert>
 
-</mapper>
+</mapper>

+ 66 - 0
ruoyi-admin/src/main/resources/templates/biz/calcEnergy/add.html

@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+<head>
+    <th:block th:include="include :: header('新增能源1小时统计数据')" />
+    <th:block th:include="include :: datetimepicker-css" />
+</head>
+<body class="white-bg">
+    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
+        <form class="form-horizontal m" id="form-calcEnergy-add">
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">日期:</label>
+                <div class="col-sm-8">
+                    <div class="input-group date">
+                        <input name="dataDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
+                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
+                    </div>
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">小时;0-23:</label>
+                <div class="col-sm-8">
+                    <input name="hour" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">设备ID:</label>
+                <div class="col-sm-8">
+                    <input name="energyId" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">统计数据:</label>
+                <div class="col-sm-8">
+                    <input name="dataValue" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">
+                <label class="col-sm-3 control-label">备注:</label>
+                <div class="col-sm-8">
+                    <textarea name="remark" class="form-control"></textarea>
+                </div>
+            </div>
+        </form>
+    </div>
+    <th:block th:include="include :: footer" />
+    <th:block th:include="include :: datetimepicker-js" />
+    <script th:inline="javascript">
+        var prefix = ctx + "biz/calcEnergy"
+        $("#form-calcEnergy-add").validate({
+            focusCleanup: true
+        });
+
+        function submitHandler() {
+            if ($.validate.form()) {
+                $.operate.save(prefix + "/add", $('#form-calcEnergy-add').serialize());
+            }
+        }
+
+        $("input[name='dataDate']").datetimepicker({
+            format: "yyyy-mm-dd",
+            minView: "month",
+            autoclose: true
+        });
+    </script>
+</body>
+</html>

+ 114 - 0
ruoyi-admin/src/main/resources/templates/biz/calcEnergy/calcEnergy.html

@@ -0,0 +1,114 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
+<head>
+    <th:block th:include="include :: header('能源1小时统计数据列表')" />
+</head>
+<body class="gray-bg">
+     <div class="container-div">
+        <div class="row">
+            <div class="col-sm-12 search-collapse">
+                <form id="formId">
+                    <div class="select-list">
+                        <ul>
+                            <li>
+                                <label>日期:</label>
+                                <input type="text" class="time-input" placeholder="请选择日期" name="dataDate"/>
+                            </li>
+                            <li>
+                                <label>小时;0-23:</label>
+                                <input type="text" name="hour"/>
+                            </li>
+                            <li>
+                                <label>设备ID:</label>
+                                <input type="text" name="energyId"/>
+                            </li>
+                            <li>
+                                <label>统计数据:</label>
+                                <input type="text" name="dataValue"/>
+                            </li>
+                            <li>
+                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
+                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
+                            </li>
+                        </ul>
+                    </div>
+                </form>
+            </div>
+
+            <div class="btn-group-sm" id="toolbar" role="group">
+                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="biz:calcEnergy:add">
+                    <i class="fa fa-plus"></i> 添加
+                </a>
+                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="biz:calcEnergy:edit">
+                    <i class="fa fa-edit"></i> 修改
+                </a>
+                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="biz:calcEnergy:remove">
+                    <i class="fa fa-remove"></i> 删除
+                </a>
+                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="biz:calcEnergy:export">
+                    <i class="fa fa-download"></i> 导出
+                </a>
+            </div>
+            <div class="col-sm-12 select-table table-striped">
+                <table id="bootstrap-table"></table>
+            </div>
+        </div>
+    </div>
+    <th:block th:include="include :: footer" />
+    <script th:inline="javascript">
+        var editFlag = [[${@permission.hasPermi('biz:calcEnergy:edit')}]];
+        var removeFlag = [[${@permission.hasPermi('biz:calcEnergy:remove')}]];
+        var prefix = ctx + "biz/calcEnergy";
+
+        $(function() {
+            var options = {
+                url: prefix + "/list",
+                createUrl: prefix + "/add",
+                updateUrl: prefix + "/edit/{id}",
+                removeUrl: prefix + "/remove",
+                exportUrl: prefix + "/export",
+                modalName: "能源1小时统计数据",
+                columns: [{
+                    checkbox: true
+                },
+                {
+                    field: 'autoId',
+                    title: 'ID',
+                    visible: false
+                },
+                {
+                    field: 'dataDate',
+                    title: '日期'
+                },
+                {
+                    field: 'hour',
+                    title: '小时;0-23'
+                },
+                {
+                    field: 'energyId',
+                    title: '设备ID'
+                },
+                {
+                    field: 'dataValue',
+                    title: '统计数据'
+                },
+                {
+                    field: 'remark',
+                    title: '备注'
+                },
+                {
+                    title: '操作',
+                    align: 'center',
+                    formatter: function(value, row, index) {
+                        var actions = [];
+                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.autoId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
+                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.autoId + '\')"><i class="fa fa-remove"></i>删除</a>');
+                        return actions.join('');
+                    }
+                }]
+            };
+            $.table.init(options);
+        });
+    </script>
+</body>
+</html>

+ 67 - 0
ruoyi-admin/src/main/resources/templates/biz/calcEnergy/edit.html

@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+<head>
+    <th:block th:include="include :: header('修改能源1小时统计数据')" />
+    <th:block th:include="include :: datetimepicker-css" />
+</head>
+<body class="white-bg">
+    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
+        <form class="form-horizontal m" id="form-calcEnergy-edit" th:object="${twinCalcHourEnergy}">
+            <input name="autoId" th:field="*{autoId}" type="hidden">
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">日期:</label>
+                <div class="col-sm-8">
+                    <div class="input-group date">
+                        <input name="dataDate" th:value="${#dates.format(twinCalcHourEnergy.dataDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
+                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
+                    </div>
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">小时;0-23:</label>
+                <div class="col-sm-8">
+                    <input name="hour" th:field="*{hour}" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">设备ID:</label>
+                <div class="col-sm-8">
+                    <input name="energyId" th:field="*{energyId}" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">统计数据:</label>
+                <div class="col-sm-8">
+                    <input name="dataValue" th:field="*{dataValue}" class="form-control" type="text">
+                </div>
+            </div>
+            <div class="form-group">
+                <label class="col-sm-3 control-label">备注:</label>
+                <div class="col-sm-8">
+                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
+                </div>
+            </div>
+        </form>
+    </div>
+    <th:block th:include="include :: footer" />
+    <th:block th:include="include :: datetimepicker-js" />
+    <script th:inline="javascript">
+        var prefix = ctx + "biz/calcEnergy";
+        $("#form-calcEnergy-edit").validate({
+            focusCleanup: true
+        });
+
+        function submitHandler() {
+            if ($.validate.form()) {
+                $.operate.save(prefix + "/edit", $('#form-calcEnergy-edit').serialize());
+            }
+        }
+
+        $("input[name='dataDate']").datetimepicker({
+            format: "yyyy-mm-dd",
+            minView: "month",
+            autoclose: true
+        });
+    </script>
+</body>
+</html>

+ 36 - 0
ruoyi-admin/src/main/resources/templates/biz/data/data.html

@@ -40,6 +40,29 @@
         <a class="btn btn-primary btn-rounded btn-sm" onclick="bl3()"><i class="fa fa-database"></i>&nbsp;补录</a>
     </label>
 </div>
+<div class="form-group">
+    <label class="col-sm-3 control-label">按天补录能耗数据:</label>
+    <label class="col-sm-6">
+        <input id="energyS" class="time-input" placeholder="开始时间" type="text">&nbsp;
+        <input id="energyE" class="time-input" placeholder="结束时间" type="text">&nbsp;
+    </label>
+    <label class="col-sm-2 control-label">
+        <a class="btn btn-primary btn-rounded btn-sm" onclick="bl4()"><i class="fa fa-database"></i>&nbsp;补录</a>
+    </label>
+</div>
+<div class="form-group">
+    <label class="col-sm-3 control-label">按时间段补录能耗数据:</label>
+    <div class="col-sm-6">
+        <div class="input-group date">
+            <input id="date5" name="date" class="time-input" placeholder="日期" type="text">&nbsp;
+            <input type="number" id="sp5" placeholder="开始时段" min="0" max="23" step="1" value="1"/> 至
+            <input type="number" id="ep5" placeholder="结束时段" min="0" max="23" step="1" value="1"/>
+        </div>
+    </div>
+    <label class="col-sm-2 control-label">
+        <a class="btn btn-primary btn-rounded btn-sm" onclick="bl5()"><i class="fa fa-database"></i>&nbsp;补录</a>
+    </label>
+</div>
 <th:block th:include="include :: footer"/>
 <th:block th:include="include :: datetimepicker-js"/>
 <script th:inline="javascript">
@@ -68,6 +91,19 @@
             }
         })
     }
+    function bl4() {
+        $.getJSON(prefix + "/bl4", {sd: $("#energyS").val(), ed: $("#energyE").val()}, function (data) {
+            if (data.code == 0) {
+                $.modal.msgSuccess("操作成功!");
+            }
+        })
+    } function bl5() {
+        $.getJSON(prefix + "/bl5", {date: $("#date5").val(), sp: $("#sp5").val(), ep: $("#ep5").val()}, function (data) {
+            if (data.code == 0) {
+                $.modal.msgSuccess("操作成功!");
+            }
+        })
+    }
 </script>
 </body>
 </html>

+ 82 - 69
ruoyi-admin/src/main/resources/templates/biz/workshop/add.html

@@ -1,75 +1,79 @@
 <!DOCTYPE html>
-<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+<html lang="zh" xmlns:th="http://www.thymeleaf.org">
 <head>
-    <th:block th:include="include :: header('新增车间管理')" />
+    <th:block th:include="include :: header('新增车间管理')"/>
 </head>
 <body class="white-bg">
-    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
-        <form class="form-horizontal m" id="form-workshop-add">
-            <h4 class="form-header h4">车间管理信息</h4>
-            <div class="form-group">
-                <label class="col-sm-3 control-label">车间名称:</label>
-                <div class="col-sm-8">
-                    <input name="wsName" class="form-control" type="text">
-                </div>
+<div class="wrapper wrapper-content animated fadeInRight ibox-content">
+    <form class="form-horizontal m" id="form-workshop-add">
+        <h4 class="form-header h4">车间管理信息</h4>
+        <div class="form-group">
+            <label class="col-sm-3 control-label is-required">车间编码:</label>
+            <div class="col-sm-8">
+                <input name="wsCode" class="form-control" type="text" required>
             </div>
-            <div class="form-group">
-                <label class="col-sm-3 control-label">备注:</label>
-                <div class="col-sm-8">
-                    <textarea name="remark" class="form-control"></textarea>
-                </div>
+        </div>
+        <div class="form-group">
+            <label class="col-sm-3 control-label is-required">车间名称:</label>
+            <div class="col-sm-8">
+                <input name="wsName" class="form-control" type="text" required>
             </div>
-            <h4 class="form-header h4">车间能源管理信息</h4>
-            <div class="row">
-                <div class="col-sm-12">
-                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
-                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
-                    <div class="col-sm-12 select-table table-striped">
-                        <table id="bootstrap-table"></table>
-                    </div>
+        </div>
+        <div class="form-group">
+            <label class="col-sm-3 control-label">备注:</label>
+            <div class="col-sm-8">
+                <textarea name="remark" class="form-control"></textarea>
+            </div>
+        </div>
+        <h4 class="form-header h4">车间能源管理信息</h4>
+        <div class="row">
+            <div class="col-sm-12">
+                <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i>
+                </button>
+                <div class="col-sm-12 select-table table-striped">
+                    <table id="bootstrap-table"></table>
                 </div>
             </div>
-        </form>
-    </div>
-    <th:block th:include="include :: footer" />
-    <script th:inline="javascript">
-        var prefix = ctx + "biz/workshop"
-        var energyTypeDatas = [[${@dict.getType('energy_type')}]];
-        $("#form-workshop-add").validate({
-            focusCleanup: true
-        });
+        </div>
+    </form>
+</div>
+<th:block th:include="include :: footer"/>
+<script th:inline="javascript">
+    var prefix = ctx + "biz/workshop"
+    var energyTypeDatas = [[${@dict.getType('energy_type')}]];
+    $("#form-workshop-add").validate({
+        focusCleanup: true
+    });
 
-        function submitHandler() {
-            if ($.validate.form()) {
-                $.operate.save(prefix + "/add", $('#form-workshop-add').serialize());
-            }
+    function submitHandler() {
+        if ($.validate.form()) {
+            $.operate.save(prefix + "/add", $('#form-workshop-add').serialize());
         }
+    }
 
-        $(function() {
-            var options = {
-                pagination: false,
-                showSearch: false,
-                showRefresh: false,
-                showToggle: false,
-                showColumns: false,
-                sidePagination: "client",
-                columns: [{
-                    checkbox: true
-                },
+    $(function () {
+        var options = {
+            pagination: false,
+            showSearch: false,
+            showRefresh: false,
+            showToggle: false,
+            showColumns: false,
+            sidePagination: "client",
+            columns: [
                 {
                     field: 'index',
                     align: 'center',
                     title: "序号",
                     formatter: function (value, row, index) {
-                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
-                    	return columnIndex + $.table.serialNumber(index);
+                        var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
+                        return columnIndex + $.table.serialNumber(index);
                     }
                 },
                 {
                     field: 'energyName',
                     align: 'center',
                     title: '能源设备名称',
-                    formatter: function(value, row, index) {
+                    formatter: function (value, row, index) {
                         var html = $.common.sprintf("<input class='form-control' type='text' name='twinWorkshopEnergyList[%s].energyName' value='%s'>", index, value);
                         return html;
                     }
@@ -79,7 +83,7 @@
                     align: 'center',
                     title: '能源设备类型',
                     width: 60,
-                    formatter: function(value, row, index) {
+                    formatter: function (value, row, index) {
                         var name = $.common.sprintf("twinWorkshopEnergyList[%s].energyType", index);
                         return $.common.dictToSelect(energyTypeDatas, value, name);
                     }
@@ -89,7 +93,7 @@
                     align: 'center',
                     title: '能源设备路径',
                     width: 600,
-                    formatter: function(value, row, index) {
+                    formatter: function (value, row, index) {
                         var html = $.common.sprintf("<input class='form-control' type='text' name='twinWorkshopEnergyList[%s].energyPath' value='%s'>", index, value);
                         return html;
                     }
@@ -98,35 +102,44 @@
                     field: 'energyCode',
                     align: 'center',
                     title: '字段编码',
-                    formatter: function(value, row, index) {
+                    formatter: function (value, row, index) {
                         var html = $.common.sprintf("<input class='form-control' type='text' name='twinWorkshopEnergyList[%s].energyCode' value='%s'>", index, value);
                         return html;
                     }
                 },
                 {
+                    field: 'coefficient',
+                    align: 'center',
+                    title: '计算系数',
+                    formatter: function (value, row, index) {
+                        var html = $.common.sprintf("<input class='form-control' type='text' name='twinWorkshopEnergyList[%s].coefficient' value='%s'>", index, value);
+                        return html;
+                    }
+                },
+                {
                     title: '操作',
                     align: 'center',
-                    formatter: function(value, row, index) {
+                    formatter: function (value, row, index) {
                         var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                         return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                     }
                 }]
-            };
-            $.table.init(options);
-        });
+        };
+        $.table.init(options);
+    });
 
-        function addRow() {
-            var count = $("#" + table.options.id).bootstrapTable('getData').length;
-            var row = {
-                index: $.table.serialNumber(count),
-                energyName: "",
-                energyType: "",
-                energyPath: "",
-                energyCode: "",
-                remark: "",
-            }
-            sub.addRow(row);
+    function addRow() {
+        var count = $("#" + table.options.id).bootstrapTable('getData').length;
+        var row = {
+            index: $.table.serialNumber(count),
+            energyName: "",
+            energyType: "",
+            energyPath: "",
+            energyCode: "",
+            remark: "",
         }
-    </script>
+        sub.addRow(row);
+    }
+</script>
 </body>
 </html>

+ 119 - 72
ruoyi-admin/src/main/resources/templates/biz/workshop/edit.html

@@ -1,78 +1,90 @@
 <!DOCTYPE html>
-<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+<html lang="zh" xmlns:th="http://www.thymeleaf.org">
 <head>
-    <th:block th:include="include :: header('修改车间管理')" />
+    <th:block th:include="include :: header('修改车间管理')"/>
 </head>
 <body class="white-bg">
-    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
-        <form class="form-horizontal m" id="form-workshop-edit" th:object="${twinWorkshop}">
-            <h4 class="form-header h4">车间管理信息</h4>
-            <input name="wsId" th:field="*{wsId}" type="hidden">
-            <div class="form-group">
-                <label class="col-sm-3 control-label">车间名称:</label>
-                <div class="col-sm-8">
-                    <input name="wsName" th:field="*{wsName}" class="form-control" type="text">
-                </div>
+<div class="wrapper wrapper-content animated fadeInRight ibox-content">
+    <form class="form-horizontal m" id="form-workshop-edit" th:object="${twinWorkshop}">
+        <h4 class="form-header h4">车间管理信息</h4>
+        <input name="wsId" th:field="*{wsId}" type="hidden">
+        <div class="form-group">
+            <label class="col-sm-3 control-label is-required">车间编码:</label>
+            <div class="col-sm-8">
+                <input name="wsCode" th:field="*{wsCode}" class="form-control" type="text" required>
             </div>
-            <div class="form-group">
-                <label class="col-sm-3 control-label">备注:</label>
-                <div class="col-sm-8">
-                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
-                </div>
+        </div>
+        <div class="form-group">
+            <label class="col-sm-3 control-label is-required">车间名称:</label>
+            <div class="col-sm-8">
+                <input name="wsName" th:field="*{wsName}" class="form-control" type="text" required>
+            </div>
+        </div>
+        <div class="form-group">
+            <label class="col-sm-3 control-label">备注:</label>
+            <div class="col-sm-8">
+                <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
             </div>
-            <h4 class="form-header h4">车间能源管理信息</h4>
-            <div class="row">
-                <div class="col-sm-12">
-                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
-                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
-                    <div class="col-sm-12 select-table table-striped">
-                        <table id="bootstrap-table"></table>
-                    </div>
+        </div>
+        <h4 class="form-header h4">车间能源管理信息</h4>
+        <div class="row">
+            <div class="col-sm-12">
+                <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i>
+                </button>
+                <div class="col-sm-12 select-table table-striped">
+                    <table id="bootstrap-table"></table>
                 </div>
             </div>
-        </form>
-    </div>
-    <th:block th:include="include :: footer" />
-    <script th:inline="javascript">
-        var prefix = ctx + "biz/workshop";
-        var energyTypeDatas = [[${@dict.getType('energy_type')}]];
-        $("#form-workshop-edit").validate({
-            focusCleanup: true
-        });
+        </div>
+    </form>
+</div>
+<th:block th:include="include :: footer"/>
+<script th:inline="javascript">
+    var prefix = ctx + "biz/workshop";
+    var energyTypeDatas = [[${@dict.getType('energy_type')}]];
+    $("#form-workshop-edit").validate({
+        focusCleanup: true
+    });
 
-        function submitHandler() {
-            if ($.validate.form()) {
-                $.operate.save(prefix + "/edit", $('#form-workshop-edit').serialize());
-            }
+    function submitHandler() {
+        if ($.validate.form()) {
+            $.operate.save(prefix + "/edit", $('#form-workshop-edit').serialize());
         }
+    }
 
-        $(function() {
-            var options = {
-                data: [[${twinWorkshop.twinWorkshopEnergyList}]],
-                pagination: false,
-                showSearch: false,
-                showRefresh: false,
-                showToggle: false,
-                showColumns: false,
-                sidePagination: "client",
-                columns: [{
-                    checkbox: true
+    $(function () {
+        var options = {
+            data: [[${twinWorkshop.twinWorkshopEnergyList}]],
+            pagination: false,
+            showSearch: false,
+            showRefresh: false,
+            showToggle: false,
+            showColumns: false,
+            sidePagination: "client",
+            columns: [
+                {
+                    field: 'energyId',
+                    title: '能源设备ID',
+                    formatter: function (value, row, index) {
+                        let html = "<input type='hidden' name='twinWorkshopEnergyList[" + index + "].energyId' value='" + value + "'>";
+                        return html+value;
+                    }
                 },
                 {
                     field: 'index',
                     align: 'center',
                     title: "序号",
                     formatter: function (value, row, index) {
-                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
-                    	return columnIndex + $.table.serialNumber(index);
+                        let columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
+                        return columnIndex + $.table.serialNumber(index);
                     }
                 },
                 {
                     field: 'energyName',
                     align: 'center',
                     title: '能源设备名称',
-                    formatter: function(value, row, index) {
-                        var html = $.common.sprintf("<input class='form-control' type='text' name='twinWorkshopEnergyList[%s].energyName' value='%s'>", index, value);
+                    formatter: function (value, row, index) {
+                        let html= $.common.sprintf("<input class='form-control' type='text' name='twinWorkshopEnergyList[%s].energyName' value='%s'>", index, value);
                         return html;
                     }
                 },
@@ -82,7 +94,7 @@
                     align: 'center',
                     title: '能源设备类型',
                     width: 60,
-                    formatter: function(value, row, index) {
+                    formatter: function (value, row, index) {
                         var name = $.common.sprintf("twinWorkshopEnergyList[%s].energyType", index);
                         return $.common.dictToSelect(energyTypeDatas, value, name);
                     }
@@ -92,7 +104,7 @@
                     align: 'center',
                     title: '能源设备路径',
                     width: 600,
-                    formatter: function(value, row, index) {
+                    formatter: function (value, row, index) {
                         var html = $.common.sprintf("<input class='form-control' type='text' name='twinWorkshopEnergyList[%s].energyPath' value='%s'>", index, value);
                         return html;
                     }
@@ -101,35 +113,70 @@
                     field: 'energyCode',
                     align: 'center',
                     title: '字段编码',
-                    formatter: function(value, row, index) {
+                    width: 300,
+                    formatter: function (value, row, index) {
                         var html = $.common.sprintf("<input class='form-control' type='text' name='twinWorkshopEnergyList[%s].energyCode' value='%s'>", index, value);
                         return html;
                     }
                 },
                 {
+                    field: 'coefficient',
+                    align: 'center',
+                    title: '计算系数',
+                    width: 60,
+                    formatter: function (value, row, index) {
+                        var html = $.common.sprintf("<input class='form-control' type='text' name='twinWorkshopEnergyList[%s].coefficient' value='%s'>", index, value);
+                        return html;
+                    }
+                },
+                {
                     title: '操作',
                     align: 'center',
-                    formatter: function(value, row, index) {
+                    formatter: function (value, row, index) {
                         var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
-                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
+                        // return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.energyId + '\')"><i class="fa fa-remove"></i>删除</a>';
+                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="delRow(\'' + value + '\',\'' + row.energyId + '\')"><i class="fa fa-remove"></i>删除</a>';
                     }
                 }]
-            };
-            $.table.init(options);
-        });
+        };
+        $.table.init(options);
+    });
+
+    function delRow(value, energyId) {
+        table.set();
+        if (energyId) {
+            $.modal.confirm("确定删除该条信息吗?", function () {
+                var url = ctx + "biz/energy/remove";
+                var data = {"ids": energyId};
+                $.operate.submit(url, "post", "json", data);
+                var currentId = table.options.id;
+                sub.editRow();
+                $("#" + currentId).bootstrapTable('remove', {field: "index", values: [value]});
+                sub.editRow();
+            });
+        } else {
+            var currentId = table.options.id;
+            sub.editRow();
+            $("#" + currentId).bootstrapTable('remove', {field: "index", values: [value]});
+            sub.editRow();
+        }
+
+    }
 
-        function addRow() {
-            var count = $("#" + table.options.id).bootstrapTable('getData').length;
-            var row = {
-                index: $.table.serialNumber(count),
-                energyName: "",
-                energyType: "",
-                energyPath: "",
-                energyCode: "",
-                remark: "",
-            }
-            sub.addRow(row);
+    function addRow() {
+        var count = $("#" + table.options.id).bootstrapTable('getData').length;
+        var row = {
+            index: $.table.serialNumber(count),
+            energyId: "",
+            energyName: "",
+            energyType: "",
+            energyPath: "",
+            energyCode: "",
+            coefficient: "",
+            remark: "",
         }
-    </script>
+        sub.addRow(row);
+    }
+</script>
 </body>
 </html>

+ 27 - 0
ruoyi-admin/src/test/java/com/jjt/CalcEnergyTest.java

@@ -0,0 +1,27 @@
+package com.jjt;
+
+import com.ruoyi.RuoYiApplication;
+import com.ruoyi.biz.service.ITaskService;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import javax.annotation.Resource;
+
+/**
+ * DataProcess$
+ *
+ * @author wukai
+ * @date 2024/5/7 11:49
+ */
+@SpringBootTest(classes = RuoYiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class CalcEnergyTest {
+    @Resource
+    private ITaskService taskService;
+
+    @Test
+    void test() {
+        taskService.calcLastEnergy();
+    }
+
+
+}