嘉禾二期

master
sunjianxi 2 years ago
parent 1c0b965fbb
commit dfe45614db
  1. 43
      lab-service-api/lab-lims-api/src/main/java/org/springblade/lims/entry/CarbonEmission.java
  2. 66
      lab-service-api/lab-lims-api/src/main/java/org/springblade/lims/entry/CarbonEmissionPlan.java
  3. 43
      lab-service-api/lab-lims-api/src/main/java/org/springblade/lims/entry/CarbonIntensity.java
  4. 20
      lab-service-api/lab-lims-api/src/main/java/org/springblade/lims/entry/InstrumentData.java
  5. 28
      lab-service-api/lab-lims-api/src/main/java/org/springblade/lims/entry/LargeScreenVO.java
  6. 25
      lab-service-api/lab-lims-api/src/main/java/org/springblade/lims/entry/TimeVO.java
  7. 8
      lab-service/lab-capital/src/main/java/org/springblade/lims/capital/controller/ProductClassController.java
  8. 4
      lab-service/lab-capital/src/main/java/org/springblade/lims/capital/controller/WareHouseController.java
  9. 2
      lab-service/lab-capital/src/main/java/org/springblade/lims/capital/mapper/ProductClassMapper.java
  10. 7
      lab-service/lab-capital/src/main/java/org/springblade/lims/capital/mapper/ProductClassMapper.xml
  11. 2
      lab-service/lab-capital/src/main/java/org/springblade/lims/capital/service/IProductClassService.java
  12. 11
      lab-service/lab-capital/src/main/java/org/springblade/lims/capital/service/impl/ProductClassServiceImpl.java
  13. 80
      lab-service/lab-lims/src/main/java/org/springblade/lims/controller/CarbonEmissionController.java
  14. 70
      lab-service/lab-lims/src/main/java/org/springblade/lims/controller/CarbonEmissionPlanController.java
  15. 80
      lab-service/lab-lims/src/main/java/org/springblade/lims/controller/CarbonIntensityController.java
  16. 65
      lab-service/lab-lims/src/main/java/org/springblade/lims/controller/LargeScreenController.java
  17. 8
      lab-service/lab-lims/src/main/java/org/springblade/lims/controller/MaintainRecordController.java
  18. 17
      lab-service/lab-lims/src/main/java/org/springblade/lims/job/GetInstrumentRunStatusJob.java
  19. 14
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/CarbonEmissionMapper.java
  20. 5
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/CarbonEmissionMapper.xml
  21. 15
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/CarbonEmissionPlanMapper.java
  22. 23
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/CarbonEmissionPlanMapper.xml
  23. 16
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/CarbonIntensityMapper.java
  24. 6
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/CarbonIntensityMapper.xml
  25. 12
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/LargeScreenMapper.java
  26. 216
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/LargeScreenMapper.xml
  27. 64
      lab-service/lab-lims/src/main/java/org/springblade/lims/mqtt/callback/MyMQTTCallback.java
  28. 23
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/ICarbonEmissionPlanService.java
  29. 25
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/ICarbonEmissionService.java
  30. 25
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/ICarbonIntensityService.java
  31. 18
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/ILargeScreenService.java
  32. 81
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/CarbonEmissionPlanServiceImpl.java
  33. 98
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/CarbonEmissionServiceImpl.java
  34. 98
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/CarbonIntensityServiceImpl.java
  35. 438
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/LargeScreenServiceImpl.java
  36. 19
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/MaintainRecordServiceImpl.java

@ -0,0 +1,43 @@
package org.springblade.lims.entry;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springblade.core.mp.base.BaseEntity;
import org.springframework.data.annotation.Id;
import java.io.Serializable;
import java.util.List;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
@Data
@TableName("t_carbon_emission")
public class CarbonEmission extends BaseEntity implements Serializable {
/**
* 业务主键
*/
@Id
private Long id;
/**
* 月份
*/
private String currentMonth;
/**
* 排放量
*/
private Double emissions;
/**
* 租户
*/
private String tenantId;
}

@ -0,0 +1,66 @@
package org.springblade.lims.entry;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springblade.core.mp.base.BaseEntity;
import org.springframework.data.annotation.Id;
import java.io.Serializable;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
@Data
@TableName("t_carbon_emission_plan")
public class CarbonEmissionPlan extends BaseEntity implements Serializable {
/**
* 业务主键
*/
@Id
private Long id;
/**
* 年份
*/
private String currentYear;
/**
* 碳排放计划量
*/
private Double totalCarbonPlan;
/**
* 碳排放计划量
*/
private Double carbonPlan;
/**
* 碳减排总量
*/
private Double totalCarbonReduction;
/**
* 光伏发电碳减排量
*/
private Double pvPower;
/**
* 工艺优化碳减排量
*/
private Double processOpt;
/**
* 设备更换碳减排量
*/
private Double equipReplace;
/**
* 租户
*/
private String tenantId;
}

@ -0,0 +1,43 @@
package org.springblade.lims.entry;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springblade.core.mp.base.BaseEntity;
import org.springframework.data.annotation.Id;
import java.io.Serializable;
import java.util.List;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
@Data
@TableName("t_carbon_intensity")
public class CarbonIntensity extends BaseEntity implements Serializable {
/**
* 业务主键
*/
@Id
private Long id;
/**
* 月份
*/
private String currentMonth;
/**
* 排放强度
*/
private Double intensity;
/**
* 租户
*/
private String tenantId;
}

@ -227,4 +227,24 @@ public class InstrumentData extends BaseEntity implements Serializable {
*/
private String loadLevel;
/**
* 年份
*/
private String currentYear;
/**
* 月份
*/
private String currentMonth;
/**
* 日期
*/
private String currentDay;
/**
* 时间段尖峰平谷
*/
private String period;
}

@ -8,6 +8,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @author sjx
@ -136,4 +137,31 @@ public class LargeScreenVO implements Serializable {
*/
private Integer count;
/**
* 碳排放总量
*/
private Double totalCarbonEmissions;
/**
* 月份集合
*/
private List<String> monthList;
/**
* 开始时间
*/
private String startTime;
/**
* 结束时间
*/
private String endTime;
private List<TimeVO> jianList;
private List<TimeVO> fengList;
private List<TimeVO> pingList;
private List<TimeVO> guList;
}

@ -0,0 +1,25 @@
package org.springblade.lims.entry;
import lombok.Data;
import java.io.Serializable;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
@Data
public class TimeVO implements Serializable {
/**
* 开始时间
*/
private String startTime;
/**
* 结束时间
*/
private String endTime;
}

@ -232,8 +232,12 @@ public class ProductClassController extends BladeController {
@GetMapping("/tree")
@ApiOperationSupport(order = 9)
@ApiOperation(value = "树形结构(物品类型下拉接口)", notes = "树形结构")
public R<List<ProductClassVO>> tree(Integer type) {
List<ProductClassVO> tree = productClassService.tree(type);
public R<List<ProductClassVO>> tree(ProductClass entry) {
List<String> roles = Arrays.asList(AuthUtil.getUserRole().split(","));
if(!roles.contains("admin") && !roles.contains("政府")){
entry.setCreateDept(Long.parseLong(AuthUtil.getDeptId()));
}
List<ProductClassVO> tree = productClassService.tree(entry);
return R.data(tree);
}

@ -152,8 +152,8 @@ public class WareHouseController extends BladeController {
@GetMapping("/tree")
@ApiOperationSupport(order = 9)
@ApiOperation(value = "树形结构(物品类型下拉接口)", notes = "树形结构")
public R<List<ProductClassVO>> tree(Integer type) {
List<ProductClassVO> tree = productClassService.tree(type);
public R<List<ProductClassVO>> tree(ProductClass entry) {
List<ProductClassVO> tree = productClassService.tree(entry);
return R.data(tree);
}

@ -37,7 +37,7 @@ public interface ProductClassMapper extends BaseMapper<ProductClass> {
* 获取产品类型树
* @return
*/
List<ProductClassVO> tree(Integer type);
List<ProductClassVO> tree(ProductClass entry);
/**
* 懒加载产品类型树

@ -58,8 +58,11 @@
<select id="tree" resultMap="treeNodeResultMap">
select id, parent_id, name as title, id as "value", id as "key" from t_product_class where is_deleted = 0
<if test="param1!=null">
and product_category = #{param1}
<if test="createDept !=null">
and create_dept = #{createDept}
</if>
<if test="productCategory !=null">
and product_category = #{productCategory}
</if>
ORDER BY sort
</select>

@ -37,7 +37,7 @@ public interface IProductClassService extends IService<ProductClass> {
* 树形结构
* @return
*/
List<ProductClassVO> tree(Integer type);
List<ProductClassVO> tree(ProductClass entry);
/**
* 懒加载树形结构

@ -1,17 +1,14 @@
package org.springblade.lims.capital.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.lims.capital.entity.ProductClass;
import org.springblade.lims.capital.vo.ProductClassVO;
import org.springblade.lims.capital.mapper.ProductClassMapper;
import org.springblade.lims.capital.service.IProductClassService;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.lims.capital.vo.ProductClassVO;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
import java.util.Map;
@ -36,8 +33,8 @@ public class ProductClassServiceImpl extends ServiceImpl<ProductClassMapper, Pro
}
@Override
public List<ProductClassVO> tree(Integer type) {
return ForestNodeMerger.merge(baseMapper.tree(type));
public List<ProductClassVO> tree(ProductClass entry) {
return ForestNodeMerger.merge(baseMapper.tree(entry));
}
@Override

@ -0,0 +1,80 @@
package org.springblade.lims.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.lims.entry.CarbonEmission;
import org.springblade.lims.service.ICarbonEmissionService;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
@RestController
@AllArgsConstructor
@RequestMapping("/carbonEmission")
@Api(value = "", tags = "")
public class CarbonEmissionController extends BladeController {
private final ICarbonEmissionService service;
@GetMapping("/page")
public R<Object> page(CarbonEmission entry, Query query) {
List<String> roles = Arrays.asList(AuthUtil.getUserRole().split(","));
if(!roles.contains("admin") && !roles.contains("政府")){
entry.setCreateDept(Long.parseLong(AuthUtil.getDeptId()));
}
return R.data(service.findPage(entry, query));
}
/**
* 保存碳排放量
*/
@PostMapping("/saveCarbon")
@ApiOperation(value = "保存碳排放量", notes = "保存碳排放量")
public R saveRoute(@RequestBody CarbonEmission entry) {
return service.saveCarbon(entry);
}
/**
* 根据id查询信息
*/
@GetMapping("/getById")
@ApiOperation(value = "根据id查询信息", notes = "根据id查询信息")
public R getById(String id) {
return R.data(service.findById(id));
}
/**
* 删除
*/
@GetMapping("/deleteById")
@ApiOperation(value = "逻辑删除", notes = "传入id")
public R deleteById(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
return R.status(service.deleteLogic(Func.toLongList(id)));
}
/**
* 查询近半年光伏发电折合碳排放趋势
* @param currentMonth
* @return
*/
@GetMapping("/findTrendList")
public R<Object> findTrendList(String currentMonth) {
return R.data(service.findTrendList(currentMonth));
}
}

@ -0,0 +1,70 @@
package org.springblade.lims.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.lims.entry.CarbonEmissionPlan;
import org.springblade.lims.service.ICarbonEmissionPlanService;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
@RestController
@AllArgsConstructor
@RequestMapping("/carbonEmissionPlan")
@Api(value = "", tags = "")
public class CarbonEmissionPlanController extends BladeController {
private final ICarbonEmissionPlanService service;
@GetMapping("/page")
public R<Object> page(CarbonEmissionPlan entry, Query query) {
List<String> roles = Arrays.asList(AuthUtil.getUserRole().split(","));
if(!roles.contains("admin") && !roles.contains("政府")){
entry.setCreateDept(Long.parseLong(AuthUtil.getDeptId()));
}
return R.data(service.findPage(entry, query));
}
/**
* 保存碳排放计划
*/
@PostMapping("/saveCarbon")
@ApiOperation(value = "保存碳排放量", notes = "保存碳排放量")
public R saveRoute(@RequestBody CarbonEmissionPlan entry) {
return service.saveCarbon(entry);
}
/**
* 根据id查询信息
*/
@GetMapping("/getById")
@ApiOperation(value = "根据id查询信息", notes = "根据id查询信息")
public R getById(String id) {
return R.data(service.findById(id));
}
/**
* 删除
*/
@GetMapping("/deleteById")
@ApiOperation(value = "逻辑删除", notes = "传入id")
public R deleteById(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
return R.status(service.deleteLogic(Func.toLongList(id)));
}
}

@ -0,0 +1,80 @@
package org.springblade.lims.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.lims.entry.CarbonIntensity;
import org.springblade.lims.service.ICarbonIntensityService;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
@RestController
@AllArgsConstructor
@RequestMapping("/carbonIntensity")
@Api(value = "", tags = "")
public class CarbonIntensityController extends BladeController {
private final ICarbonIntensityService service;
@GetMapping("/page")
public R<Object> page(CarbonIntensity entry, Query query) {
List<String> roles = Arrays.asList(AuthUtil.getUserRole().split(","));
if(!roles.contains("admin") && !roles.contains("政府")){
entry.setCreateDept(Long.parseLong(AuthUtil.getDeptId()));
}
return R.data(service.findPage(entry, query));
}
/**
* 保存碳排强度
*/
@PostMapping("/saveCarbon")
@ApiOperation(value = "保存碳排放量", notes = "保存碳排放量")
public R saveRoute(@RequestBody CarbonIntensity entry) {
return service.saveCarbon(entry);
}
/**
* 根据id查询信息
*/
@GetMapping("/getById")
@ApiOperation(value = "根据id查询信息", notes = "根据id查询信息")
public R getById(String id) {
return R.data(service.findById(id));
}
/**
* 删除
*/
@GetMapping("/deleteById")
@ApiOperation(value = "逻辑删除", notes = "传入id")
public R deleteById(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
return R.status(service.deleteLogic(Func.toLongList(id)));
}
/**
* 查询近半年月单位产值碳排放强度
* @param entry
* @return
*/
@GetMapping("/findIntensityList")
public R<Object> findTrendList(String currentMonth) {
return R.data(service.findIntensityList(currentMonth));
}
}

@ -3,11 +3,10 @@ package org.springblade.lims.controller;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.lims.entry.LargeScreenVO;
import org.springblade.lims.service.ILargeScreenService;
import org.springblade.lims.tools.RedisUtil;
import org.springblade.system.feign.ISysClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -27,10 +26,6 @@ public class LargeScreenController extends BladeController {
private final ILargeScreenService largeScreenService;
private final ISysClient sysClient;
private final RedisUtil redisUtil;
/**
* 总量分析
*/
@ -83,9 +78,65 @@ public class LargeScreenController extends BladeController {
* 设备日均负载分析
*/
@GetMapping("/getInstrumentDaylyLoad")
public R<Map<String, Map<String, Integer>>> getInstrumentDaylyLoad(LargeScreenVO entity) {
public R<List<Map<String,Object>>> getInstrumentDaylyLoad(LargeScreenVO entity) {
return R.data(largeScreenService.getInstrumentDaylyLoad(entity));
}
/**
* 设备运行状态
*/
@GetMapping("/getInstrumentRunStatus")
public R<List<Map<String,Object>>> getInstrumentRunStatus(LargeScreenVO entity) {
return R.data(largeScreenService.getInstrumentRunStatus(entity));
}
/**
* 碳排放总量
*/
@GetMapping("/getTotalCarbonEmissions")
public R<Map<String, Double>> getTotalCarbonEmissions() {
return R.data(largeScreenService.getTotalCarbonEmissions());
}
/**
* 企业能源消耗及碳排放统计
*/
@GetMapping("/getEnterprisePower")
public R<List<Map<String, Object>>> getEnterprisePower(LargeScreenVO entity) {
return R.data(largeScreenService.getEnterprisePower(entity));
}
/**
* 近6个月用电趋势
*/
@GetMapping("/getSixMonthElectricity")
public R<Map<String, Double>> getSixMonthElectricity() {
return R.data(largeScreenService.getSixMonthElectricity());
}
/**
* 碳排放月总量环比
*/
@GetMapping("/getSixMonthCarbonQoq")
public R<Map<String, String>> getSixMonthCarbonQoq() {
return R.data(largeScreenService.getSixMonthCarbonQoq());
}
/**
* 碳排放月总量同比
*/
@GetMapping("/getSixMonthCarbonYoy")
public R<List<Map<String, Object>>> getSixMonthCarbonYoy() {
return R.data(largeScreenService.getSixMonthCarbonYoy());
}
/**
* 账单明细
*/
@GetMapping("/getInstrumentRunDetail")
public R<Object> getInstrumentRunDetail(LargeScreenVO entity, Query query) {
return R.data(largeScreenService.getInstrumentRunDetail(entity,query));
}
}

@ -5,7 +5,6 @@ import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.lims.entry.MaintainRecord;
import org.springblade.lims.service.IMaintainRecordService;
@ -13,9 +12,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.List;
/**
* @author sjx
@ -31,10 +27,6 @@ public class MaintainRecordController extends BladeController {
@GetMapping("/page")
public R<Object> page(MaintainRecord entry, Query query) {
List<String> roles = Arrays.asList(AuthUtil.getUserRole().split(","));
if(!roles.contains("admin") && !roles.contains("政府")){
entry.setCreateDept(Long.parseLong(AuthUtil.getDeptId()));
}
return R.data(service.findPage(entry, query));
}

@ -0,0 +1,17 @@
package org.springblade.lims.job;
import lombok.AllArgsConstructor;
import org.springblade.lims.service.ILargeScreenService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@AllArgsConstructor
public class GetInstrumentRunStatusJob {
private final ILargeScreenService largeScreenService;
@Scheduled(cron ="0 0/1 * * * ? ")
public void getInstrumentRunStatusJob(){
largeScreenService.getInstrumentRunStatusJob();
}
}

@ -0,0 +1,14 @@
package org.springblade.lims.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springblade.lims.entry.CarbonEmission;
/**
*
*
* @author swj
* @since 2022年6月2日15:47:39
*/
public interface CarbonEmissionMapper extends BaseMapper<CarbonEmission> {
}

@ -0,0 +1,5 @@
<?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="org.springblade.lims.mapper.CarbonEmissionMapper">
</mapper>

@ -0,0 +1,15 @@
package org.springblade.lims.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springblade.lims.entry.CarbonEmissionPlan;
/**
*
*
* @author swj
* @since 2022年6月2日15:47:39
*/
public interface CarbonEmissionPlanMapper extends BaseMapper<CarbonEmissionPlan> {
CarbonEmissionPlan getCarbonEmissionPlan(String currentYear);
}

@ -0,0 +1,23 @@
<?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="org.springblade.lims.mapper.CarbonEmissionPlanMapper">
<select id="getCarbonEmissionPlan" resultType="org.springblade.lims.entry.CarbonEmissionPlan">
SELECT
total_carbon_plan,
carbon_plan,
total_carbon_reduction,
pv_power,
process_opt,
equip_replace
FROM
t_carbon_emission_plan
<where>
<if test="currentYear !=null and currentYear != ''">
and current_year = #{currentYear}
</if>
</where>
</select>
</mapper>

@ -0,0 +1,16 @@
package org.springblade.lims.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springblade.lims.entry.CarbonIntensity;
import java.util.List;
/**
*
*
* @author swj
* @since 2022年6月2日15:47:39
*/
public interface CarbonIntensityMapper extends BaseMapper<CarbonIntensity> {
}

@ -0,0 +1,6 @@
<?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="org.springblade.lims.mapper.CarbonIntensityMapper">
</mapper>

@ -22,8 +22,20 @@ public interface LargeScreenMapper extends BaseMapper {
List<LargeScreenVO> getPeriodElectricity(LargeScreenVO entity);
List<LargeScreenVO> getMaxElectricity();
List<LargeScreenVO> getInstrumentActLoad(LargeScreenVO entity);
List<LargeScreenVO> getInstrumentDaylyLoad(LargeScreenVO entity);
List<LargeScreenVO> getInstrumentDaylyCount(LargeScreenVO entity);
List<LargeScreenVO> getWeekElectricity(LargeScreenVO entity);
LargeScreenVO getTotalCarbonEmissions(String currentYear);
List<LargeScreenVO> getEnterprisePower(LargeScreenVO entity);
List<LargeScreenVO> getSixMonthElectricity(LargeScreenVO entity);
List<LargeScreenVO> getMonthCarbon(LargeScreenVO entity);
List<LargeScreenVO> getInstrumentRunDetail(LargeScreenVO entity);
}

@ -9,16 +9,16 @@
LEFT JOIN t_instrument b ON a.imei = b.CODE
<where>
<if test="currentYear !=null and currentYear != ''">
and DATE_FORMAT(a.send_time, '%Y') = #{currentYear}
and a.current_year = #{currentYear}
</if>
<if test="currentMonth !=null and currentMonth != ''">
and DATE_FORMAT(a.send_time, '%Y-%m') = #{currentMonth}
and a.current_month = #{currentMonth}
</if>
<if test="today !=null and today != ''">
and DATE_FORMAT(a.send_time, '%Y-%m-%d') = #{today}
and a.current_day = #{today}
</if>
<if test="yesterday !=null and yesterday != ''">
and DATE_FORMAT(a.send_time, '%Y-%m-%d') = #{yesterday}
and a.current_day = #{yesterday}
</if>
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
and b.manufacturer_brand = #{manufacturerBrand}
@ -29,13 +29,13 @@
<select id="getDayElectricity" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
sum( a.single_electricity ) total_electricity,
DATE_FORMAT( a.send_time, '%Y-%m-%d' ) AS `date`
a.current_day AS `date`
FROM
t_instrument_data a
LEFT JOIN t_instrument b ON a.imei = b.CODE
<where>
<if test="currentMonth !=null and currentMonth != ''">
and DATE_FORMAT(send_time, '%Y-%m') = #{currentMonth}
and a.current_month = #{currentMonth}
</if>
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
and b.manufacturer_brand = #{manufacturerBrand}
@ -57,7 +57,7 @@
and b.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
and DATE_FORMAT(a.send_time, '%Y-%m-%d') = #{today}
and a.current_day = #{today}
</if>
</where>
GROUP BY
@ -91,7 +91,7 @@
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
and DATE_FORMAT(b.send_time, '%Y-%m-%d') = #{today}
and b.current_day = #{today}
</if>
</where>
GROUP BY
@ -106,12 +106,19 @@
t_instrument a
LEFT JOIN t_instrument_data b ON a.`code` = b.imei
<where>
AND b.period = '尖'
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
AND ( b.send_time BETWEEN CONCAT(#{today},' 19:00:00') AND CONCAT(#{today},' 22:00:00') )
AND b.current_day = #{today}
</if>
<!--<if test="jianList !=null ">
AND
<foreach collection="jianList" item="item" index="index" open="(" close=")" separator="or">
(b.send_time BETWEEN #{item.startTime} AND #{item.endTime})
</foreach>
</if>-->
</where>
GROUP BY
b.imei
@ -125,13 +132,19 @@
t_instrument a
LEFT JOIN t_instrument_data b ON a.`code` = b.imei
<where>
AND b.period = '峰'
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
AND ( (b.send_time BETWEEN CONCAT(#{today},' 08:00:00') AND CONCAT(#{today},' 11:00:00'))
or (b.send_time BETWEEN CONCAT(#{today},' 15:00:00') AND CONCAT(#{today},' 19:00:00')) )
AND b.current_day = #{today}
</if>
<!--<if test="fengList !=null ">
AND
<foreach collection="fengList" item="item" index="index" open="(" close=")" separator="or">
(b.send_time BETWEEN #{item.startTime} AND #{item.endTime})
</foreach>
</if>-->
</where>
GROUP BY
b.imei
@ -145,14 +158,19 @@
t_instrument a
LEFT JOIN t_instrument_data b ON a.`code` = b.imei
<where>
AND b.period = '平'
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
AND ( (b.send_time BETWEEN CONCAT(#{today},' 07:00:00') AND CONCAT(#{today},' 08:00:00'))
or (b.send_time BETWEEN CONCAT(#{today},' 11:00:00') AND CONCAT(#{today},' 15:00:00'))
or (b.send_time BETWEEN CONCAT(#{today},' 22:00:00') AND CONCAT(#{today},' 23:00:00')))
AND b.current_day = #{today}
</if>
<!--<if test="pingList !=null ">
AND
<foreach collection="pingList" item="item" index="index" open="(" close=")" separator="or">
(b.send_time BETWEEN #{item.startTime} AND #{item.endTime})
</foreach>
</if>-->
</where>
GROUP BY
b.imei
@ -166,13 +184,19 @@
t_instrument a
LEFT JOIN t_instrument_data b ON a.`code` = b.imei
<where>
AND b.period = '谷'
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
AND ( (b.send_time BETWEEN CONCAT(#{today},' 00:00:00') AND CONCAT(#{today},' 07:00:00'))
or (b.send_time BETWEEN CONCAT(#{today},' 23:00:00') AND CONCAT(#{today},' 24:00:00')))
AND b.current_day = #{today}
</if>
<!--<if test="guList !=null ">
AND
<foreach collection="guList" item="item" index="index" open="(" close=")" separator="or">
(b.send_time BETWEEN #{item.startTime} AND #{item.endTime})
</foreach>
</if>-->
</where>
GROUP BY
b.imei
@ -187,12 +211,19 @@
t_instrument a
LEFT JOIN t_instrument_data b ON a.`code` = b.imei
<where>
AND b.period = '尖'
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
AND ( b.send_time BETWEEN CONCAT(#{today},' 19:00:00') AND CONCAT(#{today},' 22:00:00') )
AND b.current_day = #{today}
</if>
<!--<if test="jianList !=null ">
AND
<foreach collection="jianList" item="item" index="index" open="(" close=")" separator="or">
(b.send_time BETWEEN #{item.startTime} AND #{item.endTime})
</foreach>
</if>-->
</where>
UNION
SELECT
@ -202,13 +233,19 @@
t_instrument a
LEFT JOIN t_instrument_data b ON a.`code` = b.imei
<where>
AND b.period = '峰'
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
AND ( (b.send_time BETWEEN CONCAT(#{today},' 08:00:00') AND CONCAT(#{today},' 11:00:00'))
or (b.send_time BETWEEN CONCAT(#{today},' 15:00:00') AND CONCAT(#{today},' 19:00:00')) )
AND b.current_day = #{today}
</if>
<!--<if test="fengList !=null ">
AND
<foreach collection="fengList" item="item" index="index" open="(" close=")" separator="or">
(b.send_time BETWEEN #{item.startTime} AND #{item.endTime})
</foreach>
</if>-->
</where>
UNION
SELECT
@ -218,14 +255,19 @@
t_instrument a
LEFT JOIN t_instrument_data b ON a.`code` = b.imei
<where>
AND b.period = '平'
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
AND ( (b.send_time BETWEEN CONCAT(#{today},' 07:00:00') AND CONCAT(#{today},' 08:00:00'))
or (b.send_time BETWEEN CONCAT(#{today},' 11:00:00') AND CONCAT(#{today},' 15:00:00'))
or (b.send_time BETWEEN CONCAT(#{today},' 22:00:00') AND CONCAT(#{today},' 23:00:00')))
AND b.current_day = #{today}
</if>
<!--<if test="pingList !=null ">
AND
<foreach collection="pingList" item="item" index="index" open="(" close=")" separator="or">
(b.send_time BETWEEN #{item.startTime} AND #{item.endTime})
</foreach>
</if>-->
</where>
UNION
SELECT
@ -235,13 +277,19 @@
t_instrument a
LEFT JOIN t_instrument_data b ON a.`code` = b.imei
<where>
AND b.period = '谷'
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
AND ( (b.send_time BETWEEN CONCAT(#{today},' 00:00:00') AND CONCAT(#{today},' 07:00:00'))
or (b.send_time BETWEEN CONCAT(#{today},' 23:00:00') AND CONCAT(#{today},' 24:00:00')))
AND b.current_day = #{today}
</if>
<!--<if test="guList !=null ">
AND
<foreach collection="guList" item="item" index="index" open="(" close=")" separator="or">
(b.send_time BETWEEN #{item.startTime} AND #{item.endTime})
</foreach>
</if>-->
</where>
</select>
@ -252,7 +300,7 @@
a.imei,
b.load_rate
FROM
( SELECT max( a.send_time ) send_time, a.imei FROM t_instrument_data a where DATE_FORMAT(a.send_time,'%Y-%m-%d') = DATE_FORMAT(now(),'%Y-%m-%d') GROUP BY a.imei ) a
( SELECT max( a.send_time ) send_time, a.imei FROM t_instrument_data a where a.current_day = DATE_FORMAT(now(),'%Y-%m-%d') GROUP BY a.imei ) a
LEFT JOIN t_instrument_data b ON a.imei = b.imei
AND a.send_time = b.send_time
LEFT JOIN t_instrument c ON a.imei = c.CODE
@ -277,13 +325,129 @@
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
AND DATE_FORMAT( b.send_time, '%Y-%m-%d' ) = #{today}
AND b.current_day = #{today}
</if>
</where>
GROUP BY
b.imei,b.load_level
</select>
<select id="getInstrumentDaylyCount" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
a.NAME,
a.code imei,
count( a.NAME ) count
FROM
t_instrument a
LEFT JOIN t_instrument_data b ON a.CODE = b.imei
<where>
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="today !=null and today != ''">
AND b.current_day = #{today}
</if>
</where>
GROUP BY
b.imei
</select>
<select id="getTotalCarbonEmissions" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
ROUND( sum( IFNULL( a.single_electricity, 0 )) * 0.997, 2 ) totalCarbonEmissions
FROM
t_instrument_data a
<where>
<if test="currentYear !=null and currentYear != ''">
AND a.current_year = #{currentYear}
</if>
</where>
</select>
<select id="getEnterprisePower" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
a.manufacturer_brand,
sum( ifnull(b.single_electricity,0) ) `sum`,
round(sum( ifnull(b.single_electricity,0) ) * 0.997,2) totalCarbonEmissions
FROM
t_instrument a
LEFT JOIN t_instrument_data b ON a.`code` = b.imei
<where>
<if test="currentYear !=null and currentYear != ''">
and b.current_year = #{currentYear}
</if>
<if test="currentMonth !=null and currentMonth != ''">
and b.current_month = #{currentMonth}
</if>
<if test="today !=null and today != ''">
and b.current_day = #{today}
</if>
</where>
GROUP BY
a.manufacturer_brand order by sum( ifnull(b.single_electricity,0) ) desc
</select>
<select id="getSixMonthElectricity" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
current_month,
sum(
ifnull( single_electricity, 0 )) AS `sum`
FROM
t_instrument_data
<where>
<if test="monthList !=null">
AND current_month in
<foreach collection="monthList" item = "currentMonth" index="index" open="(" close=")" separator=",">
#{currentMonth}
</foreach>
</if>
</where>
GROUP BY
current_month order by current_month
</select>
<select id="getMonthCarbon" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
current_month,
ROUND(sum(
ifnull( single_electricity, 0 )) * 0.997,2) AS totalCarbonEmissions
FROM
t_instrument_data
<where>
<if test="monthList !=null">
AND current_month in
<foreach collection="monthList" item = "currentMonth" index="index" open="(" close=")" separator=",">
#{currentMonth}
</foreach>
</if>
</where>
GROUP BY
current_month order by current_month
</select>
<select id="getInstrumentRunDetail" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
a.NAME,
b.load_rate,
b.single_electricity,
b.send_time
FROM
t_instrument a
LEFT JOIN t_instrument_data b on a.`code` = b.imei
<where>
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
AND a.manufacturer_brand = #{manufacturerBrand}
</if>
<if test="name !=null and name != ''">
AND a.name = #{name}
</if>
<if test="today !=null and today != ''">
AND b.current_day = #{today}
</if>
</where>
order by b.send_time desc
</select>
<select id="getMaxElectricity" resultType="org.springblade.lims.entry.LargeScreenVO">
select ifnull(max(total_electricity),0.0) total_electricity,imei from t_instrument_data group by imei
</select>

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
@ -24,6 +25,8 @@ import org.springblade.lims.service.IInstrumentDataService;
import org.springblade.lims.service.IInstrumentService;
import org.springblade.lims.service.IInstrumentStatusService;
import org.springblade.lims.service.ILargeScreenService;
import org.springblade.system.cache.DictCache;
import org.springblade.system.entity.Dict;
import java.util.*;
@ -57,6 +60,12 @@ public class MyMQTTCallback implements MqttCallbackExtended {
//设备额定功率集合
private Map<String,Integer> powerMap = new HashMap<>();
//负载率数据字典集合
private Map<String,Integer> loadRateMap = new HashMap<>();
//尖峰平谷集合
private Map<String,String> periodMap = new HashMap<>();
/**
* 丢失连接可在这里做重连
@ -99,12 +108,33 @@ public class MyMQTTCallback implements MqttCallbackExtended {
log.info("接收消息主题 : {},接收消息内容 : {}", topic, new String(mqttMessage.getPayload()));
//接收消息主题
if (topic.contains("/device/data")){
count++;
InstrumentData data = new InstrumentData();
Map map = (Map) JSON.parse(new String(mqttMessage.getPayload(), Charsets.UTF_8.name()));
Map map1 = (Map) JSON.parse(map.get("vals").toString());
data.setSendTime(DateUtils.parseDate(map.get("tsstr").toString(),"yyyy-MM-dd hh:mm:ss"));
data.setCurrentYear(map.get("tsstr").toString().substring(0,4));
data.setCurrentMonth(map.get("tsstr").toString().substring(0,7));
data.setCurrentDay(map.get("tsstr").toString().substring(0,10));
data.setImei(map.get("imei").toString());
//计算尖峰平谷
String today = DateFormatUtils.format(new Date(),"yyyy-MM-dd");
for(Map.Entry<String,String> entry : periodMap.entrySet()){
boolean flag = false;
List<String> timeList = Arrays.asList(entry.getValue().split(","));
for(String timePeriod : timeList){
String[] times = timePeriod.split("-");
Date startTime = DateUtils.parseDate(today + " " + times[0],"yyyy-MM-dd HH:mm:ss");
Date endTime = DateUtils.parseDate(today + " " + times[1],"yyyy-MM-dd HH:mm:ss");
if(data.getSendTime().compareTo(startTime) >0 && data.getSendTime().compareTo(endTime) <=0){
flag = true;
break;
}
}
if(flag){
data.setPeriod(entry.getKey());
break;
}
}
if(map1.containsKey("总用电")){
data.setTotalElectricity(Double.parseDouble(map1.get("总用电").toString()));
//计算电表从上一次到这一次的用电量
@ -121,15 +151,15 @@ public class MyMQTTCallback implements MqttCallbackExtended {
if(powerMap.get(map.get("imei").toString()) != null){
int loadRate = Math.abs((int)Math.round(data.getTotalActivePower()/powerMap.get(map.get("imei").toString())*100));
String loadLevel = "";
if(loadRate == 0){
if(loadRate == loadRateMap.get("空载")){
loadLevel = "空载";
}else if(loadRate > 0 && loadRate <= 20){
}else if(loadRate > loadRateMap.get("空载") && loadRate <= loadRateMap.get("轻载")){
loadLevel = "轻载";
}else if (loadRate > 20 && loadRate <= 50){
}else if (loadRate > loadRateMap.get("轻载") && loadRate <= loadRateMap.get("正常")){
loadLevel = "正常";
}else if(loadRate >50 && loadRate <= 80){
}else if(loadRate >loadRateMap.get("正常") && loadRate <= loadRateMap.get("过载")){
loadLevel = "过载";
}else if(loadRate > 80){
}else if(loadRate > loadRateMap.get("过载")){
loadLevel = "重载";
}
data.setLoadRate(loadRate);
@ -293,6 +323,28 @@ public class MyMQTTCallback implements MqttCallbackExtended {
powerMap.put(instrument.getCode(),instrument.getRatedPower());
});
}
List<Dict> dictlist = DictCache.getList("load_rate");
dictlist.forEach(dict -> {
loadRateMap.put(dict.getDictValue(),Integer.parseInt(dict.getDictKey()));
});
List<Dict> periodlist = DictCache.getList("electricity_period");
Map<String,Map<String,String>> map = new HashMap<>();
periodlist.forEach(dict -> {
periodMap.put(dict.getDictValue(),dict.getDictKey());
});
/*for(Dict dict : periodlist){
List<String> timeList1 = Arrays.asList(dict.getDictKey().split(","));
timeList1.forEach(s -> {
String[] times = s.split("-");
Map<String,Date> map1 = new HashMap<>();
try {
map1.put("startTime",DateUtils.parseDate(today+" "+times[0]));
map1.put("endTime",DateUtils.parseDate(today+" "+times[1]));
} catch (ParseException e) {
throw new RuntimeException(e);
}
});
}*/
}

@ -0,0 +1,23 @@
package org.springblade.lims.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.lims.entry.CarbonEmissionPlan;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
public interface ICarbonEmissionPlanService extends BaseService<CarbonEmissionPlan> {
IPage<CarbonEmissionPlan> findPage(CarbonEmissionPlan entry, Query query);
R saveCarbon(CarbonEmissionPlan entry);
CarbonEmissionPlan findById(String id);
CarbonEmissionPlan getCarbonEmissionPlan(String currentYear);
}

@ -0,0 +1,25 @@
package org.springblade.lims.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.lims.entry.CarbonEmission;
import java.util.List;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
public interface ICarbonEmissionService extends BaseService<CarbonEmission> {
IPage<CarbonEmission> findPage(CarbonEmission entry, Query query);
R saveCarbon(CarbonEmission entry);
CarbonEmission findById(String id);
List<CarbonEmission> findTrendList(String currentMonth);
}

@ -0,0 +1,25 @@
package org.springblade.lims.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.lims.entry.CarbonIntensity;
import java.util.List;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
public interface ICarbonIntensityService extends BaseService<CarbonIntensity> {
IPage<CarbonIntensity> findPage(CarbonIntensity entry, Query query);
R saveCarbon(CarbonIntensity entry);
CarbonIntensity findById(String id);
List<CarbonIntensity> findIntensityList(String currentMonth);
}

@ -2,6 +2,8 @@
package org.springblade.lims.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.support.Query;
import org.springblade.lims.entry.LargeScreenVO;
import java.util.List;
@ -22,6 +24,20 @@ public interface ILargeScreenService{
List<LargeScreenVO> getMaxElectricity();
List<LargeScreenVO> getInstrumentActLoad(LargeScreenVO entity);
Map<String, Map<String, Integer>> getInstrumentDaylyLoad(LargeScreenVO entity);
List<Map<String,Object>> getInstrumentDaylyLoad(LargeScreenVO entity);
Map<String,Map<String,Double>> getWeekElectricity(LargeScreenVO entity);
List<Map<String,Object>> getInstrumentRunStatus(LargeScreenVO entity);
Map<String,Double> getTotalCarbonEmissions();
List<Map<String, Object>> getEnterprisePower(LargeScreenVO entity);
Map<String,Double> getSixMonthElectricity();
Map<String,String> getSixMonthCarbonQoq();
List<Map<String, Object>> getSixMonthCarbonYoy();
void getInstrumentRunStatusJob();
IPage<LargeScreenVO> getInstrumentRunDetail(LargeScreenVO entry, Query query);
}

@ -0,0 +1,81 @@
package org.springblade.lims.service.impl;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.lims.entry.CarbonEmissionPlan;
import org.springblade.lims.mapper.CarbonEmissionPlanMapper;
import org.springblade.lims.service.ICarbonEmissionPlanService;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
* @author swj
* @since 2022年6月2日15:53:01
*/
@Service
@AllArgsConstructor
public class CarbonEmissionPlanServiceImpl extends BaseServiceImpl<CarbonEmissionPlanMapper, CarbonEmissionPlan> implements ICarbonEmissionPlanService {
@Override
public IPage<CarbonEmissionPlan> findPage(CarbonEmissionPlan entry, Query query) {
LambdaQueryWrapper<CarbonEmissionPlan> wrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotBlank(entry.getCurrentYear())) {
wrapper.eq(CarbonEmissionPlan::getCurrentYear, entry.getCurrentYear());
}
if(entry.getCreateDept() != null){
wrapper.eq(BaseEntity::getCreateDept,entry.getCreateDept());
}
wrapper.eq(BaseEntity::getIsDeleted, 0);
wrapper.orderByDesc(CarbonEmissionPlan::getCreateTime);
IPage<CarbonEmissionPlan> page = this.page(Condition.getPage(query), wrapper);
return page;
}
@Override
public R saveCarbon(CarbonEmissionPlan entry) {
Double pvPower = entry.getPvPower() == null ? 0.0 : entry.getPvPower();
Double processOpt = entry.getProcessOpt() == null ? 0.0 : entry.getProcessOpt();
Double equipReplace = entry.getEquipReplace() == null ? 0.0 : entry.getEquipReplace();
entry.setTotalCarbonReduction(pvPower+processOpt+equipReplace);
if (entry.getId() == null) {
//根据月份和部门检验是否重复
LambdaQueryWrapper<CarbonEmissionPlan> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CarbonEmissionPlan::getCurrentYear,entry.getCurrentYear());
CarbonEmissionPlan carbonEmissionPlan = this.getOne(wrapper);
if(carbonEmissionPlan != null){
return R.fail("当前年份数据已录入!");
}
entry.setCreateUser(AuthUtil.getUserId());
entry.setCreateTime(new Date());
entry.setCreateDept(Long.parseLong(AuthUtil.getDeptId()));
baseMapper.insert(entry);
} else {
entry.setUpdateUser(AuthUtil.getUserId());
entry.setUpdateTime(new Date());
baseMapper.updateById(entry);
}
return R.success("保存成功!");
}
@Override
public CarbonEmissionPlan findById(String id) {
return this.getById(id);
}
@Override
public CarbonEmissionPlan getCarbonEmissionPlan(String currentYear) {
return baseMapper.getCarbonEmissionPlan(currentYear);
}
}

@ -0,0 +1,98 @@
package org.springblade.lims.service.impl;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.lims.entry.CarbonEmission;
import org.springblade.lims.mapper.CarbonEmissionMapper;
import org.springblade.lims.service.ICarbonEmissionService;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author swj
* @since 2022年6月2日15:53:01
*/
@Service
@AllArgsConstructor
public class CarbonEmissionServiceImpl extends BaseServiceImpl<CarbonEmissionMapper, CarbonEmission> implements ICarbonEmissionService {
@Override
public IPage<CarbonEmission> findPage(CarbonEmission entry, Query query) {
LambdaQueryWrapper<CarbonEmission> wrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotBlank(entry.getCurrentMonth())) {
wrapper.eq(CarbonEmission::getCurrentMonth, entry.getCurrentMonth());
}
if(entry.getCreateDept() != null){
wrapper.eq(BaseEntity::getCreateDept,entry.getCreateDept());
}
wrapper.eq(BaseEntity::getIsDeleted, 0);
wrapper.orderByDesc(CarbonEmission::getCreateTime);
IPage<CarbonEmission> page = this.page(Condition.getPage(query), wrapper);
return page;
}
@Override
public R saveCarbon(CarbonEmission entry) {
if (entry.getId() == null) {
//根据月份和部门检验是否重复
LambdaQueryWrapper<CarbonEmission> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CarbonEmission::getCurrentMonth,entry.getCurrentMonth());
CarbonEmission carbonEmission = this.getOne(wrapper);
if(carbonEmission != null){
return R.fail("当前月份数据已录入!");
}
entry.setCreateUser(AuthUtil.getUserId());
entry.setCreateTime(new Date());
entry.setCreateDept(Long.parseLong(AuthUtil.getDeptId()));
baseMapper.insert(entry);
} else {
entry.setUpdateUser(AuthUtil.getUserId());
entry.setUpdateTime(new Date());
baseMapper.updateById(entry);
}
return R.success("保存成功!");
}
@Override
public CarbonEmission findById(String id) {
return this.getById(id);
}
@Override
public List<CarbonEmission> findTrendList(String currentMonth) {
List<CarbonEmission> list = new ArrayList<>();
try {
List<String> monthList = new ArrayList<>();
monthList.add(currentMonth);
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-1),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-2),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-3),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-4),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-5),"yyyy-MM"));
LambdaQueryWrapper<CarbonEmission> wrapper = new LambdaQueryWrapper<>();
wrapper.in(CarbonEmission::getCurrentMonth,monthList);
list = this.list(wrapper);
} catch (ParseException e) {
throw new RuntimeException(e);
}
return list;
}
}

@ -0,0 +1,98 @@
package org.springblade.lims.service.impl;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.lims.entry.CarbonIntensity;
import org.springblade.lims.mapper.CarbonIntensityMapper;
import org.springblade.lims.service.ICarbonIntensityService;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author swj
* @since 2022年6月2日15:53:01
*/
@Service
@AllArgsConstructor
public class CarbonIntensityServiceImpl extends BaseServiceImpl<CarbonIntensityMapper, CarbonIntensity> implements ICarbonIntensityService {
@Override
public IPage<CarbonIntensity> findPage(CarbonIntensity entry, Query query) {
LambdaQueryWrapper<CarbonIntensity> wrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotBlank(entry.getCurrentMonth())) {
wrapper.eq(CarbonIntensity::getCurrentMonth, entry.getCurrentMonth());
}
if(entry.getCreateDept() != null){
wrapper.eq(BaseEntity::getCreateDept,entry.getCreateDept());
}
wrapper.eq(BaseEntity::getIsDeleted, 0);
wrapper.orderByDesc(CarbonIntensity::getCreateTime);
IPage<CarbonIntensity> page = this.page(Condition.getPage(query), wrapper);
return page;
}
@Override
public R saveCarbon(CarbonIntensity entry) {
if (entry.getId() == null) {
//根据月份和部门检验是否重复
LambdaQueryWrapper<CarbonIntensity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CarbonIntensity::getCurrentMonth,entry.getCurrentMonth());
CarbonIntensity carbonIntensity = this.getOne(wrapper);
if(carbonIntensity != null){
return R.fail("当前月份数据已录入!");
}
entry.setCreateUser(AuthUtil.getUserId());
entry.setCreateTime(new Date());
entry.setCreateDept(Long.parseLong(AuthUtil.getDeptId()));
baseMapper.insert(entry);
} else {
entry.setUpdateUser(AuthUtil.getUserId());
entry.setUpdateTime(new Date());
baseMapper.updateById(entry);
}
return R.success("保存成功!");
}
@Override
public CarbonIntensity findById(String id) {
return this.getById(id);
}
@Override
public List<CarbonIntensity> findIntensityList(String currentMonth) {
List<CarbonIntensity> list = new ArrayList<>();
try {
List<String> monthList = new ArrayList<>();
monthList.add(currentMonth);
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-1),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-2),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-3),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-4),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-5),"yyyy-MM"));
LambdaQueryWrapper<CarbonIntensity> wrapper = new LambdaQueryWrapper<>();
wrapper.in(CarbonIntensity::getCurrentMonth,monthList);
list = this.list(wrapper);
} catch (ParseException e) {
throw new RuntimeException(e);
}
return list;
}
}

@ -2,19 +2,28 @@
package org.springblade.lims.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springblade.core.mp.support.Query;
import org.springblade.lims.entry.CarbonEmissionPlan;
import org.springblade.lims.entry.Instrument;
import org.springblade.lims.entry.LargeScreenVO;
import org.springblade.lims.mapper.LargeScreenMapper;
import org.springblade.lims.service.ICarbonEmissionPlanService;
import org.springblade.lims.service.IInstrumentService;
import org.springblade.lims.service.ILargeScreenService;
import org.springblade.lims.tools.RedisUtil;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.time.YearMonth;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -25,6 +34,9 @@ import java.util.stream.Collectors;
@AllArgsConstructor
public class LargeScreenServiceImpl implements ILargeScreenService {
private final LargeScreenMapper largeScreenMapper;
private final IInstrumentService instrumentService;
private final RedisUtil redisUtil;
private final ICarbonEmissionPlanService carbonEmissionPlanService;
@Override
public Map<String, Double> getTotalElectricity(String manufacturerBrand) {
@ -69,14 +81,17 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
Map<String, Map<String, Double>> map = new HashMap<>();
try {
String lastMonth = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(entity.getCurrentMonth(), "yyyy-MM"), -1), "yyyy-MM");
//初始化每月电量数据
Map<String, Double> currentMap = initMonthData(entity.getCurrentMonth());
Map<String, Double> lastMap = initMonthData(lastMonth);
//查询本月电量
List<LargeScreenVO> currentList = largeScreenMapper.getDayElectricity(entity);
if (CollectionUtils.isNotEmpty(currentList)) {
currentList.forEach(largeScreenVO -> {
currentMap.put(largeScreenVO.getDate(), largeScreenVO.getTotalElectricity());
});
}
//查询上月电量
entity.setCurrentMonth(lastMonth);
List<LargeScreenVO> lastList = largeScreenMapper.getDayElectricity(entity);
if (CollectionUtils.isNotEmpty(lastList)) {
@ -104,6 +119,38 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
@Override
public List<LargeScreenVO> getPeriodElectricity(LargeScreenVO entity) {
/*List<TimeVO> jianList = new ArrayList<>();
List<TimeVO> fengList = new ArrayList<>();
List<TimeVO> pingList = new ArrayList<>();
List<TimeVO> guList = new ArrayList<>();
List<Dict> dictlist = DictCache.getList("electricity_period");
for(Dict dict : dictlist){
List<String> timeList1 = Arrays.asList(dict.getDictKey().split(","));
timeList1.forEach(s -> {
String[] times = s.split("-");
TimeVO timeVO = new TimeVO();
timeVO.setStartTime(entity.getToday()+" "+times[0]);
timeVO.setEndTime(entity.getToday()+" "+times[1]);
if(dict.getDictValue().equals("尖")){
jianList.add(timeVO);
}
if(dict.getDictValue().equals("峰")){
fengList.add(timeVO);
}
if(dict.getDictValue().equals("平")){
pingList.add(timeVO);
}
if(dict.getDictValue().equals("谷")){
guList.add(timeVO);
}
});
}
entity.setJianList(jianList);
entity.setFengList(fengList);
entity.setPingList(pingList);
entity.setGuList(guList);*/
return largeScreenMapper.getPeriodElectricity(entity);
}
@ -118,53 +165,82 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
}
@Override
public Map<String, Map<String, Integer>> getInstrumentDaylyLoad(LargeScreenVO entity) {
List<LargeScreenVO> list = largeScreenMapper.getInstrumentDaylyLoad(entity);
Map<String, Map<String, Integer>> map = new HashMap<>();
if(CollectionUtils.isNotEmpty(list)){
List<String> nameList = list.stream().map(LargeScreenVO::getName).distinct().collect(Collectors.toList());
nameList.forEach(s -> {
Map<String,Integer> map1 = new HashMap<>();
map1.put("空载",0);
map1.put("轻载",0);
map1.put("正常",0);
map1.put("过载",0);
map1.put("重载",0);
map.put(s,map1);
});
for(LargeScreenVO largeScreenVO : list){
Map<String,Integer> map1 = map.get(largeScreenVO.getName());
if(map1.containsKey(largeScreenVO.getLoadLevel())){
map1.put(largeScreenVO.getLoadLevel(),largeScreenVO.getCount());
}
}
for (Map.Entry<String, Map<String, Integer>> entry : map.entrySet()) {
Map<String,Integer> map1 = entry.getValue();
int sum = 0;
for (Map.Entry<String, Integer> entry1 : map1.entrySet()) {
sum+=entry1.getValue();
}
for (Map.Entry<String, Integer> entry1 : map1.entrySet()) {
double load = (double)entry1.getValue()/sum*100;
map1.put(entry1.getKey(),(int)Math.round(load));
public List<Map<String,Object>> getInstrumentDaylyLoad(LargeScreenVO entity) {
List<Map<String,Object>> list = new ArrayList<>();
List<LargeScreenVO> list1 = largeScreenMapper.getInstrumentDaylyCount(entity);
List<LargeScreenVO> list2 = largeScreenMapper.getInstrumentDaylyLoad(entity);
if(CollectionUtils.isNotEmpty(list1)){
for(LargeScreenVO vo1 : list1){
Map<String,Object> map = new HashMap<>();
map.put("name",vo1.getName());
map.put("kongzai",0);
map.put("qingzai",0);
map.put("zhengchang",0);
map.put("guozai",0);
map.put("zhongzai",0);
for(LargeScreenVO vo2 : list2){
if(vo1.getName().equals(vo2.getName())){
int load = (int)Math.round((double) vo2.getCount()/ vo1.getCount() *100);
if("空载".equals(vo2.getLoadLevel())){
map.put("kongzai",load);
}else if("轻载".equals(vo2.getLoadLevel())){
map.put("qingzai",load);
}else if("正常".equals(vo2.getLoadLevel())){
map.put("zhengchang",load);
}else if("过载".equals(vo2.getLoadLevel())){
map.put("guozai",load);
}else if("重载".equals(vo2.getLoadLevel())){
map.put("zhongzai",load);
}
}
}
map.put(entry.getKey(),map1);
list.add(map);
}
}
return map;
return list;
}
@Override
public Map<String, Map<String, Double>> getWeekElectricity(LargeScreenVO entity) {
String day = entity.getToday();
Map<String, Map<String, Double>> map = new HashMap<>();
/* List<TimeVO> jianList = new ArrayList<>();
List<TimeVO> fengList = new ArrayList<>();
List<TimeVO> pingList = new ArrayList<>();
List<TimeVO> guList = new ArrayList<>();
List<Dict> dictlist = DictCache.getList("electricity_period");*/
for (int i = 0; i < 7; i++) {
try {
String today = DateFormatUtils.format(DateUtils.addDays(DateUtils.parseDate(day, "yyyy-MM-dd"), -i), "yyyy-MM-dd");
entity.setToday(today);
/*for(Dict dict : dictlist){
List<String> timeList1 = Arrays.asList(dict.getDictKey().split(","));
timeList1.forEach(s -> {
String[] times = s.split("-");
TimeVO timeVO = new TimeVO();
timeVO.setStartTime(entity.getToday()+" "+times[0]);
timeVO.setEndTime(entity.getToday()+" "+times[1]);
if(dict.getDictValue().equals("尖")){
jianList.add(timeVO);
}
if(dict.getDictValue().equals("峰")){
fengList.add(timeVO);
}
if(dict.getDictValue().equals("平")){
pingList.add(timeVO);
}
if(dict.getDictValue().equals("谷")){
guList.add(timeVO);
}
});
}
entity.setJianList(jianList);
entity.setFengList(fengList);
entity.setPingList(pingList);
entity.setGuList(guList);*/
List<LargeScreenVO> list1 = largeScreenMapper.getWeekElectricity(entity);
Map<String, Double> map1 = new HashMap<>();
list1.forEach(largeScreenVO -> {
@ -178,6 +254,300 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
return map;
}
@Override
public List<Map<String, Object>> getInstrumentRunStatus(LargeScreenVO entity) {
List<Map<String, Object>> list = new ArrayList<>();
Date date = new Date();
if(Integer.parseInt(DateFormatUtils.format(date,"HH")) >= 8 && Integer.parseInt(DateFormatUtils.format(date,"HH")) <= 20){
//查询设备运行状态
LambdaQueryWrapper<Instrument> wrapper = new LambdaQueryWrapper<>();
if(StringUtils.isNotEmpty(entity.getManufacturerBrand())){
wrapper.eq(Instrument::getManufacturerBrand,entity.getManufacturerBrand());
}
List<Instrument> instrumentList = instrumentService.list(wrapper);
if(CollectionUtils.isNotEmpty(instrumentList)){
for(Instrument instrument : instrumentList){
Map<String,Object> map = new HashMap<>();
List<Map<String,String>> list1 = (List)redisUtil.get(instrument.getName() + "-runStatus");
map.put("name",instrument.getName());
map.put("list",list1);
list.add(map);
}
}
return list;
}
return null;
}
@Override
public Map<String,Double> getTotalCarbonEmissions() {
String currentYear = DateFormatUtils.format(new Date(),"yyyy");
LargeScreenVO largeScreenVO = largeScreenMapper.getTotalCarbonEmissions(currentYear);
CarbonEmissionPlan carbonEmissionPlan = carbonEmissionPlanService.getCarbonEmissionPlan(currentYear);
String lastYear = DateFormatUtils.format(DateUtils.addYears(new Date(),-1),"yyyy");
LargeScreenVO largeScreenVO1 = largeScreenMapper.getTotalCarbonEmissions(lastYear);
CarbonEmissionPlan carbonEmissionPlan1 = carbonEmissionPlanService.getCarbonEmissionPlan(lastYear);
Map<String,Double> map = new HashMap<>();
map.put("jnzl",largeScreenVO.getTotalCarbonEmissions());
if(largeScreenVO1 != null){
map.put("qnzl",largeScreenVO1.getTotalCarbonEmissions());
}else{
map.put("qnzl",0.0);
}
if(carbonEmissionPlan1 != null){
map.put("qnjhl",carbonEmissionPlan1.getCarbonPlan());
map.put("qnjpzl",carbonEmissionPlan1.getTotalCarbonReduction());
}else{
map.put("qnjhl",0.0);
map.put("qnjpzl",0.0);
}
map.put("jnjhzl",carbonEmissionPlan.getTotalCarbonPlan());
map.put("jnjhl",carbonEmissionPlan.getCarbonPlan());
map.put("jnjpzl",carbonEmissionPlan.getTotalCarbonReduction());
map.put("gffd",carbonEmissionPlan.getPvPower());
map.put("gyyh",carbonEmissionPlan.getProcessOpt());
map.put("sbgh",carbonEmissionPlan.getEquipReplace());
map.put("gffdzb",Double.parseDouble(String.format("%.2f",carbonEmissionPlan.getPvPower()/carbonEmissionPlan.getTotalCarbonReduction()*100)));
map.put("gyyhzb",Double.parseDouble(String.format("%.2f",carbonEmissionPlan.getProcessOpt()/carbonEmissionPlan.getTotalCarbonReduction()*100)));
map.put("sbghzb",Double.parseDouble(String.format("%.2f",carbonEmissionPlan.getEquipReplace()/carbonEmissionPlan.getTotalCarbonReduction()*100)));
map.put("ypfzb",Double.parseDouble(String.format("%.2f",carbonEmissionPlan.getTotalCarbonPlan()/largeScreenVO.getTotalCarbonEmissions()*100)));
return map;
}
@Override
public List<Map<String, Object>> getEnterprisePower(LargeScreenVO entity) {
List<Map<String, Object>> list = new ArrayList<>();
List<LargeScreenVO> dataList = largeScreenMapper.getEnterprisePower(entity);
if(CollectionUtils.isNotEmpty(dataList)){
for(LargeScreenVO largeScreenVO : dataList){
Map<String,Object> map = new TreeMap<>();
map.put("name",largeScreenVO.getManufacturerBrand());
map.put("electricity",largeScreenVO.getSum());
map.put("carbon",largeScreenVO.getTotalCarbonEmissions());
list.add(map);
}
}
return list;
}
@Override
public Map<String, Double> getSixMonthElectricity() {
Map<String,Double> map = new HashMap<>();
try {
List<String> monthList = new ArrayList<>();
String currentMonth = DateFormatUtils.format(new Date(),"yyyy-MM");
monthList.add(currentMonth);
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-1),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-2),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-3),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-4),"yyyy-MM"));
monthList.add(DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-5),"yyyy-MM"));
monthList.forEach(s -> {
map.put(s,0.0);
});
LargeScreenVO largeScreenVO = new LargeScreenVO();
largeScreenVO.setMonthList(monthList);
List<LargeScreenVO> dataList = largeScreenMapper.getSixMonthElectricity(largeScreenVO);
if(CollectionUtils.isNotEmpty(dataList)){
dataList.forEach(largeScreenVO1 -> {
map.put(largeScreenVO1.getCurrentMonth(),largeScreenVO1.getSum());
});
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
return map;
}
@Override
public Map<String, String> getSixMonthCarbonQoq() {
Map<String,String> map = new HashMap<>();
Map<String,Double> map1 = new HashMap<>();
try {
List<String> monthList = new ArrayList<>();
String currentMonth = DateFormatUtils.format(new Date(),"yyyy-MM");
String month1 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-1),"yyyy-MM");
String month2 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-2),"yyyy-MM");
String month3 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-3),"yyyy-MM");
String month4 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-4),"yyyy-MM");
String month5 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-5),"yyyy-MM");
String month6 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(currentMonth,"yyyy-MM"),-6),"yyyy-MM");
monthList.add(currentMonth);
monthList.add(month1);
monthList.add(month2);
monthList.add(month3);
monthList.add(month4);
monthList.add(month5);
monthList.forEach(s -> {
map.put(s,"0");
});
monthList.add(month6);
monthList.forEach(s -> {
map1.put(s,0.0);
});
LargeScreenVO largeScreenVO = new LargeScreenVO();
largeScreenVO.setMonthList(monthList);
List<LargeScreenVO> dataList = largeScreenMapper.getMonthCarbon(largeScreenVO);
if(CollectionUtils.isNotEmpty(dataList)){
dataList.forEach(largeScreenVO1 -> {
map1.put(largeScreenVO1.getCurrentMonth(),largeScreenVO1.getTotalCarbonEmissions());
});
if(map1.get(month6) != 0){
map.put(month5,String.format("%.2f",(map1.get(month5)-map1.get(month6))/map1.get(month6)*100));
}
if(map1.get(month5) != 0){
map.put(month4,String.format("%.2f",(map1.get(month4)-map1.get(month5))/map1.get(month5)*100));
}
if(map1.get(month4) != 0){
map.put(month3,String.format("%.2f",(map1.get(month3)-map1.get(month4))/map1.get(month4)*100));
}
if(map1.get(month3) != 0){
map.put(month2,String.format("%.2f",(map1.get(month2)-map1.get(month3))/map1.get(month3)*100));
}
if(map1.get(month2) != 0){
map.put(month1,String.format("%.2f",(map1.get(month1)-map1.get(month2))/map1.get(month2)*100));
}
if(map1.get(month1) != 0){
map.put(currentMonth,String.format("%.2f",(map1.get(currentMonth)-map1.get(month1))/map1.get(month1)*100));
}
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
return map;
}
@Override
public List<Map<String, Object>> getSixMonthCarbonYoy() {
List<Map<String, Object>> list = new ArrayList<>();
try {
List<String> monthList = new ArrayList<>();
String month = DateFormatUtils.format(new Date(),"yyyy-MM");;
String month1 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(month,"yyyy-MM"),-1),"yyyy-MM");
String month2 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(month,"yyyy-MM"),-2),"yyyy-MM");
String month3 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(month,"yyyy-MM"),-3),"yyyy-MM");
String month4 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(month,"yyyy-MM"),-4),"yyyy-MM");
String month5 = DateFormatUtils.format(DateUtils.addMonths(DateUtils.parseDate(month,"yyyy-MM"),-5),"yyyy-MM");
monthList.add(month);
monthList.add(month1);
monthList.add(month2);
monthList.add(month3);
monthList.add(month4);
monthList.add(month5);
monthList.forEach(s -> {
Map<String,Object> map = new HashMap<>();
try {
map.put("jn",s);
map.put("qn",DateFormatUtils.format(DateUtils.addYears(DateUtils.parseDate(s,"yyyy-MM"),-1),"yyyy-MM"));
map.put("jnpf",0.0);
map.put("qnpf",0.0);
map.put("tongbi",0.0);
} catch (ParseException e) {
throw new RuntimeException(e);
}
list.add(map);
});
LargeScreenVO largeScreenVO = new LargeScreenVO();
largeScreenVO.setMonthList(monthList);
List<LargeScreenVO> dataList1 = largeScreenMapper.getMonthCarbon(largeScreenVO);
if(CollectionUtils.isNotEmpty(dataList1)){
for(LargeScreenVO largeScreenVO1 : dataList1){
for(Map<String,Object> map : list){
if(map.get("jn").toString().equals(largeScreenVO1.getCurrentMonth())){
map.put("jnpf",largeScreenVO1.getTotalCarbonEmissions());
}
}
}
}
String lmonth = DateFormatUtils.format(DateUtils.addYears(DateUtils.parseDate(month,"yyyy-MM"),-1),"yyyy-MM");
String lmonth1 = DateFormatUtils.format(DateUtils.addYears(DateUtils.parseDate(month1,"yyyy-MM"),-1),"yyyy-MM");
String lmonth2 = DateFormatUtils.format(DateUtils.addYears(DateUtils.parseDate(month2,"yyyy-MM"),-1),"yyyy-MM");
String lmonth3 = DateFormatUtils.format(DateUtils.addYears(DateUtils.parseDate(month3,"yyyy-MM"),-1),"yyyy-MM");
String lmonth4 = DateFormatUtils.format(DateUtils.addYears(DateUtils.parseDate(month4,"yyyy-MM"),-1),"yyyy-MM");
String lmonth5 = DateFormatUtils.format(DateUtils.addYears(DateUtils.parseDate(month5,"yyyy-MM"),-1),"yyyy-MM");
monthList.clear();
monthList.add(lmonth);
monthList.add(lmonth1);
monthList.add(lmonth2);
monthList.add(lmonth3);
monthList.add(lmonth4);
monthList.add(lmonth5);
largeScreenVO.setMonthList(monthList);
List<LargeScreenVO> dataList2 = largeScreenMapper.getMonthCarbon(largeScreenVO);
if(CollectionUtils.isNotEmpty(dataList2)){
for(LargeScreenVO largeScreenVO1 : dataList2){
for(Map<String,Object> map : list){
if(map.get("qn").toString().equals(largeScreenVO1.getCurrentMonth())){
map.put("qnpf",largeScreenVO1.getTotalCarbonEmissions());
}
}
}
}
for(Map<String,Object> map : list){
if((double)map.get("qnpf") != 0.0){
map.put("tongbi",Double.parseDouble(String.format("%.2f",((double)map.get("jnpf")-(double)map.get("qnpf"))/(double)map.get("qnpf")*100)));
}
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
return list;
}
@Override
public void getInstrumentRunStatusJob() {
Date date = new Date();
if(Integer.parseInt(DateFormatUtils.format(date,"HH")) >= 8 && Integer.parseInt(DateFormatUtils.format(date,"HH")) <= 20){
List<Instrument> instrumentList = instrumentService.list(new LambdaQueryWrapper<>());
if(CollectionUtils.isNotEmpty(instrumentList)){
for(Instrument instrument : instrumentList){
List<Map<String,String>> list = new ArrayList<>();
if(redisUtil.get(instrument.getName() + "-runStatus") == null){
list = new ArrayList<>();
Map<String,String> map = new HashMap<>();
map.put("time",DateFormatUtils.format(date,"HH:mm"));
map.put("runStatus",instrument.getRunStatus()==null?"2":instrument.getRunStatus().toString());
list.add(map);
//早8点到晚8点,redis过期时间设置为4小时
redisUtil.set(instrument.getName() + "-runStatus",list,60*60*4);
}else{
list = (List)redisUtil.get(instrument.getName() + "-runStatus");
Map<String,String> map = new HashMap<>();
map.put("time",DateFormatUtils.format(date,"HH:mm"));
map.put("runStatus",instrument.getRunStatus()==null?"2":instrument.getRunStatus().toString());
list.add(map);
redisUtil.set(instrument.getName() + "-runStatus",list,60*60*4);
}
}
}
}
}
@Override
public IPage<LargeScreenVO> getInstrumentRunDetail(LargeScreenVO entity, Query query) {
List<LargeScreenVO> list = largeScreenMapper.getInstrumentRunDetail(entity);
IPage<LargeScreenVO> page = new Page<>(query.getCurrent(),query.getSize());
int startIndex = (int)((query.getCurrent() - 1)*query.getSize());
if(null == list || list.isEmpty() || startIndex > list.size()){
page.setTotal(0);
page.setRecords(null);
}
else {
page.setTotal(list.size());
int toIndex = (int)(query.getCurrent()*query.getSize());
page.setRecords(list.subList(startIndex,toIndex > list.size() ? list.size() : toIndex));
}
return page;
}
public TreeMap<String, Double> initMonthData(String currentMonth) {
int year = Integer.parseInt(currentMonth.split("-")[0]);
int month = Integer.parseInt(currentMonth.split("-")[1]);

@ -5,17 +5,26 @@ package org.springblade.lims.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.lims.entry.Instrument;
import org.springblade.lims.entry.MaintainRecord;
import org.springblade.lims.mapper.MaintainRecordMapper;
import org.springblade.lims.service.IInstrumentService;
import org.springblade.lims.service.IMaintainRecordService;
import org.springblade.system.cache.SysCache;
import org.springblade.system.entity.Dept;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
*
@ -33,6 +42,16 @@ public class MaintainRecordServiceImpl extends BaseServiceImpl<MaintainRecordMap
if(entry.getCreateDept() != null){
wrapper.eq(BaseEntity::getCreateDept,entry.getCreateDept());
}
List<String> roles = Arrays.asList(AuthUtil.getUserRole().split(","));
if(!roles.contains("admin") && !roles.contains("政府")){
List<Long> deptIds = new ArrayList<>();
List<Dept> depts = SysCache.getDeptChild(Long.parseLong(AuthUtil.getDeptId()));
if(CollectionUtils.isNotEmpty(depts)){
deptIds = depts.stream().map(Dept::getId).collect(Collectors.toList());
}
deptIds.add(Long.parseLong(AuthUtil.getDeptId()));
wrapper.in(BaseEntity::getCreateDept,deptIds);
}
wrapper.eq(BaseEntity::getIsDeleted,0);
wrapper.orderByDesc(MaintainRecord::getCreateTime);
IPage<MaintainRecord> page = this.page(Condition.getPage(query), wrapper);

Loading…
Cancel
Save