| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.moral.api.entity.MonitorPoint; |
| | | import com.moral.api.entity.Organization; |
| | |
| | | Page<MonitorPoint> page = new Page(current,size); |
| | | QueryWrapper<MonitorPoint> wrapper = new QueryWrapper(); |
| | | wrapper.eq("is_delete",0); |
| | | int totalNumber = monitorPointMapper.selectCount(wrapper); |
| | | String orderType = map.get("orderType").toString(); |
| | | if (orderType.equals(Constants.ORDER_ASC)){ |
| | | wrapper.orderByAsc("create_time"); |
| | |
| | | monitorPointMap.put("key",monitorPoint.getId()); |
| | | monitorPointtList.add(monitorPointMap); |
| | | } |
| | | resultMap.put("manageRoles",monitorPointtList); |
| | | int totalNumber = monitorPoints.size(); |
| | | resultMap.put("monitorPoints",monitorPointtList); |
| | | resultMap.put("totalNumber",totalNumber); |
| | | resultMap.put("current",current); |
| | | int totalPageNumber = totalNumber/size; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String, Object> updateMonitorPoint(Map<String,Object> updateMap) { |
| | | Map resultMap = new HashMap(); |
| | | if(!updateMap.containsKey("id")){ |
| | |
| | | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | return resultMap; |
| | | } |
| | | if (updateMap.containsKey("name")){ |
| | | if (updateMap.get("name")==null||updateMap.get("name")==""){ |
| | | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | return resultMap; |
| | | } |
| | | QueryWrapper<MonitorPoint> wapper_name = new QueryWrapper<>(); |
| | | wapper_name.eq("name",updateMap.get("name")); |
| | | wapper_name.eq("is_delete",Constants.NOT_DELETE); |
| | | MonitorPoint monitorPoint_name = monitorPointMapper.selectOne(wapper_name); |
| | | if(monitorPoint_name!=null&&!monitorPoint_name.getId().equals(updateMap.get("id"))){ |
| | | resultMap.put("code",ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getMsg()); |
| | | return resultMap; |
| | | } |
| | | } |
| | | QueryWrapper<MonitorPoint> wapper_id = new QueryWrapper<>(); |
| | | wapper_id.eq("id",updateMap.get("id")); |
| | | wapper_id.eq("is_delete",Constants.NOT_DELETE); |
| | | monitorPointMapper.selectOne(wapper_id); |
| | | return null; |
| | | MonitorPoint oldMonitorPoint = monitorPointMapper.selectOne(wapper_id); |
| | | if (oldMonitorPoint==null){ |
| | | resultMap.put("code",ResponseCodeEnum.MONITOR_POINT_IS_NOT_EXIST.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.MONITOR_POINT_IS_NOT_EXIST.getMsg()); |
| | | return resultMap; |
| | | } |
| | | if (updateMap.get("name")==null||updateMap.get("name")==""){ |
| | | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | return resultMap; |
| | | } |
| | | QueryWrapper<MonitorPoint> wapper_name = new QueryWrapper<>(); |
| | | wapper_name.eq("name",updateMap.get("name")); |
| | | wapper_name.eq("is_delete",Constants.NOT_DELETE); |
| | | MonitorPoint monitorPoint_name = monitorPointMapper.selectOne(wapper_name); |
| | | if(monitorPoint_name!=null&&!monitorPoint_name.getId().toString().equals(updateMap.get("id").toString())){ |
| | | resultMap.put("code",ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getMsg()); |
| | | return resultMap; |
| | | } |
| | | monitorPointMapper.updateMonitorPoint(updateMap); |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | String content = "修改了站点:"+oldMonitorPoint.getName()+";"; |
| | | for (Object key:updateMap.keySet()) { |
| | | if (key.toString().equals("name")){ |
| | | content = content+"站点名称:"+oldMonitorPoint.getName()+"->"+updateMap.get(key)+";"; |
| | | } |
| | | if (key.toString().equals("longitude")){ |
| | | content = content+"经度:"+oldMonitorPoint.getLongitude()+"->"+updateMap.get(key)+";"; |
| | | } |
| | | if (key.toString().equals("latitude")){ |
| | | content = content+"纬度:"+oldMonitorPoint.getLatitude()+"->"+updateMap.get(key)+";"; |
| | | } |
| | | if (key.toString().equals("province_code")){ |
| | | content = content+"省份编码:"+oldMonitorPoint.getProvinceCode()+"->"+updateMap.get(key)+";"; |
| | | } |
| | | if (key.toString().equals("city_code")){ |
| | | content = content+"地级市编码:"+oldMonitorPoint.getCityCode()+"->"+updateMap.get(key)+";"; |
| | | } |
| | | if (key.toString().equals("area_code")){ |
| | | content = content+"县/区/县级市:"+oldMonitorPoint.getAreaCode()+"->"+updateMap.get(key)+";"; |
| | | } |
| | | if (key.toString().equals("address")){ |
| | | content = content+"地址:"+oldMonitorPoint.getAddress()+"->"+updateMap.get(key)+";"; |
| | | } |
| | | if (key.toString().equals("organization_id")){ |
| | | content = content+"组织id:"+oldMonitorPoint.getOrganizationId()+"->"+updateMap.get(key)+";"; |
| | | } |
| | | if (key.toString().equals("desc")){ |
| | | content = content+"描述:"+oldMonitorPoint.getDesc()+"->"+updateMap.get(key)+";"; |
| | | } |
| | | } |
| | | logUtils.saveOperationForManage(request,content,Constants.UPDATE_OPERATE_TYPE); |
| | | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); |
| | | return resultMap; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String, Object> deleteMonitorPoint(Map map) { |
| | | Map resultMap = new HashMap(); |
| | | QueryWrapper<MonitorPoint> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("id",map.get("id")); |
| | | wrapper.eq("is_delete","0"); |
| | | MonitorPoint monitorPoint = monitorPointMapper.selectOne(wrapper); |
| | | if(ObjectUtils.isEmpty(monitorPoint)){ |
| | | resultMap.put("code",ResponseCodeEnum.MONITOR_POINT_IS_NOT_EXIST.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.MONITOR_POINT_IS_NOT_EXIST.getMsg()); |
| | | return resultMap; |
| | | } |
| | | MonitorPoint deleteMonitorPoint = new MonitorPoint(); |
| | | deleteMonitorPoint.setIsDelete("1"); |
| | | monitorPointMapper.update(deleteMonitorPoint,wrapper); |
| | | //操作插入日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | String content = "删除了站点:"+monitorPoint.getName()+";"; |
| | | logUtils.saveOperationForManage(request,content,Constants.DELETE_OPERATE_TYPE); |
| | | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); |
| | | return resultMap; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getMonitorPointByFuzzy(Map map) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | if (!map.containsKey("current")||!map.containsKey("size")||!map.containsKey("orderType")){ |
| | | 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<MonitorPoint> page = new Page(current,size); |
| | | QueryWrapper<MonitorPoint> wrapper = new QueryWrapper(); |
| | | wrapper.eq("is_delete",0); |
| | | if (map.containsKey("organization_id")){ |
| | | String organization_id = ""; |
| | | organization_id = map.get("organization_id").toString(); |
| | | wrapper.eq("organization_id",organization_id); |
| | | } |
| | | if (map.containsKey("name")){ |
| | | String name = ""; |
| | | name = map.get("name").toString(); |
| | | wrapper.like("name",name); |
| | | } |
| | | int totalNumber = monitorPointMapper.selectCount(wrapper); |
| | | String orderType = map.get("orderType").toString(); |
| | | if (orderType.equals(Constants.ORDER_ASC)){ |
| | | wrapper.orderByAsc("create_time"); |
| | | }else { |
| | | wrapper.orderByDesc("create_time"); |
| | | } |
| | | Page resultPage = monitorPointMapper.selectPage(page,wrapper); |
| | | List<MonitorPoint> monitorPoints = resultPage.getRecords(); |
| | | SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | List<Map<String,Object>> monitorPointtList = new ArrayList<>(); |
| | | for (MonitorPoint monitorPoint:monitorPoints) { |
| | | Map monitorPointMap = JSON.parseObject(JSON.toJSONString(monitorPoint),Map.class); |
| | | String createTime = SDF.format(monitorPoint.getCreateTime()); |
| | | String updateTime = SDF.format(monitorPoint.getUpdateTime()); |
| | | monitorPointMap.put("createTime",createTime); |
| | | monitorPointMap.put("updateTime",updateTime); |
| | | monitorPointMap.put("key",monitorPoint.getId()); |
| | | monitorPointtList.add(monitorPointMap); |
| | | } |
| | | resultMap.put("monitorPoints",monitorPointtList); |
| | | resultMap.put("totalNumber",totalNumber); |
| | | resultMap.put("current",current); |
| | | int totalPageNumber = totalNumber/size; |
| | | if(totalNumber%size != 0){ |
| | | totalPageNumber += 1; |
| | | } |
| | | resultMap.put("totalPageNumber",totalPageNumber); |
| | | return resultMap; |
| | | } |
| | | } |