新增安防告警不带图片和只上传图片

This commit is contained in:
wyw
2024-08-17 14:24:26 +08:00
parent 15dd120b0d
commit 8b13375a24
6 changed files with 110 additions and 19 deletions

View File

@ -30,15 +30,14 @@ import static com.fastbee.common.utils.StringUtils.isEmpty;
/** /**
* 设备告警上传Controller * 设备告警上传Controller
* *
* @author Dunxi Zang * @author Dunxi Zang
* @date 2024-06-19 * @date 2024-06-19
*/ */
@RestController @RestController
@RequestMapping("/iot/photos") @RequestMapping("/iot/photos")
@Api(tags = "安防小板") @Api(tags = "安防小板")
public class UploadedPhotosController extends BaseController public class UploadedPhotosController extends BaseController {
{
@Autowired @Autowired
private IUploadedPhotosService uploadedPhotosService; private IUploadedPhotosService uploadedPhotosService;
@ -47,8 +46,7 @@ public class UploadedPhotosController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('iot:photos:list')") @PreAuthorize("@ss.hasPermi('iot:photos:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(UploadedPhotos uploadedPhotos) public TableDataInfo list(UploadedPhotos uploadedPhotos) {
{
startPage(); startPage();
List<UploadedPhotos> list = uploadedPhotosService.selectUploadedPhotosList(uploadedPhotos); List<UploadedPhotos> list = uploadedPhotosService.selectUploadedPhotosList(uploadedPhotos);
return getDataTable(list); return getDataTable(list);
@ -60,8 +58,7 @@ public class UploadedPhotosController extends BaseController
@PreAuthorize("@ss.hasPermi('iot:photos:export')") @PreAuthorize("@ss.hasPermi('iot:photos:export')")
@Log(title = "设备告警上传", businessType = BusinessType.EXPORT) @Log(title = "设备告警上传", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, UploadedPhotos uploadedPhotos) public void export(HttpServletResponse response, UploadedPhotos uploadedPhotos) {
{
List<UploadedPhotos> list = uploadedPhotosService.selectUploadedPhotosList(uploadedPhotos); List<UploadedPhotos> list = uploadedPhotosService.selectUploadedPhotosList(uploadedPhotos);
ExcelUtil<UploadedPhotos> util = new ExcelUtil<UploadedPhotos>(UploadedPhotos.class); ExcelUtil<UploadedPhotos> util = new ExcelUtil<UploadedPhotos>(UploadedPhotos.class);
util.exportExcel(response, list, "设备告警上传数据"); util.exportExcel(response, list, "设备告警上传数据");
@ -72,8 +69,7 @@ public class UploadedPhotosController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('iot:photos:query')") @PreAuthorize("@ss.hasPermi('iot:photos:query')")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) public AjaxResult getInfo(@PathVariable("id") Long id) {
{
return success(uploadedPhotosService.selectUploadedPhotosById(id)); return success(uploadedPhotosService.selectUploadedPhotosById(id));
} }
@ -101,12 +97,11 @@ public class UploadedPhotosController extends BaseController
String filePath = RuoYiConfig.getUploadPath(); String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称 // 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, photo); String fileName = FileUploadUtils.upload(filePath, photo);
// 处理可能为空的字段 // 处理可能为空的字段
Double latitude = isEmpty(lat) ? 0.0 : Double.valueOf(lat); Double latitude = isEmpty(lat) ? 0.0 : Double.valueOf(lat);
Double longitude = isEmpty(lng) ? 0.0 : Double.valueOf(lng); Double longitude = isEmpty(lng) ? 0.0 : Double.valueOf(lng);
Double temperature = isEmpty(temp) ? 0.0 : convertAndRoundTemperature(temp); Double temperature = isEmpty(temp) ? 0.0 : convertAndRoundTemperature(temp);
if(doorState.equals("0")){ if (doorState.equals("0")) {
shakeState = "1"; shakeState = "1";
} }
// 处理时间戳 // 处理时间戳
@ -117,7 +112,7 @@ public class UploadedPhotosController extends BaseController
//推送告警短信通知 //推送告警短信通知
uploadedPhotosService.sendAlarmMessage(sn, doorState, shakeState); uploadedPhotosService.sendAlarmMessage(sn, doorState, shakeState);
UploadedPhotos uploadedPhotos = new UploadedPhotos( UploadedPhotos uploadedPhotos = new UploadedPhotos(
null, fileName, monitorPath,imei, sn, latitude, longitude, temperature, doorState, shakeState, date null, fileName, monitorPath, imei, sn, latitude, longitude, temperature, doorState, shakeState, date
); );
return toAjax(uploadedPhotosService.insertUploadedPhotos(uploadedPhotos)); return toAjax(uploadedPhotosService.insertUploadedPhotos(uploadedPhotos));
} catch (IOException e) { } catch (IOException e) {
@ -127,6 +122,7 @@ public class UploadedPhotosController extends BaseController
/** /**
* 箱门告警 * 箱门告警
*
* @return * @return
*/ */
@PostMapping("doorAlert") @PostMapping("doorAlert")
@ -134,6 +130,66 @@ public class UploadedPhotosController extends BaseController
return toAjax(uploadedPhotosService.doorAlert(doorAlertBto)); return toAjax(uploadedPhotosService.doorAlert(doorAlertBto));
} }
/**
* 新增设备告警上传不带图片
*/
@PostMapping("eventNotPic")
public AjaxResult uploadEvent(
@RequestParam("imei") String imei,
@RequestParam("sn") String sn,
@RequestParam("lat") String lat,
@RequestParam("lng") String lng,
@RequestParam("temp") String temp,
@RequestParam("doorState") String doorState,
@RequestParam("shakeState") String shakeState,
@RequestParam("time") String time) {
// 处理可能为空的字段
Double latitude = isEmpty(lat) ? 0.0 : Double.valueOf(lat);
Double longitude = isEmpty(lng) ? 0.0 : Double.valueOf(lng);
Double temperature = isEmpty(temp) ? 0.0 : convertAndRoundTemperature(temp);
if (doorState.equals("0")) {
shakeState = "1";
}
// 处理时间戳
long timestamp = Long.parseLong(time + "000");
Date date = new Date(timestamp);
//抓拍监控,并返回路径
String monitorPath = uploadedPhotosService.captureMonitorPhoto(sn);
//推送告警短信通知
uploadedPhotosService.sendAlarmMessage(sn, doorState, shakeState);
UploadedPhotos uploadedPhotos = new UploadedPhotos(
null, "", monitorPath, imei, sn, latitude, longitude, temperature, doorState, shakeState, date
);
return toAjax(uploadedPhotosService.insertUploadedPhotos(uploadedPhotos));
}
/**
* 只上传告警图片
*/
@PostMapping("uploadPicByTime")
public AjaxResult uploadPicByTime(
@RequestParam("fileToUpload") MultipartFile photo,
@RequestParam("sn") String sn,
@RequestParam("time") String time) {
// 处理时间戳
try {
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, photo);
// 处理时间戳
long timestamp = Long.parseLong(time + "000");
Date date = new Date(timestamp);
//推送告警短信通知
UploadedPhotos uploadedPhotos = new UploadedPhotos();
uploadedPhotos.setSn(sn);
uploadedPhotos.setPhotoPath(fileName);
uploadedPhotos.setUploadTime(date);
return toAjax(uploadedPhotosService.uploadPicByTime(uploadedPhotos));
} catch (IOException e) {
throw new ServiceException("设备告警信息上传失败");
}
}
/** /**
* 修改设备告警上传 * 修改设备告警上传
@ -141,8 +197,7 @@ public class UploadedPhotosController extends BaseController
@PreAuthorize("@ss.hasPermi('iot:photos:edit')") @PreAuthorize("@ss.hasPermi('iot:photos:edit')")
@Log(title = "设备告警上传", businessType = BusinessType.UPDATE) @Log(title = "设备告警上传", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody UploadedPhotos uploadedPhotos) public AjaxResult edit(@RequestBody UploadedPhotos uploadedPhotos) {
{
return toAjax(uploadedPhotosService.updateUploadedPhotos(uploadedPhotos)); return toAjax(uploadedPhotosService.updateUploadedPhotos(uploadedPhotos));
} }
@ -151,11 +206,11 @@ public class UploadedPhotosController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('iot:photos:remove')") @PreAuthorize("@ss.hasPermi('iot:photos:remove')")
@Log(title = "设备告警上传", businessType = BusinessType.DELETE) @Log(title = "设备告警上传", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) public AjaxResult remove(@PathVariable Long[] ids) {
{
return toAjax(uploadedPhotosService.deleteUploadedPhotosByIds(ids)); return toAjax(uploadedPhotosService.deleteUploadedPhotosByIds(ids));
} }
public static Double convertAndRoundTemperature(String tempStr) { public static Double convertAndRoundTemperature(String tempStr) {
// 将字符串转换为double // 将字符串转换为double
double temp = Double.parseDouble(tempStr); double temp = Double.parseDouble(tempStr);

View File

@ -77,4 +77,6 @@ public interface IUploadedPhotosService
void sendAlarmMessage(String sn, String doorState, String shakeState); void sendAlarmMessage(String sn, String doorState, String shakeState);
String doorAlert(DoorAlertBto doorAlertBto) throws Exception; String doorAlert(DoorAlertBto doorAlertBto) throws Exception;
int uploadPicByTime(UploadedPhotos uploadedPhotos);
} }

View File

@ -302,4 +302,10 @@ public class UploadedPhotosServiceImpl implements IUploadedPhotosService {
return "生成失败"; return "生成失败";
} }
} }
@Override
public int uploadPicByTime(UploadedPhotos uploadedPhotos) {
//根据时间和sn进行复制图片链接
return uploadedPhotosMapper.updateBySnAndTime(uploadedPhotos);
}
} }

View File

@ -45,6 +45,15 @@ public interface UploadedPhotosMapper
*/ */
public int updateUploadedPhotos(UploadedPhotos uploadedPhotos); public int updateUploadedPhotos(UploadedPhotos uploadedPhotos);
/**
* 通过SN和图片进行更新数据
* @param uploadedPhotos
* @return
*/
public int updateBySnAndTime(UploadedPhotos uploadedPhotos);
/** /**
* 删除存储上传的照片信息 * 删除存储上传的照片信息
* *

View File

@ -89,6 +89,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id} where id = #{id}
</update> </update>
<update id="updateBySnAndTime" parameterType="com.fastbee.iot.model.anfang.UploadedPhotos">
update uploaded_photos
<trim prefix="SET" suffixOverrides=",">
<if test="photoPath != null and photoPath != ''">photo_path = #{photoPath},</if>
<if test="monitorPath != null and monitorPath != ''">monitor_path = #{monitorPath},</if>
<if test="imei != null and imei != ''">imei = #{imei},</if>
<if test="sn != null">sn = #{sn},</if>
<if test="lat != null">lat = #{lat},</if>
<if test="lng != null">lng = #{lng},</if>
<if test="temp != null">temp = #{temp},</if>
<if test="doorState != null">door_state = #{doorState},</if>
<if test="shakeState != null">shake_state = #{shakeState},</if>
<if test="uploadTime != null">upload_time = #{uploadTime},</if>
</trim>
where sn = #{sn} and upload_time = #{uploadTime}
</update>
<delete id="deleteUploadedPhotosById" parameterType="Long"> <delete id="deleteUploadedPhotosById" parameterType="Long">
delete from uploaded_photos where id = #{id} delete from uploaded_photos where id = #{id}
</delete> </delete>

View File

@ -119,8 +119,10 @@ public class MaGuangaiRecordServiceImpl implements IMaGuangaiRecordService
record.setCardId(item.get("card_id").toString()); record.setCardId(item.get("card_id").toString());
record.setAreaCode(item.get("area_code").toString()); record.setAreaCode(item.get("area_code").toString());
record.setUserBalance(com.fastbee.common.utils.NumberUtils.formatFloat(Float.parseFloat(item.get("user_balance").toString())/100)+""); record.setUserBalance(com.fastbee.common.utils.NumberUtils.formatFloat(Float.parseFloat(item.get("user_balance").toString())/100)+"");
record.setCurFlow(item.get("cur_flow").toString()); record.setCurFlow(item.get("cur_flow").toString().equals("null")?"--":
record.setCurEle(item.get("cur_ele").toString()); (com.fastbee.common.utils.NumberUtils.formatFloat(Float.parseFloat(item.get("cur_flow").toString())/100)+""));
record.setCurEle(item.get("cur_ele").toString().equals("null")?"--":
(com.fastbee.common.utils.NumberUtils.formatFloat(Float.parseFloat(item.get("cur_ele").toString())/100)+""));
record.setStatus(Integer.parseInt(item.get("status").toString())); record.setStatus(Integer.parseInt(item.get("status").toString()));
if(StringUtils.isNotEmpty(item.get("create_time").toString())){ if(StringUtils.isNotEmpty(item.get("create_time").toString())){
if(NumberUtil.isNumber(item.get("create_time").toString())) { if(NumberUtil.isNumber(item.get("create_time").toString())) {