refactor(iot): 调整设备映射和数据库脚本

- 修改 DeviceMapper.xml 中 name 字段的属性映射,从 name 改为 productName
-移除 gateway.sql 中的冗余数据插入和表删除语句- 优化 RoleServiceImpl 中的角色权限更新逻辑
This commit is contained in:
zhuangtianxiang 2025-01-08 10:17:44 +08:00
parent bd6f4c2ed6
commit bc82a1bfd1
7 changed files with 13 additions and 41 deletions

View File

@ -65,11 +65,10 @@ public class ApiExceptionHandler {
return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR);
} }
//TODO 冲突 // @ExceptionHandler(value = {Exception.class})
@ExceptionHandler(value = {Exception.class}) // public ResponseEntity<Object> handleException(Exception ex) throws JsonProcessingException {
public ResponseEntity<Object> handleException(Exception ex) throws JsonProcessingException { // log.error("Exception: {}", objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())));
log.error("Exception: {}", objectMapper.writeValueAsString(Map.of("msg", ex.getMessage()))); // return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR); // }
}
} }

View File

@ -33,7 +33,6 @@ import javax.sql.DataSource;
@AllArgsConstructor @AllArgsConstructor
@EnableMethodSecurity @EnableMethodSecurity
@Configuration @Configuration
@EnableWebSecurity
public class SpringSecurityConfig { public class SpringSecurityConfig {
private final UserDetailsService userDetailsService; private final UserDetailsService userDetailsService;

View File

@ -1,14 +1,11 @@
package com.zsc.edu.gateway.modules.iot.device.service; package com.zsc.edu.gateway.modules.iot.device.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.zsc.edu.gateway.modules.iot.device.dto.BatchDeviceDto; import com.zsc.edu.gateway.modules.iot.device.dto.BatchDeviceDto;
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceDto; import com.zsc.edu.gateway.modules.iot.device.dto.DeviceDto;
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceServeDto; import com.zsc.edu.gateway.modules.iot.device.dto.DeviceServeDto;
import com.zsc.edu.gateway.modules.iot.device.entity.Device; import com.zsc.edu.gateway.modules.iot.device.entity.Device;
import com.zsc.edu.gateway.modules.iot.device.entity.DeviceDiff; import com.zsc.edu.gateway.modules.iot.device.entity.DeviceDiff;
import com.zsc.edu.gateway.modules.iot.device.query.DeviceQuery;
import com.zsc.edu.gateway.modules.iot.device.vo.DeviceVo; import com.zsc.edu.gateway.modules.iot.device.vo.DeviceVo;
import java.util.List; import java.util.List;

View File

@ -1,6 +1,7 @@
package com.zsc.edu.gateway.modules.iot.tsl.service.impl; package com.zsc.edu.gateway.modules.iot.tsl.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.gateway.exception.ApiException;
import com.zsc.edu.gateway.modules.iot.tsl.dto.PropertyDto; import com.zsc.edu.gateway.modules.iot.tsl.dto.PropertyDto;
import com.zsc.edu.gateway.modules.iot.tsl.entity.Property; import com.zsc.edu.gateway.modules.iot.tsl.entity.Property;
import com.zsc.edu.gateway.modules.iot.tsl.mapper.PropertyMapper; import com.zsc.edu.gateway.modules.iot.tsl.mapper.PropertyMapper;
@ -25,7 +26,7 @@ public class PropertyServiceImpl extends ServiceImpl<PropertyRepository, Propert
@Override @Override
public Property create(PropertyDto dto) { public Property create(PropertyDto dto) {
if (baseMapper.findByName(dto.getName()) != null) { if (baseMapper.findByName(dto.getName()) != null) {
throw new RuntimeException("该属性已存在!"); throw new ApiException("该属性已存在!");
} }
Property property = mapper.toEntity(dto); Property property = mapper.toEntity(dto);
save(property); save(property);
@ -40,7 +41,7 @@ public class PropertyServiceImpl extends ServiceImpl<PropertyRepository, Propert
public Property update(PropertyDto dto, Long id) { public Property update(PropertyDto dto, Long id) {
Property property = baseMapper.selectById(id); Property property = baseMapper.selectById(id);
if (property == null) { if (property == null) {
throw new RuntimeException("Serve not found with id: " + id); throw new ApiException("Serve not found with id: " + id);
} }
mapper.convert(dto, property); mapper.convert(dto, property);
baseMapper.updateById(property); baseMapper.updateById(property);
@ -51,7 +52,7 @@ public class PropertyServiceImpl extends ServiceImpl<PropertyRepository, Propert
public Property detail(Long id) { public Property detail(Long id) {
Property property = baseMapper.selectById(id); Property property = baseMapper.selectById(id);
if (property == null) { if (property == null) {
throw new RuntimeException("属性不存在请检查输入ID是否正确"); throw new ApiException("属性不存在请检查输入ID是否正确");
} }
return property; return property;
} }

View File

@ -86,8 +86,10 @@ public class RoleServiceImpl extends ServiceImpl<RoleRepository, Role> implement
throw new ConstraintException("name", dto.getName(), "同名角色已存在"); throw new ConstraintException("name", dto.getName(), "同名角色已存在");
} }
mapper.convert(dto, existingRole); mapper.convert(dto, existingRole);
if (existingRole.getAuthorities() != null) {
roleAuthService.remove(new LambdaQueryWrapper<RoleAuthority>().eq(RoleAuthority::getRoleId, id)); roleAuthService.remove(new LambdaQueryWrapper<RoleAuthority>().eq(RoleAuthority::getRoleId, id));
saveRoleAuths(id, dto.getAuthorities()); saveRoleAuths(id, dto.getAuthorities());
}
return updateById(existingRole); return updateById(existingRole);
} }

View File

@ -688,29 +688,3 @@ comment on column sys_user.enable_state is '状态';
alter table sys_user alter table sys_user
owner to gitea; owner to gitea;
-- 插入备份的数据
INSERT INTO sys_user (dept_id, role_id, username, password, phone, email, name, avatar, address, create_by, update_by,
create_time, update_time, remark, enable_state)
SELECT dept_id,
role_id,
username,
password,
phone,
email,
name,
avatar,
address,
create_by,
update_by,
create_time,
update_time,
remark,
enable_state
FROM sys_user_backup;
-- 删除备份表
DROP TABLE sys_user_backup;
ALTER TABLE iot_property
ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY;

View File

@ -22,7 +22,7 @@
<result column="create_time" jdbcType="DATE" property="deviceCreateTime"/> <result column="create_time" jdbcType="DATE" property="deviceCreateTime"/>
<result column="update_time" jdbcType="DATE" property="deviceUpdateTime"/> <result column="update_time" jdbcType="DATE" property="deviceUpdateTime"/>
<result column="remark" jdbcType="VARCHAR" property="deviceRemark"/> <result column="remark" jdbcType="VARCHAR" property="deviceRemark"/>
<result column="name" property="name"/> <result column="name" property="productName"/>
<result column="product_type" jdbcType="VARCHAR" property="productType"/> <result column="product_type" jdbcType="VARCHAR" property="productType"/>
<result column="model" property="model"/> <result column="model" property="model"/>
<result column="link" property="link"/> <result column="link" property="link"/>