Commit e0cd5f82 by 杨林龙

开发1.14.0版本需求

1 parent de37699e
package cn.com.glsx.app.modules.controller;
import cn.com.glsx.app.modules.model.param.VehicleDeviceSearch;
import cn.com.glsx.app.modules.model.view.VehicleDeviceDTO;
import cn.com.glsx.app.modules.model.view.VehicleSharedDTO;
import cn.com.glsx.app.modules.service.MenuService;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.common.annotation.SysLog;
import com.glsx.plat.common.enums.OperateType;
import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 获取web短牵线菜单 controller
*
* @author Yanglinlong
* @date 2022/12/1 14:56
*/
@Slf4j
@RestController
@RequestMapping(value = "/menu")
@Api(value = "权限菜单管理", tags = {"权限菜单管理"})
public class MenuController {
private final static String MODULE = "权限菜单管理";
@Autowired
private MenuService menuService;
@ApiOperation(value = "车辆列表")
@SysLog(module = MODULE, value = "查询权限菜单", action = OperateType.QUERY)
@GetMapping("/getPermissionMenuByTag")
public R<Boolean> getPermissionMenuByTag(@RequestParam String permissionTag) {
Boolean flag = menuService.getPermissionMenuByTag(permissionTag);
return R.ok().data(flag);
}
}
package cn.com.glsx.app.modules.entity; import com.glsx.plat.mybatis.base.BaseEntity;import lombok.Data;import lombok.experimental.Accessors; import javax.persistence.Column;import javax.persistence.Table; /** * 假性离线车架号数据 * * @author yangll */@Data@Accessors(chain = true)@Table(name = "t_fake_offline_vin")public class FakeOfflineVin extends BaseEntity { /** * 车架号 */ private String vin; /** * 围栏类型: 1.家庭所在地围栏 2.工作所在地围栏 */ @Column(name = "merchant_type") private Integer merchantType; /** * 预测家庭地址 */ @Column(name = "home_addr") private String homeAddr; /** * 预测工作地址 */ @Column(name = "work_addr") private String workAddr; }
\ No newline at end of file
package cn.com.glsx.app.modules.mapper;
import cn.com.glsx.app.modules.entity.FakeOfflineVin;
import com.glsx.plat.common.annotation.DataPerm;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
/**
* mapper
*
* @author yangll
*/
@Mapper
public interface FakeOfflineVinMapper extends CommonBaseMapper<FakeOfflineVin> {
/**
* 通过离线设备绑定关系集合获取假性离线设备号集合
*
* @return 假性离线设备号集合
*/
List<String> getFakeOfflineSnList(@Param("allOfflineDevices") Collection<Long> allOfflineDevices);
}
\ No newline at end of file
......@@ -77,5 +77,5 @@ public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> {
*/
@DataPerm(permTable = "tv", showSql = true)
@DataPermShare(linkTable = "t_vehicle", showSql = true)
List<Integer> countOfflineDeviceWithAuth(@Param("search") StatSearch search);
List<Long> countOfflineDeviceWithAuth(@Param("search") StatSearch search);
}
\ No newline at end of file
package cn.com.glsx.app.modules.model.view;
import lombok.Data;
/**
* 在线率dto
*
* @author Yanglinlong
* @date 2022/12/1 15:09
*/
@Data
public class OnlineRateDTO {
/**
* 在线率
*/
private String onlineRate;
/**
* 假性离线率
*/
private String fakeOfflineRate;
}
......@@ -65,4 +65,10 @@ public class StatisticalInfoVO implements Serializable {
*/
@ApiModelProperty("在线率")
private String onlineRate;
/**
* 在线率
*/
@ApiModelProperty("假性离线率")
private String fakeOfflineRate;
}
......@@ -24,6 +24,7 @@ import com.github.pagehelper.PageInfo;
import com.glsx.plat.context.utils.PropertiesUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.time.DateUtils;
......@@ -70,6 +71,9 @@ public class DashboardService extends AbstractCommonService {
@Autowired
private RemoteAlarmService remoteAlarmService;
@Autowired
private FakeOfflineVinMapper fakeOfflineVinMapper;
public List<DeviceActiveVO> getActiveDeviceWeekReport(DeviceActiveSearch search) {
List<StatActivatedVehicleDevice> activeDeviceList = vehicleDeviceMapper.getActiveDeviceInfo(search);
Map<String, List<StatActivatedVehicleDevice>> groupByActiveTimeMap = activeDeviceList.stream().collect(Collectors.groupingBy(StatActivatedVehicleDevice::getActiveTime));
......@@ -233,7 +237,7 @@ public class DashboardService extends AbstractCommonService {
log.info("{} 耗时:{} ms", "看板统计信息 - 今日围栏报警查询", stopWatch.getLastTaskTimeMillis());
//在线率
String onlineRate = getOnLineRate(totalActiveDevice);
OnlineRateDTO onlineRateDTO = getOnLineRate(totalActiveDevice);
int powerOffCount;
int lightCount;
try {
......@@ -244,7 +248,7 @@ public class DashboardService extends AbstractCommonService {
}
long t2 = System.currentTimeMillis();
log.info("{} 总耗时:{} ms", "看板统计信息", t2 - t1);
return new StatisticalInfoVO(totalActiveDevice, totalVehicle, todayActiveDevice, powerOffCount, fenceCount, lightCount, onlineRate);
return new StatisticalInfoVO(totalActiveDevice, totalVehicle, todayActiveDevice, powerOffCount, fenceCount, lightCount, onlineRateDTO.getOnlineRate(), onlineRateDTO.getFakeOfflineRate());
}
/**
......@@ -284,7 +288,8 @@ public class DashboardService extends AbstractCommonService {
/**
* 在线率
*/
public String getOnLineRate(Integer totalActiveDevice) {
public OnlineRateDTO getOnLineRate(Integer totalActiveDevice) {
OnlineRateDTO onlineRateDTO = new OnlineRateDTO();
StopWatch stopWatch = new StopWatch();
stopWatch.start();
//获取不计算离线的设备列表(并同时将该设备计算为在线设备数量) by 杨林龙
......@@ -293,16 +298,23 @@ public class DashboardService extends AbstractCommonService {
injectSettled(offlineSearch);
offlineSearch.setOfflineTime(Constants.OFFLINE_TIME_OTHER);
offlineSearch.setOfflineSnStr(offlineSnWhitelist);
List<Integer> allOfflineList = vehicleDeviceMapper.countOfflineDeviceWithAuth(offlineSearch);
int allOfflineNumber = allOfflineList.stream().reduce(0, Integer::sum);
List<Long> allOfflineList = vehicleDeviceMapper.countOfflineDeviceWithAuth(offlineSearch);
int allOfflineNumber = allOfflineList.size();
int onlineNumber = Math.abs(totalActiveDevice - allOfflineNumber);
// 获取假性离线设备号集合
Set<String> fakeOfflineSnSet = Sets.newHashSet();
fakeOfflineSnSet.addAll(fakeOfflineVinMapper.getFakeOfflineSnList(allOfflineList));
//计算在线率
NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(2);
String result = numberFormat.format((float) onlineNumber / (float) totalActiveDevice * 100);
String onlineRate = numberFormat.format((float) onlineNumber / (float) totalActiveDevice * 100);
// 计算假性离线率
String fakeOfflineRate = numberFormat.format((float) fakeOfflineSnSet.size() / (float) totalActiveDevice * 100);
onlineRateDTO.setOnlineRate(onlineRate);
onlineRateDTO.setFakeOfflineRate(fakeOfflineRate);
stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 在线率查询", stopWatch.getLastTaskTimeMillis());
return result;
return onlineRateDTO;
}
......
......@@ -40,7 +40,7 @@ public class MenuService {
* @param permissionTag 角色权限
* @return
*/
public Boolean getAdjFreqMenu(Collection<Long> userIds, String permissionTag) {
public Boolean getPermissionMenu(Collection<Long> userIds, String permissionTag) {
if (CollectionUtil.isEmpty(userIds)) {
log.info("getAdjFreqMenu, userIds is null");
return Boolean.FALSE;
......@@ -69,14 +69,25 @@ public class MenuService {
List<Long> accorderIdList = Arrays.stream(accorderIds.split(",")).map(Long::parseLong).collect(Collectors.toList());
List<AppUser> appUserList = userService.getRelUserByUserIds(accorderIdList);
List<Long> webUserIds = appUserList.stream().map(AppUser::getUserId).collect(Collectors.toList());
Boolean adjFreqMenuFlag = getAdjFreqMenu(webUserIds, permissionTag);
Boolean adjFreqMenuFlag = getPermissionMenu(webUserIds, permissionTag);
vehicleDeviceDTO.setAdjFredFlag(adjFreqMenuFlag);
}
});
} else {
// 分享者获取自己的菜单权限 每辆车一致
Boolean adjFreqMenuFlag = getAdjFreqMenu(Lists.newArrayList(ShieldContextHolder.getUserId()), permissionTag);
Boolean adjFreqMenuFlag = getPermissionMenu(Lists.newArrayList(ShieldContextHolder.getUserId()), permissionTag);
list.forEach(vehicleDeviceDTO -> vehicleDeviceDTO.setAdjFredFlag(adjFreqMenuFlag));
}
}
/**
* 根据用户id和tag获取权限菜单
*
* @param permissionTag tag
* @return 是否有该权限
*/
public Boolean getPermissionMenuByTag(String permissionTag) {
log.info("getPermissionMenuByTag param===" + permissionTag);
return getPermissionMenu(Lists.newArrayList(ShieldContextHolder.getUserId()), permissionTag);
}
}
<?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="cn.com.glsx.app.modules.mapper.FakeOfflineVinMapper">
<resultMap id="BaseMap" type="cn.com.glsx.app.modules.entity.FakeOfflineVin">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="vin" property="vin" jdbcType="VARCHAR"/>
<result column="merchant_type" property="merchantType" jdbcType="TINYINT"/>
<result column="home_addr" property="homeAddr" jdbcType="VARCHAR"/>
<result column="work_addr" property="workAddr" jdbcType="VARCHAR"/>
<result column="del_flag" property="delFlag" jdbcType="TINYINT"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
<result column="created_by" property="createdBy" jdbcType="INTEGER"/>
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP"/>
<result column="updated_by" property="updatedBy" jdbcType="INTEGER"/>
</resultMap>
<sql id="BaseColumns">
id
, vin, merchant_type, home_addr, work_addr, del_flag, created_date, created_by, updated_date, updated_by
</sql>
<select id="getFakeOfflineSnList" resultType="java.lang.String">
select tfofs.sn
from t_fake_offline_fence_sn tfofs
left join t_vehicle_device tvd on tvd.sn = tfofs.sn
where tfofs.del_flag = 0
and tfofs.status = 1
and tvd.id in
<foreach collection="allOfflineDevices" item="itemId" index="index" open="(" close=")" separator=",">
#{itemId}
</foreach>
union
select tfocf.sn
from t_fake_offline_change_frequently tfocf
left join t_vehicle_device tvd on tvd.sn = tfocf.sn
where tfocf.del_flag = 0
and tfocf.status = 1
and tvd.id in
<foreach collection="allOfflineDevices" item="itemId" index="index" open="(" close=")" separator=",">
#{itemId}
</foreach>
union
select tws.sn
from t_whitelist_sn tws
left join t_vehicle_device tvd on tvd.sn = tws.sn
where tws.del_flag = 0
and tvd.id in
<foreach collection="allOfflineDevices" item="itemId" index="index" open="(" close=")" separator=",">
#{itemId}
</foreach>
</select>
</mapper>
\ No newline at end of file
......@@ -130,17 +130,18 @@
${search.settleCondition}
</if>
</where>
</select>
</select>
<select id="countOfflineDeviceWithAuth" resultType="java.lang.Integer">
select count(tvd.id)
<select id="countOfflineDeviceWithAuth" resultType="java.lang.Long">
select tvd.id
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_device_location tdl on tdl.sn = td.sn
WHERE tvd.del_flag = 0 and tv.del_flag = 0 and tvd.bind_status = 1
and ((timestampdiff(SECOND, tdl.last_gps_time, now()) &gt; #{search.offlineTime} and timestampdiff(SECOND, tdl.last_bs_time, now()) &gt; #{search.offlineTime})
and ((timestampdiff(SECOND, tdl.last_gps_time, now()) &gt; #{search.offlineTime} and timestampdiff(SECOND,
tdl.last_bs_time, now()) &gt; #{search.offlineTime})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and timestampdiff(SECOND, tdl.last_bs_time, now()) &gt; #{search.offlineTime})
or (timestampdiff(SECOND, tdl.last_gps_time, now()) &gt; #{search.offlineTime} and tdl.last_bs_time is null)
......
......@@ -14,8 +14,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import static org.junit.Assert.*;
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
......@@ -35,7 +33,7 @@ public class RemoteMenuServiceTest {
@Test
public void testGetAdjFreqMenu(){
Boolean vehicle_vin_settle = menuService.getAdjFreqMenu(Lists.newArrayList(1L), "vehicle_vin_settle");
Boolean vehicle_vin_settle = menuService.getPermissionMenu(Lists.newArrayList(1L), "vehicle_vin_settle");
System.out.println("vehicle_vin_settle = " + vehicle_vin_settle);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!