| | |
| | | package com.moral.controller; |
| | | |
| | | import java.util.List; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | import com.moral.common.bean.PageBean; |
| | | import com.moral.common.bean.ResultBean; |
| | | import com.moral.entity.Role; |
| | | import com.moral.service.ChannelService; |
| | | import com.moral.service.RoleService; |
| | | |
| | | @RestController |
| | |
| | | |
| | | @Autowired |
| | | RoleService roleService; |
| | | |
| | | @GetMapping("page-list") |
| | | public PageBean pageList(PageBean pageBean) { |
| | | return roleService.queryByPageBean(pageBean); |
| | | } |
| | | |
| | | @GetMapping("count-by-example") |
| | | public ResultBean<Integer> countByExample(PageBean pageBean){ |
| | |
| | | return resultBean; |
| | | } |
| | | |
| | | @GetMapping("get-role-ids") |
| | | public List<Integer> getRoleIds(int accountId){ |
| | | return roleService.getRoleIds(accountId); |
| | | } |
| | | |
| | | @PostMapping("allot-role/{id}") |
| | | public ResultBean allotRole(@PathVariable("id") Integer accountId, @RequestBody Integer [] roleIds){ |
| | | ResultBean resultBean = new ResultBean(); |
| | | if(accountId==null){ |
| | | resultBean.setCode(ResultBean.NO_PERMISSION); |
| | | resultBean.setMessage("账户ID不能为null"); |
| | | return resultBean; |
| | | }else{ |
| | | roleService.allotRole(accountId,roleIds); |
| | | resultBean.setCode(ResultBean.SUCCESS); |
| | | } |
| | | return resultBean; |
| | | } |
| | | |
| | | } |
| | |
| | | import java.util.stream.Collectors;
|
| | |
|
| | | import org.apache.commons.collections.CollectionUtils;
|
| | | import org.apache.commons.collections.MapUtils;
|
| | | import org.apache.commons.net.ftp.FTPClient;
|
| | | import org.apache.log4j.Logger;
|
| | | import org.dom4j.Document;
|
| | |
| | | LocalDateTime timeLocalDateTime = LocalDateTime.parse(time, dateTimeFormatter);
|
| | | int month = timeLocalDateTime.getMonth().getValue();
|
| | | Point dirPoint = historyHourlyService.getDirPoint(parameters);
|
| | | Map<String, Object> getPollutionSourceData = historyHourlyService.getPollutionSourceData(parameters);
|
| | | Map<String, Object> getPollutionSourceData = historyHourlyService.getPollutionSourceDataByHour(parameters);
|
| | | if (MapUtils.isEmpty(getPollutionSourceData)) {
|
| | | getPollutionSourceData = historyHourlyService.getPollutionSourceDataAll(parameters);
|
| | | }
|
| | | String mac = parameters.get("mac").toString();
|
| | | Device device = deviceService.getDeviceByMac(mac, false);
|
| | | JSONObject params = new JSONObject();
|
| | |
| | | public interface HistoryHourlyMapper { |
| | | |
| | | Map<String, Object> getPollutionSourceData(Map<String, Object> parameters); |
| | | |
| | | Map<String, Object> getPollutionSourceDataByHour(Map<String, Object> parameters); |
| | | |
| | | Map<String, Object> getPollutionSourceDataAll(Map<String, Object> parameters); |
| | | } |
| | |
| | | public interface HistoryHourlyService { |
| | | Map<String, Object> getPollutionSourceData(Map<String, Object> parameters) throws Exception; |
| | | |
| | | Map<String, Object> getPollutionSourceDataByHour(Map<String, Object> parameters) throws Exception; |
| | | |
| | | Map<String, Object> getPollutionSourceDataAll(Map<String, Object> parameters) throws Exception; |
| | | |
| | | Point getDirPoint(Map<String, Object> parameters) throws Exception; |
| | | } |
| | |
| | | |
| | | PageBean getRoleList(PageBean pageBean); |
| | | |
| | | PageBean queryByPageBean(PageBean pageBean); |
| | | |
| | | void deleteByIds(Integer... ids); |
| | | |
| | | List<Integer> getRoleIds(int accountId); |
| | | |
| | | void allotRole(Integer accountId, Integer[] roleIds); |
| | | } |
| | |
| | | import com.moral.service.DeviceService; |
| | | import com.moral.service.HistoryHourlyService; |
| | | import com.moral.service.SensorService; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Service |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getPollutionSourceDataByHour(Map<String, Object> parameters) throws Exception { |
| | | List<Sensor> sensors = sensorMapper.getSensorsByMac(parameters); |
| | | List<String> sensorKeys = new ArrayList<>(); |
| | | for (Sensor sensor : sensors) { |
| | | sensorKeys.add(sensor.getSensorKey()); |
| | | } |
| | | parameters.put("sensorKeys", sensorKeys); |
| | | Map<String, Object> pollutionSourceData = historyHourlyMapper.getPollutionSourceDataByHour(parameters); |
| | | if (MapUtils.isNotEmpty(pollutionSourceData)) { |
| | | Map<String, String> sensorsMap = sensorService.getSensorsMap(parameters); |
| | | String selectSensorKey = parameters.get("sensorKey").toString(); |
| | | for (Map.Entry<String, String> s : sensorsMap.entrySet()) { |
| | | if (selectSensorKey.equals(s.getKey())) { |
| | | selectSensorKey = s.getValue(); |
| | | } |
| | | } |
| | | pollutionSourceData.put("selectSensorKey", selectSensorKey); |
| | | } |
| | | return pollutionSourceData; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getPollutionSourceDataAll(Map<String, Object> parameters) throws Exception { |
| | | List<Sensor> sensors = sensorMapper.getSensorsByMac(parameters); |
| | | List<String> sensorKeys = new ArrayList<>(); |
| | | for (Sensor sensor : sensors) { |
| | | sensorKeys.add(sensor.getSensorKey()); |
| | | } |
| | | parameters.put("sensorKeys", sensorKeys); |
| | | Map<String, Object> pollutionSourceData = historyHourlyMapper.getPollutionSourceDataAll(parameters); |
| | | if (MapUtils.isNotEmpty(pollutionSourceData)) { |
| | | Map<String, String> sensorsMap = sensorService.getSensorsMap(parameters); |
| | | String selectSensorKey = parameters.get("sensorKey").toString(); |
| | | for (Map.Entry<String, String> s : sensorsMap.entrySet()) { |
| | | if (selectSensorKey.equals(s.getKey())) { |
| | | selectSensorKey = s.getValue(); |
| | | } |
| | | } |
| | | pollutionSourceData.put("selectSensorKey", selectSensorKey); |
| | | } |
| | | return pollutionSourceData; |
| | | } |
| | | |
| | | @Override |
| | | public Point getDirPoint(Map<String, Object> parameters) throws Exception { |
| | | Map<String, Object> pollutionSourceData = getPollutionSourceData(parameters); |
| | | Map<String, Object> pollutionSourceData = getPollutionSourceDataByHour(parameters); |
| | | if (MapUtils.isEmpty(pollutionSourceData)) { |
| | | pollutionSourceData = getPollutionSourceDataAll(parameters); |
| | | } |
| | | String mac = parameters.get("mac").toString(); |
| | | Device device = deviceService.getDeviceByMac(mac, false); |
| | | Point pointEnd = new Point(); |
| | |
| | | package com.moral.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | import com.moral.common.bean.Constants; |
| | | import com.moral.common.bean.PageBean; |
| | | import com.moral.common.util.ExampleUtil; |
| | | import com.moral.common.util.MyBatisBaseMapUtil; |
| | | import com.moral.entity.AccountRole; |
| | | import com.moral.entity.Role; |
| | | import com.moral.mapper.AccountRoleMapper; |
| | | import com.moral.mapper.RoleMapper; |
| | | import com.moral.service.RoleService; |
| | | import com.moral.util.TkMybatisUtils; |
| | |
| | | @Resource |
| | | RoleMapper roleMapper; |
| | | |
| | | @Resource |
| | | AccountRoleMapper accountRoleMapper; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void addOrModify(Role role) { |
| | |
| | | role.setUpdateTime(new Date()); |
| | | role.setUpdateUser(role.getUpdateUser()); |
| | | if (role.getId() != null) { |
| | | roleMapper.updateByPrimaryKey(role); |
| | | roleMapper.updateByPrimaryKeySelective(role); |
| | | } else { |
| | | Role roleQuery = new Role(); |
| | | roleQuery.setRoleCode(role.getRoleCode()); |
| | |
| | | roleMapper.updateByExampleSelective(role, example); |
| | | } |
| | | |
| | | @Override |
| | | public List<Integer> getRoleIds(int accountId) { |
| | | AccountRole accountRole = new AccountRole(); |
| | | accountRole.setAccountId(accountId); |
| | | List<AccountRole> accountRoleList = accountRoleMapper.select(accountRole); |
| | | List<Integer> roleIds = new ArrayList<>(); |
| | | for(AccountRole accRole:accountRoleList ){ |
| | | roleIds.add(accRole.getRoleId()); |
| | | } |
| | | return roleIds; |
| | | } |
| | | |
| | | @Override |
| | | public void allotRole(Integer accountId, Integer[] roleIds) { |
| | | Example example = new Example(AccountRole.class); |
| | | example.or().andEqualTo("accountId",accountId); |
| | | accountRoleMapper.deleteByExample(example); |
| | | if(roleIds!=null && roleIds.length >0){ |
| | | List<AccountRole> accountRoleList = new ArrayList<>(); |
| | | for(int roleId:roleIds){ |
| | | AccountRole accountRole = new AccountRole(); |
| | | accountRole.setAccountId(accountId); |
| | | accountRole.setRoleId(roleId); |
| | | accountRoleList.add(accountRole); |
| | | } |
| | | accountRoleMapper.insertList(accountRoleList); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public PageBean<Role> queryByPageBean(PageBean pageBean){ |
| | | return MyBatisBaseMapUtil.queryPage(roleMapper,pageBean,ENTITY_CLASS); |
| | | } |
| | | |
| | | } |
| | |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="getPollutionSourceDataByHour" resultType="java.util.Map"> |
| | | SELECT |
| | | DATE_FORMAT(time,'%Y-%m-%d %H') time, |
| | | <foreach collection="sensorKeys" separator="," item="sensorKey"> |
| | | AVG(h.value ->'$.${sensorKey}') AS '${sensorKey}' |
| | | </foreach> |
| | | FROM |
| | | history h |
| | | <where> |
| | | <if test="mac!=null"> |
| | | and h.mac=#{mac} |
| | | </if> |
| | | </where> |
| | | GROUP BY |
| | | DATE_FORMAT(time,'%Y-%m-%d %H') |
| | | <if test="time!=null"> |
| | | having time=DATE_FORMAT(DATE_SUB(#{time}, INTERVAL 1 HOUR),'%Y-%m-%d %H') |
| | | </if> |
| | | </select> |
| | | |
| | | <select id="getPollutionSourceDataAll" resultType="java.util.Map"> |
| | | SELECT |
| | | DATE_FORMAT(time,'%Y-%m-%d %H') time, |
| | | <foreach collection="sensorKeys" separator="," item="sensorKey"> |
| | | AVG(h.value ->'$.${sensorKey}') AS '${sensorKey}' |
| | | </foreach> |
| | | FROM |
| | | history h |
| | | <where> |
| | | <if test="mac!=null"> |
| | | and h.mac=#{mac} |
| | | </if> |
| | | </where> |
| | | GROUP BY |
| | | DATE_FORMAT(time,'%Y-%m-%d %H') |
| | | order by time desc |
| | | limit 0,1 |
| | | </select> |
| | | </mapper> |
| | |
| | | var marker = new BMap.Marker(point, {icon: icon, offset: new BMap.Size(0, -20)}); |
| | | map.addOverlay(marker); |
| | | map.centerAndZoom(point, 16); |
| | | if (!$.isEmptyObject(dirPoint) && !$.isEmptyObject(getPollutionSourceData) && typeof (getPollutionSourceData["e6"]) != "undefined" && typeof (getPollutionSourceData["e7"]) != "undefined" && typeof (getPollutionSourceData["e18"]) != "undefined" && typeof (getPollutionSourceData["e23"]) != "undefined" && getPollutionSourceData["e18"] > 0.03) { |
| | | if (!$.isEmptyObject(dirPoint) && !$.isEmptyObject(getPollutionSourceData) && typeof (getPollutionSourceData["e6"]) != "undefined" && typeof (getPollutionSourceData["e7"]) != "undefined" && typeof (getPollutionSourceData["e18"]) != "undefined" && typeof (getPollutionSourceData["e23"]) != "undefined") { |
| | | var windSpeed = parseFloat(getPollutionSourceData["e18"]); |
| | | var windDir = parseFloat(getPollutionSourceData["e23"]); |
| | | var distance = windSpeed * 3600; |
| | | var distance = windSpeed * 3600>108? windSpeed * 3600:108; |
| | | var winDirStart = 255 - windDir; |
| | | var winDirEnd = 285 - windDir; |
| | | var marker1 = new BMap.Marker(EOffsetBearing(dirPoint, distance * 0.15, winDirStart), { |
| | |
| | | |
| | | $("#show").one('click', function () { |
| | | setTimeout(function () { |
| | | if ($.isEmptyObject(dirPoint) || $.isEmptyObject(getPollutionSourceData) || typeof (getPollutionSourceData["e6"]) == "undefined" || typeof (getPollutionSourceData["e7"]) == "undefined" || typeof (getPollutionSourceData["e18"]) == "undefined" || typeof (getPollutionSourceData["e23"]) == "undefined" || getPollutionSourceData["e18"] <= 0.03) { |
| | | if ($.isEmptyObject(dirPoint) || $.isEmptyObject(getPollutionSourceData) || typeof (getPollutionSourceData["e6"]) == "undefined" || typeof (getPollutionSourceData["e7"]) == "undefined" || typeof (getPollutionSourceData["e18"]) == "undefined" || typeof (getPollutionSourceData["e23"]) == "undefined") { |
| | | showNoData(); |
| | | } else { |
| | | var humidity = parseFloat(getPollutionSourceData["e6"]); |
| | |
| | | }); |
| | | map.addOverlay(lab); |
| | | |
| | | var distance = windSpeed * 3600; |
| | | var distance = windSpeed * 3600>108? windSpeed * 3600:108; |
| | | var winDirStartLeft = 240 - windDir; |
| | | var winDirEndLeft = 250 - windDir; |
| | | var winDirStartMiddle = 250 - windDir; |