101captain
2021-09-16 bed5cd20e7564733a554f3f62cf1ec404374f70a
一键报警相关功能修改
1个文件已添加
8个文件已修改
201 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/property/ComPropertyAlarmVO.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComPropertyAlarmApi.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/util/MyAESUtil.java 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/api/ComPropertyAlarmApi.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/entity/ComPropertyEquipment.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/service/ComPropertyAlarmService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/service/impl/ComPropertyAlarmServiceImpl.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/util/JPushUtil.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/resources/mapper/ComPropertyAlarmMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/property/ComPropertyAlarmVO.java
@@ -87,4 +87,16 @@
     */
    @ApiModelProperty("处理图片")
    private String solveUrl;
    /**
     * 经度
     */
    @ApiModelProperty("经度")
    private String longitude;
    /**
     * 纬度
     */
    @ApiModelProperty("纬度")
    private String latitude;
}
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComPropertyAlarmApi.java
@@ -1,24 +1,35 @@
package com.panzhihua.community_backstage.api;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.model.dtos.property.CommonPage;
import com.panzhihua.common.model.helper.AESUtil;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.property.ComPropertyAlarmVO;
import com.panzhihua.common.service.property.PropertyService;
import com.panzhihua.community_backstage.util.MyAESUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@Slf4j
@RestController
@RequestMapping("comPropertyAlarm")
@Api(tags = "物业报警api")
public class ComPropertyAlarmApi extends BaseController {
    private static final String key="nahankeji1234567";
    @Resource
    private PropertyService propertyService;
@@ -60,6 +71,32 @@
    }
    /**
     * 无验证新增数据
     *
     * @param str 加密json
     * @return 新增结果
     */
    @ApiOperation(value = "无验证新增数据")
    @GetMapping("/noToken")
    public R insertNoAuth(String str) {
        if(!str.isEmpty()){
            try {
                String result= MyAESUtil.Decrypt(str.replaceAll(" ", "+"), key);
                if(!result.isEmpty()){
                    ComPropertyAlarmVO comPropertyAlarmVO=JSON.parseObject(result,ComPropertyAlarmVO.class);
                    if(comPropertyAlarmVO!=null){
                        return propertyService.comPropertyAlarmInsert(comPropertyAlarmVO);
                    }
                }
            } catch (Exception e) {
                return R.fail("验证失败");
            }
        }
        return R.fail("数据异常");
    }
    /**
     * 修改数据
     *
     * @param comPropertyAlarmVO 实体对象
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/util/MyAESUtil.java
New file
@@ -0,0 +1,78 @@
package com.panzhihua.community_backstage.util;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class MyAESUtil {
    // 加密
    public static String Encrypt(String sSrc, String sKey) throws Exception {
        if (sKey == null) {
            System.out.print("Key为空null");
            return null;
        }
        // 判断Key是否为16位
        if (sKey.length() != 16) {
            System.out.print("Key长度不是16位");
            return null;
        }
        byte[] raw = sKey.getBytes("utf-8");
        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"算法/模式/补码方式"
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
        return new BASE64Encoder().encode(encrypted);//此处使用BASE64做转码功能,同时能起到2次加密的作用。
    }
    // 解密
    public static String Decrypt(String sSrc, String sKey) throws Exception {
        try {
            // 判断Key是否正确
            if (sKey == null) {
                System.out.print("Key为空null");
                return null;
            }
            // 判断Key是否为16位
            if (sKey.length() != 16) {
                System.out.print("Key长度不是16位");
                return null;
            }
            byte[] raw = sKey.getBytes("utf-8");
            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
            byte[] encrypted1 = new BASE64Decoder().decodeBuffer(sSrc);//先用base64解密
            try {
                byte[] original = cipher.doFinal(encrypted1);
                String originalString = new String(original,"utf-8");
                return originalString;
            } catch (Exception e) {
                System.out.println(e.toString());
                return null;
            }
        } catch (Exception ex) {
            System.out.println(ex.toString());
            return null;
        }
    }
    public static void main(String[] args) throws Exception {
        /*
         * 此处使用AES-128-ECB加密模式,key需要为16位。
         */
        String cKey = "jkl;POIU1234++==";
        // 需要加密的字串
        String cSrc = "www.gowhere.so";
        System.out.println(cSrc);
        // 加密
        String enString = MyAESUtil.Encrypt(cSrc, cKey);
        System.out.println("加密后的字串是:" + enString);
        // 解密
        String DeString = MyAESUtil.Decrypt(enString, cKey);
        System.out.println("解密后的字串是:" + DeString);
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/api/ComPropertyAlarmApi.java
@@ -64,7 +64,7 @@
        ComPropertyAlarm comPropertyAlarm=new ComPropertyAlarm();
        BeanUtils.copyProperties(comPropertyAlarmVO,comPropertyAlarm);
        comPropertyAlarm.setCreateTime(DateUtil.date());
        return R.ok(this.comPropertyAlarmService.save(comPropertyAlarm));
        return R.ok(this.comPropertyAlarmService.insert(comPropertyAlarm));
    }
    /**
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/entity/ComPropertyEquipment.java
@@ -84,4 +84,10 @@
     */
    @ApiModelProperty("设备类型 设备类型 1红外报警 2一键报警")
    private Integer type;
    /**
     * 手机号码
     */
    @ApiModelProperty("手机号")
    private String phone;
}
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/service/ComPropertyAlarmService.java
@@ -23,4 +23,9 @@
     * 查询报警详情
     */
    R selectDetail(Integer id);
    /**
     * 新增报警记录
     */
    R insert(ComPropertyAlarm comPropertyAlarm);
}
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/service/impl/ComPropertyAlarmServiceImpl.java
@@ -1,18 +1,26 @@
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)表服务实现类
@@ -25,6 +33,8 @@
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);
@@ -35,4 +45,47 @@
    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();
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/java/com/panzhihua/service_property/util/JPushUtil.java
@@ -42,8 +42,8 @@
        PushPayload payload = PushPayload.newBuilder()
                // 指定android平台的用户
                .setPlatform(Platform.android())
                // 你项目中的所有用户
                .setAudience(Audience.all())
                // 同社区账号推送
                .setAudience(Audience.tag(parm.get("communityId")))
//                .setAudience(Audience.alias(parm.get("alias"))) // 设置别名发送,单发,点对点方式
                //.setAudience(Audience.tag("tag1")) // 设置按标签发送,相当于群发
@@ -55,7 +55,7 @@
                // TimeToLive 两个小时的缓存时间
                .setOptions(Options.newBuilder().setApnsProduction(true).setTimeToLive(7200).build())
                // 自定义信息
                .setMessage(Message.content(parm.get("msg")))
                .setMessage(Message.content(parm.get("alarm")))
                .build();
        try {
            PushResult pu = jpushClient.sendPush(payload);
springcloud_k8s_panzhihuazhihuishequ/service_property/src/main/resources/mapper/ComPropertyAlarmMapper.xml
@@ -18,7 +18,7 @@
    </resultMap>
    <select id="selectList" resultType="com.panzhihua.common.model.vos.property.ComPropertyAlarmVO">
        select t.*,t1.position,t2.name as solveName from com_property_Alarm t
        select t.*,t1.position,t1.longitude,t1.latitude,t2.name as solveName from com_property_Alarm t
        left join com_property_equipment t1 on t.serial_no = t1.serial_no
        left join sys_user t2 on t.solve_id = user_id
        <where>