Commit 180b1bdc by 李小龙

整理代码

parent 7875e1b8
...@@ -33,8 +33,8 @@ public class PushCallback implements MqttCallback { ...@@ -33,8 +33,8 @@ public class PushCallback implements MqttCallback {
// 收到消息并设置返回字符串格式 // 收到消息并设置返回字符串格式
String payload = new String(message.getPayload(), "UTF-8"); String payload = new String(message.getPayload(), "UTF-8");
//logger.info("接收消息主题:{}, 接收消息QoS:{}", topic, message.getQos()); logger.info("接收消息主题:{}, 接收消息QoS:{}", topic, message.getQos());
//logger.info("接收消息内容:payload格式:{}", payload); logger.info("接收消息内容:payload格式:{}", payload);
// 解析数据 // 解析数据
DeviceInfo device = JSON.parseObject(payload, DeviceInfo.class); DeviceInfo device = JSON.parseObject(payload, DeviceInfo.class);
......
package com.makeit.module.controller.system;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.module.system.dto.ChinaAreaDTO;
import com.makeit.module.system.entity.ChinaArea;
import com.makeit.module.system.service.ChinaAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* 省市区表 前端控制器
* </p>
*
* @author ywc
* @since 2021-06-09
*/
@Api(tags = "租户端-省市区")
@RestController
@RequestMapping("/sys/china-area")
public class ChinaAreaController {
@Autowired
private ChinaAreaService chinaAreaService;
@ApiOperation(value = "列表", notes = "列表")
@PostMapping("list")
public ApiResponseEntity<List<ChinaArea>> list(@RequestBody ChinaAreaDTO dto) {
return ApiResponseUtils.success(chinaAreaService.list(dto));
}
@ApiOperation(value = "树形列表", notes = "树形列表")
@PostMapping("tree")
public ApiResponseEntity<List<ChinaArea>> tree(@RequestBody ChinaAreaDTO dto) {
List<ChinaArea> list = chinaAreaService.tree(dto);
return ApiResponseUtils.success(list);
}
@ApiOperation(value = "树形列表-有深度", notes = "树形列表-有深度")
@PostMapping("treeDepth")
public ApiResponseEntity<List<ChinaArea>> treeDepth(@RequestBody ChinaAreaDTO dto) {
if (dto.getDepth() == null) {
dto.setDepth(1);
}
List<ChinaArea> list = chinaAreaService.tree(dto);
return ApiResponseUtils.success(list);
}
}
...@@ -787,8 +787,8 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser> ...@@ -787,8 +787,8 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
user.setAccount(dto.getMobile()); user.setAccount(dto.getMobile());
PlatOrg platOrg = platOrgService.getById(dto.getId()); fillOrgPath(dto, user);
user.setOrgPath(platOrg.getPath()+","+platOrg.getId());
save(user); save(user);
dto.setId(user.getId()); dto.setId(user.getId());
setRoleList(dto); setRoleList(dto);
...@@ -796,6 +796,13 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser> ...@@ -796,6 +796,13 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
return user.getId(); return user.getId();
} }
private void fillOrgPath(PlatPersonDTOVO dto, PlatUser user) {
PlatOrg platOrg = platOrgService.getById(dto.getId());
if(platOrg!=null) {
user.setOrgPath(platOrg.getPath() + "," + platOrg.getId());
}
}
@Transactional @Transactional
@Override @Override
...@@ -807,8 +814,8 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser> ...@@ -807,8 +814,8 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
setPassword(user); setPassword(user);
PlatOrg platOrg = platOrgService.getById(dto.getId()); fillOrgPath(dto, user);
user.setOrgPath(platOrg.getPath()+","+platOrg.getId());
updateById(user); updateById(user);
setRoleList(dto); setRoleList(dto);
} }
......
...@@ -8,6 +8,8 @@ import com.makeit.enums.CommonEnum; ...@@ -8,6 +8,8 @@ import com.makeit.enums.CommonEnum;
import com.makeit.global.aspect.tenant.TenantIdIgnore; import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.service.IotOrgService; import com.makeit.module.iot.service.IotOrgService;
import com.makeit.module.iot.vo.DeviceInstanceEntity; import com.makeit.module.iot.vo.DeviceInstanceEntity;
import com.makeit.module.system.service.SysDictionaryCategoryService;
import com.makeit.module.system.vo.DictionaryVo;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.PlatTenantService; import com.makeit.service.saas.PlatTenantService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -35,6 +37,8 @@ public class IotSyncTask { ...@@ -35,6 +37,8 @@ public class IotSyncTask {
private PlatTenantService platTenantService; private PlatTenantService platTenantService;
@Autowired @Autowired
private PlatDeviceService platDeviceService; private PlatDeviceService platDeviceService;
@Autowired
private SysDictionaryCategoryService sysDictionaryCategoryService;
/** /**
* 一小时同步一次 * 一小时同步一次
...@@ -47,14 +51,18 @@ public class IotSyncTask { ...@@ -47,14 +51,18 @@ public class IotSyncTask {
log.info("开始执行同步设备信息接口"); log.info("开始执行同步设备信息接口");
LambdaQueryWrapper<PlatTenant> tenantLambdaQueryWrapper = new LambdaQueryWrapper<PlatTenant>().eq(PlatTenant::getStatus, CommonEnum.YES.getValue()); LambdaQueryWrapper<PlatTenant> tenantLambdaQueryWrapper = new LambdaQueryWrapper<PlatTenant>().eq(PlatTenant::getStatus, CommonEnum.YES.getValue());
List<PlatTenant> platTenants = platTenantService.list(tenantLambdaQueryWrapper); List<PlatTenant> platTenants = platTenantService.list(tenantLambdaQueryWrapper);
List<DictionaryVo> dictionaryVos = sysDictionaryCategoryService.getByCategoryCode("device.category");
Map<String, String> dicNameIdMap = dictionaryVos.stream().collect(Collectors.toMap(DictionaryVo::getName, DictionaryVo::getValue, (v1, v2) -> v1));
for (PlatTenant platTenant : platTenants) { for (PlatTenant platTenant : platTenants) {
String iotOrgId = platTenant.getIotOrgId(); String iotOrgId = platTenant.getIotOrgId();
if(StringUtils.isBlank(iotOrgId)){ if (StringUtils.isBlank(iotOrgId)) {
continue; continue;
} }
//查询iot设备 //查询iot设备
List<DeviceInstanceEntity> iotDeviceList = iotOrgService.getOrgDevice(iotOrgId); List<DeviceInstanceEntity> iotDeviceList = iotOrgService.getOrgDevice(iotOrgId);
if(CollectionUtils.isEmpty(iotDeviceList)){ if (CollectionUtils.isEmpty(iotDeviceList)) {
continue; continue;
} }
//查询平台设备 //查询平台设备
...@@ -63,7 +71,7 @@ public class IotSyncTask { ...@@ -63,7 +71,7 @@ public class IotSyncTask {
.in(PlatDevice::getOriDeviceId, iotDeviceIdSet); .in(PlatDevice::getOriDeviceId, iotDeviceIdSet);
List<PlatDevice> deviceList = platDeviceService.list(deviceLambdaQueryWrapper); List<PlatDevice> deviceList = platDeviceService.list(deviceLambdaQueryWrapper);
//更新平台设备 //更新平台设备
Collection<PlatDevice> platDevices = convertToPlatDevice(iotDeviceList, deviceList,platTenant.getId()); Collection<PlatDevice> platDevices = convertToPlatDevice(iotDeviceList, deviceList, platTenant.getId(), dicNameIdMap);
platDeviceService.saveOrUpdateBatch(platDevices); platDeviceService.saveOrUpdateBatch(platDevices);
} }
...@@ -80,28 +88,28 @@ public class IotSyncTask { ...@@ -80,28 +88,28 @@ public class IotSyncTask {
} }
private Collection<PlatDevice> convertToPlatDevice(List<DeviceInstanceEntity> iotDeviceList, List<PlatDevice> deviceList,String tenantId){ private Collection<PlatDevice> convertToPlatDevice(List<DeviceInstanceEntity> iotDeviceList, List<PlatDevice> deviceList, String tenantId, Map<String, String> dicNameIdMap) {
Map<String, PlatDevice> deviceMap = deviceList.stream().collect(Collectors.toMap(PlatDevice::getOriDeviceId, v -> v, (a, b) -> a)); Map<String, PlatDevice> deviceMap = deviceList.stream().collect(Collectors.toMap(PlatDevice::getOriDeviceId, v -> v, (a, b) -> a));
iotDeviceList.forEach(iotDevice->{ iotDeviceList.forEach(iotDevice -> {
PlatDevice platDevice = deviceMap.get(iotDevice.getId()); PlatDevice platDevice = deviceMap.get(iotDevice.getId());
if(platDevice==null){ if (platDevice == null) {
platDevice=new PlatDevice(); platDevice = new PlatDevice();
platDevice.setTenantId(tenantId); platDevice.setTenantId(tenantId);
deviceMap.put(iotDevice.getId(),platDevice); deviceMap.put(iotDevice.getId(), platDevice);
} }
platDevice.setOriDeviceId(iotDevice.getId()); platDevice.setOriDeviceId(iotDevice.getId());
platDevice.setName(iotDevice.getName()); platDevice.setName(iotDevice.getName());
platDevice.setProductName(iotDevice.getProductName()); platDevice.setProductName(iotDevice.getProductName());
platDevice.setProductId(iotDevice.getProductId()); platDevice.setProductId(iotDevice.getProductId());
LocalDateTime registryTime = LocalDateTime.ofEpochSecond(iotDevice.getRegistryTime()/1000, 0, ZoneOffset.ofHours(8)); LocalDateTime registryTime = LocalDateTime.ofEpochSecond(iotDevice.getRegistryTime() / 1000, 0, ZoneOffset.ofHours(8));
platDevice.setRegistrationDate(registryTime); platDevice.setRegistrationDate(registryTime);
platDevice.setDescription(iotDevice.getDescribe()); platDevice.setDescription(iotDevice.getDescribe());
String state = iotDevice.getState(); String state = iotDevice.getState();
platDevice.setStatus(StringUtils.equals("online",state)?CommonEnum.YES.getValue() : CommonEnum.NO.getValue()); platDevice.setStatus(StringUtils.equals("online", state) ? CommonEnum.YES.getValue() : CommonEnum.NO.getValue());
//todo 根据类型名称来匹配 //todo 根据类型名称来匹配
// platDevice.setCategory(); platDevice.setCategory(dicNameIdMap.get(iotDevice.getProductName()));
// platDevice.setFirmwareVersion(); // platDevice.setFirmwareVersion();
// platDevice.setLastOnlineData(); // platDevice.setLastOnlineData();
// platDevice.setOrgId(); // platDevice.setOrgId();
......
...@@ -40,6 +40,8 @@ public class PlatPersonDTOVO extends BaseIdDTO { ...@@ -40,6 +40,8 @@ public class PlatPersonDTOVO extends BaseIdDTO {
@ApiModelProperty(value = "手机号") @ApiModelProperty(value = "手机号")
private String mobile; private String mobile;
private String email;
@NotBlank(message = "状态不能为空") @NotBlank(message = "状态不能为空")
@Pattern(regexp = "0|1", message = "状态可选值为 0禁用 1启用") @Pattern(regexp = "0|1", message = "状态可选值为 0禁用 1启用")
@ApiModelProperty(value = "状态 0禁用 1启用") @ApiModelProperty(value = "状态 0禁用 1启用")
......
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 sign in to comment