Commit 91744783 authored by xixinzhao's avatar xixinzhao

车辆赋码方式修改

parent 46712f86
package com.yeejoin.equipmanage.common.entity.dto;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @author DELL
*/
@Data
public class EquipQrDateDto {
/**
* 类型
*/
private String type;
/**
* 对比属性
*/
private String contrast;
/**
* 需要赋码判断的数据
*/
private List<Map<String, String>> data;
}
package com.yeejoin.equipmanage.common.enums;
/**
* 赋码计算规则
* @author DELL
*/
public enum CalculationRulesEnum {
EQ("eq", "等于"),
NE("ne", "不等于"),
GT("gt", "大于"),
GE("ge", "大于等于"),
LT("lt", "小于"),
LE("le", "小于等于");
private String code;
private String type;
CalculationRulesEnum(String code, String type) {
this.code=code;
this.type=type;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public static CalculationRulesEnum getEnum(String code) {
CalculationRulesEnum calculationRulesEnum = null;
for(CalculationRulesEnum type: CalculationRulesEnum.values()) {
if (type.getCode().equals(code)) {
calculationRulesEnum = type;
break;
}
}
return calculationRulesEnum;
}
}
package com.yeejoin.equipmanage.action;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.yeejoin.amos.component.rule.MethodParam;
import com.yeejoin.amos.component.rule.RuleActionBean;
import com.yeejoin.amos.component.rule.RuleMethod;
import com.yeejoin.equipmanage.common.entity.dto.EquipQrDateDto;
import com.yeejoin.equipmanage.common.enums.CalculationRulesEnum;
import com.yeejoin.equipmanage.common.utils.DateUtils;
import com.yeejoin.equipmanage.service.ICarService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 赋码动作
* @author DELL
*/
@Component
@RuleActionBean(beanLabel = "动态预案")
@Slf4j
public class UpdateQrCodeAction {
@Autowired
private ICarService carService;
private final String CAR_ID = "carId";
@RuleMethod(methodLabel = "更新码", project = "车辆更新码颜色")
public void updateCarQrCode(@MethodParam(paramLabel = "判断值") String value, @MethodParam(paramLabel = "赋码颜色") String color,
@MethodParam(paramLabel = "判断对象") Object equipQrDateDto, @MethodParam(paramLabel = "是否启用") Boolean enable,
@MethodParam(paramLabel = "计算规则") String rule) {
if (Boolean.TRUE.equals(enable)) {
EquipQrDateDto equipQrDateDtoN = JSONObject.parseObject(equipQrDateDto.toString(), EquipQrDateDto.class);
List<Map<String, String>> data = equipQrDateDtoN.getData();
String contrast = equipQrDateDtoN.getContrast();
if (!CollectionUtils.isEmpty(data)) {
List<String> collect = data.stream().map(map -> {
try {
String carId = null;
String s = map.get(contrast).replace("T", " ");
Date date = DateUtils.longStr2Date(s);
int i = DateUtils.dateBetween(date, new Date());
CalculationRulesEnum anEnum = CalculationRulesEnum.getEnum(rule);
switch (anEnum) {
case EQ:
if (i == Integer.parseInt(value)) {
carId = String.valueOf(map.get(CAR_ID));
}
break;
case GT:
if (i > Integer.parseInt(value)) {
carId = String.valueOf(map.get(CAR_ID));
}
break;
case GE:
if (i >= Integer.parseInt(value)) {
carId = String.valueOf(map.get(CAR_ID));
}
break;
case LE:
if (i <= Integer.parseInt(value)) {
carId = String.valueOf(map.get(CAR_ID));
}
break;
case LT:
if (i < Integer.parseInt(value)) {
carId = String.valueOf(map.get(CAR_ID));
}
break;
case NE:
if (i != Integer.parseInt(value)) {
carId = String.valueOf(map.get(CAR_ID));
}
break;
default:
break;
}
return carId;
} catch (ParseException e) {
log.error("日期转换失败");
e.printStackTrace();
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList());
carService.updateCarQrCode(collect, color);
}
}
}
}
......@@ -37,6 +37,6 @@ public interface CarPropertyMapper extends BaseMapper<CarProperty> {
Map<String, Object> getCarPropertyByCarIds(List<Long> carIds);
List<Map<String, Object>> selectIndexByTime(String carStartIndexKey);
List<Map<String, String>> selectIndexByTime(String carStartIndexKey);
}
package com.yeejoin.equipmanage.quartz;
import com.yeejoin.amos.component.rule.RuleTrigger;
import com.yeejoin.equipmanage.common.entity.dto.EquipQrDateDto;
import com.yeejoin.equipmanage.service.ICarService;
import com.yeejoin.equipmanage.service.impl.CarServiceImpl;
import lombok.extern.slf4j.Slf4j;
......@@ -8,6 +10,9 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* 定时监控车辆相关指标
* @author xxz
......@@ -20,13 +25,25 @@ public class CarPropertyJob {
@Autowired
private ICarService carService;
@Autowired
private RuleTrigger ruleTrigger;
/**
* 车辆赋红码。定时查询车辆启停更新时间,
*/
@Scheduled(cron = "${update.car.qrCode}")
public void UpdateCarQrCode(){
public void UpdateCarQrCode() {
carService.updateCarStartStatus();
List<Map<String, String>> list = carService.updateCarStartStatus();
EquipQrDateDto equipQrDateDto = new EquipQrDateDto();
equipQrDateDto.setContrast("updateDate");
equipQrDateDto.setType("car");
equipQrDateDto.setData(list);
try {
ruleTrigger.publish(equipQrDateDto, "中心配置赋码规则/update-qr-code", null);
} catch (Exception e) {
log.error("调用规则失败: {}", e.getMessage());
}
}
}
......@@ -211,7 +211,12 @@ public interface ICarService extends IService<Car> {
/**
* 查询车辆启动状态,赋码
*/
void updateCarStartStatus();
List<Map<String, String>> updateCarStartStatus();
/**
* 赋码
*/
void updateCarQrCode(List<String> carIds, String status);
}
......@@ -1969,14 +1969,12 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarS
}
@Override
public void updateCarStartStatus() {
List<Map<String, Object>> list = carPropertyMapper.selectIndexByTime(CAR_START_INDEX_KEY);
List<String> carIds = list.stream().map(o -> String.valueOf(o.get("carId"))).collect(Collectors.toList());
// 近七天未启动赋红码
updateCarQrCode(carIds, "2");
public List<Map<String, String>> updateCarStartStatus() {
return carPropertyMapper.selectIndexByTime(CAR_START_INDEX_KEY);
}
private void updateCarQrCode(List<String> carIds, String status) {
@Override
public void updateCarQrCode(List<String> carIds, String status) {
carMapper.updateStatusByIds(carIds, status);
}
}
......@@ -100,12 +100,13 @@
<select id="selectIndexByTime" resultType="map">
SELECT
car_id carId
car_id carId,
update_date updateDate
FROM
wl_car_property
WHERE
equipment_index_key = #{carStartIndexKey} AND `value` IS NOT NULL AND
DATE_SUB(CURDATE( ), INTERVAL 7 DAY ) > update_date
equipment_index_key = #{carStartIndexKey} AND `value` IS NOT NULL
-- AND DATE_SUB(CURDATE( ), INTERVAL 7 DAY ) > update_date
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment