diff --git a/src/main/java/org/springblade/modules/business/service/impl/DeviceServiceImpl.java b/src/main/java/org/springblade/modules/business/service/impl/DeviceServiceImpl.java index 1dce758..d2a9294 100644 --- a/src/main/java/org/springblade/modules/business/service/impl/DeviceServiceImpl.java +++ b/src/main/java/org/springblade/modules/business/service/impl/DeviceServiceImpl.java @@ -195,6 +195,7 @@ public class DeviceServiceImpl extends BaseServiceImpl imp throw new ServiceException("实验室【" + device.getLimsName() + "】的房间【" + device.getRoomName() + "】不存在,请修改后再上传!"); } device.setRoomId(rooms.get(0).getId()); + device.setRunStatus(CommonConstant.DEVICE_RUN_STATUS_WORKING); list.add(device); } }); @@ -214,16 +215,20 @@ public class DeviceServiceImpl extends BaseServiceImpl imp .eq(Device::getFloorId, device.getFloorId()) .eq(Device::getRoomId, device.getRoomId()); List devices = this.list(wrapper); - // 查询关联的设备巡检数据 - List maintenances = maintenanceService.list(Wrappers.lambdaQuery(DeviceMaintenance.class).in(DeviceMaintenance::getDeviceId, devices.stream().map(Device::getId).toList())); - // 组装视图返回 - devices.forEach(devic -> { - DeviceVO deviceVO = BeanUtil.copyProperties(devic, DeviceVO.class); - if (deviceVO != null) { - deviceVO.setMaintenances(maintenances.stream().filter(maintenance -> maintenance.getDeviceId().equals(devic.getId())).toList()); - deviceVOList.add(deviceVO); - } - }); + + if (CollectionUtil.isNotEmpty(devices)) { + // 查询关联的设备巡检数据 + List deviceIds = devices.stream().map(Device::getId).toList(); + List maintenances = maintenanceService.list(Wrappers.lambdaQuery(DeviceMaintenance.class).in(DeviceMaintenance::getDeviceId, deviceIds)); + // 组装视图返回 + devices.forEach(devic -> { + DeviceVO deviceVO = BeanUtil.copyProperties(devic, DeviceVO.class); + if (deviceVO != null) { + deviceVO.setMaintenances(maintenances.stream().filter(maintenance -> maintenance.getDeviceId().equals(devic.getId())).toList()); + deviceVOList.add(deviceVO); + } + }); + } return deviceVOList; } diff --git a/src/main/java/org/springblade/modules/business/sms/AliYunSmsConfig.java b/src/main/java/org/springblade/modules/business/sms/AliYunSmsConfig.java new file mode 100644 index 0000000..7568e96 --- /dev/null +++ b/src/main/java/org/springblade/modules/business/sms/AliYunSmsConfig.java @@ -0,0 +1,39 @@ +package org.springblade.modules.business.sms; + +import com.aliyun.teaopenapi.models.*; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @author xueyaoxuan + */ +@Data +@Component +@ConfigurationProperties(prefix = "sms.aliyun") +public class AliYunSmsConfig { + + private String accessKeyId; + private String accessKeySecret; + private String signName; + private boolean isPushSms; + + /** + * 使用AK&SK初始化账号Client + * + * @return Client + * @throws Exception + */ + public com.aliyun.dysmsapi20170525.Client createClient() throws Exception { + Config config = new Config() + // AccessKey ID + .setAccessKeyId(this.getAccessKeyId()) + // AccessKey Secret + .setAccessKeySecret(this.getAccessKeySecret()); + // 访问的域名 + config.endpoint = "dysmsapi.aliyuncs.com"; + return new com.aliyun.dysmsapi20170525.Client(config); + } + +} + diff --git a/src/main/java/org/springblade/modules/business/sms/AliYunSmsManager.java b/src/main/java/org/springblade/modules/business/sms/AliYunSmsManager.java new file mode 100644 index 0000000..e3b08d6 --- /dev/null +++ b/src/main/java/org/springblade/modules/business/sms/AliYunSmsManager.java @@ -0,0 +1,72 @@ +package org.springblade.modules.business.sms; + +import cn.hutool.core.util.StrUtil; +import com.aliyun.dysmsapi20170525.Client; +import com.aliyun.dysmsapi20170525.models.SendSmsRequest; +import com.aliyun.dysmsapi20170525.models.SendSmsResponse; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.stream.Collectors; + +@Slf4j +@Component +public class AliYunSmsManager { + + @Autowired + private AliYunSmsConfig aliYunSmsConfig; + + public String sendSms(List mobiles, String message, String code) { + SendSmsResponse sendSmsResponse = null; + try{ + //调用阿里云api手机号上限1000 + if (mobiles.size()>1000){ + throw new ServiceException("发送短信手机号上限!"); + } + //检验手机号格式 + mobiles.forEach(mobile->{ + if (StrUtil.isAllEmpty(mobile)){ + throw new ServiceException("手机号格式错误!"); + } + }); + sendSmsResponse = sendALiYunSms(mobiles.stream().collect(Collectors.joining(",")), + message, code); + // + if (200 == sendSmsResponse.getStatusCode()) { + // 发送短信成功,返回短信码进行redis存储 + return message; + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 发送阿里云短信 + * + * @param mobiles 手机号列表 + * @param message json格式的模板参数 + * @param code 阿里云短信模板code + * @return + * @throws Exception + */ + private SendSmsResponse sendALiYunSms(String mobiles, String message, String code) throws Exception { + + //初始化Client对象 + Client client = aliYunSmsConfig.createClient(); + + //构建请求参数 + SendSmsRequest sendSmsRequest = new SendSmsRequest() + .setPhoneNumbers(mobiles) + .setSignName(aliYunSmsConfig.getSignName()) + .setTemplateCode(code) + .setTemplateParam(message); + //发送短信 + return client.sendSms(sendSmsRequest); + + } +} diff --git a/src/main/java/org/springblade/modules/system/controller/DeptController.java b/src/main/java/org/springblade/modules/system/controller/DeptController.java index ddb2abb..f0c10c1 100644 --- a/src/main/java/org/springblade/modules/system/controller/DeptController.java +++ b/src/main/java/org/springblade/modules/system/controller/DeptController.java @@ -71,7 +71,7 @@ import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE; @NonDS @RestController @AllArgsConstructor -@RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "") +@RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/dept") @Tag(name = "部门", description = "部门") public class DeptController extends BladeController { diff --git a/src/main/java/org/springblade/modules/system/mapper/TopMenuSettingMapper.xml b/src/main/java/org/springblade/modules/system/mapper/TopMenuSettingMapper.xml deleted file mode 100644 index f1901dd..0000000 --- a/src/main/java/org/springblade/modules/system/mapper/TopMenuSettingMapper.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index a104c79..7f6095f 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -11,8 +11,8 @@ spring: enabled: false datasource: # MySql -# url: jdbc:mysql://192.168.1.12:3306/lab-ops?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true - url: jdbc:mysql://127.0.0.1:3306/lab-ops?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true + url: jdbc:mysql://192.168.1.12:3306/lab-ops?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true +# url: jdbc:mysql://127.0.0.1:3306/lab-ops?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true username: root password: 123456 @@ -29,6 +29,12 @@ sms: secret-key: PWFmEByyD5YrjMlAyioZZqLtMGxZLu # 地域,主要由阿里云配置 region-id: cn-hangzhou + aliyun: + accessKeyId: 111 + accessKeySecret: 111 + signName: 111 + isPushSms: true + templateCode: 111 #blade配置 #blade: