于紫祥_1901
2020-12-24 f28149d8183a62f87fa9c8df9ae589070d83f612
波动补偿
5 files added
1 files modified
95 ■■■■■ changed files
src/main/java/com/moral/controller/PageController.java 35 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/FluctuationCompensationMapper.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/FluctuationCompensationService.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/FluctuationCompensationServiceImpl.java 24 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/webSocketServer/ElectronicSWebSocketServer.java 4 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/FluctuationCompensationMapper.xml 11 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/PageController.java
New file
@@ -0,0 +1,35 @@
package com.moral.controller;
import com.moral.service.FluctuationCompensationService;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/page")
@CrossOrigin(origins = "*", maxAge = 3600)
public class PageController {
    @Resource
    private FluctuationCompensationService fluctuationCompensationService;
    @PostMapping("getFC")
    public List<Map> getFC(@RequestBody Map<String, Object> parameters) {
        String mac = parameters.get("mac").toString();
        List<Map> fcMap = fluctuationCompensationService.getFc(mac);
        return fcMap;
    }
    @PostMapping("update")
    public int updateFC(@RequestBody Map<String, Object> parameters){
        Object value = parameters.get("val");
        System.out.println(value);
        JSONObject jsonObject = JSONObject.fromObject(value);
        String val = jsonObject.get("json").toString();
        String mac = jsonObject.get("mac").toString();
        int i = fluctuationCompensationService.update(mac, val);
        return i;
    }
}
src/main/java/com/moral/mapper/FluctuationCompensationMapper.java
New file
@@ -0,0 +1,12 @@
package com.moral.mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface FluctuationCompensationMapper {
    List<Map> getFC(@Param("mac") String mac);
    int update(@Param("mac") String mac, @Param("val") String val);
}
src/main/java/com/moral/service/FluctuationCompensationService.java
New file
@@ -0,0 +1,9 @@
package com.moral.service;
import java.util.List;
import java.util.Map;
public interface FluctuationCompensationService {
    List<Map> getFc(String mac);
    int update(String mac,String val);
}
src/main/java/com/moral/service/impl/FluctuationCompensationServiceImpl.java
New file
@@ -0,0 +1,24 @@
package com.moral.service.impl;
import com.moral.mapper.FluctuationCompensationMapper;
import com.moral.service.FluctuationCompensationService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Service
public class FluctuationCompensationServiceImpl implements FluctuationCompensationService {
@Resource
private FluctuationCompensationMapper fluctuationCompensationMapper;
    @Override
    public List<Map> getFc(String mac) {
        return fluctuationCompensationMapper.getFC(mac);
    }
    @Override
    public int update(String mac, String val) {
        return fluctuationCompensationMapper.update(mac,val);
    }
}
src/main/java/com/moral/webSocketServer/ElectronicSWebSocketServer.java
@@ -138,13 +138,13 @@
                                            JexlExpression jexlExpression = jexlEngine.createExpression(s);
                                            Object evaluate = jexlExpression.evaluate(null);
                                            BigDecimal bg = new BigDecimal(evaluate.toString());
                                            value = bg.setScale(3, BigDecimal.ROUND_HALF_UP).toString();
                                            value = bg.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
                                            reMap.put(sensor.getName(), value+sensorUnits.get(0).getName());
                                        }
                                    }else {
                                        if (sensor.getName().equals("挥发性有机气体(TVOC)")){
                                            BigDecimal bg = new BigDecimal(Double.parseDouble(value)*2.5);
                                            value = bg.setScale(3, BigDecimal.ROUND_HALF_UP).toString();
                                            value = bg.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
                                            reMap.put(sensor.getName(), value+sensor.getUnit());
                                        }else {
                                            reMap.put(sensor.getName(), value+sensor.getUnit());
src/main/resources/mapper/FluctuationCompensationMapper.xml
New file
@@ -0,0 +1,11 @@
<?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.FluctuationCompensationMapper" >
    <update id="update">
        update `fluctuation_compensation` set json=#{val} where mac=#{mac}
    </update>
    <select id="getFC" resultType="java.util.Map">
    SELECT * FROM `fluctuation_compensation` where mac like concat('%',#{mac},'%')
  </select>
</mapper>