mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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<ComPropertyAlarmDao, ComPropertyAlarm> implements ComPropertyAlarmService {
    @Resource
    private ComPropertyAlarmDao comPropertyAlarmDao;
    @Resource
    private ComPropertyEquipmentDao comPropertyEquipmentDao;
    @Override
    public R pageList(CommonPage commonPage) {
        IPage<ComPropertyAlarmVO> 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<ComPropertyEquipment>().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<String, String> 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<String, String> 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();
    }
}