Merge remote-tracking branch 'origin/master'
	
		
		7 files added
	
		
		12 files modified
	
	
 
	
	
	
	
	
	
	
	
|  |  |  | 
|---|
|  |  |  | <artifactId>jjwt</artifactId> | 
|---|
|  |  |  | <version>0.9.0</version> | 
|---|
|  |  |  | </dependency> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <!-- 阿里大于 --> | 
|---|
|  |  |  | <dependency> | 
|---|
|  |  |  | <groupId>com.taobao.api</groupId> | 
|---|
|  |  |  | <artifactId>taobao-sdk</artifactId> | 
|---|
|  |  |  | <version>1.0.0</version> | 
|---|
|  |  |  | <scope>system</scope> | 
|---|
|  |  |  | <systemPath>${project.basedir}/lib/taobao-sdk-java-auto_1455552377940-20160607.jar</systemPath> | 
|---|
|  |  |  | </dependency> | 
|---|
|  |  |  | </dependencies> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <build> | 
|---|
|  |  |  | 
|---|
|  |  |  | <groupId>org.springframework.boot</groupId> | 
|---|
|  |  |  | <artifactId>spring-boot-maven-plugin</artifactId> | 
|---|
|  |  |  | </plugin> | 
|---|
|  |  |  | <plugin> | 
|---|
|  |  |  | <groupId>org.apache.maven.plugins</groupId> | 
|---|
|  |  |  | <artifactId>maven-dependency-plugin</artifactId> | 
|---|
|  |  |  | <version>3.1.0</version> | 
|---|
|  |  |  | <executions> | 
|---|
|  |  |  | <execution> | 
|---|
|  |  |  | <id>copy-dependencies</id> | 
|---|
|  |  |  | <phase>compile</phase> | 
|---|
|  |  |  | <goals> | 
|---|
|  |  |  | <goal>copy-dependencies</goal> | 
|---|
|  |  |  | </goals> | 
|---|
|  |  |  | <configuration> | 
|---|
|  |  |  | <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory> | 
|---|
|  |  |  | <includeScope>system</includeScope> | 
|---|
|  |  |  | </configuration> | 
|---|
|  |  |  | </execution> | 
|---|
|  |  |  | </executions> | 
|---|
|  |  |  | </plugin> | 
|---|
|  |  |  | </plugins> | 
|---|
|  |  |  | </build> | 
|---|
|  |  |  | </project> | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.util.Crypto; | 
|---|
|  |  |  | import com.moral.util.MessageUtils; | 
|---|
|  |  |  | import com.taobao.api.ApiException; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.common.bean.AppData; | 
|---|
|  |  |  | import com.moral.entity.Device; | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param password the password | 
|---|
|  |  |  | * @return the result bean | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("accountlogin") | 
|---|
|  |  |  | @PostMapping("accountlogin") | 
|---|
|  |  |  | public AppData<OperateUser> mobileLogin(String username, String password) { | 
|---|
|  |  |  | OperateUser operateUser = operateUserService.mobileLogin(username,password); | 
|---|
|  |  |  | return new AppData<OperateUser>(operateUser); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param newpassword the newpassword | 
|---|
|  |  |  | * @return the result bean | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("upPassword") | 
|---|
|  |  |  | @PostMapping("upPassword") | 
|---|
|  |  |  | public AppData<OperateUser> updatePassword(Integer uid, String password, String newpassword) { | 
|---|
|  |  |  | OperateUser operateUser = operateUserService.updatePassword(uid,password,newpassword); | 
|---|
|  |  |  | return new AppData<OperateUser>(operateUser); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param device the device | 
|---|
|  |  |  | * @return the result bean | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("reportDevice") | 
|---|
|  |  |  | @PostMapping("reportDevice") | 
|---|
|  |  |  | public AppData<String> installDevice(Device device) { | 
|---|
|  |  |  | deviceService.saveOrUpdateDevice(device); | 
|---|
|  |  |  | return new AppData<String>(""); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param pageSize the page size | 
|---|
|  |  |  | * @return the install devices by operate user | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("myRelease") | 
|---|
|  |  |  | @PostMapping("myRelease") | 
|---|
|  |  |  | public AppData<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); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param mac the mac | 
|---|
|  |  |  | * @return the device by mac | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("getEquInfoByMac") | 
|---|
|  |  |  | @PostMapping("getEquInfoByMac") | 
|---|
|  |  |  | public AppData<Device> getDeviceByMac(@RequestParam(value="mac", required=true)String mac) { | 
|---|
|  |  |  | Device device = deviceService.getDeviceByMac(mac); | 
|---|
|  |  |  | return new AppData<Device>(device); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param request the area name | 
|---|
|  |  |  | * @return the monitor points by area name | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("getMpointsByAreaName") | 
|---|
|  |  |  | @PostMapping("getMpointsByAreaName") | 
|---|
|  |  |  | public AppData<List<MonitorPoint>> getMonitorPointsByAreaName(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByAreaName(parameters); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param request the area name | 
|---|
|  |  |  | * @return the organizations by area name | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("getOrgsByAreaName") | 
|---|
|  |  |  | @PostMapping("getOrgsByAreaName") | 
|---|
|  |  |  | public AppData<List<Organization>> getOrganizationsByAreaName(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | List<Organization> organizations = organizationService.getOrganizationsByAreaName(parameters); | 
|---|
|  |  |  | return new AppData<List<Organization>>(organizations); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Send SMS | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param mobile | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("sendSms") | 
|---|
|  |  |  | public AppData<String> sendSms(String mobile) { | 
|---|
|  |  |  | AppData apiData = new AppData(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StringUtils.isBlank(mobile)){ | 
|---|
|  |  |  | apiData.setErrno(1); | 
|---|
|  |  |  | apiData.setMessage("没有输入手机号码"); | 
|---|
|  |  |  | apiData.setData("{}"); | 
|---|
|  |  |  | return  apiData; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OperateUser user = operateUserService.getOperateUserByMobile(mobile); | 
|---|
|  |  |  | if (user==null){ | 
|---|
|  |  |  | apiData.setErrno(1); | 
|---|
|  |  |  | apiData.setMessage("手机号没有关联用户"); | 
|---|
|  |  |  | apiData.setData("{}"); | 
|---|
|  |  |  | return  apiData; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //生成验证码 | 
|---|
|  |  |  | int code = (int)((Math.random() * 9 + 1) * 100000); | 
|---|
|  |  |  | user.setCode(String.valueOf(code)); | 
|---|
|  |  |  | operateUserService.updateOperateUser(user); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //发送到手机 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | int state = MessageUtils.sendMsg(mobile, String.valueOf(code)); | 
|---|
|  |  |  | if(state==0){ | 
|---|
|  |  |  | apiData.setErrno(0); | 
|---|
|  |  |  | apiData.setMessage("发送验证码成功"); | 
|---|
|  |  |  | apiData.setData("{}"); | 
|---|
|  |  |  | return  apiData; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(state==1){ | 
|---|
|  |  |  | apiData.setErrno(1); | 
|---|
|  |  |  | apiData.setMessage("发送验证码失败"); | 
|---|
|  |  |  | apiData.setData("{}"); | 
|---|
|  |  |  | return  apiData; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (ApiException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new AppData<String>(""); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Send SMS | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param mobile | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("password") | 
|---|
|  |  |  | public AppData<String> password(String username, String password, String code){ | 
|---|
|  |  |  | AppData apiData = new AppData(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StringUtils.isBlank(code)){ | 
|---|
|  |  |  | apiData.setErrno(1); | 
|---|
|  |  |  | apiData.setMessage("重置密码失败,没有输出验证码"); | 
|---|
|  |  |  | apiData.setData("{}"); | 
|---|
|  |  |  | return  apiData; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OperateUser user = operateUserService.getOperateUserByMobile(username); | 
|---|
|  |  |  | if (user==null){ | 
|---|
|  |  |  | apiData.setErrno(1); | 
|---|
|  |  |  | apiData.setMessage("手机号没有关联用户"); | 
|---|
|  |  |  | apiData.setData("{}"); | 
|---|
|  |  |  | return  apiData; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (user.getCode().equals(code)){ | 
|---|
|  |  |  | user.setPassword(Crypto.md5(password)); | 
|---|
|  |  |  | int new_code = (int)((Math.random() * 9 + 1) * 100000); | 
|---|
|  |  |  | user.setCode(String.valueOf(new_code)); | 
|---|
|  |  |  | operateUserService.updateOperateUser(user); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | apiData.setErrno(0); | 
|---|
|  |  |  | apiData.setMessage("重置密码成功"); | 
|---|
|  |  |  | apiData.setData("{}"); | 
|---|
|  |  |  | return  apiData; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | apiData.setErrno(1); | 
|---|
|  |  |  | apiData.setMessage("输入验证码不正确"); | 
|---|
|  |  |  | apiData.setData("{}"); | 
|---|
|  |  |  | return  apiData; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.common.bean.ResultBean; | 
|---|
|  |  |  | import com.moral.entity.charts.LineChartCriteria; | 
|---|
|  |  |  | import com.moral.service.AlarmService; | 
|---|
|  |  |  | import com.moral.service.AlarmDailyService; | 
|---|
|  |  |  | import com.moral.service.HistoryMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings({ "unchecked", "rawtypes" }) | 
|---|
|  |  |  | 
|---|
|  |  |  | private HistoryMinutelyService historyMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AlarmService alarmService; | 
|---|
|  |  |  | private AlarmDailyService alarmDailyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("compare") | 
|---|
|  |  |  | public ResultBean<Map<String, List>> getCompareReport(HttpServletRequest request) throws Exception { | 
|---|
|  |  |  | 
|---|
|  |  |  | @GetMapping("pie") | 
|---|
|  |  |  | public ResultBean<Map<String, Object>> getPieData(HttpServletRequest request) throws Exception { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | Map pieData = alarmService.getPieData(parameters); | 
|---|
|  |  |  | Map pieData = alarmDailyService.getPieData(parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultBean<Map<String, Object>>(pieData); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("alarm-year") | 
|---|
|  |  |  | public ResultBean<List<Integer>> getAlarmDataByYear(HttpServletRequest request) throws Exception { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | List<Integer> alarmDataByYear = alarmDailyService.getAlarmDataByYear(parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultBean<List<Integer>>(alarmDataByYear); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.io.ByteArrayInputStream; | 
|---|
|  |  |  | import java.io.InputStream; | 
|---|
|  |  |  | import java.io.InputStreamReader; | 
|---|
|  |  |  | import java.net.InetAddress; | 
|---|
|  |  |  | import java.net.URL; | 
|---|
|  |  |  | import java.net.URLConnection; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.LinkedHashMap; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.entity.alarm.AlarmSensorLevel; | 
|---|
|  |  |  | import com.moral.service.AccountService; | 
|---|
|  |  |  | import com.moral.service.AlarmConfigService; | 
|---|
|  |  |  | import com.moral.service.AlarmService; | 
|---|
|  |  |  | import com.moral.service.AlarmDailyService; | 
|---|
|  |  |  | import com.moral.service.AreaService; | 
|---|
|  |  |  | import com.moral.service.DeviceService; | 
|---|
|  |  |  | import com.moral.service.HistoryMinutelyService; | 
|---|
|  |  |  | 
|---|
|  |  |  | private String levelKey = "alarm_"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AlarmService alarmService; | 
|---|
|  |  |  | private AlarmDailyService alarmDailyService; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Screen login. 大屏登录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | 
|---|
|  |  |  | parameters.remove("organizationId"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map pieData = alarmService.getPieData(parameters); | 
|---|
|  |  |  | Map pieData = alarmDailyService.getPieData(parameters); | 
|---|
|  |  |  | List<Map<String, Object>> list = (List<Map<String, Object>>) pieData.get(sensorKey); | 
|---|
|  |  |  | return new ResultBean<List<Map<String, Object>>>(list); | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.entity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import lombok.Data; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Data | 
|---|
|  |  |  | public class AlarmDaily { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * This field was generated by MyBatis Generator. | 
|---|
|  |  |  | * This field corresponds to the database column alarm.mac | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @mbg.generated Mon Apr 16 09:27:36 CST 2018 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String mac; | 
|---|
|  |  |  | private Integer state; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * This field was generated by MyBatis Generator. | 
|---|
|  |  |  | * This field corresponds to the database column alarm.json | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @mbg.generated Mon Apr 16 09:27:36 CST 2018 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String json; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * This field was generated by MyBatis Generator. | 
|---|
|  |  |  | * This field corresponds to the database column alarm.time | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @mbg.generated Mon Apr 16 09:27:36 CST 2018 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Date time; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | private Date createTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private Date expireTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String code; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Integer getUid() { | 
|---|
|  |  |  | return id; | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.mapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.common.mapper.BaseMapper; | 
|---|
|  |  |  | import com.moral.entity.AlarmDaily; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface AlarmDailyMapper extends BaseMapper<AlarmDaily> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getAlarmData(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getAlarmDataByYear(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface AlarmMapper extends BaseMapper<Alarm> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getAlarmData(Map<String, Object> parameters); | 
|---|
|  |  |  | List<Map> countByTimes(@Param("start")Date start, @Param("end")Date end, @Param("format")String format); | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("rawtypes") | 
|---|
|  |  |  | public interface AlarmDailyService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map getPieData(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Integer> getAlarmDataByYear(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.entity.charts.TimeUnits; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.entity.charts.TimeUnits; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("rawtypes") | 
|---|
|  |  |  | public interface AlarmService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map> countByTimes(Date start, Date end, TimeUnits timeUnits); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map getPieData(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | Integer deleteOperateUsersByLogic(List<Integer> ids); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PageBean queryByPageBean(PageBean pageBean); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer updateOperateUser(OperateUser operateUser); | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.text.ParseException; | 
|---|
|  |  |  | import java.time.LocalDate; | 
|---|
|  |  |  | import java.time.temporal.TemporalAdjusters; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Arrays; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.LinkedHashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.mapper.AlarmDailyMapper; | 
|---|
|  |  |  | import com.moral.mapper.SensorMapper; | 
|---|
|  |  |  | import com.moral.service.AlarmDailyService; | 
|---|
|  |  |  | import com.moral.service.HistoryMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | @SuppressWarnings({ "rawtypes", "unchecked" }) | 
|---|
|  |  |  | public class AlarmDailyServiceImpl implements AlarmDailyService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AlarmDailyMapper alarmDailyMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private SensorMapper sensorMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private HistoryMinutelyService historyMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map getPieData(Map<String, Object> parameters) { | 
|---|
|  |  |  | Map<String, Object> resultMap = new LinkedHashMap<String, Object>(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | historyMinutelyService.convertQueryParam(parameters); | 
|---|
|  |  |  | } catch (ParseException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Map<String, Object>> alarmDatas = alarmDailyMapper.getAlarmData(parameters); | 
|---|
|  |  |  | Object dimension = parameters.get("dimension"); | 
|---|
|  |  |  | if ("monitorPoint".equals(dimension)) { | 
|---|
|  |  |  | for (Map<String, Object> alarmData : alarmDatas) { | 
|---|
|  |  |  | String name = alarmData.remove("name").toString(); | 
|---|
|  |  |  | alarmData.remove("sum"); | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : alarmData.entrySet()) { | 
|---|
|  |  |  | String key = entry.getKey(); | 
|---|
|  |  |  | Object value = entry.getValue().toString(); | 
|---|
|  |  |  | if (!"0".equals(value)) { | 
|---|
|  |  |  | List list; | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<String, Object>(); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(resultMap.get(key))) { | 
|---|
|  |  |  | list = new ArrayList(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | list = (List) resultMap.get(key); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("name", name); | 
|---|
|  |  |  | map.put("value", value); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | resultMap.put(key, list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Map<String, Object> alarmData = alarmDatas.get(0); | 
|---|
|  |  |  | List<String> sensors = (List<String>) parameters.get("sensors"); | 
|---|
|  |  |  | List list = new ArrayList(); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(alarmData)) { | 
|---|
|  |  |  | for (String key : alarmData.keySet()) { | 
|---|
|  |  |  | for (String sensor : sensors) { | 
|---|
|  |  |  | String[] split = sensor.split("-"); | 
|---|
|  |  |  | if (key.equals(split[0]) && !"0".equals(alarmData.get(key).toString())) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<String, Object>(); | 
|---|
|  |  |  | if (parameters.containsKey("description")) { | 
|---|
|  |  |  | map.put("name", split[3]); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | map.put("name", split[1]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("value", alarmData.get(key)); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resultMap.put("list", list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Integer> getAlarmDataByYear(Map<String, Object> parameters) { | 
|---|
|  |  |  | LocalDate localDate = LocalDate.now(); | 
|---|
|  |  |  | parameters.put("start", localDate.with(TemporalAdjusters.firstDayOfYear())); | 
|---|
|  |  |  | parameters.put("end", localDate.with(TemporalAdjusters.firstDayOfNextYear())); | 
|---|
|  |  |  | parameters.put("sensorKeys", | 
|---|
|  |  |  | sensorMapper.selectAll().stream().map(sensor -> sensor.getSensorKey()).collect(Collectors.toList())); | 
|---|
|  |  |  | List<Map<String, Object>> list = alarmDailyMapper.getAlarmDataByYear(parameters); | 
|---|
|  |  |  | Integer[] result = new Integer[12]; | 
|---|
|  |  |  | for (int i = 0; i < result.length; i++) { | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(list)) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Map<String, Object> map : list) { | 
|---|
|  |  |  | Integer month = Integer.valueOf(map.get("time").toString().substring(5)); | 
|---|
|  |  |  | if (i + 1 < month) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } else if (i + 1 == month) { | 
|---|
|  |  |  | result[i] = Integer.valueOf(map.get("sum").toString()); | 
|---|
|  |  |  | list.remove(map); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return Arrays.asList(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.text.ParseException; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.entity.charts.TimeUnits; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.entity.charts.TimeUnits; | 
|---|
|  |  |  | import com.moral.mapper.AlarmMapper; | 
|---|
|  |  |  | import com.moral.service.AlarmService; | 
|---|
|  |  |  | import com.moral.service.HistoryMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | @SuppressWarnings({ "rawtypes", "unchecked" }) | 
|---|
|  |  |  | @SuppressWarnings({ "rawtypes" }) | 
|---|
|  |  |  | public class AlarmServiceImpl implements AlarmService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return alarmMapper.countByTimes(start, end, format); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map getPieData(Map<String, Object> parameters) { | 
|---|
|  |  |  | Map<String, Object> resultMap = new LinkedHashMap<String, Object>(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | historyMinutelyService.convertQueryParam(parameters); | 
|---|
|  |  |  | } catch (ParseException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Map<String, Object>> alarmDatas = alarmMapper.getAlarmData(parameters); | 
|---|
|  |  |  | Object dimension = parameters.get("dimension"); | 
|---|
|  |  |  | if ("monitorPoint".equals(dimension)) { | 
|---|
|  |  |  | for (Map<String, Object> alarmData : alarmDatas) { | 
|---|
|  |  |  | String name = alarmData.remove("name").toString(); | 
|---|
|  |  |  | alarmData.remove("sum"); | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : alarmData.entrySet()) { | 
|---|
|  |  |  | String key = entry.getKey(); | 
|---|
|  |  |  | Object value = entry.getValue().toString(); | 
|---|
|  |  |  | if (!"0".equals(value)) { | 
|---|
|  |  |  | List list; | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<String, Object>(); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(resultMap.get(key))) { | 
|---|
|  |  |  | list = new ArrayList(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | list = (List) resultMap.get(key); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("name", name); | 
|---|
|  |  |  | map.put("value", value); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | resultMap.put(key, list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Map<String, Object> alarmData = alarmDatas.get(0); | 
|---|
|  |  |  | List<String> sensors = (List<String>) parameters.get("sensors"); | 
|---|
|  |  |  | List list = new ArrayList(); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(alarmData)) { | 
|---|
|  |  |  | for (String key : alarmData.keySet()) { | 
|---|
|  |  |  | for (String sensor : sensors) { | 
|---|
|  |  |  | String[] split = sensor.split("-"); | 
|---|
|  |  |  | if (key.equals(split[0]) && !"0".equals(alarmData.get(key).toString())) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<String, Object>(); | 
|---|
|  |  |  | if (parameters.containsKey("description")) { | 
|---|
|  |  |  | map.put("name", split[3]); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | map.put("name", split[1]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("value", alarmData.get(key)); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resultMap.put("list", list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.entity.charts.DataCondition; | 
|---|
|  |  |  | import com.moral.entity.charts.LineChartCriteria; | 
|---|
|  |  |  | import com.moral.entity.charts.TimePeriod; | 
|---|
|  |  |  | import com.moral.mapper.AlarmDailyMapper; | 
|---|
|  |  |  | import com.moral.mapper.AlarmMapper; | 
|---|
|  |  |  | import com.moral.mapper.DeviceMapper; | 
|---|
|  |  |  | import com.moral.mapper.HistoryMinutelyMapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | private SensorMapper sensorMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AlarmMapper alarmMapper; | 
|---|
|  |  |  | private AlarmDailyMapper alarmDailyMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> getDayAQIByDevice(Map<String, Object> parameters) { | 
|---|
|  |  |  | 
|---|
|  |  |  | Object type = parameters.get("type"); | 
|---|
|  |  |  | if ("year".equals(type) || "month".equals(type)) { | 
|---|
|  |  |  | parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e10", "e11", "e15", "e16")); | 
|---|
|  |  |  | resultMap.put("alarmData" + part, alarmMapper.getAlarmData(parameters).get(0)); | 
|---|
|  |  |  | resultMap.put("alarmData" + part, alarmDailyMapper.getAlarmData(parameters).get(0)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | public PageBean queryByPageBean(PageBean pageBean) { | 
|---|
|  |  |  | return MyBatisBaseMapUtil.queryPage(operateUserMapper,pageBean,ENTITY_CLASS); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Integer updateOperateUser(OperateUser operateUser) { | 
|---|
|  |  |  | return operateUserMapper.updateByPrimaryKeySelective(operateUser); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.util; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.taobao.api.ApiException; | 
|---|
|  |  |  | import com.taobao.api.DefaultTaobaoClient; | 
|---|
|  |  |  | import com.taobao.api.TaobaoClient; | 
|---|
|  |  |  | import com.taobao.api.domain.BizResult; | 
|---|
|  |  |  | import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest; | 
|---|
|  |  |  | import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse; | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class MessageUtils { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static Logger logger = LoggerFactory.getLogger(MessageUtils.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static int sendMsg(String mobile,String code) throws ApiException { | 
|---|
|  |  |  | String url = "http://gw.api.taobao.com/router/rest"; | 
|---|
|  |  |  | String appkey = "23531128"; | 
|---|
|  |  |  | String secret = "b079269785183c5a7520da9b8047bb42"; | 
|---|
|  |  |  | TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); | 
|---|
|  |  |  | AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest(); | 
|---|
|  |  |  | req.setExtend(""); | 
|---|
|  |  |  | req.setSmsType("normal"); | 
|---|
|  |  |  | req.setSmsFreeSignName("七星博士"); | 
|---|
|  |  |  | //${address}发生警报,警报等级:${level},请马上处理。 | 
|---|
|  |  |  | //req.setSmsParamString("{address:'" + "addre" + "',level:'" + 2 + "'}"); | 
|---|
|  |  |  | req.setSmsParamString("{code:'" + code + "'}"); | 
|---|
|  |  |  | req.setRecNum(mobile); | 
|---|
|  |  |  | req.setSmsTemplateCode("SMS_25781236"); | 
|---|
|  |  |  | AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req); | 
|---|
|  |  |  | BizResult result = rsp.getResult(); | 
|---|
|  |  |  | if (result == null) { | 
|---|
|  |  |  | logger.warn("短信报警通知失败" + rsp.getBody()); | 
|---|
|  |  |  | return 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Boolean success = result.getSuccess(); | 
|---|
|  |  |  | if (!success) { | 
|---|
|  |  |  | logger.warn("短信通知失败" + rsp.getBody()); | 
|---|
|  |  |  | return 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
| 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.AlarmDailyMapper"> | 
|---|
|  |  |  | <select id="getAlarmData" resultType="java.util.LinkedHashMap"> | 
|---|
|  |  |  | SELECT | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | `name`, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <choose> | 
|---|
|  |  |  | <when test="sensorKeys.size > 0"> | 
|---|
|  |  |  | <foreach collection="sensorKeys" separator="," item="sensorKey"> | 
|---|
|  |  |  | SUM( ${sensorKey} ) AS '${sensorKey}' | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | <foreach collection="sensorKeys" open="," separator="+" close=" AS 'sum' " item="sensorKey"> | 
|---|
|  |  |  | SUM( ${sensorKey} ) | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | </when> | 
|---|
|  |  |  | <otherwise> | 
|---|
|  |  |  | time | 
|---|
|  |  |  | </otherwise> | 
|---|
|  |  |  | </choose> | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | ( | 
|---|
|  |  |  | SELECT | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | mp.`name`, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <choose> | 
|---|
|  |  |  | <when test="sensorKeys.size > 0"> | 
|---|
|  |  |  | <foreach collection="sensorKeys" separator="," item="sensorKey"> | 
|---|
|  |  |  | CASE COUNT( json -> '$.${sensorKey}' ) WHEN 0 THEN 0 ELSE 1 END AS '${sensorKey}' | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | </when> | 
|---|
|  |  |  | <otherwise> | 
|---|
|  |  |  | h.time | 
|---|
|  |  |  | </otherwise> | 
|---|
|  |  |  | </choose> | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | alarm_daily h, | 
|---|
|  |  |  | device d, | 
|---|
|  |  |  | monitor_point mp | 
|---|
|  |  |  | WHERE d.monitor_point_id = mp.id | 
|---|
|  |  |  | AND h.mac = d.mac | 
|---|
|  |  |  | AND h.time >= #{start} | 
|---|
|  |  |  | AND h.time <![CDATA[<]]> #{end} | 
|---|
|  |  |  | <if test="provinceCode != null"> | 
|---|
|  |  |  | AND mp.province_code = #{provinceCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="cityCode != null"> | 
|---|
|  |  |  | AND mp.city_code = #{cityCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="areaCode != null"> | 
|---|
|  |  |  | AND mp.area_code = #{areaCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="monitorPointId != null"> | 
|---|
|  |  |  | AND mp.id =    #{monitorPointId} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="organizationId != null"> | 
|---|
|  |  |  | AND mp.organization_id = #{organizationId} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="mac != null"> | 
|---|
|  |  |  | AND d.mac =    #{mac} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="level != null"> | 
|---|
|  |  |  | AND h.state = #{level} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | GROUP BY | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | mp.id, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | h.time | 
|---|
|  |  |  | ) a | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | GROUP BY name | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="getAlarmDataByYear" resultType="java.util.Map"> | 
|---|
|  |  |  | SELECT | 
|---|
|  |  |  | DATE_FORMAT(h.time, '%Y-%m') AS 'time' | 
|---|
|  |  |  | <foreach collection="sensorKeys" open="," separator="+" close=" AS 'sum' " item="sensorKey"> | 
|---|
|  |  |  | COUNT(json -> '$.${sensorKey}') | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | alarm_daily h | 
|---|
|  |  |  | WHERE | 
|---|
|  |  |  | h.time >= #{start} | 
|---|
|  |  |  | AND h.time <![CDATA[<]]> #{end} | 
|---|
|  |  |  | <if test="state != null"> | 
|---|
|  |  |  | AND h.state = #{state} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | GROUP BY | 
|---|
|  |  |  | DATE_FORMAT(h.time, '%Y-%m') | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </mapper> | 
|---|
|  |  |  | 
|---|
|  |  |  | <?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.AlarmMapper"> | 
|---|
|  |  |  | <select id="getAlarmData" resultType="java.util.LinkedHashMap"> | 
|---|
|  |  |  | SELECT | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | `name`, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <choose> | 
|---|
|  |  |  | <when test="sensorKeys.size > 0"> | 
|---|
|  |  |  | <foreach collection="sensorKeys" separator="," item="sensorKey"> | 
|---|
|  |  |  | SUM( ${sensorKey} ) AS '${sensorKey}' | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | <foreach collection="sensorKeys" open="," separator="+" close=" AS 'sum' " item="sensorKey"> | 
|---|
|  |  |  | SUM( ${sensorKey} ) | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | </when> | 
|---|
|  |  |  | <otherwise> | 
|---|
|  |  |  | time | 
|---|
|  |  |  | </otherwise> | 
|---|
|  |  |  | </choose> | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | ( | 
|---|
|  |  |  | SELECT | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | mp.`name`, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <choose> | 
|---|
|  |  |  | <when test="sensorKeys.size > 0"> | 
|---|
|  |  |  | <foreach collection="sensorKeys" separator="," item="sensorKey"> | 
|---|
|  |  |  | CASE COUNT( json -> '$.${sensorKey}' ) WHEN 0 THEN 0 ELSE 1 END AS '${sensorKey}' | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | </when> | 
|---|
|  |  |  | <otherwise> | 
|---|
|  |  |  | h.time | 
|---|
|  |  |  | </otherwise> | 
|---|
|  |  |  | </choose> | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | alarm_daily h, | 
|---|
|  |  |  | device d, | 
|---|
|  |  |  | monitor_point mp | 
|---|
|  |  |  | WHERE d.monitor_point_id = mp.id | 
|---|
|  |  |  | AND h.mac = d.mac | 
|---|
|  |  |  | AND h.time >= #{start} | 
|---|
|  |  |  | AND h.time <![CDATA[<]]> #{end} | 
|---|
|  |  |  | <if test="provinceCode != null"> | 
|---|
|  |  |  | AND mp.province_code = #{provinceCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="cityCode != null"> | 
|---|
|  |  |  | AND mp.city_code = #{cityCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="areaCode != null"> | 
|---|
|  |  |  | AND mp.area_code = #{areaCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="monitorPointId != null"> | 
|---|
|  |  |  | AND mp.id =    #{monitorPointId} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="organizationId != null"> | 
|---|
|  |  |  | AND mp.organization_id = #{organizationId} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="mac != null"> | 
|---|
|  |  |  | AND d.mac =    #{mac} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="level != null"> | 
|---|
|  |  |  | AND h.state = #{level} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | GROUP BY | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | mp.id, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | h.time | 
|---|
|  |  |  | ) a | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | GROUP BY name | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | <select id="countByTimes"   resultType="java.util.Map"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | <if test="format !=null"> | 
|---|