4 files added
9 files modified
| | |
| | | public static final int NO_PERMISSION = 2;
|
| | | private String message;
|
| | | private Integer code;
|
| | | private Integer errno;
|
| | | private T data;
|
| | |
|
| | | public ResultBean() {
|
| | |
| | | public ResultBean(Throwable e) {
|
| | | this.message = e.toString();
|
| | | this.code = FAIL;
|
| | | this.errno = 1;
|
| | | }
|
| | |
|
| | | public ResultBean(T data) {
|
| | | this.message = "success";
|
| | | this.code = SUCCESS;
|
| | | this.data = data;
|
| | | this.errno = 0;
|
| | | }
|
| | |
|
| | | public ResultBean(String message, int code) {
|
| | |
| | | package com.moral.common.util;
|
| | |
|
| | | import java.text.ParseException;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.commons.lang3.time.DateUtils;
|
| | |
|
| | | public class ParameterUtils {
|
| | |
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | public static void getStartAndEndByTime(Map<String, Object> parameters) throws ParseException {
|
| | | String time = (String) parameters.get("time");
|
| | | String format = (String) parameters.get("format");
|
| | | Integer field = Integer.valueOf(parameters.get("field").toString());
|
| | | Date start = DateUtils.parseDate(time, format);
|
| | |
|
| | | Calendar instance = Calendar.getInstance();
|
| | | instance.setTime(start);
|
| | | instance.add(field, 1);
|
| | | Date end = instance.getTime();
|
| | |
|
| | | parameters.put("start", start);
|
| | | parameters.put("end", end);
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | import org.springframework.cglib.beans.BeanMap;
|
| | | import org.springframework.web.bind.annotation.CrossOrigin;
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.PostMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestParam;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | |
| | | */
|
| | | @RequestMapping("reportDevice")
|
| | | public AppData<String> installDevice(EquDeviceAdapter equDeviceAdapter) {
|
| | | deviceService.addOrModify(equDeviceAdapter.toDevice());
|
| | | //deviceService.addOrModify(equDeviceAdapter.toDevice());
|
| | | deviceService.saveOrUpdate4Mobile(equDeviceAdapter.toDevice(), equDeviceAdapter.getDeviceProperty());
|
| | | return new AppData<String>("");
|
| | | }
|
| | |
|
| | |
| | | return new ResultBean<List<Map<String, Object>>>(sensors);
|
| | | }
|
| | |
|
| | | @RequestMapping("profession-provincecode")
|
| | | @GetMapping("profession-provincecode")
|
| | | @ApiOperation(value = "根据省code返回行业数据", notes = "根据省code返回行业数据")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "provinceCode", value = "省code", required = true, paramType = "query", dataType = "String")
|
| | | })
|
| | | public ResultBean<List<Profession>> getProfessionByProvinceCode(HttpServletRequest request){
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | List<Profession> professions = professionService.getProfessiontList(parameters);
|
| | | return new ResultBean<List<Profession>>(professions);
|
| | | }
|
| | |
|
| | | @PostMapping("update-maintenance")
|
| | | @ApiOperation(value = "设备状态从离线更新为维保", notes = "设备状态从离线更新为维保")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "id", value = "设备ID", required = true, paramType = "query", dataType = "int") ,
|
| | | @ApiImplicitParam(name = "old_state", value = "旧的设备状态", required = true, paramType = "query", dataType = "String"),
|
| | | @ApiImplicitParam(name = "new_state", value = "新的设备状态", required = true, paramType = "query", dataType = "String") |
| | | |
| | | })
|
| | | public ResultBean offLinToMaintenance(HttpServletRequest request) {
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | deviceService.offLinToMaintenance(parameters);
|
| | | ResultBean resultBean = new ResultBean(parameters);
|
| | | return resultBean;
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | import org.springframework.web.bind.annotation.RestController;
|
| | |
|
| | | import com.moral.common.bean.ResultBean;
|
| | | import com.moral.common.util.WebUtils;
|
| | | import com.moral.entity.charts.LineChartCriteria;
|
| | | import com.moral.security.auth.JwtAuthenticationToken;
|
| | | import com.moral.security.model.UserContext;
|
| | | import com.moral.service.AlarmDailyService;
|
| | | import com.moral.service.HistoryDailyService;
|
| | | import com.moral.service.HistoryMinutelyService;
|
| | |
|
| | | @SuppressWarnings({ "unchecked", "rawtypes" })
|
| | |
| | | return new ResultBean<List<Map<String, Object>>>(result);
|
| | | }
|
| | |
|
| | | @Resource
|
| | | private HistoryDailyService historyDailyService;
|
| | | |
| | | @GetMapping("emissions")
|
| | | public ResultBean<List<Map<String, Object>>> getemissionsData(HttpServletRequest request, JwtAuthenticationToken token) throws Exception {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | UserContext userContext = token.getPrincipal();
|
| | | Integer orgId = userContext.getOrganizationId();
|
| | | parameters.put("orgId", orgId);
|
| | | List<Map<String, Object>> result = historyDailyService.getEmissionsData(parameters);
|
| | | return new ResultBean<List<Map<String, Object>>>(result);
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | package com.moral.entity.adapter; |
| | | |
| | | import com.moral.entity.Device; |
| | | import lombok.AccessLevel; |
| | | import lombok.Data; |
| | | import lombok.Getter; |
| | | import lombok.Setter; |
| | | |
| | | import javax.persistence.Transient; |
| | | |
| | | import static lombok.AccessLevel.*; |
| | | import com.moral.entity.DeviceProperty; |
| | | |
| | | public class EquDeviceAdapter { |
| | | private Device device; |
| | | public EquDeviceAdapter(){ |
| | | |
| | | private DeviceProperty deviceProperty; |
| | | |
| | | |
| | | public DeviceProperty getDeviceProperty() { |
| | | return deviceProperty; |
| | | } |
| | | public void setDeviceProperty(DeviceProperty deviceProperty) { |
| | | this.deviceProperty = deviceProperty; |
| | | } |
| | | public EquDeviceAdapter(){ |
| | | this.device = new Device(); |
| | | this.deviceProperty = new DeviceProperty(); |
| | | } |
| | | public void setDevice(Device device) { |
| | | this.device = device; |
| | |
| | | public void setProfessionId(Integer professionId) { |
| | | device.setProfessionId(professionId); |
| | | } |
| | | |
| | | public void setDeviceTech(Byte deviceTech) { |
| | | deviceProperty.setDeviceTech(deviceTech); |
| | | } |
| | | public void setExtC(String extC) { |
| | | deviceProperty.setExtC(extC); |
| | | } |
| | | public void setExtD(String extD) { |
| | | deviceProperty.setExtD(extD); |
| | | } |
| | | |
| | | public Device toDevice(){ |
| | | return device; |
| | | } |
New file |
| | |
| | | package com.moral.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | public interface HistoryDailyMapper {
|
| | |
|
| | | List<Map<String, Object>> getEmissionsData(Map<String, Object> parameters);
|
| | |
|
| | | }
|
| | |
| | | void saveOrUpdate(Device device, DeviceProperty deviceProperty);
|
| | |
|
| | | PageBean getDeviceList(PageBean pageBean);
|
| | |
|
| | | void offLinToMaintenance(Map<String, Object> parameters);
|
| | |
|
| | | void saveOrUpdate4Mobile(Device device, DeviceProperty deviceProperty);
|
| | |
|
| | | }
|
New file |
| | |
| | | package com.moral.service;
|
| | |
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | public interface HistoryDailyService {
|
| | | List<Map<String, Object>> getEmissionsData(Map<String, Object> parameters) throws Exception;
|
| | |
|
| | | }
|
| | |
| | | @Override
|
| | | @Transactional
|
| | | public void saveOrUpdate(Device device, DeviceProperty deviceProperty) {
|
| | | device.setMac(device.getMac().toLowerCase());
|
| | | if (ObjectUtils.isEmpty(device.getId())) {
|
| | | device.setState(Constants.DEVICE_STATE_OFFLINE);
|
| | | device.setIsDelete(Constants.IS_DELETE_FALSE);
|
| | |
| | | return new PageBean(deviceList);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void offLinToMaintenance(Map<String, Object> parameters) {
|
| | | ValidateUtil.notNull(parameters.get("id"), "param.is.null");
|
| | | ValidateUtil.notNull(parameters.get("old_state"), "param.is.null");
|
| | | ValidateUtil.notNull(parameters.get("new_state"), "param.is.null");
|
| | | int count = 0;
|
| | | if ("4".equals(parameters.get("old_state")) && "9".equals(parameters.get("new_state"))) {
|
| | | Device device = new Device();
|
| | | Example example = new Example(ENTITY_CLASS);
|
| | | example.and().andEqualTo("id", new Integer(parameters.get("id").toString())).andEqualTo("state", "4");
|
| | | device.setState("9");
|
| | | count = deviceMapper.updateByExampleSelective(device, example);
|
| | | } |
| | | if (count == 0) {
|
| | | throw new BusinessException("参数不合法!");
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void saveOrUpdate4Mobile(Device device, DeviceProperty deviceProperty) {
|
| | | device.setMac(device.getMac().toLowerCase());
|
| | | Device selectDevice = new Device();
|
| | | selectDevice.setMac(device.getMac());
|
| | | selectDevice = deviceMapper.selectOne(selectDevice);
|
| | | if (ObjectUtils.isEmpty(selectDevice)) {
|
| | | device.setState(Constants.DEVICE_STATE_OFFLINE);
|
| | | device.setIsDelete(Constants.IS_DELETE_FALSE);
|
| | | deviceMapper.insertSelective(device);
|
| | | deviceProperty.setId(device.getId());
|
| | | devicePropertyMapper.insertSelective(deviceProperty);
|
| | | } else {
|
| | | device.setId(selectDevice.getId());
|
| | | deviceMapper.updateByPrimaryKeySelective(device);
|
| | | deviceProperty.setId(selectDevice.getId());
|
| | | devicePropertyMapper.selectByPrimaryKey(selectDevice.getId());
|
| | | if (ObjectUtils.isEmpty(devicePropertyMapper.selectByPrimaryKey(deviceProperty.getId()))) {
|
| | | devicePropertyMapper.insertSelective(deviceProperty);
|
| | | } else {
|
| | | devicePropertyMapper.updateByPrimaryKeySelective(deviceProperty);
|
| | | }
|
| | | |
| | | }
|
| | | refreshDeviceInRedis(device.getMac());
|
| | |
|
| | | |
| | | }
|
| | |
|
| | | }
|
New file |
| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Map.Entry;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
|
| | | import com.moral.common.util.ParameterUtils;
|
| | | import com.moral.common.util.ResourceUtil;
|
| | | import com.moral.entity.Device;
|
| | | import com.moral.entity.DeviceProperty;
|
| | | import com.moral.mapper.HistoryDailyMapper;
|
| | | import com.moral.service.DeviceService;
|
| | | import com.moral.service.HistoryDailyService;
|
| | | import com.moral.service.OrganizationService;
|
| | |
|
| | | @Service
|
| | | public class HistoryDailyServiceImpl implements HistoryDailyService {
|
| | | @Resource
|
| | | private HistoryDailyMapper historyDailyMapper;
|
| | | |
| | | @Resource
|
| | | private OrganizationService organizationService;
|
| | |
|
| | | @Resource
|
| | | private DeviceService deviceService;
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> getEmissionsData(Map<String, Object> parameters) throws Exception {
|
| | | String sensorKey = parameters.get("sensorKey").toString();
|
| | | getAllchildrenOrg(parameters);
|
| | | ParameterUtils.getTimeType4Time(parameters);
|
| | | ParameterUtils.getElementByType(parameters);
|
| | | ParameterUtils.getStartAndEndByTime(parameters);
|
| | | ParameterUtils.getRegionType4RegionCode(parameters);
|
| | | List<Map<String, Object>> list = historyDailyMapper.getEmissionsData(parameters);
|
| | | |
| | | Map<String, Float> result = new HashMap<String, Float>();
|
| | | |
| | | for (Map<String, Object> map : list) {
|
| | | String mac = map.get("mac").toString();
|
| | | String name = map.get("name").toString();
|
| | | if (!ObjectUtils.isEmpty(map.get(sensorKey))) {
|
| | | Float thickness = Float.valueOf(map.get(sensorKey).toString());
|
| | | Device device = deviceService.getDeviceByMac(mac);
|
| | | DeviceProperty deviceProperty = device.getDeviceProperty();
|
| | | if (!ObjectUtils.isEmpty(deviceProperty)) {
|
| | | String extC = deviceProperty.getExtC();
|
| | | String extD = deviceProperty.getExtD();
|
| | | if (!(ObjectUtils.isEmpty(extC) || ObjectUtils.isEmpty(extD))) {
|
| | | Float acreage = Float.valueOf(extC);
|
| | | Float windSpeed = Float.valueOf(extD);
|
| | | Float emissions = thickness * acreage * windSpeed * 24 * 60 * 60 / 1000000;
|
| | | if (result.containsKey(name)) {
|
| | | result.put(name, emissions + result.get(name) );
|
| | | } else {
|
| | | result.put(name, emissions);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | List<Map<String, Object>> resultMap = new ArrayList<Map<String,Object>>();
|
| | | |
| | | for (Entry<String, Float> entry : result.entrySet()) {
|
| | | resultMap.add(new HashMap<String, Object>() {
|
| | | {
|
| | | put("name", entry.getKey());
|
| | | put("emissions", entry.getValue());
|
| | | }
|
| | | });
|
| | | }
|
| | | return resultMap;
|
| | | }
|
| | |
|
| | | private void getAllchildrenOrg(Map<String, Object> parameters) {
|
| | | if (parameters.containsKey("orgId")) {
|
| | | Integer orgId = Integer.valueOf(parameters.remove("orgId").toString());
|
| | | if (!(-1 == orgId || ResourceUtil.getValue("orgId").equals(orgId + ""))) {
|
| | | Set<Integer> orgIds = organizationService.getChildOrganizationIds(orgId);
|
| | | parameters.put("orgIds", orgIds);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | <result column="device_tech" property="deviceTech" jdbcType="TINYINT" /> |
| | | <result column="device_cat" property="deviceCat" jdbcType="TINYINT" /> |
| | | <result column="device_source" property="deviceSource" jdbcType="VARCHAR" /> |
| | | <result column="ext_c" property="extC" jdbcType="VARCHAR" /> |
| | | <result column="ext_d" property="extD" jdbcType="VARCHAR" /> |
| | | </association> |
| | | </resultMap> |
| | | |
| | |
| | | mpt.province_code, |
| | | dp.device_tech, |
| | | dp.device_cat, |
| | | dp.device_source |
| | | dp.device_source, |
| | | dp.ext_c, |
| | | dp.ext_d |
| | | from device dev |
| | | left join operate_user ouser on dev.operate_user_id = ouser.id |
| | | left join device_version dvn on dev.device_version_id = dvn.id |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.moral.mapper.HistoryDailyMapper">
|
| | | <select id="getEmissionsData" resultType="java.util.Map">
|
| | | SELECT
|
| | | SUM(hd.`json` ->'$.${sensorKey}[0]') AS '${sensorKey}',
|
| | | vdi.mac,
|
| | | mp.`name` 'name' |
| | | FROM
|
| | | history_daily hd,
|
| | | view_device_info vdi,
|
| | | monitor_point mp
|
| | | <where>
|
| | | hd.mac = vdi.mac
|
| | | AND vdi.monitor_point_id = mp.id
|
| | | AND vdi.device_tech = 1 |
| | | <if test="start != null">
|
| | | AND hd.time >= #{start}
|
| | | </if>
|
| | | <if test="end != null">
|
| | | AND hd.time < #{end}
|
| | | </if>
|
| | | <if test="regionCode != null">
|
| | | AND mp.${regionType}_code = #{regionCode}
|
| | | </if>
|
| | | <if test="orgIds != null and orgIds.size > 0">
|
| | | AND mp.organization_id IN
|
| | | <foreach collection="orgIds" open="(" separator="," close=")"
|
| | | item="listItem">
|
| | | #{listItem}
|
| | | </foreach>
|
| | | </if>
|
| | | </where>
|
| | | GROUP BY mp.`name`, vdi.mac
|
| | | </select>
|
| | | </mapper> |
| | |
| | | e19-standard=50
|
| | | orgId=5
|
| | | password=123456
|
| | | noFilters=/**/*.css,/**/*.json,/alarm/**,/screen/**,/**/*.jsp,/**/*.js,/**/*.gif,/**/*.png,/**/*.ico,/**/*.html,/**/*.map,/machineactivate/**,/device/**,/sensor/**,/mobile/**,/page/**,/swagger*/**,/v2/**,/webjars/**,/demo/**,/report/**,/weixin/alarm-show
|
| | | noFilters=/**/*.css,/**/*.json,/alarm/**,/screen/**,/**/*.jsp,/**/*.js,/**/*.gif,/**/*.png,/**/*.ico,/**/*.html,/**/*.map,/machineactivate/**,/device/**,/sensor/**,/mobile/**,/page/**,/swagger*/**,/v2/**,/webjars/**,/demo/**,/weixin/alarm-show
|
| | | specialOrgIds=5 |