add:第一版测试版本。

This commit is contained in:
2025-12-15 10:42:02 +08:00
parent 98e0bbcaa6
commit cd483c81d1
84 changed files with 3714 additions and 26 deletions

View File

@@ -0,0 +1,36 @@
package org.nl.setting.modular.controller;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.nl.logging.annotation.Log;
import org.nl.setting.modular.param.UpdateSettingParam;
import org.nl.setting.modular.service.SettingService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* @author dsh
* 2025/12/6
*/
@Slf4j
@RestController
@RequestMapping("/setting")
public class SettingController {
@Resource
private SettingService settingService;
@Log("查询所有设置参数")
@GetMapping("/queryAllSettingParam")
public ResponseEntity<Object> queryAllSettingParam(){
return new ResponseEntity<>(settingService.queryAllSettingParam(), HttpStatus.OK);
}
@Log("根据设置编号设置参数")
@PostMapping("/updateSettingParamByCode")
public ResponseEntity<Object> updateSettingParamByCode(@RequestBody @Validated UpdateSettingParam updateSettingParam){
return new ResponseEntity<>(settingService.updateSettingParamByCode(updateSettingParam), HttpStatus.OK);
}
}

View File

@@ -1,23 +0,0 @@
package org.nl.setting.modular.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author: lyd
* @Date: 2025/11/21
*/
@RequestMapping("/api")
@RestController
public class TestController {
@GetMapping("/")
public ResponseEntity<Object> PressedMonitor() {
return new ResponseEntity<>("aaa", HttpStatus.OK);
}
}

View File

@@ -0,0 +1,65 @@
package org.nl.setting.modular.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* @author dsh
* 2025/12/6
*/
@Data
@TableName("setting_param")
public class Setting {
/**
* 设置标识
*/
@TableId(value = "id")
private String id;
/**
* 设置类型
*/
private String setting_type;
/**
* 设置编码
*/
private String setting_code;
/**
* 设置名称
*/
private String label;
/**
* 设置值
*/
private String value;
/**
* 是否启用
*/
private String is_active;
/**
* 创建者
*/
private String create_by;
/**
* 创建时间
*/
private String create_time;
/**
* 修改者
*/
private String update_by;
/**
* 修改时间
*/
private String update_time;
}

View File

@@ -0,0 +1,61 @@
package org.nl.setting.modular.enums;
import lombok.Getter;
/**
* @author dsh
* 2025/12/8
*/
@Getter
public enum SettingCodeEnum {
/**
* 调度IP
*/
SCHEDULE_IP("0", "schedule_ip", "调度IP"),
/**
* 配送速度
*/
DELIVERY_SPEED("1", "delivery_speed", "配送速度"),
/**
* 远程呼叫
*/
FAR_CALL("2", "far_call", "远程呼叫"),
/**
* 呼叫到达等待时间
*/
CALL_ARRIVAL_WAITING_TIME("3", "call_arrival_waiting_time", "呼叫到达等待时间"),
/**
* 呼叫时等待时间
*/
WAITING_TIME_WHEN_MAKING_A_CALL("4", "waiting_time_when_making_a_call", "呼叫时等待时间"),
/**
* 自动回充
*/
AUTOMATIC_RECHARGE("5", "automatic_recharge", "自动回充"),
/**
* 充电时是否可呼叫
*/
CAN_IT_BE_CALLED_WHILE_CHARGING("6", "can_it_be_called_while_charging", "充电时是否可呼叫");
private String code;
private String name;
private String desc;
SettingCodeEnum(String code, String name, String desc) {
this.code = code;
this.name = name;
this.desc = desc;
}
public static SettingCodeEnum getByCode(String code) {
for (SettingCodeEnum e : SettingCodeEnum.values()) {
if (e.name.equals(code)) {
return e;
}
}
return null;
}
}

View File

@@ -0,0 +1,14 @@
package org.nl.setting.modular.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.nl.setting.modular.entity.Setting;
/**
* @author dsh
* 2025/12/6
*/
@Mapper
public interface SettingMapper extends BaseMapper<Setting> {
}

View File

@@ -0,0 +1,5 @@
<?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="org.nl.setting.modular.mapper.SettingMapper">
</mapper>

View File

@@ -0,0 +1,33 @@
package org.nl.setting.modular.param;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/**
* @author dsh
* 2025/12/6
*/
@Data
public class UpdateSettingParam {
/**
* 设置编码
*/
@NotBlank(message = "设置编码不能为空")
private String setting_code;
/**
* 设置值
*/
private String value;
/**
* 是否开启 0关 1开
*/
private String is_active;
/**
* 修改者 (屏幕就传车号,外部就传用户)
*/
private String update_by;
}

View File

@@ -0,0 +1,38 @@
package org.nl.setting.modular.provider;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.nl.api.setting.api.SettingAPI;
import org.nl.enums.YesOrNoEnum;
import org.nl.exception.BadRequestException;
import org.nl.setting.modular.entity.Setting;
import org.nl.setting.modular.enums.SettingCodeEnum;
import org.nl.setting.modular.service.SettingService;
import org.springframework.stereotype.Service;
/**
* @author dsh
* 2025/12/13
*/
@Slf4j
@Service
public class SettingAPIProvider implements SettingAPI {
@Resource
private SettingService settingService;
@Override
public JSONObject querySttingParamIsActiveByCode(String setting_code) {
if (StrUtil.isBlank(setting_code)){
log.info("设置编号不能为空");
throw new BadRequestException("设置编号不能为空");
}
JSONObject result = new JSONObject();
result.put("data",settingService.getOne(new LambdaQueryWrapper<>(Setting.class).eq(Setting::getSetting_code,setting_code)));
return result;
}
}

View File

@@ -0,0 +1,26 @@
package org.nl.setting.modular.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.nl.response.WebResponse;
import org.nl.setting.modular.entity.Setting;
import org.nl.setting.modular.param.UpdateSettingParam;
/**
* @author dsh
* 2025/12/6
*/
public interface SettingService extends IService<Setting> {
/**
* 获取所有设置参数
* @return WebResponse
*/
WebResponse queryAllSettingParam();
/**
* 根据设置编码修改设置参数
* @return WebResponse
*/
WebResponse updateSettingParamByCode(UpdateSettingParam updateSettingParam);
}

View File

@@ -0,0 +1,139 @@
package org.nl.setting.modular.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.nl.api.schedule.setting.api.ScheduleSettingAPI;
import org.nl.api.schedule.setting.core.ScheduleAPISettingChargeParam;
import org.nl.api.schedule.setting.core.ScheduleAPISettingSpeedParam;
import org.nl.enums.YesOrNoEnum;
import org.nl.exception.BadRequestException;
import org.nl.response.WebResponse;
import org.nl.setting.modular.entity.Setting;
import org.nl.setting.modular.enums.SettingCodeEnum;
import org.nl.setting.modular.mapper.SettingMapper;
import org.nl.setting.modular.param.UpdateSettingParam;
import org.nl.setting.modular.service.SettingService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author dsh
* 2025/12/6
*/
@Slf4j
@Service
public class SettingServiceImpl extends ServiceImpl<SettingMapper, Setting> implements SettingService {
@Resource
private SettingMapper settingMapper;
@Resource
private ScheduleSettingAPI scheduleSettingAPI;
@Override
public WebResponse queryAllSettingParam() {
List<Setting> setting = settingMapper.selectList(new LambdaQueryWrapper<>(Setting.class));
return WebResponse.requestParamOk(setting);
}
@Override
@Transactional(rollbackFor = Exception.class)
public WebResponse updateSettingParamByCode(UpdateSettingParam updateSettingParam) {
String setting_code = updateSettingParam.getSetting_code();
String is_active = updateSettingParam.getIs_active();
String setting_value = updateSettingParam.getValue();
if (StrUtil.isBlank(setting_code)){
throw new BadRequestException("设置编号不能为空");
}
SettingCodeEnum settingCodeEnum = SettingCodeEnum.getByCode(setting_code);
if (settingCodeEnum == null){
throw new BadRequestException("未找到该设置编码");
}
try {
switch (settingCodeEnum){
case SCHEDULE_IP:
log.info("修改调度IP");
break;
case DELIVERY_SPEED:
log.info("修改配送速度");
if (StrUtil.isBlank(setting_value)){
throw new BadRequestException("修改配送速度,设置值不能为空");
}
ScheduleAPISettingSpeedParam scheduleAPISettingSpeedParam = new ScheduleAPISettingSpeedParam();
// 前端值是0.1-1.0,传给调度需要转换成1-100。
int customSpeed = (int) (Double.parseDouble(setting_value) * 100);
scheduleAPISettingSpeedParam.setCustomSpeed(customSpeed);
HttpResponse speedResult = scheduleSettingAPI.settingSpeed(scheduleAPISettingSpeedParam);
if (speedResult == null || !speedResult.isOk()){
throw new BadRequestException("设置调度配送速度失败");
}
break;
case FAR_CALL:
log.info("修改远程设备呼叫");
break;
case CALL_ARRIVAL_WAITING_TIME:
log.info("修改呼叫到达等待时间");
break;
case WAITING_TIME_WHEN_MAKING_A_CALL:
log.info("修改呼叫时等待时间");
break;
case AUTOMATIC_RECHARGE:
log.info("修改自动回充");
if (StrUtil.isBlank(setting_value) || StrUtil.isBlank(is_active) ){
throw new BadRequestException("修改自动回充,设置值和是否启用值不能为空");
}
ScheduleAPISettingChargeParam scheduleAPISettingFreeChargeThreshold = new ScheduleAPISettingChargeParam();
// 调度有默认强制充电阈值(不接任务),目前我们设置的是空闲无任务时车辆自动去充电的阈值。如果没启用将阈值设置成0。
scheduleAPISettingFreeChargeThreshold.setFreeChargeThreshold(
YesOrNoEnum.YES.getCode().equals(is_active) ? Integer.parseInt(setting_value) : 0
);
HttpResponse freeChargeResult = scheduleSettingAPI.settingCharge(scheduleAPISettingFreeChargeThreshold);
if (freeChargeResult == null || !freeChargeResult.isOk()){
throw new BadRequestException("设置调度自由充电阈值失败");
}
break;
case CAN_IT_BE_CALLED_WHILE_CHARGING:
log.info("修改充电时是否可呼叫");
if (StrUtil.isBlank(setting_value) || StrUtil.isBlank(is_active) ){
throw new BadRequestException("修改充电时是否可呼叫,设置值和是否启用值不能为空");
}
ScheduleAPISettingChargeParam scheduleAPISettingUsableForTaskThreshold = new ScheduleAPISettingChargeParam();
// 如果充电时不可呼叫,将阈值改成100。
scheduleAPISettingUsableForTaskThreshold.setFreeChargeThreshold(
YesOrNoEnum.YES.getCode().equals(is_active) ? Integer.parseInt(setting_value) : 100
);
HttpResponse chargeResult = scheduleSettingAPI.settingCharge(scheduleAPISettingUsableForTaskThreshold);
if (chargeResult == null || !chargeResult.isOk()){
throw new BadRequestException("设置调度可接任务阈值失败");
}
break;
}
settingMapper.update(new LambdaUpdateWrapper<>(Setting.class)
.set(StrUtil.isNotBlank(setting_value),Setting::getValue,setting_value)
.set(StrUtil.isNotBlank(is_active),Setting::getIs_active,is_active)
.set(StrUtil.isNotBlank(updateSettingParam.getUpdate_by()),Setting::getUpdate_by,updateSettingParam.getUpdate_by())
.set(Setting::getUpdate_time, DateUtil.now())
.eq(Setting::getSetting_code,updateSettingParam.getSetting_code())
);
}catch (Exception e){
log.info("更新设置失败:{}",e.getMessage());
throw new BadRequestException("更新设置失败:"+e.getMessage());
}
return WebResponse.requestOk();
}
}