嘉禾二期

master
sunjianxi 2 years ago
parent b68b199dd2
commit e3d375ca64
  1. 4
      lab-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java
  2. 53
      lab-service-api/lab-lims-api/src/main/java/org/springblade/lims/entry/EnterprisePower.java
  3. 4
      lab-service/lab-lims/src/main/java/org/springblade/lims/job/CreateMaintainTaskJob.java
  4. 42
      lab-service/lab-lims/src/main/java/org/springblade/lims/job/EnterprisePowerTaskJob.java
  5. 19
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/EnterprisePowerMapper.java
  6. 28
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/EnterprisePowerMapper.xml
  7. 1
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/LargeScreenMapper.java
  8. 72
      lab-service/lab-lims/src/main/java/org/springblade/lims/mapper/LargeScreenMapper.xml
  9. 19
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/IEnterprisePowerService.java
  10. 35
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/EnterprisePowerServiceImpl.java
  11. 2
      lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/LargeScreenServiceImpl.java

@ -26,6 +26,10 @@ public class LauncherServiceImpl implements LauncherService {
// PropsUtil.setProperty(props, "spring.cloud.nacos.config.namespace", "44debeab-5f49-41b6-a664-2f0a33825f8f");
PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.namespace", "e9bcb975-a8b3-43d1-812f-8408ce571136");
PropsUtil.setProperty(props, "spring.cloud.nacos.config.namespace", "e9bcb975-a8b3-43d1-812f-8408ce571136");
PropsUtil.setProperty(props, "spring.cloud.nacos.username", "nacos");
//PropsUtil.setProperty(props, "spring.cloud.nacos.password", "nacos");
//服务器配置
PropsUtil.setProperty(props, "spring.cloud.nacos.password", "jiahe123!");
// PropsUtil.setProperty(props, "spring.cloud.sentinel.transport.dashboard", LauncherConstant.sentinelAddr(profile));
// PropsUtil.setProperty(props, "spring.zipkin.base-url", LauncherConstant.zipkinAddr(profile));
PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "false");

@ -0,0 +1,53 @@
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 swj
*/
@Data
@SuppressWarnings("all")
@TableName("t_enterprise_power")
public class EnterprisePower extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Long id;
/**
* 年份
*/
private String currentYear;
/**
* 月份
*/
private String currentMonth;
/**
* 日期
*/
private String currentDay;
/**
* 厂家
*/
public String manufacturerBrand;
/**
* 用电量
*/
public Double electricity;
/**
* 碳排放量
*/
public Double carbon;
}

@ -12,8 +12,8 @@ public class CreateMaintainTaskJob {
private final IMaintainPlanService maintainPlanService;
private final IInspectionPlanService inspectionPlanService;
//@Scheduled(cron ="0 0 0 1/1 * ? ")
@Scheduled(cron ="0 0/2 * * * ? ")
@Scheduled(cron ="0 0 0 1/1 * ? ")
//@Scheduled(cron ="0 0/2 * * * ? ")
public void createTask(){
inspectionPlanService.checkAndCreateTask();
maintainPlanService.checkAndCreateTask();

@ -0,0 +1,42 @@
package org.springblade.lims.job;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springblade.lims.service.IEnterprisePowerService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 企业能源消耗及碳排放统计
*/
@Component
@AllArgsConstructor
public class EnterprisePowerTaskJob {
private final IEnterprisePowerService enterprisePowerService;
//每天1点统计前一天数据,并删除7天前的数据
@Scheduled(cron ="0 0 1 * * ? ")
//@Scheduled(cron ="0 0/2 * * * ? ")
public void createTask(){
//统计前一天的数据
Date now = new Date();
String currentDay = DateFormatUtils.format(DateUtils.addDays(now,-1),"yyyy-MM-dd");
enterprisePowerService.insertData(currentDay);
//删除7天前的数据,数据表里只保留7天数据
String days = DateFormatUtils.format(DateUtils.addDays(now,-6),"yyyy-MM-dd") + " 00:00:00";
enterprisePowerService.deleteData(days);
}
//每月28号创建下个月的表
@Scheduled(cron ="0 0 1 28 * ? ")
//@Scheduled(cron ="0 0/2 * * * ? ")
public void createTable(){
Date now = new Date();
String month = DateFormatUtils.format(DateUtils.addMonths(now,1),"yyyyMM");
String tableName = "t_instrument_data_"+month;
enterprisePowerService.createTable(tableName);
}
}

@ -0,0 +1,19 @@
package org.springblade.lims.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springblade.lims.entry.EnterprisePower;
/**
*
*
* @author swj
* @since 2022年6月2日15:47:39
*/
public interface EnterprisePowerMapper extends BaseMapper<EnterprisePower> {
void insertData(String currentDay);
void createTable(String tableName);
void deleteData(String daytime);
}

@ -0,0 +1,28 @@
<?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.EnterprisePowerMapper">
<insert id="insertData">
insert into t_enterprise_power(current_day,current_month,current_year,manufacturer_brand,electricity,carbon,create_user,create_dept,create_time,update_user,update_time,is_deleted,status)
SELECT
b.current_day,
b.current_month,
b.current_year,
a.manufacturer_brand,
sum( ifnull(b.single_electricity,0) ) `electricity`,
round(sum( ifnull(b.single_electricity,0) ) * 0.997/1000,2) carbon,1,1,NOW(),1,now(),'0','0'
FROM
t_instrument a
LEFT JOIN t_instrument_data b
ON a.`code` = b.imei where b.current_day = #{currentDay}
GROUP BY
a.manufacturer_brand,b.current_day,b.current_month,b.current_year
</insert>
<update id="createTable" parameterType="java.lang.String">
CREATE TABLE `${tableName}` LIKE t_instrument_data;
</update>
<delete id="deleteData" parameterType="java.lang.String">
delete from t_instrument_data where send_time <![CDATA[ < ]]> #{daytime}
</delete>
</mapper>

@ -14,6 +14,7 @@ import java.util.List;
*/
public interface LargeScreenMapper extends BaseMapper {
LargeScreenVO getTotalElectricity(LargeScreenVO entity);
LargeScreenVO getTotalElectricityToday(LargeScreenVO entity);
List<LargeScreenVO> getDayElectricity(LargeScreenVO entity);

@ -3,23 +3,35 @@
<mapper namespace="org.springblade.lims.mapper.LargeScreenMapper">
<select id="getTotalElectricity" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
sum( ifnull( a.single_electricity, 0 ) ) total_electricity
sum( electricity ) total_electricity
FROM
t_instrument_data a
LEFT JOIN t_instrument b ON a.imei = b.CODE
t_enterprise_power
<where>
<if test="currentYear !=null and currentYear != ''">
and a.current_year = #{currentYear}
and current_year = #{currentYear}
</if>
<if test="currentMonth !=null and currentMonth != ''">
and a.current_month = #{currentMonth}
and current_month = #{currentMonth}
</if>
<if test="yesterday !=null and yesterday != ''">
and current_day = #{yesterday}
</if>
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
and manufacturer_brand = #{manufacturerBrand}
</if>
</where>
</select>
<select id="getTotalElectricityToday" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
sum( ifnull( a.single_electricity, 0 ) ) total_electricity
FROM
t_instrument_data a
LEFT JOIN t_instrument b ON a.imei = b.CODE
<where>
<if test="today !=null and today != ''">
and a.current_day = #{today}
</if>
<if test="yesterday !=null and yesterday != ''">
and a.current_day = #{yesterday}
</if>
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
and b.manufacturer_brand = #{manufacturerBrand}
</if>
@ -28,21 +40,18 @@
<select id="getDayElectricity" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
sum( a.single_electricity ) total_electricity,
a.current_day AS `date`
electricity total_electricity,
current_day AS `date`
FROM
t_instrument_data a
LEFT JOIN t_instrument b ON a.imei = b.CODE
t_enterprise_power
<where>
<if test="currentMonth !=null and currentMonth != ''">
and a.current_month = #{currentMonth}
and current_month = #{currentMonth}
</if>
<if test="manufacturerBrand !=null and manufacturerBrand != ''">
and b.manufacturer_brand = #{manufacturerBrand}
and manufacturer_brand = #{manufacturerBrand}
</if>
</where>
GROUP BY
a.current_day
</select>
<select id="getHourElectricity" resultType="org.springblade.lims.entry.LargeScreenVO">
@ -354,9 +363,9 @@
<select id="getTotalCarbonEmissions" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
ROUND( sum( IFNULL( a.single_electricity, 0 )) * 0.997/1000, 2 ) totalCarbonEmissions
sum(carbon) totalCarbonEmissions
FROM
t_instrument_data a
t_enterprise_power a
<where>
<if test="currentYear !=null and currentYear != ''">
AND a.current_year = #{currentYear}
@ -367,33 +376,31 @@
<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/1000,2) totalCarbonEmissions
sum(a.electricity) `sum`,
sum(a.carbon) totalCarbonEmissions
FROM
t_instrument a
LEFT JOIN t_instrument_data b ON a.`code` = b.imei
t_enterprise_power a
<where>
<if test="currentYear !=null and currentYear != ''">
and b.current_year = #{currentYear}
and a.current_year = #{currentYear}
</if>
<if test="currentMonth !=null and currentMonth != ''">
and b.current_month = #{currentMonth}
and a.current_month = #{currentMonth}
</if>
<if test="today !=null and today != ''">
and b.current_day = #{today}
and a.current_day = #{today}
</if>
</where>
GROUP BY
a.manufacturer_brand order by sum( ifnull(b.single_electricity,0) ) desc
group by a.manufacturer_brand
order by sum(a.electricity) desc
</select>
<select id="getSixMonthElectricity" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
current_month,
sum(
ifnull( single_electricity, 0 )) AS `sum`
sum(electricity) AS `sum`
FROM
t_instrument_data
t_enterprise_power
<where>
<if test="monthList !=null">
AND current_month in
@ -409,10 +416,9 @@
<select id="getMonthCarbon" resultType="org.springblade.lims.entry.LargeScreenVO">
SELECT
current_month,
ROUND(sum(
ifnull( single_electricity, 0 )) * 0.997/1000,2) AS totalCarbonEmissions
sum(carbon) AS totalCarbonEmissions
FROM
t_instrument_data
t_enterprise_power
<where>
<if test="monthList !=null">
AND current_month in

@ -0,0 +1,19 @@
package org.springblade.lims.service;
import org.springblade.core.mp.base.BaseService;
import org.springblade.lims.entry.EnterprisePower;
/**
* @author sjx
* @date 2023年11月27日15:34:17
*/
public interface IEnterprisePowerService extends BaseService<EnterprisePower> {
void insertData(String currentDay);
void createTable(String tableName);
void deleteData(String daytime);
}

@ -0,0 +1,35 @@
package org.springblade.lims.service.impl;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.lims.entry.EnterprisePower;
import org.springblade.lims.mapper.EnterprisePowerMapper;
import org.springblade.lims.service.IEnterprisePowerService;
import org.springframework.stereotype.Service;
/**
* @author swj
* @since 2022年6月2日15:53:01
*/
@Service
@AllArgsConstructor
public class EnterprisePowerServiceImpl extends BaseServiceImpl<EnterprisePowerMapper, EnterprisePower> implements IEnterprisePowerService {
@Override
public void insertData(String currentDay) {
baseMapper.insertData(currentDay);
}
@Override
public void createTable(String tableName) {
baseMapper.createTable(tableName);
}
@Override
public void deleteData(String daytime) {
baseMapper.deleteData(daytime);
}
}

@ -59,7 +59,7 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
LargeScreenVO entity2 = new LargeScreenVO();
entity2.setToday(DateFormatUtils.format(new Date(), "yyyy-MM-dd"));
entity2.setManufacturerBrand(manufacturerBrand);
entity2 = largeScreenMapper.getTotalElectricity(entity2);
entity2 = largeScreenMapper.getTotalElectricityToday(entity2);
today = entity2 == null ? 0.0 : entity2.getTotalElectricity();
LargeScreenVO entity3 = new LargeScreenVO();

Loading…
Cancel
Save