From 5cb926178a929e34ff4fa3a4c0f4c351f976d1e7 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期一, 29 七月 2024 11:48:20 +0800 Subject: [PATCH] 车辆点位在线接口 --- ycl-server/src/main/java/com/ycl/platform/service/ICheckIndexCarService.java | 3 + ycl-server/src/main/java/com/ycl/platform/mapper/CheckIndexCarMapper.java | 20 ++++++---- ycl-server/src/main/resources/mapper/zgyw/CheckIndexCarMapper.xml | 16 +++++--- ycl-server/src/main/java/com/ycl/platform/service/impl/CheckIndexCarServiceImpl.java | 68 +++++++++++++++++++++++++++------- 4 files changed, 78 insertions(+), 29 deletions(-) diff --git a/ycl-server/src/main/java/com/ycl/platform/mapper/CheckIndexCarMapper.java b/ycl-server/src/main/java/com/ycl/platform/mapper/CheckIndexCarMapper.java index 7e50c1c..fc7401b 100644 --- a/ycl-server/src/main/java/com/ycl/platform/mapper/CheckIndexCarMapper.java +++ b/ycl-server/src/main/java/com/ycl/platform/mapper/CheckIndexCarMapper.java @@ -1,20 +1,21 @@ package com.ycl.platform.mapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ycl.platform.domain.entity.CheckIndexCar; import java.util.List; /** * 杞﹁締鎸囨爣姒傜巼鏁版嵁Mapper鎺ュ彛 - * + * * @author ruoyi * @date 2024-04-29 */ -public interface CheckIndexCarMapper +public interface CheckIndexCarMapper extends BaseMapper<CheckIndexCar> { /** * 鏌ヨ杞﹁締鎸囨爣姒傜巼鏁版嵁 - * + * * @param id 杞﹁締鎸囨爣姒傜巼鏁版嵁涓婚敭 * @return 杞﹁締鎸囨爣姒傜巼鏁版嵁 */ @@ -22,7 +23,7 @@ /** * 鏌ヨ杞﹁締鎸囨爣姒傜巼鏁版嵁鍒楄〃 - * + * * @param checkIndexCar 杞﹁締鎸囨爣姒傜巼鏁版嵁 * @return 杞﹁締鎸囨爣姒傜巼鏁版嵁闆嗗悎 */ @@ -30,7 +31,7 @@ /** * 鏂板杞﹁締鎸囨爣姒傜巼鏁版嵁 - * + * * @param checkIndexCar 杞﹁締鎸囨爣姒傜巼鏁版嵁 * @return 缁撴灉 */ @@ -38,7 +39,7 @@ /** * 淇敼杞﹁締鎸囨爣姒傜巼鏁版嵁 - * + * * @param checkIndexCar 杞﹁締鎸囨爣姒傜巼鏁版嵁 * @return 缁撴灉 */ @@ -46,7 +47,7 @@ /** * 鍒犻櫎杞﹁締鎸囨爣姒傜巼鏁版嵁 - * + * * @param id 杞﹁締鎸囨爣姒傜巼鏁版嵁涓婚敭 * @return 缁撴灉 */ @@ -54,9 +55,12 @@ /** * 鎵归噺鍒犻櫎杞﹁締鎸囨爣姒傜巼鏁版嵁 - * + * * @param ids 闇�瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 * @return 缁撴灉 */ public int deleteCheckIndexCarByIds(Long[] ids); + + public List<CheckIndexCar> selectToday(String today); + } diff --git a/ycl-server/src/main/java/com/ycl/platform/service/ICheckIndexCarService.java b/ycl-server/src/main/java/com/ycl/platform/service/ICheckIndexCarService.java index 2f53b66..f5cb235 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/ICheckIndexCarService.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/ICheckIndexCarService.java @@ -1,5 +1,6 @@ package com.ycl.platform.service; +import com.baomidou.mybatisplus.extension.service.IService; import com.ycl.platform.domain.entity.CheckIndexCar; import com.ycl.platform.domain.result.HK.SnapshotDataMonitorResult; @@ -11,7 +12,7 @@ * @author ruoyi * @date 2024-04-29 */ -public interface ICheckIndexCarService +public interface ICheckIndexCarService extends IService<CheckIndexCar> { /** * 鏌ヨ杞﹁締鎸囨爣姒傜巼鏁版嵁 diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckIndexCarServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckIndexCarServiceImpl.java index 5741332..8fa5174 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckIndexCarServiceImpl.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckIndexCarServiceImpl.java @@ -1,24 +1,29 @@ package com.ycl.platform.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ycl.platform.domain.entity.CalculateReport; import com.ycl.platform.domain.entity.CheckIndexCar; import com.ycl.platform.domain.entity.TMonitor; import com.ycl.platform.domain.result.HK.SnapshotDataMonitorResult; +import com.ycl.platform.mapper.CalculateReportMapper; import com.ycl.platform.mapper.CheckIndexCarMapper; import com.ycl.platform.service.ICheckIndexCarService; import com.ycl.platform.service.ITMonitorService; import com.ycl.system.entity.SysDept; import com.ycl.system.mapper.SysDeptMapper; import constant.ApiConstants; +import constant.CheckConstants; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import utils.DateUtils; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.SimpleDateFormat; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -29,7 +34,8 @@ * @date 2024-04-29 */ @Service -public class CheckIndexCarServiceImpl implements ICheckIndexCarService { +@Slf4j +public class CheckIndexCarServiceImpl extends ServiceImpl<CheckIndexCarMapper, CheckIndexCar> implements ICheckIndexCarService { @Autowired private CheckIndexCarMapper checkIndexCarMapper; @Autowired @@ -103,12 +109,14 @@ public int deleteCheckIndexCarById(Long id) { return checkIndexCarMapper.deleteCheckIndexCarById(id); } - /** * 璁$畻杞﹁締鐐逛綅鍦ㄧ嚎鐜囥�佽鍥惧簱瀵规帴绋冲畾鎬� - * + * 鑾峰彇鍒嗙渷鍘呫�佸尯鍩熺殑map<k,v> k涓篸eptId鎴栬�匬rovince_deptId + * 寰幆map璁$畻鐐逛綅鍦ㄧ嚎鐜� + * 鏇存柊鎴栨柊澧� * @param list */ + //TODO:瑙嗗浘搴撳鎺ョǔ瀹氭�� @Override public void siteOnline(List<SnapshotDataMonitorResult> list) { //璁惧id @@ -130,7 +138,7 @@ deptIds.forEach(deptId -> areaStatsMap.put(deptId + "", new AreaStats())); //杞崲涓簃ap - //TODO锛氬垎鐪佸巺甯傚眬 + //TODO锛氬垎鐪佸巺甯傚眬 闇�瑕佽ˉ鍏呴泦鍚堟暟鎹� List<String> provinceIds = new ArrayList<>(); Map<String, TMonitor> monitorMap = monitors.stream().collect(Collectors.toMap(TMonitor::getSerialNumber, Function.identity())); for (SnapshotDataMonitorResult result : list) { @@ -158,23 +166,55 @@ provinceStats.offlineSites++; } else { //鍖哄煙鎬绘姄鎷嶉噺 - provinceStats.totalSites += result.getDataCount(); + provinceStats.totalDataSum += result.getDataCount(); } //鍖哄煙鐐逛綅鎬绘暟 - provinceStats.totalDataSum++; + provinceStats.totalSites++; areaStatsMap.put("Province_" + monitor.getDeptId(), areaStats); } } areaStatsMap.put(monitor.getDeptId() + "", areaStats); } - + List<CheckIndexCar> checkIndexCarList = checkIndexCarMapper.selectToday(DateUtils.getDate()); + List<CheckIndexCar> checkIndexCars = new ArrayList<>(); areaStatsMap.forEach((k, v) -> { - if (k.startsWith("Province_")) { - + if (v.totalSites == 0) { + log.info("閮ㄩ棬id涓簕}鎬荤偣浣嶆暟涓�0", k); + } else { + CheckIndexCar checkIndexCar = new CheckIndexCar(); + //鎵炬槸鍚﹀凡缁忓瓨鍦ㄦ暟鎹� + Optional<CheckIndexCar> first; + if (k.startsWith("Province_")) { + //鐪佸巺 + String[] idArray = k.split("_"); + first = checkIndexCarList.stream().filter(item -> idArray[1].equals(item.getDeptId() + "") && CheckConstants.Examine_Tag_City.equals(item.getExamineTag())) + .findFirst(); + checkIndexCar.setExamineTag(CheckConstants.Examine_Tag_City); + checkIndexCar.setDeptId(Long.parseLong(idArray[1])); + } else { + //鍖哄幙 + first = checkIndexCarList.stream().filter(item -> k.equals(item.getDeptId() + "") && CheckConstants.Examine_Tag_County.equals(item.getExamineTag())) + .findFirst(); + checkIndexCar.setExamineTag(CheckConstants.Examine_Tag_County); + checkIndexCar.setDeptId(Long.parseLong(k)); + } + checkIndexCar.setCreateTime(new Date()); + if (first.isPresent()) { + checkIndexCar = first.get(); + } + // 灏嗘暣鏁拌浆鎹负BigDecimal + BigDecimal totalSitesBd = new BigDecimal(v.totalSites); + BigDecimal offlineSitesBd = new BigDecimal(v.offlineSites); + // 鎵ц璁$畻锛屼繚鐣欏洓浣嶅皬鏁板苟鍥涜垗浜斿叆 + BigDecimal onlineSitesBd = totalSitesBd.subtract(offlineSitesBd); + BigDecimal siteOnline = onlineSitesBd.divide(totalSitesBd, 4, RoundingMode.HALF_UP); + checkIndexCar.setSiteOnline(siteOnline); + checkIndexCars.add(checkIndexCar); } }); - CheckIndexCar checkIndexCar = new CheckIndexCar(); + saveOrUpdateBatch(checkIndexCars); } } + } diff --git a/ycl-server/src/main/resources/mapper/zgyw/CheckIndexCarMapper.xml b/ycl-server/src/main/resources/mapper/zgyw/CheckIndexCarMapper.xml index 5281b89..3e251b2 100644 --- a/ycl-server/src/main/resources/mapper/zgyw/CheckIndexCarMapper.xml +++ b/ycl-server/src/main/resources/mapper/zgyw/CheckIndexCarMapper.xml @@ -3,7 +3,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.ycl.platform.mapper.CheckIndexCarMapper"> - + <resultMap type="com.ycl.platform.domain.entity.CheckIndexCar" id="CheckIndexCarResult"> <result property="id" column="id" /> <result property="deptId" column="dept_id" /> @@ -28,7 +28,7 @@ <select id="selectCheckIndexCarList" resultMap="CheckIndexCarResult"> select tcic.*,sd.dept_name from t_check_index_car tcic left join sys_dept sd on tcic.dept_id = sd.dept_id - <where> + <where> <if test="deptId != null "> and tcic.dept_id = #{deptId}</if> <if test="examineTag != null "> and examine_tag = #{examineTag}</if> <if test="date != null "> and date_format(tcic.create_time,'%Y-%m') = #{date}</if> @@ -50,12 +50,12 @@ </if> </where> </select> - + <select id="selectCheckIndexCarById" resultMap="CheckIndexCarResult"> <include refid="selectCheckIndexCarVo"/> where id = #{id} </select> - + <insert id="insertCheckIndexCar" useGeneratedKeys="true" keyProperty="id"> insert into t_check_index_car <trim prefix="(" suffix=")" suffixOverrides=","> @@ -115,9 +115,13 @@ </delete> <delete id="deleteCheckIndexCarByIds"> - delete from t_check_index_car where id in + delete from t_check_index_car where id in <foreach item="id" collection="array" open="(" separator="," close=")"> #{id} </foreach> </delete> -</mapper> \ No newline at end of file + + <select id="selectToday"> + select * from t_check_index_car where DATE(create_time) = #{today} + </select> +</mapper> -- Gitblit v1.8.0