SectionServiceImpl.java 3.03 KB
package com.bsth.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Section;
import com.bsth.repository.SectionRepository;
import com.bsth.service.SectionService;

/**
 * 
 * @ClassName: SectionServiceImpl(路段service业务层实现类)
 * 
 * @Extends : BaseService
 * 
 * @Description: TODO(路段service业务层)
 * 
 * @Author bsth@lq
 * 
 * @Date 2016年05月03日 上午9:21:17
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */

@Service
public class SectionServiceImpl extends BaseServiceImpl<Section, Integer> implements SectionService{
	
	@Autowired
	SectionRepository repository;
	
	@Override
	public Map<String, Object> sectionUpdate(Map<String, Object> map) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
			
			Integer sectionId = map.get("sectionId").equals("") ? 0 : Integer.parseInt(map.get("sectionId").toString());
			
			// 路段信息字符串
			String sectionJSON = map.get("sectionJSON").toString().equals("")  ? "" : map.get("sectionJSON").toString();
			
			// 如果路段信息JSON字符串不为空
			if(!sectionJSON.equals("")) {
				

				// 转换成JSON数组
				JSONArray sectionsArray = JSONArray.parseArray(sectionJSON);
				
				// 原始线状图形坐标集合
				String sectionsBpoints = "";
				
				// WGS线状图形坐标集合
				String sectionsWJPpoints = "";
				
				// 遍历
				for(int s = 0 ;s<sectionsArray.size();s++) {
					
					String pointsLngStr = sectionsArray.getJSONObject(s).get("lng").toString();
					
					String pointsLatStr = sectionsArray.getJSONObject(s).get("lat").toString();
					
					String WGSLngStr = JSONObject.parseObject(sectionsArray.getJSONObject(s).get("WGSpotion").toString()).get("Lng").toString();
					
					String WGSLatStr = JSONObject.parseObject(sectionsArray.getJSONObject(s).get("WGSpotion").toString()).get("Lat").toString();
					
					if(s==0) {
						
						sectionsBpoints = pointsLngStr + " " + pointsLatStr;
						
						sectionsWJPpoints = WGSLngStr + " " + WGSLatStr;
						
					}else {
						
						sectionsBpoints = sectionsBpoints + "," +  pointsLngStr + " " + pointsLatStr;
						
						sectionsWJPpoints = sectionsWJPpoints + ","  +   WGSLngStr + " " + WGSLatStr;
						
					}
					
					
				}
				
				// WGS坐标点集合
				String gsectionVector = "LINESTRING(" + sectionsWJPpoints +")";
				
				// 原坐标点集合
				String bsectionVector = "LINESTRING(" + sectionsBpoints + ")";
				repository.sectionUpdate(sectionId, gsectionVector, bsectionVector);
			}
			
			resultMap.put("status", ResponseCode.SUCCESS);
			
		} catch (Exception e) {

			resultMap.put("status", ResponseCode.ERROR);
			
			logger.error("save erro.", e);
			
		}
		
		return resultMap;
	}

}