| package com.moral.api.service.impl; | 
|   | 
| 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 com.moral.api.mapper.*; | 
| import com.moral.api.service.SpecialDeviceHistoryService; | 
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
| import com.moral.api.util.LogUtils; | 
| import com.moral.constant.Constants; | 
| import com.moral.constant.ResponseCodeEnum; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.web.context.request.RequestContextHolder; | 
| import org.springframework.web.context.request.ServletRequestAttributes; | 
|   | 
| import javax.servlet.http.HttpServletRequest; | 
| import java.text.SimpleDateFormat; | 
| import java.util.*; | 
|   | 
| /** | 
|  * <p> | 
|  *  服务实现类 | 
|  * </p> | 
|  * | 
|  * @author moral | 
|  * @since 2021-08-11 | 
|  */ | 
| @Service | 
| public class SpecialDeviceHistoryServiceImpl extends ServiceImpl<SpecialDeviceHistoryMapper, SpecialDeviceHistory> implements SpecialDeviceHistoryService { | 
|   | 
|     @Autowired(required = false) | 
|     private SpecialDeviceHistoryMapper specialDeviceHistoryMapper; | 
|   | 
|     @Autowired(required = false) | 
|     private ManageAccountMapper manageAccountMapper; | 
|   | 
|     @Autowired(required = false) | 
|     private VersionMapper versionMapper; | 
|   | 
|     @Autowired(required = false) | 
|     private SysDictDataMapper sysDictDataMapper; | 
|   | 
|     @Autowired(required = false) | 
|     private OrganizationMapper organizationMapper; | 
|   | 
|     @Autowired(required = false) | 
|     private GovMonitorPointMapper govMonitorPointMapper; | 
|   | 
|   | 
|     @Override | 
|     public Map<String, Object> getDataByCondition(Map map) { | 
|         Map<String,Object> resultMap = new HashMap<>(); | 
|         if (!map.containsKey("current")||!map.containsKey("size")){ | 
|             resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|             resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|             return resultMap; | 
|         } | 
|         int current = Integer.parseInt(map.get("current").toString()); | 
|         int size = Integer.parseInt(map.get("size").toString()); | 
|         Page<SpecialDeviceHistory> page = new Page<>(current,size); | 
|         QueryWrapper<SpecialDeviceHistory> wrapper_Condition = new QueryWrapper<>(); | 
|         wrapper_Condition.eq("is_delete",Constants.NOT_DELETE); | 
|         if (!ObjectUtils.isEmpty(map.get("organization_id"))){ | 
|             wrapper_Condition.eq("organization_id",map.get("organization_id").toString()); | 
|         } | 
|         if (!ObjectUtils.isEmpty(map.get("keyword"))){ | 
|             wrapper_Condition.and(wc -> wc.like("name",map.get("keyword").toString()).or().like("mac",map.get("keyword").toString())); | 
|             //wrapper_Condition.like("name",map.get("keyword").toString()).or().like("mac",map.get("keyword").toString()); | 
|         } | 
|         wrapper_Condition.orderByDesc("create_time"); | 
|         Page resultPage = specialDeviceHistoryMapper.selectPage(page,wrapper_Condition); | 
|         int totalNumber = specialDeviceHistoryMapper.selectCount(wrapper_Condition); | 
|         List<SpecialDeviceHistory> specialDeviceHistories = resultPage.getRecords(); | 
|         SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|         List<Map<String,Object>> specialDeviceList = new ArrayList<>(); | 
|         for (SpecialDeviceHistory specialDeviceHistory:specialDeviceHistories) { | 
|             Map specialDeviceHistoryMap = JSON.parseObject(JSON.toJSONString(specialDeviceHistory),Map.class); | 
|             String createTime = SDF.format(specialDeviceHistory.getCreateTime()); | 
|             String updateTime = SDF.format(specialDeviceHistory.getUpdateTime()); | 
|             specialDeviceHistoryMap.put("createTime",createTime); | 
|             specialDeviceHistoryMap.put("updateTime",updateTime); | 
|             Map<String,Object> govMonitorPointMap = new HashMap<>(); | 
|             if (!ObjectUtils.isEmpty(specialDeviceHistory.getGuid()) && specialDeviceHistory.getGuid()!=null && !"".equals(specialDeviceHistory.getGuid())){ | 
|                 String  guid = specialDeviceHistory.getGuid().toString(); | 
|                 QueryWrapper<GovMonitorPoint> wapper_govMonitorPoint = new QueryWrapper<>(); | 
|                 wapper_govMonitorPoint.eq("is_delete",Constants.NOT_DELETE); | 
|                 wapper_govMonitorPoint.eq("guid",guid); | 
|                 GovMonitorPoint govMonitorPoint = govMonitorPointMapper.selectOne(wapper_govMonitorPoint); | 
|                 if (!ObjectUtils.isEmpty(govMonitorPoint)){ | 
|                     govMonitorPointMap.put("id",govMonitorPoint.getId()); | 
|                     govMonitorPointMap.put("guid",govMonitorPoint.getGuid()); | 
|                     govMonitorPointMap.put("name",govMonitorPoint.getName()); | 
|                 } | 
|             } | 
|             specialDeviceHistoryMap.put("govMonitorPoint",govMonitorPointMap); | 
|             List<Map<String,Object>> operateList = new ArrayList<>(); | 
|             if (!ObjectUtils.isEmpty(specialDeviceHistory.getOperateIds()) && specialDeviceHistory.getOperateIds()!=null){ | 
|                 String operateIds = specialDeviceHistory.getOperateIds(); | 
|                 String[] operateIdArr = operateIds.split(","); | 
|                 if (operateIdArr.length>0){ | 
|                     List<Integer> operateIdList = new ArrayList<>(); | 
|                     for (int i = 0; i < operateIdArr.length; i++){ | 
|                         operateIdList.add(Integer.parseInt(operateIdArr[i])); | 
|                     } | 
|                     QueryWrapper<ManageAccount> wapper_manageAccount = new QueryWrapper<>(); | 
|                     wapper_manageAccount.eq("is_delete",Constants.NOT_DELETE); | 
|                     wapper_manageAccount.in("id",operateIdList); | 
|                     wapper_manageAccount.select("id", "user_name"); | 
|                     List<ManageAccount> manageAccounts = manageAccountMapper.selectList(wapper_manageAccount); | 
|                     for (ManageAccount manageAccount:manageAccounts) { | 
|                         Map<String,Object> operateMap = new HashMap<>(); | 
|                         operateMap.put("id",manageAccount.getId()); | 
|                         operateMap.put("name",manageAccount.getUserName()); | 
|                         operateList.add(operateMap); | 
|                     } | 
|                 } | 
|             } | 
|             specialDeviceHistoryMap.put("operates",operateList); | 
|             Map<String,Object> deviceVersionMap = new HashMap<>(); | 
|             if (!ObjectUtils.isEmpty(specialDeviceHistory.getDeviceVersionId()) && specialDeviceHistory.getDeviceVersionId()!=null && !"".equals(specialDeviceHistory.getDeviceVersionId())){ | 
|                 int versionId = Integer.parseInt(specialDeviceHistory.getDeviceVersionId().toString()); | 
|                 QueryWrapper<Version> wapper_version = new QueryWrapper<>(); | 
|                 wapper_version.eq("is_delete",Constants.NOT_DELETE); | 
|                 wapper_version.eq("id",versionId); | 
|                 Version version = versionMapper.selectOne(wapper_version); | 
|                 if (!ObjectUtils.isEmpty(version)){ | 
|                     deviceVersionMap.put("id",version.getId()); | 
|                     deviceVersionMap.put("name",version.getName()); | 
|                 } | 
|             } | 
|             specialDeviceHistoryMap.put("version",deviceVersionMap); | 
|             Map<String,Object> specialTypeMap = new HashMap<>(); | 
|             if (!ObjectUtils.isEmpty(specialDeviceHistory.getSpecialType()) && specialDeviceHistory.getSpecialType()!=null && !"".equals(specialDeviceHistory.getSpecialType())){ | 
|                 int specialTypeId = Integer.parseInt(specialDeviceHistory.getSpecialType().toString()); | 
|                 QueryWrapper<SysDictData> wapper_sysDictData = new QueryWrapper<>(); | 
|                 wapper_sysDictData.eq("is_delete",Constants.NOT_DELETE); | 
|                 wapper_sysDictData.eq("dict_type_id",27); | 
|                 wapper_sysDictData.eq("dataKey",specialTypeId); | 
|                 SysDictData sysDictData = sysDictDataMapper.selectOne(wapper_sysDictData); | 
|                 if (!ObjectUtils.isEmpty(sysDictData)){ | 
|                     specialTypeMap.put("id",sysDictData.getId()); | 
|                     specialTypeMap.put("dataKey",sysDictData.getDataKey()); | 
|                     specialTypeMap.put("name",sysDictData.getDataValue()); | 
|                 } | 
|             } | 
|             specialDeviceHistoryMap.put("specialType",specialTypeMap); | 
|             Map<String,Object> organizationMap = new HashMap<>(); | 
|             if (!ObjectUtils.isEmpty(specialDeviceHistory.getOrganizationId()) && specialDeviceHistory.getOrganizationId()!=null && !"".equals(specialDeviceHistory.getOrganizationId())){ | 
|                 int organizationId = Integer.parseInt(specialDeviceHistory.getOrganizationId().toString()); | 
|                 QueryWrapper<Organization> wapper_organization = new QueryWrapper<>(); | 
|                 wapper_organization.eq("is_delete",Constants.NOT_DELETE); | 
|                 wapper_organization.eq("id",organizationId); | 
|                 Organization organization = organizationMapper.selectOne(wapper_organization); | 
|                 if (!ObjectUtils.isEmpty(organization)){ | 
|                     organizationMap.put("id",organization.getId()); | 
|                     organizationMap.put("name",organization.getName()); | 
|                 } | 
|             } | 
|             specialDeviceHistoryMap.put("organization",organizationMap); | 
|             specialDeviceList.add(specialDeviceHistoryMap); | 
|         } | 
|         resultMap.put("specialDevices",specialDeviceList); | 
|         resultMap.put("totalNumber",totalNumber); | 
|         resultMap.put("current",current); | 
|         int totalPageNumber = totalNumber/size; | 
|         if(totalNumber%size != 0){ | 
|             totalPageNumber += 1; | 
|         } | 
|         resultMap.put("totalPageNumber",totalPageNumber); | 
|         return resultMap; | 
|     } | 
|   | 
|     @Override | 
|     public void delete(Integer specialDeviceHistoryId) { | 
|         SpecialDeviceHistory specialDeviceHistory = specialDeviceHistoryMapper.selectById(specialDeviceHistoryId); | 
|         UpdateWrapper<SpecialDeviceHistory> updateWrapper = new UpdateWrapper<>(); | 
|         updateWrapper.eq("id",specialDeviceHistoryId).set("is_delete",Constants.DELETE); | 
|         specialDeviceHistoryMapper.update(null,updateWrapper); | 
|         String mac = specialDeviceHistory.getMac(); | 
|         //操作日志记录 | 
|         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|         StringBuilder content = new StringBuilder(); | 
|         content.append("删除了历史特殊设备:").append(specialDeviceHistory.getName()).append(";").append("mac:").append(mac); | 
|         LogUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE); | 
|     } | 
| } |