From cf311a43c3a6b941738de9ca5735e1acca451fc2 Mon Sep 17 00:00:00 2001 From: lizijie <lzjiiie@163.com> Date: Tue, 17 Aug 2021 16:43:46 +0800 Subject: [PATCH] 特殊设备删除接口 --- screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java | 184 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 184 insertions(+), 0 deletions(-) diff --git a/screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java b/screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java index 2a00d2a..bfca277 100644 --- a/screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java +++ b/screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.moral.api.entity.*; @@ -24,6 +25,9 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.*; @@ -258,12 +262,46 @@ BeanUtils.copyProperties(specialDevice,insertSpecialDeviceHistory); if (ObjectUtils.isEmpty(specialDeviceHistory)){ specialDeviceHistoryMapper.insert(insertSpecialDeviceHistory); + //������������������ + HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); + StringBuilder content = new StringBuilder(); + content.append("������������������������������������").append(insertSpecialDeviceHistory.getName()).append(":").append("mac���").append(insertSpecialDeviceHistory.getMac()); + logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); }else { /*UpdateWrapper<SpecialDeviceHistory> wrapper_insertSpecialDeviceHistory = new UpdateWrapper<>(); wrapper_specialDeviceHistory.eq("is_delete",Constants.NOT_DELETE); wrapper_specialDeviceHistory.eq("mac",mac); wrapper_specialDeviceHistory.eq("organization_id",organizationId);*/ specialDeviceHistoryMapper.update(insertSpecialDeviceHistory,wrapper_specialDeviceHistory); + //������������������ + HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); + StringBuilder content = new StringBuilder(); + content.append("������������������������").append(specialDeviceHistory.getId()).append("���"); + Field[] fields = SpecialDevice.class.getDeclaredFields(); + for (Field field : fields) { + if (field.getName().equals("id")) { + continue; + } + if ("serialVersionUID".equals(field.getName())) { + continue; + } + String fieldName = field.getName(); + PropertyDescriptor pd = null; + try { + pd = new PropertyDescriptor(fieldName, SpecialDeviceHistory.class); + Method method = pd.getReadMethod(); + Object o1 = method.invoke(specialDeviceHistory); + Object o2 = method.invoke(insertSpecialDeviceHistory); + if (o2 != null) { + content.append(fieldName).append("���").append(o1).append("-->").append(o2).append(":"); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); } Map<String, Object> deviceInfo = selectDeviceInfoById(specialDevice.getId()); //��������������������������� @@ -284,6 +322,136 @@ resultMap.put("code", ResponseCodeEnum.SUCCESS.getCode()); resultMap.put("msg", ResponseCodeEnum.SUCCESS.getMsg()); return resultMap; + } + + @Transactional + @Override + public void update(SpecialDevice specialDevice) { + Integer specialDeviceId = specialDevice.getId(); + SpecialDevice oldSpecialDevice = specialDeviceMapper.selectById(specialDeviceId); + specialDeviceMapper.updateById(specialDevice); + SpecialDevice updateSpecialDevice = specialDeviceMapper.selectById(specialDeviceId); + String oleMac = oldSpecialDevice.getMac(); + //��������������������������� + Integer oldOrgId = oldSpecialDevice.getOrganizationId(); + Integer newOrgId = updateSpecialDevice.getOrganizationId(); + Integer oldVersionId = oldSpecialDevice.getDeviceVersionId(); + Integer newVersionId = updateSpecialDevice.getDeviceVersionId(); + if (!oldOrgId.equals(newOrgId) || !oldVersionId.equals(newVersionId)) { + deleteOrganizationUnitAlarm(oldOrgId, oldVersionId); + insertOrganizationUnitAlarm(newOrgId, newVersionId); + } + //���redis��������������������� + delDeviceInfoFromRedis(oleMac); + Map<String, Object> deviceInfo = selectDeviceInfoById(specialDeviceId); + //������������������redis + setDeviceInfoToRedis(updateSpecialDevice.getMac(), deviceInfo); + //������deviceInfo������ + CacheUtils.refreshSpecialDeviceAlarmInfo(); + QueryWrapper<SpecialDeviceHistory> wrapper_specialDeviceHistory = new QueryWrapper<>(); + wrapper_specialDeviceHistory.eq("is_delete",Constants.NOT_DELETE); + wrapper_specialDeviceHistory.eq("mac",updateSpecialDevice.getMac()); + wrapper_specialDeviceHistory.eq("organization_id",updateSpecialDevice.getOrganizationId()); + SpecialDeviceHistory specialDeviceHistory = specialDeviceHistoryMapper.selectOne(wrapper_specialDeviceHistory); + SpecialDeviceHistory updateSpecialDeviceHistory = new SpecialDeviceHistory(); + BeanUtils.copyProperties(updateSpecialDevice,updateSpecialDeviceHistory); + updateSpecialDeviceHistory.setCreateTime(null); + updateSpecialDeviceHistory.setUpdateTime(null); + updateSpecialDeviceHistory.setIsDelete(null); + if (ObjectUtils.isEmpty(specialDeviceHistory)){ + specialDeviceHistoryMapper.insert(updateSpecialDeviceHistory); + //������������������ + HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); + StringBuilder content = new StringBuilder(); + content.append("������������������������������������").append(updateSpecialDeviceHistory.getName()).append(":").append("mac���").append(updateSpecialDeviceHistory.getMac()); + logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); + }else { + /*UpdateWrapper<SpecialDeviceHistory> wrapper_insertSpecialDeviceHistory = new UpdateWrapper<>(); + wrapper_specialDeviceHistory.eq("is_delete",Constants.NOT_DELETE); + wrapper_specialDeviceHistory.eq("mac",mac); + wrapper_specialDeviceHistory.eq("organization_id",organizationId);*/ + specialDeviceHistoryMapper.update(updateSpecialDeviceHistory,wrapper_specialDeviceHistory); + //������������������ + HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); + StringBuilder content = new StringBuilder(); + content.append("������������������������").append(specialDeviceHistory.getId()).append("���"); + Field[] fields = SpecialDevice.class.getDeclaredFields(); + for (Field field : fields) { + if (field.getName().equals("id")) { + continue; + } + if ("serialVersionUID".equals(field.getName())) { + continue; + } + String fieldName = field.getName(); + PropertyDescriptor pd = null; + try { + pd = new PropertyDescriptor(fieldName, SpecialDeviceHistory.class); + Method method = pd.getReadMethod(); + Object o1 = method.invoke(specialDeviceHistory); + Object o2 = method.invoke(updateSpecialDeviceHistory); + if (o2 != null) { + content.append(fieldName).append("���").append(o1).append("-->").append(o2).append(":"); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); + } + //������������������ + HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); + StringBuilder content = new StringBuilder(); + content.append("������������������������").append(specialDeviceId).append("���"); + Field[] fields = SpecialDevice.class.getDeclaredFields(); + for (Field field : fields) { + if (field.getName().equals("id")) { + continue; + } + if ("serialVersionUID".equals(field.getName())) { + continue; + } + String fieldName = field.getName(); + PropertyDescriptor pd = null; + try { + pd = new PropertyDescriptor(fieldName, SpecialDevice.class); + Method method = pd.getReadMethod(); + Object o1 = method.invoke(oldSpecialDevice); + Object o2 = method.invoke(specialDevice); + if (o2 != null) { + content.append(fieldName).append("���").append(o1).append("-->").append(o2).append(":"); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); + } + + @Override + public void delete(Integer specialDeviceId) { + SpecialDevice specialDevice = specialDeviceMapper.selectById(specialDeviceId); + UpdateWrapper<SpecialDevice> updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("id",specialDeviceId).set("is_delete",Constants.DELETE); + specialDeviceMapper.update(null,updateWrapper); + String mac = specialDevice.getMac(); + //���redis��������������������� + delDeviceInfoFromRedis(mac); + //��������������������������� + Integer versionId = specialDevice.getDeviceVersionId(); + Integer orgId = specialDevice.getOrganizationId(); + deleteOrganizationUnitAlarm(orgId, versionId); + //������deviceInfo������ + CacheUtils.refreshDeviceAlarmInfo(); + //������������������ + HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); + StringBuilder content = new StringBuilder(); + content.append("������������������").append(specialDevice.getName()).append(";").append("mac���").append(mac); + logUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE); } @Override @@ -372,4 +540,20 @@ } } } + + private void deleteOrganizationUnitAlarm(Integer orgId, Integer versionId) { + QueryWrapper<SpecialDevice> queryOrganizationVersionWrapper = new QueryWrapper<>(); + queryOrganizationVersionWrapper.eq("organization_id", orgId); + queryOrganizationVersionWrapper.eq("device_version_id", versionId); + queryOrganizationVersionWrapper.eq("is_delete", Constants.NOT_DELETE); + List<SpecialDevice> specialDevices = specialDeviceMapper.selectList(queryOrganizationVersionWrapper); + if (org.springframework.util.ObjectUtils.isEmpty(specialDevices)) {//������������������������������������������������������ + UpdateWrapper deleteWrapper = new UpdateWrapper(); + deleteWrapper.eq("organization_id", orgId); + deleteWrapper.eq("version_id", versionId); + deleteWrapper.eq("is_delete", Constants.NOT_DELETE); + deleteWrapper.set("is_delete", Constants.DELETE); + organizationUnitAlarmMapper.update(null, deleteWrapper); + } + } } -- Gitblit v1.8.0