ZhuDongming
2019-11-08 b284d078f196af80a105dc3bcb610d8ed37d9251
update
9 files modified
188 ■■■■■ changed files
src/main/java/com/moral/controller/RoleController.java 28 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ScreenController.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/HistoryHourlyMapper.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/HistoryHourlyService.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/RoleService.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java 50 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/RoleServiceImpl.java 43 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryHourlyMapper.xml 39 ●●●●● patch | view | raw | blame | history
src/main/webapp/view/pollutionsource.jsp 8 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/RoleController.java
@@ -1,8 +1,11 @@
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;
@@ -11,7 +14,6 @@
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
@@ -21,6 +23,11 @@
    @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){
@@ -46,4 +53,23 @@
        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;
    }
}
src/main/java/com/moral/controller/ScreenController.java
@@ -21,6 +21,7 @@
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;
@@ -1210,7 +1211,10 @@
        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();
src/main/java/com/moral/mapper/HistoryHourlyMapper.java
@@ -5,4 +5,8 @@
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);
}
src/main/java/com/moral/service/HistoryHourlyService.java
@@ -7,5 +7,9 @@
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;
}
src/main/java/com/moral/service/RoleService.java
@@ -15,5 +15,11 @@
    PageBean getRoleList(PageBean pageBean);
    PageBean queryByPageBean(PageBean pageBean);
    void deleteByIds(Integer... ids);
    List<Integer> getRoleIds(int accountId);
    void allotRole(Integer accountId, Integer[] roleIds);
}
src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java
@@ -16,6 +16,7 @@
import com.moral.service.DeviceService;
import com.moral.service.HistoryHourlyService;
import com.moral.service.SensorService;
import javax.annotation.Resource;
@Service
@@ -55,8 +56,55 @@
    }
    @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();
src/main/java/com/moral/service/impl/RoleServiceImpl.java
@@ -1,5 +1,6 @@
package com.moral.service.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@@ -13,7 +14,10 @@
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;
@@ -28,6 +32,9 @@
    @Resource
    RoleMapper roleMapper;
    @Resource
    AccountRoleMapper accountRoleMapper;
    @Override
    @Transactional
    public void addOrModify(Role role) {
@@ -35,7 +42,7 @@
            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());
@@ -87,4 +94,38 @@
        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);
    }
}
src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -17,4 +17,43 @@
            </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>
src/main/webapp/view/pollutionsource.jsp
@@ -162,10 +162,10 @@
    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), {
@@ -192,7 +192,7 @@
    $("#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"]);
@@ -213,7 +213,7 @@
                });
                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;