package com.panzhihua.service_property.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.panzhihua.common.model.dtos.property.CommonPage; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.property.ComPropertyAlarmVO; import com.panzhihua.service_property.dao.ComPropertyEquipmentDao; import com.panzhihua.service_property.entity.ComPropertyAlarm; import com.panzhihua.service_property.dao.ComPropertyAlarmDao; import com.panzhihua.service_property.entity.ComPropertyEquipment; import com.panzhihua.service_property.service.ComPropertyAlarmService; import com.panzhihua.service_property.util.JPushUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * (ComPropertyAlarm)表服务实现类 * * @author makejava * @since 2021-09-07 13:29:50 */ @Slf4j @Service public class ComPropertyAlarmServiceImpl extends ServiceImpl implements ComPropertyAlarmService { @Resource private ComPropertyAlarmDao comPropertyAlarmDao; @Resource private ComPropertyEquipmentDao comPropertyEquipmentDao; @Override public R pageList(CommonPage commonPage) { IPage page=comPropertyAlarmDao.selectList(new Page(commonPage.getPage(), commonPage.getSize()),commonPage); return R.ok(page); } @Override public R selectDetail(Integer id) { return R.ok(comPropertyAlarmDao.selectById(id)); } @Override public R insert(ComPropertyAlarm comPropertyAlarm) { if(comPropertyAlarm!=null){ ComPropertyEquipment comPropertyEquipment=comPropertyEquipmentDao.selectOne(new QueryWrapper().lambda().eq(ComPropertyEquipment::getSerialNo,comPropertyAlarm.getSerialNo())); ComPropertyAlarmVO propertyAlarmVO=new ComPropertyAlarmVO(); if(comPropertyEquipment!=null) { if (comPropertyAlarm.getType().equals(ComPropertyAlarm.type.one)) { comPropertyAlarm.setStatus(ComPropertyAlarm.status.dcl); comPropertyAlarm.setCommunityId(comPropertyEquipment.getCommunityId()); comPropertyAlarm.setPhone(comPropertyEquipment.getPhone()); comPropertyAlarm.setName(comPropertyEquipment.getUsername()); if (comPropertyAlarmDao.insert(comPropertyAlarm) > 0) { BeanUtils.copyProperties(comPropertyAlarm,propertyAlarmVO); propertyAlarmVO.setLatitude(comPropertyEquipment.getLatitude()); propertyAlarmVO.setLongitude(comPropertyEquipment.getLongitude()); Map map = new HashMap<>(); map.put("title", "一键报警通知"); map.put("msg", comPropertyEquipment.getPosition() + "," + comPropertyEquipment.getUsername() + "发起报警"); map.put("communityId", comPropertyEquipment.getCommunityId().toString()); map.put("alarm",JSONObject.toJSONString(propertyAlarmVO)); JPushUtil.jpushAndroid(map); return R.ok(); } } else { if (comPropertyAlarmDao.insert(comPropertyAlarm) > 0) { BeanUtils.copyProperties(comPropertyAlarm,propertyAlarmVO); propertyAlarmVO.setLatitude(comPropertyEquipment.getLatitude()); propertyAlarmVO.setLongitude(comPropertyEquipment.getLongitude()); Map map = new HashMap<>(); map.put("title", "长时间未移动报警通知"); map.put("msg", comPropertyEquipment.getPosition() + "," + comPropertyEquipment.getUsername() + "长时间未移动报警"); map.put("communityId", comPropertyEquipment.getCommunityId().toString()); map.put("alarm",JSONObject.toJSONString(propertyAlarmVO)); JPushUtil.jpushAndroid(map); return R.ok(); } } } } return R.fail(); } }