| | |
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
|
| | | import org.apache.commons.collections.CollectionUtils;
|
| | | import org.apache.commons.collections.MapUtils;
|
| | | import org.apache.commons.collections4.CollectionUtils;
|
| | | import org.apache.commons.collections4.MapUtils;
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | | import org.apache.commons.lang.time.DateUtils;
|
| | | import org.apache.commons.lang3.time.DateUtils;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
| | | import com.moral.monitor.entity.AccountEntityExample;
|
| | | import com.moral.monitor.service.OrganizationService;
|
| | | import com.moral.monitor.service.ScreenService;
|
| | | import com.moral.monitor.util.BusinessException;
|
| | | import com.moral.monitor.util.ResourceUtil;
|
| | |
|
| | | @Service
|
| | |
| | | return accountMapper.selectByExample(example);
|
| | | }
|
| | |
|
| | | @SuppressWarnings("deprecation")
|
| | | public Map<String, Object> getMonthDataByEquipment(Map<String, Object> parameters) {
|
| | | Map<String, Object> resultMap = new HashMap<String, Object>();
|
| | | Date date = new Date();
|
| | |
|
| | | /** 临时代码 以保证查询有数据 **/
|
| | | date.setMonth(6);
|
| | | int day = date.getDate();
|
| | | if (day < 13) {
|
| | | day = 31 - day;
|
| | | }else if (day < 19) {
|
| | | day += 10;
|
| | | }else if (day > 29) {
|
| | | day -= 10;
|
| | | //每月一日的数据取上月的数据
|
| | | if (1 == Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) {
|
| | | parameters.put("start", DateUtils.truncate(DateUtils.addMonths(date, -1), Calendar.MONTH));
|
| | | }
|
| | | date.setDate(day);
|
| | | /** 临时代码 结束 **/
|
| | |
|
| | | parameters.put("start", DateUtils.truncate(date, Calendar.MONTH));
|
| | | parameters.put("end", DateUtils.truncate(date, Calendar.DATE));
|
| | |
|
| | | //每月一日的数据取上月的数据
|
| | | /*if (1 == Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) {
|
| | | date = DateUtils.setMonths(date, -1);
|
| | | parameters.put("end", DateUtils.ceiling(date, Calendar.MONTH));
|
| | | }*/
|
| | | parameters.put("start", DateUtils.truncate(date, Calendar.MONTH));
|
| | | //
|
| | | parameters.put("mac", "898602b8191630065884");
|
| | | parameters.put("macKey", "e1");
|
| | | Map<String, Object> average = historyMapper.getMonthAverageBySensor(parameters);
|
| | |
| | | if (MapUtils.isNotEmpty(average)) {
|
| | | resultMap.putAll(average);
|
| | | } else {
|
| | | resultMap.put("average", 0);
|
| | | resultMap.put("average", 90.0384 + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) / 5);
|
| | | }
|
| | |
|
| | | //AQI 指数
|
| | |
| | | }
|
| | | double minIAQI = Double.valueOf(IAQIValues[index]);
|
| | | double maxIAQI = Double.valueOf(IAQIValues[index + 1]);
|
| | | |
| | | IAQIs.add(calculateIAQI(maxIAQI, minIAQI, maxMacKey, minMacKey, avg));
|
| | | }
|
| | | if (!resultMap.containsKey("AQI")) {
|
| | |
| | | }
|
| | |
|
| | | //实际标准值
|
| | | String standard = ResourceUtil.getValue(parameters.get("macKey")+"-standard");
|
| | | if (StringUtils.isBlank(standard)) {
|
| | | standard = "50";
|
| | | }
|
| | | resultMap.put("standard", standard);
|
| | | resultMap.put("standard", ResourceUtil.getValue(parameters.get("macKey")+"-standard"));
|
| | | return resultMap;
|
| | | }
|
| | |
|
| | | @SuppressWarnings("deprecation")
|
| | | public Map<String, Object> getAverageByAll(Map<String, Object> parameters) {
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | |
|
| | | setOrgIdsByAccount(parameters);
|
| | |
|
| | | Date date = new Date();
|
| | | |
| | | /** 临时代码 以保证查询有数据 **/
|
| | | date.setMonth(6);
|
| | | int day = date.getDate();
|
| | | if (day < 19 || day > 29) {
|
| | | day = (int) Math.floor(Math.random() * (29 - 19 + 1) + 19);
|
| | | date.setDate(day);
|
| | | }
|
| | | /** 临时代码 结束 **/
|
| | |
|
| | | parameters.put("start", DateUtils.addMinutes(date, -10));
|
| | | parameters.put("end", DateUtils.addMinutes(date, -5));
|
| | | List<Map<String, Object>> averageByAll = historyMapper.getAverageByAll(parameters);
|
| | |
| | | }
|
| | |
|
| | | public void setOrgIdsByAccount(Map<String, Object> parameters) {
|
| | | String accountId = ObjectUtils.nullSafeToString(parameters.get("accountId"));
|
| | | if (!StringUtils.isNumeric(accountId) ) {
|
| | | return;
|
| | | String accountId = (String) parameters.get("accountId");
|
| | | if (!StringUtils.isNumeric((String)parameters.get("accountId")) ) {
|
| | | throw new BusinessException("accountId 参数不合法!");
|
| | | }
|
| | |
|
| | | AccountEntity account = accountMapper.selectByPrimaryKey((Integer.valueOf(accountId)));
|
| | | if (ObjectUtils.isEmpty(account)) {
|
| | | return;
|
| | | throw new BusinessException(accountId +"该账号不存在!");
|
| | | }
|
| | | String organization = account.getOrganization();
|
| | | //不是摩瑞尔账号的需要根据组织来获取数据权限
|