kaiyu
2021-05-24 52f100ec7860c781c1b44259c6c54b221a30c100
screen-manage/src/main/java/com/moral/api/service/impl/SensorServiceImpl.java
@@ -5,13 +5,18 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.entity.ManageRole;
import com.moral.api.entity.Sensor;
import com.moral.api.entity.SysDictData;
import com.moral.api.entity.VersionSensorUnit;
import com.moral.api.mapper.SensorMapper;
import com.moral.api.mapper.SysDictDataMapper;
import com.moral.api.mapper.VersionSensorUnitMapper;
import com.moral.api.service.SensorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.util.LogUtils;
import com.moral.constant.Constants;
import com.moral.constant.RedisConstants;
import com.moral.constant.ResponseCodeEnum;
import com.moral.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
@@ -41,6 +46,12 @@
    @Autowired(required = false)
    private SensorMapper sensorMapper;
    @Autowired(required = false)
    private VersionSensorUnitMapper versionSensorUnitMapper;
    @Autowired(required = false)
    private SysDictDataMapper sysDictDataMapper;
    @Autowired
    LogUtils logUtils;
@@ -123,14 +134,29 @@
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String content = "修改因子:"+oldSensor.getName()+";";
        for (Object key:updateSensorMap.keySet()) {
            if (key.toString().equals("name")){
                content = content+"角色名:"+oldSensor.getName()+"->"+updateSensorMap.get(key)+";";
            if (key.toString().equals("name")&&updateSensorMap.get(key)!=null){
                content = content+"因子名:"+oldSensor.getName()+"->"+updateSensorMap.get(key)+";";
            }
            if (key.toString().equals("code")){
            if (key.toString().equals("code")&&updateSensorMap.get(key)!=null){
                QueryWrapper<VersionSensorUnit> wrapper_Version = new QueryWrapper<>();
                wrapper_Version.eq("sensor_code",oldSensor.getCode());
                wrapper_Version.eq("is_delete","0");
                VersionSensorUnit versionSensorUnit = new VersionSensorUnit();
                versionSensorUnit.setSensorCode(updateSensorMap.get(key).toString());
                versionSensorUnitMapper.update(versionSensorUnit,wrapper_Version);
                content = content+"编号:"+oldSensor.getCode()+"->"+updateSensorMap.get(key)+";";
            }
            if (key.toString().equals("desc")){
            if (key.toString().equals("desc")&&updateSensorMap.get(key)!=null){
                content = content+"备注:"+oldSensor.getDesc()+"->"+updateSensorMap.get(key)+";";
            }
            if (key.toString().equals("upper")&&updateSensorMap.get(key)!=null){
                content = content+"上限:"+oldSensor.getDesc()+"->"+updateSensorMap.get(key)+";";
            }
            if (key.toString().equals("lower")&&updateSensorMap.get(key)!=null){
                content = content+"下限:"+oldSensor.getDesc()+"->"+updateSensorMap.get(key)+";";
            }
            if (key.toString().equals("default_unit_key")&&updateSensorMap.get(key)!=null){
                content = content+"默认单位:"+oldSensor.getDesc()+"->"+updateSensorMap.get(key)+";";
            }
        }
        logUtils.saveOperationForManage(request,content,Constants.UPDATE_OPERATE_TYPE);
@@ -167,9 +193,16 @@
            sensorMap.put("createTime",createTime);
            sensorMap.put("updateTime",updateTime);
            sensorMap.put("key",sensor.getId());
            if (sensor.getDefaultUnitKey()!=null&&sensor.getDefaultUnitKey()!=""){
                QueryWrapper<SysDictData> wrapper_VSU = new QueryWrapper();
                wrapper_VSU.eq("is_delete",0);
                wrapper_VSU.eq("dataKey",sensor.getDefaultUnitKey());
                wrapper_VSU.eq("dict_type_id",14);
                sensorMap.put("default_unit_key",sysDictDataMapper.selectOne(wrapper_VSU).getDataValue());
            }
            sensorList.add(sensorMap);
        }
        resultMap.put("manageRoles",sensorList);
        resultMap.put("sensors",sensorList);
        resultMap.put("totalNumber",totleNum);
        resultMap.put("current",current);
        int totalPageNumber = totleNum/size;
@@ -194,8 +227,14 @@
            return resultMap;
        }
        Sensor deleteSensor = new Sensor();
        deleteSensor.setIsDelete("1");
        deleteSensor.setIsDelete(Constants.DELETE);
        sensorMapper.update(deleteSensor,wrapper);
        QueryWrapper<VersionSensorUnit> wrapper_Version = new QueryWrapper<>();
        wrapper_Version.eq("sensor_code",sensor.getCode());
        wrapper_Version.eq("is_delete","0");
        VersionSensorUnit versionSensorUnit = new VersionSensorUnit();
        versionSensorUnit.setIsDelete(Constants.DELETE);
        versionSensorUnitMapper.update(versionSensorUnit,wrapper_Version);
        //操作插入日志
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String content = "删除因子:"+sensor.getName()+";";
@@ -204,6 +243,8 @@
        resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
        //刷新缓存
        refreshCache();
        //注销token
        TokenUtils.destoryToken(Integer.parseInt(map.get("id").toString()));
        return resultMap;
    }
@@ -234,9 +275,16 @@
            sensorMap.put("createTime",createTime);
            sensorMap.put("updateTime",updateTime);
            sensorMap.put("key",sensor.getId());
            if (sensor.getDefaultUnitKey()!=null&&sensor.getDefaultUnitKey()!=""){
                QueryWrapper<SysDictData> wrapper_VSU = new QueryWrapper();
                wrapper_VSU.eq("is_delete",0);
                wrapper_VSU.eq("dataKey",sensor.getDefaultUnitKey());
                wrapper_VSU.eq("dict_type_id",14);
                sensorMap.put("default_unit_key",sysDictDataMapper.selectOne(wrapper_VSU).getDataValue());
            }
            sensorList.add(sensorMap);
        }
        resultMap.put("manageRoles",sensorList);
        resultMap.put("sensors",sensorList);
        resultMap.put("totalNumber",totleNum);
        resultMap.put("current",current);
        int totalPageNumber = totleNum/size;