xufenglei
2017-12-11 59d80f82ef195f03b714fa0e9aec5d21d119c335
接口 增加校验
15 files modified
164 ■■■■■ changed files
src/main/java/com/moral/config/PageHelperConfig.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/MobileController.java 19 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ReportController.java 36 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ScreenController.java 41 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/MonitorPointMapper.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/OrganizationMapper.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/MonitorPointService.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/OrganizationService.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/DeviceServiceImpl.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/HistoryServiceImpl.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java 7 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/OperateUserServiceImpl.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/OrganizationServiceImpl.java 9 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/MonitorPointMapper.xml 11 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/OrganizationMapper.xml 9 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/config/PageHelperConfig.java
@@ -17,6 +17,7 @@
        Properties properties = new Properties();
        properties.setProperty("offsetAsPageNum","true");
        properties.setProperty("rowBoundsWithCount","true");
        properties.setProperty("pageSizeZero","true");
        properties.setProperty("reasonable","true");
        properties.setProperty("dialect","mysql");    //配置mysql数据库的方言
        pageHelper.setProperties(properties);
src/main/java/com/moral/controller/MobileController.java
@@ -1,12 +1,17 @@
package com.moral.controller;
import static com.moral.common.util.WebUtils.getParametersStartingWith;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.moral.common.bean.ResultBean;
@@ -91,7 +96,7 @@
     * @return the install devices by operate user
     */
    @GetMapping(value = "myRelease")
    public ResultBean<List<Device>> getInstallDevicesByOperateUser(Integer uid, Integer pageIndex, Integer pageSize) {
    public ResultBean<List<Device>> getInstallDevicesByOperateUser(@RequestParam(value="uid", required=true)Integer uid, @RequestParam(defaultValue="0")Integer pageIndex, @RequestParam(defaultValue="0")Integer pageSize) {
        List<Device> devices = deviceService.getInstallDevicesByOperateUser(uid,pageIndex,pageSize);
        return new ResultBean<List<Device>>(devices);
    }
@@ -103,7 +108,7 @@
     * @return the device by mac
     */
    @GetMapping(value = "getEquInfoByMac")
    public ResultBean<Device> getDeviceByMac(String mac) {
    public ResultBean<Device> getDeviceByMac(@RequestParam(value="mac", required=true)String mac) {
        Device device = deviceService.getDeviceByMac(mac);
        return new ResultBean<Device>(device);
    }
@@ -115,8 +120,9 @@
     * @return the monitor points by area name
     */
    @GetMapping(value = "getMpointsByAreaName")
    public ResultBean<List<MonitorPoint>> getMonitorPointsByAreaName(String areaName) {
        List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByAreaName(areaName);
    public ResultBean<List<MonitorPoint>> getMonitorPointsByAreaName(HttpServletRequest request) {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByAreaName(parameters);
        return new ResultBean<List<MonitorPoint>>(monitorPoints);
    }
@@ -127,8 +133,9 @@
     * @return the organizations by area name
     */
    @GetMapping(value = "getOrgsByAreaName")
    public ResultBean<List<Organization>> getOrganizationsByAreaName(String areaName) {
        List<Organization> organizations = organizationService.getOrganizationsByAreaName(areaName);
    public ResultBean<List<Organization>> getOrganizationsByAreaName(HttpServletRequest request) {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        List<Organization> organizations = organizationService.getOrganizationsByAreaName(parameters);
        return new ResultBean<List<Organization>>(organizations);
    }
}
src/main/java/com/moral/controller/ReportController.java
@@ -19,6 +19,7 @@
import org.springframework.web.bind.annotation.RestController;
import com.moral.common.exception.BusinessException;
import com.moral.common.util.ValidateUtil;
import com.moral.service.DeviceService;
import com.moral.service.HistoryService;
@@ -41,26 +42,25 @@
            Object mac = parameters.get("mac");
            Object time = parameters.get("time");
            Object type = parameters.get("type");
            if (isEmpty(mac) || isEmpty(time) || isEmpty(type)) {
                result.put("msg", "参数不能为空!");
            ValidateUtil.notNull(mac, "param.is.null");
            ValidateUtil.notNull(time, "param.is.null");
            ValidateUtil.notNull(type, "param.is.null");
            List<Map<String, Object>> sensors = deviceService.getSensorsByDevice(mac.toString());
            List<Map<String, Object>> sensorsAverage = historyService.getSensorsAverageByDevice4Report(parameters,sensors);
            if (isEmpty(sensorsAverage)) {
                result.put("msg", "无有效数据");
            } else {
                List<Map<String, Object>> sensors = deviceService.getSensorsByDevice(mac.toString());
                List<Map<String, Object>> sensorsAverage = historyService.getSensorsAverageByDevice4Report(parameters,sensors);
                if (isEmpty(sensorsAverage)) {
                    result.put("msg", "无有效数据");
                } else {
                    String[][] exportColumn = new String[sensors.size() + 1][];
                    exportColumn[0] = new String[] { "时间", "20", "time" };
                    for (int i = 0; i < sensors.size(); i++) {
                        String name = (String) sensors.get(i).get("name");
                        String key = (String) sensors.get(i).get("key");
                        exportColumn[i + 1] = new String[] { name, "10", key };
                    }
                    OutputStream outputStream = exportData(response, time + "_" + mac + "_" + type, sensorsAverage, exportColumn);
                    outputStream.flush();
                    outputStream.close();
                String[][] exportColumn = new String[sensors.size() + 1][];
                exportColumn[0] = new String[] { "时间", "20", "time" };
                for (int i = 0; i < sensors.size(); i++) {
                    String name = (String) sensors.get(i).get("name");
                    String key = (String) sensors.get(i).get("key");
                    exportColumn[i + 1] = new String[] { name, "10", key };
                }
                OutputStream outputStream = exportData(response, time + "_" + mac + "_" + type, sensorsAverage, exportColumn);
                outputStream.flush();
                outputStream.close();
            }
        } catch (BusinessException be) {
            be.printStackTrace();
src/main/java/com/moral/controller/ScreenController.java
@@ -91,14 +91,8 @@
     */
    @GetMapping("equipment-state")
    public Map<String, Object> getDeviceStatesByAccount(HttpServletRequest request) {
        Map<String, Object> result = new LinkedHashMap<String, Object>();
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        if (!parameters.containsKey("accountId")) {
            result.put("msg", "参数不能为空!");
        } else {
            result = deviceService.getDeviceStatesByAccount(parameters);
        }
        return result;
        return deviceService.getDeviceStatesByAccount(parameters);
    }
    /**
@@ -151,14 +145,8 @@
     */
    @GetMapping("day-aqi")
    public Map<String, Object> getDayAQIByDevice(HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>();
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        if (!parameters.containsKey("mac")) {
            result.put("msg", "参数不能为空!");
        } else {
            result = historyService.getDayAQIByDevice(parameters);
        }
        return result;
        return historyService.getDayAQIByDevice(parameters);
    }
    /**
@@ -170,14 +158,8 @@
     */
    @GetMapping("all-average")
    public Map<String, Object> getAllSensorAverageByDevice(HttpServletRequest request) {
        Map<String, Object> result = new LinkedHashMap<String, Object>();
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        if (!(parameters.containsKey("areaCode") && parameters.containsKey("accountId"))) {
            result.put("msg", "参数不能为空!");
        } else {
            result = historyService.getAllSensorAverageByDevice(parameters);
        }
        return result;
        return historyService.getAllSensorAverageByDevice(parameters);
    }
    /**
@@ -189,15 +171,8 @@
     */
    @GetMapping("sensor-average")
    public Map<String, Object> getDeviceRankingBySensorAverage(HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>();
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        if (!(parameters.containsKey("areaCode") && parameters.containsKey("accountId")
                && parameters.containsKey("macKey"))) {
            result.put("msg", "参数不能为空!");
        } else {
            result = historyService.getDeviceRankingBySensorAverage(parameters);
        }
        return result;
        return historyService.getDeviceRankingBySensorAverage(parameters);
    }
    /**
@@ -209,14 +184,8 @@
     */
    @GetMapping("month-sensor-average")
    public Map<String, Object> getMonthAverageBySensor(HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>();
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        if (!(parameters.containsKey("mac") && parameters.containsKey("macKey"))) {
            result.put("msg", "参数不能为空!");
        } else {
            result = historyService.getMonthAverageBySensor(parameters);
        }
        return result;
        return historyService.getMonthAverageBySensor(parameters);
    }
}
src/main/java/com/moral/mapper/MonitorPointMapper.java
@@ -1,11 +1,12 @@
package com.moral.mapper;
import java.util.List;
import java.util.Map;
import com.moral.common.mapper.BaseMapper;
import com.moral.entity.MonitorPoint;
public interface MonitorPointMapper extends BaseMapper<MonitorPoint>{
    List<MonitorPoint> getMonitorPointsByAreaName(String areaName);
    List<MonitorPoint> getMonitorPointsByAreaName(Map<String, Object> parameters);
}
src/main/java/com/moral/mapper/OrganizationMapper.java
@@ -1,11 +1,12 @@
package com.moral.mapper;
import java.util.List;
import java.util.Map;
import com.moral.common.mapper.BaseMapper;
import com.moral.entity.Organization;
public interface OrganizationMapper extends BaseMapper<Organization> {
    List<Organization> getOrganizationsByAreaName(String areaName);
    List<Organization> getOrganizationsByAreaName(Map<String, Object> parameters);
}
src/main/java/com/moral/service/MonitorPointService.java
@@ -1,11 +1,12 @@
package com.moral.service;
import java.util.List;
import java.util.Map;
import com.moral.entity.MonitorPoint;
public interface MonitorPointService {
    List<MonitorPoint> getMonitorPointsByAreaName(String areaName);
    List<MonitorPoint> getMonitorPointsByAreaName(Map<String, Object> parameters);
}
src/main/java/com/moral/service/OrganizationService.java
@@ -1,6 +1,7 @@
package com.moral.service;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.moral.entity.Organization;
@@ -9,6 +10,6 @@
    Set<Integer> getChildOrganizationIds(Integer orgId);
    List<Organization> getOrganizationsByAreaName(String areaName);
    List<Organization> getOrganizationsByAreaName(Map<String, Object> parameters);
}
src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -29,6 +29,7 @@
    @Override
    public Map<String, Object> getDeviceStatesByAccount(Map<String, Object> parameters) {
        ValidateUtil.notNull(parameters.get("accountId"), "param.is.null");
        Map<String, Object> result = new HashMap<String, Object>();
        accountService.setOrgIdsByAccount(parameters);
        List<Map<String, Object>> list = deviceMapper.getDeviceStatesByAccount(parameters);
@@ -81,6 +82,7 @@
    @Override
    public List<Device> getInstallDevicesByOperateUser(Integer uid, Integer pageIndex, Integer pageSize) {
        ValidateUtil.notNull(uid, "param.is.null");
        Device device = new Device();
        device.setOperateUserId(uid);
        PageHelper.startPage(pageIndex, pageSize);
src/main/java/com/moral/service/impl/HistoryServiceImpl.java
@@ -32,6 +32,7 @@
import com.moral.common.exception.BusinessException;
import com.moral.common.util.CalculateUtils;
import com.moral.common.util.ResourceUtil;
import com.moral.common.util.ValidateUtil;
import com.moral.mapper.HistoryMapper;
import com.moral.service.AccountService;
import com.moral.service.HistoryService;
@@ -50,6 +51,8 @@
    @Override
    public Map<String, Object> getAllSensorAverageByDevice(Map<String, Object> parameters) {
        ValidateUtil.notNull(parameters.get("areaCode"), "param.is.null");
        ValidateUtil.notNull(parameters.get("accountId"), "param.is.null");
        accountService.setOrgIdsByAccount(parameters);
        Date date = new Date();
        // 当前时间 -10分钟
@@ -73,8 +76,11 @@
    @Override
    public Map<String, Object> getDeviceRankingBySensorAverage(Map<String, Object> parameters) {
        Map<String, Object> result = new LinkedHashMap<String, Object>();
        ValidateUtil.notNull(parameters.get("areaCode"), "param.is.null");
        ValidateUtil.notNull(parameters.get("accountId"), "param.is.null");
        ValidateUtil.notNull(parameters.get("macKey"), "param.is.null");
        Map<String, Object> result = new LinkedHashMap<String, Object>();
        accountService.setOrgIdsByAccount(parameters);
        Date date = new Date();
        // 当前时间 -1小时
@@ -91,6 +97,7 @@
    @Override
    public Map<String, Object> getDayAQIByDevice(Map<String, Object> parameters) {
        ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Date date = new Date();
        // 昨日00:00:00
@@ -150,6 +157,8 @@
    @Override
    public Map<String, Object> getMonthAverageBySensor(Map<String, Object> parameters) {
        ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
        ValidateUtil.notNull(parameters.get("macKey"), "param.is.null");
        Map<String, Object> result = new HashMap<String, Object>();
        Date date = new Date();
        Long end = truncate(date, Calendar.DATE).getTime(), start;
src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
@@ -1,11 +1,13 @@
package com.moral.service.impl;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.moral.common.util.ValidateUtil;
import com.moral.entity.MonitorPoint;
import com.moral.mapper.MonitorPointMapper;
import com.moral.service.MonitorPointService;
@@ -16,8 +18,9 @@
    private MonitorPointMapper monitorPointMapper;
    @Override
    public List<MonitorPoint> getMonitorPointsByAreaName(String areaName) {
        return monitorPointMapper.getMonitorPointsByAreaName(areaName);
    public List<MonitorPoint> getMonitorPointsByAreaName(Map<String, Object> parameters) {
        ValidateUtil.notNull(parameters.get("areaName"), "param.is.null");
        return monitorPointMapper.getMonitorPointsByAreaName(parameters);
    }
}
src/main/java/com/moral/service/impl/OperateUserServiceImpl.java
@@ -8,6 +8,7 @@
import com.moral.common.exception.BusinessException;
import com.moral.common.util.Crypto;
import com.moral.common.util.ValidateUtil;
import com.moral.entity.OperateUser;
import com.moral.mapper.OperateUserMapper;
import com.moral.service.OperateUserService;
@@ -27,6 +28,8 @@
    @Override
    public OperateUser mobileLogin(String mobile, String password) {
        ValidateUtil.notEmpty(mobile, "param.is.null");
        ValidateUtil.notEmpty(password, "param.is.null");
        OperateUser operateUser = new OperateUser();
        operateUser.setMobile(mobile);
        operateUser.setPassword(Crypto.md5(password));
@@ -42,6 +45,9 @@
    @Override
    @Transactional
    public OperateUser updatePassword(Integer uid, String password, String newPassword) {
        ValidateUtil.notNull(uid, "param.is.null");
        ValidateUtil.notEmpty(password, "param.is.null");
        ValidateUtil.notEmpty(newPassword, "param.is.null");
        OperateUser operateUser = operateUserMapper.selectByPrimaryKey(uid);
        if (ObjectUtils.isEmpty(operateUser) || !Crypto.md5(password).equals(operateUser.getPassword())) {
            throw new BusinessException("旧密码错误,修改密码失败!");
src/main/java/com/moral/service/impl/OrganizationServiceImpl.java
@@ -4,12 +4,15 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.moral.common.exception.ValidateException;
import com.moral.common.util.ValidateUtil;
import com.moral.entity.Organization;
import com.moral.entity.OrganizationRelation;
import com.moral.mapper.OrganizationMapper;
@@ -42,9 +45,11 @@
        return orgIds;
    }
    @Override
    public List<Organization> getOrganizationsByAreaName(String areaName) {
        List<Organization> organizations = organizationMapper.getOrganizationsByAreaName(areaName);
    public List<Organization> getOrganizationsByAreaName(Map<String, Object> parameters) {
        ValidateUtil.notNull(parameters.get("areaName"), "param.is.null");
        List<Organization> organizations = organizationMapper.getOrganizationsByAreaName(parameters);
        return organizations;
    }
src/main/resources/mapper/MonitorPointMapper.xml
@@ -6,9 +6,16 @@
            mp.* 
        FROM
            monitor_point mp,
            area a
            area a
        <if test="cityName != null">
            ,city c
        </if>
        WHERE
            mp.area_code = a.area_code 
        AND a.area_name = #{areaName}
            AND a.area_name = #{areaName}
        <if test="cityName != null">
            AND c.city_name = #{cityName}
            AND mp.city_code = c.city_code
        </if>
    </select>
</mapper>
src/main/resources/mapper/OrganizationMapper.xml
@@ -7,8 +7,15 @@
        FROM
            organization o,
            area a 
        <if test="cityName != null">
            ,city c
        </if>
        WHERE
            o.area_code = a.area_code 
        AND a.area_name = #{areaName}
            AND a.area_name = #{areaName}
        <if test="cityName != null">
            AND c.city_name = #{cityName}
            AND o.city_code = c.city_code
        </if>
    </select>
</mapper>