From 71d98475af435f71a0d9ed55f03ff66946eef550 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 01 四月 2025 09:13:59 +0800
Subject: [PATCH] 最新版本541200007
---
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformServiceImpl.java | 308 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 298 insertions(+), 10 deletions(-)
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformServiceImpl.java
index 82709a7..45d200c 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformServiceImpl.java
@@ -2,15 +2,18 @@
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
-import com.doumee.core.model.LoginUserInfo;
-import com.doumee.core.model.PageData;
-import com.doumee.core.model.PageWrap;
+import com.doumee.service.business.third.model.LoginUserInfo;
+import com.doumee.service.business.third.model.PageData;
+import com.doumee.service.business.third.model.PageWrap;
import com.doumee.core.utils.Constants;
+import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
-import com.doumee.dao.business.PlatformMapper;
-import com.doumee.dao.business.model.Member;
-import com.doumee.dao.business.model.Platform;
-import com.doumee.dao.business.model.PlatformGroup;
+import com.doumee.dao.business.*;
+import com.doumee.dao.business.join.PlatformJobJoinMapper;
+import com.doumee.dao.business.join.PlatformJoinMapper;
+import com.doumee.dao.business.model.*;
+import com.doumee.dao.openapi.response.PlatformNumByStatusResponse;
+import com.doumee.dao.openapi.response.PlatformStatusListResponse;
import com.doumee.service.business.PlatformService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -20,10 +23,12 @@
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
-import java.util.Date;
-import java.util.List;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* 鏈堝彴淇℃伅琛⊿ervice瀹炵幇
@@ -35,10 +40,70 @@
@Autowired
private PlatformMapper platformMapper;
+ @Autowired
+ private PlatformGroupMapper platformGroupMapper;
+ @Autowired
+ private PlatformJoinMapper platformJoinMapper;
+ @Autowired
+ private PlatformDeviceMapper platformDeviceMapper;
+ @Autowired
+ private DeviceMapper deviceMapper;
+ @Autowired
+ private PlatformJobJoinMapper platformJobJoinMapper;
+
+
@Override
+ @Transactional(rollbackFor = {BusinessException.class,Exception.class})
public Integer create(Platform platform) {
+ platform.setCreateDate(new Date());
+ platform.setIsdeleted(Constants.ZERO);
+ platform.setCreator(platform.getLoginUserInfo().getId());
platformMapper.insert(platform);
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platform.getLedIds())){
+ List<PlatformDevice> platformDeviceList = new ArrayList<>();
+ for (Integer ledId:platform.getLedIds()) {
+ Device device = deviceMapper.selectById(ledId);
+ if(Objects.isNull(device)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏈煡璇㈠埌led璁惧淇℃伅銆�"+ledId+"銆�");
+ }
+ PlatformDevice platformDevice = new PlatformDevice();
+ platformDevice.setIsdeleted(Constants.ZERO);
+ platformDevice.setPlatformId(platform.getId());
+ platformDevice.setCreateDate(new Date());
+ platformDevice.setCreator(platform.getLoginUserInfo().getId());
+ platformDevice.setType(Constants.ZERO);
+ platformDevice.setDeviceId(ledId.toString());
+ platformDevice.setHkId(device.getHkId());
+ platformDevice.setHkNo(device.getNo());
+ platformDevice.setName(device.getName());
+ platformDeviceList.add(platformDevice);
+ }
+ platformDeviceMapper.insert(platformDeviceList);
+ }
+
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platform.getBroadcastIds())){
+ List<PlatformDevice> platformDeviceList = new ArrayList<>();
+ for (Integer broadcastId:platform.getBroadcastIds()) {
+ Device device = deviceMapper.selectById(broadcastId);
+ if(Objects.isNull(device)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏈煡璇㈠埌骞挎挱璁惧淇℃伅銆�"+broadcastId+"銆�");
+ }
+ PlatformDevice platformDevice = new PlatformDevice();
+ platformDevice.setIsdeleted(Constants.ZERO);
+ platformDevice.setPlatformId(platform.getId());
+ platformDevice.setCreateDate(new Date());
+ platformDevice.setCreator(platform.getLoginUserInfo().getId());
+ platformDevice.setType(Constants.TWO);
+ platformDevice.setDeviceId(broadcastId.toString());
+ platformDevice.setHkId(device.getHkId());
+ platformDevice.setHkNo(device.getNo());
+ platformDevice.setName(device.getName());
+ platformDeviceList.add(platformDevice);
+ }
+ platformDeviceMapper.insert(platformDeviceList);
+ }
+
return platform.getId();
}
@@ -62,9 +127,87 @@
}
@Override
+ @Transactional(rollbackFor = {BusinessException.class,Exception.class})
public void updateById(Platform platform) {
+ platform.setEditor(platform.getLoginUserInfo().getId());
+ platform.setEditDate(new Date());
+ Platform model = platformMapper.selectById(platform.getId());
+ if(model ==null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY);
+ }
+ if(model.getGroupId()!= null && platform.getGroupId()!=null && !Constants.equalsInteger(platform.getGroupId(),model.getGroupId())){
+ PlatformGroup group = platformGroupMapper.selectById(platform.getGroupId());
+ if(group ==null || Constants.equalsInteger(group.getIsdeleted(),Constants.ONE)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"瀵逛笉璧凤紝鏈堝彴缁勪俊鎭笉姝g‘锛�");
+ }
+ //濡傛灉鏈堝彴鍒嗙粍鍙戠敓鍙樺寲
+ Long count = platformJobJoinMapper.selectCount( new QueryWrapper<PlatformJob>().lambda()
+ .eq(PlatformJob::getIsdeleted,Constants.ZERO)
+ .notIn(PlatformJob::getStatus,Constants.PlatformJobStatus.WART_SIGN_IN.getKey()
+ ,Constants.PlatformJobStatus.WAIT_CONFIRM.getKey()
+ ,Constants.PlatformJobStatus.DONE.getKey()
+ ,Constants.PlatformJobStatus.LEAVED.getKey()
+ ,Constants.PlatformJobStatus.CANCEL.getKey()
+ ));
+ if(count!=null && count>0){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝褰撳墠鏈堝彴鏈夋鍦ㄤ綔涓氱殑浠诲姟锛屼笉鑳借繘琛屾湀鍙扮粍鍒囨崲鎿嶄綔锛�");
+ }
+ }
+ //鍒犻櫎LED/骞挎挱鏁版嵁
+ platformDeviceMapper.delete(new QueryWrapper<PlatformDevice>().lambda()
+ .eq(PlatformDevice::getPlatformId,platform.getId())
+ .in(PlatformDevice::getType,Constants.ZERO,Constants.TWO)
+ );
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platform.getLedIds())){
+ List<PlatformDevice> platformDeviceList = new ArrayList<>();
+ String ledNames = "";
+ for (Integer ledId:platform.getLedIds()) {
+ Device device = deviceMapper.selectById(ledId);
+ if(Objects.isNull(device)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏈煡璇㈠埌led璁惧淇℃伅銆�"+ledId+"銆�");
+ }
+ PlatformDevice platformDevice = new PlatformDevice();
+ platformDevice.setIsdeleted(Constants.ZERO);
+ platformDevice.setPlatformId(platform.getId());
+ platformDevice.setCreateDate(new Date());
+ platformDevice.setCreator(platform.getLoginUserInfo().getId());
+ platformDevice.setType(Constants.ZERO);
+ platformDevice.setDeviceId(ledId.toString());
+ platformDevice.setHkId(device.getHkId());
+ platformDevice.setHkNo(device.getNo());
+ platformDevice.setName(device.getName());
+ platformDeviceList.add(platformDevice);
+ }
+ platformDeviceMapper.insert(platformDeviceList);
+ platform.setLedNames(ledNames);
+ }
+
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platform.getBroadcastIds())){
+ List<PlatformDevice> platformDeviceList = new ArrayList<>();
+ String ledNames = "";
+ for (Integer broadcastId:platform.getBroadcastIds()) {
+ Device device = deviceMapper.selectById(broadcastId);
+ if(Objects.isNull(device)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏈煡璇㈠埌骞挎挱璁惧淇℃伅銆�"+broadcastId+"銆�");
+ }
+ PlatformDevice platformDevice = new PlatformDevice();
+ platformDevice.setIsdeleted(Constants.ZERO);
+ platformDevice.setPlatformId(platform.getId());
+ platformDevice.setCreateDate(new Date());
+ platformDevice.setCreator(platform.getLoginUserInfo().getId());
+ platformDevice.setType(Constants.TWO);
+ platformDevice.setDeviceId(broadcastId.toString());
+ platformDevice.setHkId(device.getHkId());
+ platformDevice.setHkNo(device.getNo());
+ platformDevice.setName(device.getName());
+ platformDeviceList.add(platformDevice);
+ }
+ platformDeviceMapper.insert(platformDeviceList);
+ }
+
platformMapper.updateById(platform);
}
+
@Override
public void updateStatusById(Platform platform) {
Platform model =platformMapper.selectById(platform.getId());
@@ -154,7 +297,91 @@
queryWrapper.orderByAsc(sortData.getProperty());
}
}
- return PageData.from(platformMapper.selectJoinPage(page,Platform.class, queryWrapper));
+ PageData<Platform> platformPageData = PageData.from(platformMapper.selectJoinPage(page,Platform.class, queryWrapper));
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformPageData.getRecords())){
+ for (Platform platform:platformPageData.getRecords()) {
+ List<PlatformDevice> ledDevice = platformDeviceMapper.selectList(new QueryWrapper<PlatformDevice>().lambda()
+ .eq(PlatformDevice::getPlatformId,platform.getId())
+ .eq(PlatformDevice::getType,Constants.ZERO)
+ );
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ledDevice)){
+ platform.setLedNames(String.join(",", ledDevice.stream().map(m->m.getName()).collect(Collectors.toList())));
+ platform.setLedIds(
+ ledDevice.stream().map(m->Integer.valueOf(m.getDeviceId())).collect(Collectors.toList())
+ );
+ }
+
+ List<PlatformDevice> broadcastDevice = platformDeviceMapper.selectList(new QueryWrapper<PlatformDevice>().lambda()
+ .eq(PlatformDevice::getPlatformId,platform.getId())
+ .eq(PlatformDevice::getType,Constants.TWO)
+ );
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(broadcastDevice)){
+ platform.setBroadcastNames(String.join(",", broadcastDevice.stream().map(m->m.getName()).collect(Collectors.toList())));
+ platform.setBroadcastIds(
+ broadcastDevice.stream().map(m->Integer.valueOf(m.getDeviceId())).collect(Collectors.toList())
+ );
+ }
+ }
+ }
+ return platformPageData;
+ }
+
+ @Override
+ public List<Platform> platformWorkReportList(Platform platform) {
+ if(Objects.isNull(platform)
+ || Objects.isNull(platform.getQueryDateStart())
+ || Objects.isNull(platform.getQueryDateEnd())){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍙傛暟閿欒");
+ }
+ MPJLambdaWrapper<Platform> queryWrapper = new MPJLambdaWrapper<>();
+ queryWrapper.selectAll(Platform.class)
+ .selectAs(PlatformGroup::getName,Platform::getGroupName)
+ .select(" (select ifnull(TIMESTAMPDIFF(HOUR, '2023-01-01 '||pg.start_time||':00', '2023-01-01 '||pg.end_time||':00' ),0) from platform_group pg " +
+ " where t.group_id = pg.id ) as openTime ")
+ .select(" ( select ROUND( ifnull(SUM(pl.PARAM3),0) / 3600 , 2 ) from platform_log pl where pl.remark = t.id " +
+ " and pl.CREATE_DATE > '"+DateUtil.getFomartDate(platform.getQueryDateStart(),"yyyy-MM-dd")+" 00:00:00' " +
+ "and pl.CREATE_DATE <= '"+DateUtil.getFomartDate(platform.getQueryDateEnd(),"yyyy-MM-dd")+" 23:59:59' ) as workCountTime ")
+ .select(" ( select count(1) from platform_log pl where pl.remark = t.id " +
+ " and pl.CREATE_DATE > '"+DateUtil.getFomartDate(platform.getQueryDateStart(),"yyyy-MM-dd")+" 00:00:00' " +
+ "and pl.CREATE_DATE <= '"+DateUtil.getFomartDate(platform.getQueryDateEnd(),"yyyy-MM-dd")+" 23:59:59' and pl.OBJ_TYPE = 5 ) as stopCount ")
+ .leftJoin(PlatformGroup.class,PlatformGroup::getId,Platform::getGroupId);
+ queryWrapper
+ .eq(platform.getGroupId() != null, Platform::getGroupId, platform.getGroupId())
+ .eq( Platform::getIsdeleted, Constants.ZERO)
+ .like(platform.getName() != null, Platform::getName, platform.getName())
+ .orderByDesc(Platform::getId);
+ List<Platform> platformList = platformJoinMapper.selectList(queryWrapper);
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformList)){
+ //鏌ヨ鎵�鏈夋湀鍙版暟鎹笅鐨� 浠诲姟鏁版嵁 浠诲姟鏁版嵁涓�
+ List<PlatformJob> platformJobList = platformJobJoinMapper.selectJoinList(PlatformJob.class,
+ new MPJLambdaWrapper<PlatformJob>()
+ .selectAll(PlatformJob.class)
+ .in(PlatformJob::getStatus,Constants.PlatformJobStatus.WORKING.getKey(),
+ Constants.PlatformJobStatus.DONE.getKey(),
+ Constants.PlatformJobStatus.TRANSFERING.getKey(),
+ Constants.PlatformJobStatus.EXCEPTION.getKey(),
+ Constants.PlatformJobStatus.AUTHED_LEAVE.getKey(),
+ Constants.PlatformJobStatus.LEAVED.getKey()
+ )
+ .in(PlatformJob::getPlatformId,platformList.stream().map(i->i.getId()).collect(Collectors.toList()))
+ .ge(platform.getQueryDateStart() != null, PlatformJob::getStartDate, Utils.Date.getStart(platform.getQueryDateStart()))
+ .le(platform.getQueryDateEnd() != null, PlatformJob::getStartDate, Utils.Date.getEnd(platform.getQueryDateEnd()))
+ );
+ //鏌ヨ2鏃ユ湡鐩稿樊澶╂暟
+ Integer sumDays = DateUtil.daysBetweenDates(platform.getQueryDateEnd(),platform.getQueryDateStart())+1;
+ for (Platform bean:platformList) {
+ if(Objects.isNull(bean.getOpenTime())||bean.getOpenTime().compareTo(BigDecimal.ZERO)<=0){
+ bean.setUseRata(BigDecimal.ZERO);
+ continue;
+ }
+ BigDecimal sumTime = BigDecimal.valueOf(sumDays).multiply(bean.getOpenTime());
+ bean.setUseRata(
+ bean.getWorkCountTime().multiply(new BigDecimal(100)).divide(sumTime,BigDecimal.ROUND_HALF_DOWN,2)
+ );
+ bean.setUseRata(Constants.formatBigdecimal2Float(bean.getUseRata()));//寮哄埗淇濈暀涓や綅灏忔暟
+ }
+ }
+ return platformList;
}
@Override
@@ -162,4 +389,65 @@
QueryWrapper<Platform> wrapper = new QueryWrapper<>(platform);
return platformMapper.selectCount(wrapper);
}
+
+
+ @Override
+ public PlatformNumByStatusResponse getPlatformNumByStatusResponse(){
+ PlatformNumByStatusResponse platformNumByStatusResponse = new PlatformNumByStatusResponse();
+ List<Platform> platformList = platformJoinMapper.selectJoinList(Platform.class,new MPJLambdaWrapper<Platform>()
+ .selectAll(Platform.class)
+ .select(" ( select count(1) from platform_job pj where t.id = pj.PLATFORM_ID and pj.STATUS = "+Constants.PlatformJobStatus.WORKING.getKey()+" ) as workStatus ")
+ .eq(Platform::getIsdeleted,Constants.ZERO)
+ );
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformList)){
+ //鍋滅敤鏁伴噺
+ platformNumByStatusResponse.setForbiddenNum(
+ platformList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ONE)).collect(Collectors.toList()).size()
+ );
+ //宸ヤ綔鏁伴噺
+ platformNumByStatusResponse.setUsingNum(
+ platformList.stream().filter(i->i.getWorkStatus()>Constants.ZERO).collect(Collectors.toList()).size()
+ );
+ //绌洪棽鏁伴噺
+ platformNumByStatusResponse.setIdleNum(
+ platformList.stream().filter(i->i.getWorkStatus()<=Constants.ZERO).collect(Collectors.toList()).size()
+ );
+ }
+ return platformNumByStatusResponse;
+ }
+
+
+
+ @Override
+ public List<PlatformStatusListResponse> getPlatformStatusList(){
+ List<Platform> platformList = platformJoinMapper.selectJoinList(Platform.class,new MPJLambdaWrapper<Platform>()
+ .selectAll(Platform.class)
+ .select(" ( select count(1) from platform_job pj where t.id = pj.PLATFORM_ID and pj.STATUS = "+Constants.PlatformJobStatus.WORKING.getKey()+" ) as workStatus ")
+ .select(" ( select pj.CAR_CODE_FRONT from platform_job pj where t.id = pj.PLATFORM_ID and pj.STATUS = "+Constants.PlatformJobStatus.WORKING.getKey()+" limit 1 ) as workCarCode ")
+ .eq(Platform::getIsdeleted,Constants.ZERO)
+ );
+ List<PlatformStatusListResponse> platformStatusListResponses = new ArrayList<>();
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformList)){
+ for (Platform platform:platformList) {
+ PlatformStatusListResponse response = new PlatformStatusListResponse();
+ response.setPlatformHkId(platform.getHkId());
+ response.setPlatformName(platform.getName());
+ response.setStatus(platform.getPlatformStatus());
+ if(Constants.equalsInteger(platform.getPlatformStatus(),Constants.ONE)){
+ response.setCarCode(platform.getWorkCarCode());
+ }
+ platformStatusListResponses.add(response);
+ }
+ }
+ return platformStatusListResponses;
+ }
+
+
+
+
+
+
+
+
+
}
--
Gitblit v1.9.3