| | |
| | | |
| | | 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.*; |
| | |
| | | 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.*; |
| | | |
| | |
| | | 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()); |
| | | //维护组织型号关系表 |
| | |
| | | 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 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | } |