diff --git a/equip/src/main/java/com/foreverwin/mesnac/equip/consumer/ResourceMQConsume.java b/equip/src/main/java/com/foreverwin/mesnac/equip/consumer/ResourceMQConsume.java index 81f79d18..65a049c2 100644 --- a/equip/src/main/java/com/foreverwin/mesnac/equip/consumer/ResourceMQConsume.java +++ b/equip/src/main/java/com/foreverwin/mesnac/equip/consumer/ResourceMQConsume.java @@ -54,4 +54,10 @@ public class ResourceMQConsume { logger.info("接收设备参数数据:" + text); resourceMQProcess.resourceParamProcess(text); } + + @JmsListener(destination = "resource.runtime.process", containerFactory = "defaultFactory", concurrency = "5") + public void resourceRunTimeProcess(String text) { + logger.info("接收设备每日运行时长:" + text); + resourceMQProcess.resourceRunTimeProcess(text); + } } diff --git a/equip/src/main/java/com/foreverwin/mesnac/equip/consumer/ResourceMQProcess.java b/equip/src/main/java/com/foreverwin/mesnac/equip/consumer/ResourceMQProcess.java index b1f1d4ae..3db489ac 100644 --- a/equip/src/main/java/com/foreverwin/mesnac/equip/consumer/ResourceMQProcess.java +++ b/equip/src/main/java/com/foreverwin/mesnac/equip/consumer/ResourceMQProcess.java @@ -3,6 +3,7 @@ package com.foreverwin.mesnac.equip.consumer; import com.foreverwin.mesnac.equip.service.EdcDataResourceService; import com.foreverwin.mesnac.equip.service.ResourceFaultReceiveService; +import com.foreverwin.mesnac.equip.service.ResourceRunTimeService; import com.foreverwin.mesnac.equip.service.ResourceStatusReceiveService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,6 +32,9 @@ public class ResourceMQProcess { @Autowired private EdcDataResourceService edcDataResourceService; + @Autowired + private ResourceRunTimeService resourceRunTimeService; + /** * 设备状态变更 * @@ -73,4 +77,18 @@ public class ResourceMQProcess { } } + /** + * 设备每日运行时长数据接收 + * @param text + * @return + */ + public void resourceRunTimeProcess(String text){ + try { + resourceRunTimeService.saveResourceRunTimeByMq(text); + logger.info("设备运行时长数据记录成功"); + } catch (Exception e) { + logger.error("设备运行时长数据记录失败:"+e.getMessage()); + } + } + } diff --git a/equip/src/main/java/com/foreverwin/mesnac/equip/controller/ResourceRunTimeController.java b/equip/src/main/java/com/foreverwin/mesnac/equip/controller/ResourceRunTimeController.java new file mode 100644 index 00000000..07e4b424 --- /dev/null +++ b/equip/src/main/java/com/foreverwin/mesnac/equip/controller/ResourceRunTimeController.java @@ -0,0 +1,122 @@ +package com.foreverwin.mesnac.equip.controller; + +import com.foreverwin.modular.core.util.R; +import com.foreverwin.modular.core.util.FrontPage; +import com.foreverwin.modular.core.util.CommonMethods; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import com.foreverwin.mesnac.equip.service.ResourceRunTimeService; +import com.foreverwin.mesnac.equip.model.ResourceRunTime; +import java.util.List; + +/** + * + * @author pavel.liu + * @since 2021-09-27 + */ +@RestController +@RequestMapping("/Z-RESOURCE-RUN-TIME") +public class ResourceRunTimeController { + + @Autowired + public ResourceRunTimeService resourceRunTimeService; + + /** + * 根据id查询 + * + * @param id 主键 + * @return + */ + @ResponseBody + @GetMapping("/{id:.+}") + public R getResourceRunTimeById(@PathVariable String id) { + return R.ok( resourceRunTimeService.getById(id)); + } + + /** + * 查询所有数据 + * + * @return + */ + @ResponseBody + @GetMapping("") + public R getResourceRunTimeList(ResourceRunTime resourceRunTime){ + List result; + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.setEntity(resourceRunTime); + result = resourceRunTimeService.list(queryWrapper); + return R.ok(result); + } + + /** + * 分页查询数据 + * + * @param frontPage 分页信息 + * @return + */ + @ResponseBody + @GetMapping("/page") + public R page(FrontPage frontPage, ResourceRunTime resourceRunTime){ + IPage result; + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.setEntity(resourceRunTime); + if (frontPage.getGlobalQuery() != null && !"".equals(frontPage.getGlobalQuery().trim())) { + //TODO modify global query + queryWrapper.lambda().and(wrapper -> wrapper + .like(ResourceRunTime::getHandle, frontPage.getGlobalQuery()) + .or().like(ResourceRunTime::getSite, frontPage.getGlobalQuery()) + .or().like(ResourceRunTime::getResrce, frontPage.getGlobalQuery()) + .or().like(ResourceRunTime::getCreatedUser, frontPage.getGlobalQuery()) + .or().like(ResourceRunTime::getModifiedUser, frontPage.getGlobalQuery()) + ); + } + result = resourceRunTimeService.page(frontPage.getPagePlus(), queryWrapper); + return R.ok(result); + } + + /** + * 新增 + * @param resourceRunTime 传递的实体 + * @return null 失败 实体成功 + */ + @PostMapping + public R save(@RequestBody ResourceRunTime resourceRunTime) { + return R.ok(resourceRunTimeService.save(resourceRunTime)); + } + + /** + * 修改 + * @param resourceRunTime 传递的实体 + * @return null 失败 实体成功 + */ + @PutMapping + public R updateById(@RequestBody ResourceRunTime resourceRunTime) { + return R.ok(resourceRunTimeService.updateById(resourceRunTime)); + } + + /** + * 根据id删除对象 + * @param id 实体ID + * @return 0 失败 1 成功 + */ + @ResponseBody + @RequestMapping(method = RequestMethod.DELETE, value = "/{id:.+}") + public R removeById(@PathVariable("id") String id){ + return R.ok(resourceRunTimeService.removeById(id)); + } + + /** + * 批量删除对象 + * @param ids 实体集合ID + * @return 0 失败 1 成功 + */ + @ResponseBody + @RequestMapping(method = RequestMethod.POST, value = "/delete-batch") + public R removeByIds(List ids){ + return R.ok(resourceRunTimeService.removeByIds(ids)); + } +} \ No newline at end of file diff --git a/equip/src/main/java/com/foreverwin/mesnac/equip/mapper/ResourceRunTimeMapper.java b/equip/src/main/java/com/foreverwin/mesnac/equip/mapper/ResourceRunTimeMapper.java new file mode 100644 index 00000000..430484df --- /dev/null +++ b/equip/src/main/java/com/foreverwin/mesnac/equip/mapper/ResourceRunTimeMapper.java @@ -0,0 +1,18 @@ +package com.foreverwin.mesnac.equip.mapper; + +import com.foreverwin.mesnac.equip.model.ResourceRunTime; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springframework.stereotype.Repository; + +/** + *

+ * Mapper 接口 + *

+ * + * @author pavel.liu + * @since 2021-09-27 + */ +@Repository +public interface ResourceRunTimeMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/equip/src/main/java/com/foreverwin/mesnac/equip/model/ResourceRunTime.java b/equip/src/main/java/com/foreverwin/mesnac/equip/model/ResourceRunTime.java new file mode 100644 index 00000000..4beeb7dd --- /dev/null +++ b/equip/src/main/java/com/foreverwin/mesnac/equip/model/ResourceRunTime.java @@ -0,0 +1,158 @@ +package com.foreverwin.mesnac.equip.model; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.TableField; +import java.io.Serializable; +import com.baomidou.mybatisplus.annotation.IdType; + +/** + *

+ * + *

+ * + * @author pavel.liu + * @since 2021-09-27 + */ + +@TableName("Z_RESOURCE_RUN_TIME") + +public class ResourceRunTime extends Model { + + private static final long serialVersionUID = 1L; + + @TableId(value = "HANDLE", type = IdType.INPUT) + private String handle; + @TableField("SITE") + private String site; + @TableField("SEND_DATE") + private LocalDateTime sendDate; + @TableField("RESRCE") + private String resrce; + @TableField("RUN_TIME") + private Double runTime; + @TableField("CREATED_USER") + private String createdUser; + @TableField("CREATED_DATA_TIME") + private LocalDateTime createdDataTime; + @TableField("MODIFIED_USER") + private String modifiedUser; + @TableField("MODIFIED_DATE_TIME") + private LocalDateTime modifiedDateTime; + + + public String getHandle() { + return handle; + } + + public void setHandle(String handle) { + this.handle = handle; + } + + public String getSite() { + return site; + } + + public void setSite(String site) { + this.site = site; + } + + public LocalDateTime getSendDate() { + return sendDate; + } + + public void setSendDate(LocalDateTime sendDate) { + this.sendDate = sendDate; + } + + public String getResrce() { + return resrce; + } + + public void setResrce(String resrce) { + this.resrce = resrce; + } + + public Double getRunTime() { + return runTime; + } + + public void setRunTime(Double runTime) { + this.runTime = runTime; + } + + public String getCreatedUser() { + return createdUser; + } + + public void setCreatedUser(String createdUser) { + this.createdUser = createdUser; + } + + public LocalDateTime getCreatedDataTime() { + return createdDataTime; + } + + public void setCreatedDataTime(LocalDateTime createdDataTime) { + this.createdDataTime = createdDataTime; + } + + public String getModifiedUser() { + return modifiedUser; + } + + public void setModifiedUser(String modifiedUser) { + this.modifiedUser = modifiedUser; + } + + public LocalDateTime getModifiedDateTime() { + return modifiedDateTime; + } + + public void setModifiedDateTime(LocalDateTime modifiedDateTime) { + this.modifiedDateTime = modifiedDateTime; + } + +public static final String HANDLE = "HANDLE"; + +public static final String SITE = "SITE"; + +public static final String SEND_DATE = "SEND_DATE"; + +public static final String RESRCE = "RESRCE"; + +public static final String RUN_TIME = "RUN_TIME"; + +public static final String CREATED_USER = "CREATED_USER"; + +public static final String CREATED_DATA_TIME = "CREATED_DATA_TIME"; + +public static final String MODIFIED_USER = "MODIFIED_USER"; + +public static final String MODIFIED_DATE_TIME = "MODIFIED_DATE_TIME"; + + + @Override + protected Serializable pkVal() { + return this.handle; + } + + @Override + public String toString() { + return "ResourceRunTime{" + + "handle = " + handle + + ", site = " + site + + ", sendDate = " + sendDate + + ", resrce = " + resrce + + ", runTime = " + runTime + + ", createdUser = " + createdUser + + ", createdDataTime = " + createdDataTime + + ", modifiedUser = " + modifiedUser + + ", modifiedDateTime = " + modifiedDateTime + + "}"; + } +} \ No newline at end of file diff --git a/equip/src/main/java/com/foreverwin/mesnac/equip/service/ResourceRunTimeService.java b/equip/src/main/java/com/foreverwin/mesnac/equip/service/ResourceRunTimeService.java new file mode 100644 index 00000000..b2aec37c --- /dev/null +++ b/equip/src/main/java/com/foreverwin/mesnac/equip/service/ResourceRunTimeService.java @@ -0,0 +1,30 @@ +package com.foreverwin.mesnac.equip.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.foreverwin.mesnac.equip.model.ResourceRunTime; +import com.baomidou.mybatisplus.extension.service.IService; +import com.foreverwin.modular.core.util.FrontPage; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author pavel.liu + * @since 2021-09-27 + */ +public interface ResourceRunTimeService extends IService { + + /** + * 分页查询 + * @param frontPage + * @return + */ + IPage selectPage(FrontPage frontPage, ResourceRunTime resourceRunTime); + + List selectList(ResourceRunTime resourceRunTime); + + void saveResourceRunTimeByMq(String text); +} \ No newline at end of file diff --git a/equip/src/main/java/com/foreverwin/mesnac/equip/service/impl/ResourceRunTimeServiceImpl.java b/equip/src/main/java/com/foreverwin/mesnac/equip/service/impl/ResourceRunTimeServiceImpl.java new file mode 100644 index 00000000..92385681 --- /dev/null +++ b/equip/src/main/java/com/foreverwin/mesnac/equip/service/impl/ResourceRunTimeServiceImpl.java @@ -0,0 +1,97 @@ +package com.foreverwin.mesnac.equip.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.foreverwin.mesnac.common.util.StringUtil; +import com.foreverwin.modular.core.exception.BusinessException; +import com.foreverwin.modular.core.util.CommonMethods; +import com.foreverwin.modular.core.util.FrontPage; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.foreverwin.mesnac.equip.model.ResourceRunTime; +import com.foreverwin.mesnac.equip.mapper.ResourceRunTimeMapper; +import com.foreverwin.mesnac.equip.service.ResourceRunTimeService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + *

+ * 服务实现类 + *

+ * + * @author pavel.liu + * @since 2021-09-27 + */ +@Service +@Transactional(rollbackFor = Exception.class) +public class ResourceRunTimeServiceImpl extends ServiceImpl implements ResourceRunTimeService { + + @Autowired + private ResourceRunTimeService resourceRunTimeService; + + @Override + public IPage selectPage(FrontPage frontPage, ResourceRunTime resourceRunTime) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.setEntity(resourceRunTime); + return super.page(frontPage.getPagePlus(), queryWrapper); + } + + @Override + public List selectList(ResourceRunTime resourceRunTime) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.setEntity(resourceRunTime); + return super.list(queryWrapper); + } + + @Override + public void saveResourceRunTimeByMq(String text) { + String user = CommonMethods.getUser(); + JSONObject jsonObject = JSONObject.parseObject(text); + String site = jsonObject.getString("SITE"); + // 数据传输时间 + String sendTime = jsonObject.getString("SEND_TIME"); + DateTimeFormatter dataFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime dateTime = LocalDateTime.parse(sendTime,dataFormatter); + // 设备运行时间的日期 + DateTimeFormatter dataFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String sendDate = jsonObject.getString("SENE_DATE"); + LocalDateTime dateDay = LocalDateTime.parse(sendDate + " 08:00:00",dataFormatter2); + + if (StringUtil.isBlank(site)) { + throw BusinessException.build("站点不能为空!"); + } + + String resourceList = jsonObject.getString("RESOURCE_LIST"); + JSONArray jsonArray = JSON.parseArray(resourceList); + List list = new ArrayList<>(); + for (int i = 0; i < jsonArray.size(); i++) { + ResourceRunTime resourceRunTime = new ResourceRunTime(); + // 设备编号、站点、创建时间-使用SEND_TIME、创建用户 + resourceRunTime.setSite(site); + resourceRunTime.setCreatedDataTime(dateTime); + resourceRunTime.setCreatedUser(user); + resourceRunTime.setSendDate(dateDay); + + JSONObject jsonObj = (JSONObject) jsonArray.get(i); + String runTime = jsonObj.getString("RUN_TIME"); + String resource = jsonObj.getString("RESOURCE"); + resourceRunTime.setRunTime(Double.valueOf(runTime)); + resourceRunTime.setResrce(resource); + resourceRunTime.setHandle(UUID.randomUUID().toString()); + list.add(resourceRunTime); + } + resourceRunTimeService.saveBatch(list); + + } + + +} \ No newline at end of file diff --git a/equip/src/main/resources/mapper/ResourceRunTimeMapper.xml b/equip/src/main/resources/mapper/ResourceRunTimeMapper.xml new file mode 100644 index 00000000..37842960 --- /dev/null +++ b/equip/src/main/resources/mapper/ResourceRunTimeMapper.xml @@ -0,0 +1,386 @@ + + + + + + + + + + + + + + + + + + + + HANDLE, SITE, SEND_DATE, RESRCE, RUN_TIME, CREATED_USER, CREATED_DATA_TIME, MODIFIED_USER, MODIFIED_DATE_TIME + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO Z_RESOURCE_RUN_TIME + + HANDLE, + SITE, + SEND_DATE, + RESRCE, + RUN_TIME, + CREATED_USER, + CREATED_DATA_TIME, + MODIFIED_USER, + MODIFIED_DATE_TIME, + VALUES + + #{handle}, + #{site}, + #{sendDate}, + #{resrce}, + #{runTime}, + #{createdUser}, + #{createdDataTime}, + #{modifiedUser}, + #{modifiedDateTime}, + + + + + INSERT INTO Z_RESOURCE_RUN_TIME + + + VALUES + + #{handle}, + #{site}, + #{sendDate}, + #{resrce}, + #{runTime}, + #{createdUser}, + #{createdDataTime}, + #{modifiedUser}, + #{modifiedDateTime}, + + + + + + UPDATE Z_RESOURCE_RUN_TIME + SITE=#{et.site}, + SEND_DATE=#{et.sendDate}, + RESRCE=#{et.resrce}, + RUN_TIME=#{et.runTime}, + CREATED_USER=#{et.createdUser}, + CREATED_DATA_TIME=#{et.createdDataTime}, + MODIFIED_USER=#{et.modifiedUser}, + MODIFIED_DATE_TIME=#{et.modifiedDateTime}, + WHERE HANDLE=#{et.handle} and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL} + + + + + UPDATE Z_RESOURCE_RUN_TIME + SITE=#{et.site}, + SEND_DATE=#{et.sendDate}, + RESRCE=#{et.resrce}, + RUN_TIME=#{et.runTime}, + CREATED_USER=#{et.createdUser}, + CREATED_DATA_TIME=#{et.createdDataTime}, + MODIFIED_USER=#{et.modifiedUser}, + MODIFIED_DATE_TIME=#{et.modifiedDateTime}, + WHERE HANDLE=#{et.handle} and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL} + + + + + UPDATE Z_RESOURCE_RUN_TIME + SITE=#{et.site}, + SEND_DATE=#{et.sendDate}, + RESRCE=#{et.resrce}, + RUN_TIME=#{et.runTime}, + CREATED_USER=#{et.createdUser}, + CREATED_DATA_TIME=#{et.createdDataTime}, + MODIFIED_USER=#{et.modifiedUser}, + MODIFIED_DATE_TIME=#{et.modifiedDateTime}, + + + + + HANDLE=#{ew.entity.handle} + AND SITE=#{ew.entity.site} + AND SEND_DATE=#{ew.entity.sendDate} + AND RESRCE=#{ew.entity.resrce} + AND RUN_TIME=#{ew.entity.runTime} + AND CREATED_USER=#{ew.entity.createdUser} + AND CREATED_DATA_TIME=#{ew.entity.createdDataTime} + AND MODIFIED_USER=#{ew.entity.modifiedUser} + AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime} + + + ${ew.sqlSegment} + + + + + ${ew.sqlSegment} + + + + + DELETE FROM Z_RESOURCE_RUN_TIME WHERE HANDLE=#{handle} + + + + DELETE FROM Z_RESOURCE_RUN_TIME + + + + + ${k} = #{cm[${k}]} + + + + + + + + DELETE FROM Z_RESOURCE_RUN_TIME + + + + + HANDLE=#{ew.entity.handle} + + AND SITE=#{ew.entity.site} + AND SEND_DATE=#{ew.entity.sendDate} + AND RESRCE=#{ew.entity.resrce} + AND RUN_TIME=#{ew.entity.runTime} + AND CREATED_USER=#{ew.entity.createdUser} + AND CREATED_DATA_TIME=#{ew.entity.createdDataTime} + AND MODIFIED_USER=#{ew.entity.modifiedUser} + AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime} + + + ${ew.sqlSegment} + + + + + ${ew.sqlSegment} + + + + + DELETE FROM Z_RESOURCE_RUN_TIME WHERE HANDLE IN ( + #{item} + ) + + + +