| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-05-06 |
| | | * @since 2021-05-08 |
| | | */ |
| | | @Service |
| | | @Transactional |
| | |
| | | LogUtils logUtils; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String, Object> insertOne(Sensor sensor) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | if (sensor.getName()==null || sensor.getSensorKey()==null){ |
| | | if (sensor.getName()==null || sensor.getCode()==null){ |
| | | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | return resultMap; |
| | |
| | | resultMap.put("msg",ResponseCodeEnum.SENSOR_IS_EXIST.getMsg()); |
| | | return resultMap; |
| | | } |
| | | QueryWrapper<Sensor> wrapper_sensorKey = new QueryWrapper<>(); |
| | | wrapper_sensorKey.eq("sensor_key",sensor.getSensorKey()); |
| | | wrapper_sensorKey.eq("is_delete","0"); |
| | | if (sensorMapper.selectCount(wrapper_sensorKey)!=0){ |
| | | resultMap.put("code",ResponseCodeEnum.SENSOR_KEY_IS_EXIST.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SENSOR_KEY_IS_EXIST.getMsg()); |
| | | QueryWrapper<Sensor> wrapper_code = new QueryWrapper<>(); |
| | | wrapper_code.eq("code",sensor.getCode()); |
| | | wrapper_code.eq("is_delete","0"); |
| | | if (sensorMapper.selectCount(wrapper_code)!=0){ |
| | | resultMap.put("code",ResponseCodeEnum.SENSOR_KEY_IS_USED.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SENSOR_KEY_IS_USED.getMsg()); |
| | | return resultMap; |
| | | } |
| | | //sensorMapper.insertOne(sensor); |
| | | sensorMapper.insertOne(sensor); |
| | | //操作插入日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | String content = "添加因子:"+sensor.getName()+";"; |
| | | //logUtils.saveOperationForManage(request,content,Constants.INSERT_OPERATE_TYPE); |
| | | logUtils.saveOperationForManage(request,content,Constants.INSERT_OPERATE_TYPE); |
| | | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); |
| | | return resultMap; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> updateSensor(Map<String,Object> updateSensorMap) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | if(ObjectUtils.isEmpty(updateSensorMap.get("id"))){ |
| | | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | return resultMap; |
| | | } |
| | | if (updateSensorMap.containsKey("name")){ |
| | | if (updateSensorMap.get("name")==null||updateSensorMap.get("name")==""){ |
| | | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | return resultMap; |
| | | } |
| | | } |
| | | if (updateSensorMap.containsKey("code")){ |
| | | if(ObjectUtils.isEmpty(updateSensorMap.get("code"))){ |
| | | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | return resultMap; |
| | | } |
| | | } |
| | | Sensor oldSensor = sensorMapper.getSensorById(Integer.parseInt(updateSensorMap.get("id").toString())); |
| | | if (ObjectUtils.isEmpty(oldSensor)){ |
| | | resultMap.put("code",ResponseCodeEnum.SENSOR_IS_NOT_EXIST.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SENSOR_IS_NOT_EXIST.getMsg()); |
| | | return resultMap; |
| | | } |
| | | QueryWrapper<Sensor> wrapper_code = new QueryWrapper<>(); |
| | | wrapper_code.eq("code",updateSensorMap.get("code")); |
| | | wrapper_code.eq("is_delete","0"); |
| | | List<Sensor> sensorList = sensorMapper.selectList(wrapper_code); |
| | | System.out.println(sensorList.get(0)); |
| | | if (sensorList.size()!=0&&!sensorList.get(0).getId().toString().equals(updateSensorMap.get("id").toString())){ |
| | | resultMap.put("code",ResponseCodeEnum.SENSOR_KEY_IS_USED.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SENSOR_KEY_IS_USED.getMsg()); |
| | | return resultMap; |
| | | } |
| | | sensorMapper.updateSensor(updateSensorMap); |
| | | 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("code")){ |
| | | content = content+"编号:"+oldSensor.getCode()+"->"+updateSensorMap.get(key)+";"; |
| | | } |
| | | if (key.toString().equals("desc")){ |
| | | content = content+"备注:"+oldSensor.getDesc()+"->"+updateSensorMap.get(key)+";"; |
| | | } |
| | | } |
| | | System.out.println(content); |
| | | logUtils.saveOperationForManage(request,content,Constants.UPDATE_OPERATE_TYPE); |
| | | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); |
| | | return resultMap; |