fengxiang
2018-08-14 120b501b7d42daf8b9432d84762feb8d730431b7
src/main/java/com/moral/controller/ScreenController.java
@@ -9,8 +9,9 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSONReader;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.*;
import com.moral.common.util.ParameterUtils;
import com.moral.common.util.StringUtils;
import com.moral.entity.*;
import com.moral.entity.alarm.AlarmConfig;
import com.moral.entity.alarm.AlarmConfigValue;
@@ -28,18 +29,9 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.xml.sax.InputSource;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.moral.common.bean.Constants;
import com.moral.common.bean.JsonData;
import com.moral.common.bean.PageResult;
@@ -58,9 +50,9 @@
 */
@RestController
@RequestMapping("/screen")
//@CrossOrigin(origins = "*", maxAge = 3600)
@CrossOrigin(origins = "*", maxAge = 3600)
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
@Api(tags = "Screen", description = "大屏相关")
@Api(tags = "Screen", description = "大屏接口")
public class ScreenController {
   public  static Logger log = Logger.getLogger(ScreenController.class);
    @Resource
@@ -110,6 +102,10 @@
   private OrganizationLayoutService orgLayoutService;
   @Resource
   private  DeviceVersionService dviceVersionService;
   @Resource
    private  OrganizationService organizationService;
   @Resource
    private  DictionaryDataService dictionaryDataService;
   /**
    * Screen login. 大屏登录
    * 
@@ -126,6 +122,30 @@
         resultMap.put("accountId", -1);
      } else {
         resultMap = accountService.screenLogin(parameters);
         // 添加返回行政区信息字符串操作
         Object orgId = resultMap.get("orgId");
         if(resultMap.get("orgId")!=null && resultMap.get("orgId") instanceof Integer) {
                StringBuilder areaNamesBuilder = new StringBuilder("中国");
                if((Integer) orgId != dictionaryDataService.querySupperOrgId()) {
                    Organization organization = organizationService.getOrganizationById((Integer) orgId);
                    if(organization.getAreaNames()!=null){
                        AreaNames areaNames =  organization.getAreaNames();
                        if(!StringUtils.isNullOrEmpty(areaNames.getProvinceName())){
                            areaNamesBuilder.append("/");
                            areaNamesBuilder.append(areaNames.getProvinceName());
                            if(!StringUtils.isNullOrEmpty(areaNames.getCityName())){
                                areaNamesBuilder.append("/");
                                areaNamesBuilder.append(areaNames.getCityName());
                                if(!StringUtils.isNullOrEmpty(areaNames.getAreaName())){
                                    areaNamesBuilder.append("/");
                                    areaNamesBuilder.append(areaNames.getAreaName());
                                }
                            }
                        }
                    }
                }
                resultMap.put("mapPath",areaNamesBuilder.toString());
            }
      }
      return resultMap;
   }
@@ -509,12 +529,10 @@
   @GetMapping("report_avg_datas")
   public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgData(HttpServletRequest request) throws Exception {
      Map<String, Object> parameters = getParametersStartingWith(request, null);
      parameters.put("type", "month");
      ParameterUtils.getTimeType4Time(parameters);
      parameters.put("monitorPointId", parameters.remove("monitorPoint"));
      String sensorKey = parameters.remove("sensorKey").toString();
      List<String> sensorKeys = new ArrayList<String>();
      sensorKeys.add(sensorKey);
      parameters.put("sensors", sensorKeys);
      Object sensorKey = parameters.remove("sensorKey");
      parameters.put("sensors", Arrays.asList(sensorKey));
      List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
      
      for (Map<String, Object> map : list) {
@@ -594,12 +612,14 @@
             DeviceVersion deviceVersion = deviceVersionService.queryVersionById(device.getDeviceVersionId());
              rtdLayout = orgLayoutService.queryRtdLayoutWithUnit(orgId,deviceVersion.getVersion());
         }else {
            return  ResultBean.fail();
            String errMsg = "device 数据异常:"+ JSON.toJSONString(device);
            log.warn(errMsg);
            return  ResultBean.fail(errMsg);
         }
      } else {
         MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(Integer.parseInt(primaryKey));
         List<DeviceVersion> versionList = deviceVersionService.queryByOrgId(monitorPoint.getOrganizationId());
         List<DeviceVersion> versionList = deviceVersionService.queryByMpointId(monitorPoint.getId());
         if(versionList.size() > 0) {
         List<Integer> versionNolist =   versionList.stream().map(item -> {
               return  item.getVersion();
@@ -626,7 +646,7 @@
   })
   public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgDataBySensorKey(HttpServletRequest request) throws Exception {
      Map<String, Object> parameters = getParametersStartingWith(request, null);
      parameters.put("type", "month");
      ParameterUtils.getTimeType4Time(parameters);
      parameters.put("monitorPointId", parameters.remove("monitorPoint"));
      String[] sensorKeys = parameters.remove("sensorKey").toString().split(",");
      parameters.put("sensors", Arrays.asList(sensorKeys));
@@ -636,8 +656,21 @@
         String time = map.get("time").toString();
         time = time.substring(time.length() - 2);
         map.put("time", Integer.valueOf(time));
         List<Number> values = new ArrayList<Number>();
         for (String string : sensorKeys) {
            values.add((Number) map.remove(string));
         }
         map.put("values", values);
      }
      return new ResultBean<List<Map<String, Object>>>(list);
   }
   @GetMapping("getmpoint-byid")
   @ApiOperation(value = "获取监测站数据", notes = "获取监测站数据,保证名称坐标等等")
   @ApiImplicitParams(value = {
         @ApiImplicitParam(name = "monitorPointId",defaultValue = "1",value = "监控站id", required = true, paramType = "query", dataType = "Integer"),
   })
    public ResultBean<MonitorPoint> getMonitorPointById(Integer monitorPointId){
      MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId);
      return new ResultBean<>(monitorPoint);
   }
}