zhanghua
2024-01-21 bc8074c56893eac3eb5002dcefeacd644d827a29
优化
5个文件已修改
1个文件已添加
503 ■■■■■ 已修改文件
ycl-platform/src/main/java/com/ycl/common/util/DateUtil.java 384 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/entity/caseHandler/DispatchInfo.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/service/message/IMessageService.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/service/message/impl/MessageServiceImpl.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/timer/SendMsg.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/common/util/DateUtil.java
@@ -12,219 +12,223 @@
public class DateUtil {
    /**
     * 获取两日期之间间隔的天数
     *
     * @param smdate
     *            较小的时间
     * @param bdate
     *            较大的时间
     * @return 相差天数
     */
    public static int daysBetween(Date smdate, Date bdate) {
        long between_days = 0;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            smdate = sdf.parse(sdf.format(smdate));
            bdate = sdf.parse(sdf.format(bdate));
            Calendar cal = Calendar.getInstance();
            cal.setTime(smdate);
            long time1 = cal.getTimeInMillis();
            cal.setTime(bdate);
            long time2 = cal.getTimeInMillis();
            between_days = (time2 - time1) / (1000 * 3600 * 24);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    /**
     * 获取两日期之间间隔的天数
     *
     * @param smdate 较小的时间
     * @param bdate  较大的时间
     * @return 相差天数
     */
    public static int daysBetween(Date smdate, Date bdate) {
        long between_days = 0;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            smdate = sdf.parse(sdf.format(smdate));
            bdate = sdf.parse(sdf.format(bdate));
            Calendar cal = Calendar.getInstance();
            cal.setTime(smdate);
            long time1 = cal.getTimeInMillis();
            cal.setTime(bdate);
            long time2 = cal.getTimeInMillis();
            between_days = (time2 - time1) / (1000 * 3600 * 24);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return Integer.parseInt(String.valueOf(between_days));
    }
        return Integer.parseInt(String.valueOf(between_days));
    }
    public static boolean isBetween(Date date, Date startDate, Date endDate) {
        try {
    public static boolean isBetween(Date date, Date startDate, Date endDate) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            startDate = sdf.parse(sdf.format(startDate));
            endDate = sdf.parse(sdf.format(endDate));
            date = sdf.parse(sdf.format(date));
        try {
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            startDate = sdf.parse(sdf.format(startDate));
            endDate = sdf.parse(sdf.format(endDate));
            date = sdf.parse(sdf.format(date));
            cal.setTime(date);
            long time0 = cal.getTimeInMillis();
            cal.setTime(startDate);
            long time1 = cal.getTimeInMillis();
            cal.setTime(endDate);
            long time2 = cal.getTimeInMillis();
            Calendar cal = Calendar.getInstance();
            if (time0 > time1 && time0 <= time2)
                return true;
            cal.setTime(date);
            long time0 = cal.getTimeInMillis();
            cal.setTime(startDate);
            long time1 = cal.getTimeInMillis();
            cal.setTime(endDate);
            long time2 = cal.getTimeInMillis();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return false;
            if (time0 > time1 && time0 <= time2)
                return true;
    }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return false;
    public static long DifferMillis(Date sDate, Date eDate) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            sDate = sdf.parse(sdf.format(sDate));
            eDate = sdf.parse(sdf.format(eDate));
            Calendar cal = Calendar.getInstance();
            cal.setTime(sDate);
            long time1 = cal.getTimeInMillis();
            cal.setTime(eDate);
            long time2 = cal.getTimeInMillis();
            return Math.abs(time1 - time2);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
        return -1L;
    }
    public static long DifferMillis(Date sDate, Date eDate) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            sDate = sdf.parse(sdf.format(sDate));
            eDate = sdf.parse(sdf.format(eDate));
            Calendar cal = Calendar.getInstance();
            cal.setTime(sDate);
            long time1 = cal.getTimeInMillis();
            cal.setTime(eDate);
            long time2 = cal.getTimeInMillis();
            return Math.abs(time1 - time2);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    public static long DifferSeconds(Date sDate, Date eDate) {
        return -1L;
    }
        return DifferMillis(sDate, eDate) / 1000;
    }
    public static long DifferSeconds(Date sDate, Date eDate) {
    /**
     * 相差分钟数
     *
     * @param sDate
     * @param eDate
     * @return
     */
    public static long DifferMinutes(Date sDate, Date eDate) {
        return DifferMillis(sDate, eDate) / 1000;
    }
        return Long.parseLong(String.valueOf(DifferMillis(sDate, eDate)
                / (1000 * 60)));
    }
    /**
     * 相差分钟数
     *
     * @param sDate
     * @param eDate
     * @return
     */
    public static long DifferMinutes(Date sDate, Date eDate) {
    public static String getNowDate(String format) {
        return new SimpleDateFormat(format).format(new Date());
    }
        return Long.parseLong(String.valueOf(DifferMillis(sDate, eDate)
                / (1000 * 60)));
    }
    public static String getDateString(Date date, String format) {
        return new SimpleDateFormat(format).format(date);
    }
    public static String getNowDate(String format) {
        return new SimpleDateFormat(format).format(new Date());
    }
    public static Date parse(String date, String format) {
    public static String getDateString(Date date, String format) {
        return new SimpleDateFormat(format).format(date);
    }
        try {
            return new SimpleDateFormat(format).parse(date);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
    public static Date parse(String date, String format) {
    public static boolean nowTimeBetween(String beginTimeStr, String endTimeStr)
            throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
        Long beginTime = dateFormat.parse(beginTimeStr).getTime();
        Long endTime = dateFormat.parse(endTimeStr).getTime();
        Long nowTime = dateFormat.parse(dateFormat.format(new Date()))
                .getTime();
        if (nowTime >= beginTime && nowTime <= endTime) {
            return true;
        }
        return false;
    }
        try {
            return new SimpleDateFormat(format).parse(date);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
    @SuppressWarnings("static-access")
    public static Date addDate(Date date, int days) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE, days);// 把日期往后增加一天.整数往后推,负数往前移动
        return calendar.getTime(); // 这个时间就是日期往后推一天的结果
    }
    public static boolean nowTimeBetween(String beginTimeStr, String endTimeStr)
            throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
        Long beginTime = dateFormat.parse(beginTimeStr).getTime();
        Long endTime = dateFormat.parse(endTimeStr).getTime();
        Long nowTime = dateFormat.parse(dateFormat.format(new Date()))
                .getTime();
        if (nowTime >= beginTime && nowTime <= endTime) {
            return true;
        }
        return false;
    }
    @SuppressWarnings("static-access")
    public static Date addHour(Date date, int hour) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.HOUR, hour);// 把日期往后增加一天.整数往后推,负数往前移动
        return calendar.getTime(); // 这个时间就是日期往后推一天的结果
    }
    @SuppressWarnings("static-access")
    public static Date addDate(Date date, int days) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE, days);// 把日期往后增加一天.整数往后推,负数往前移动
        return calendar.getTime(); // 这个时间就是日期往后推一天的结果
    }
    @SuppressWarnings("static-access")
    public static Date addMinute(Date date, int minute) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.MINUTE, minute);// 把日期往后增加一天.整数往后推,负数往前移动
        return calendar.getTime(); // 这个时间就是日期往后推一天的结果
    }
    @SuppressWarnings("static-access")
    public static Date addHour(Date date, int hour) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.HOUR, hour);// 把日期往后增加一天.整数往后推,负数往前移动
        return calendar.getTime(); // 这个时间就是日期往后推一天的结果
    }
    @SuppressWarnings("static-access")
    public static Date addSecond(Date date, int second) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.SECOND, second);// 把日期往后增加一天.整数往后推,负数往前移动
        return calendar.getTime(); // 这个时间就是日期往后推一天的结果
    }
    @SuppressWarnings("static-access")
    public static Date addMinute(Date date, int minute) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.MINUTE, minute);// 把日期往后增加一天.整数往后推,负数往前移动
        return calendar.getTime(); // 这个时间就是日期往后推一天的结果
    }
    /**
     * 统计两个时间的时间差
     * two-one
     * 相差几秒几毫秒
     */
    public static String getDistanceDateTime(Date one, Date two) {
        long day = 0;//天数差
        long hour = 0;//小时数差
        long min = 0;//分钟数差
        long second=0;//秒数差
        long diff=0 ;//毫秒差
        String result = "";
        final Calendar c = Calendar.getInstance();
        c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
        c.setTime(one);
        long time1 = one.getTime();
        long time2 = two.getTime();
        diff = time2 - time1;
        day = diff / (24 * 60 * 60 * 1000);
        hour = (diff / (60 * 60 * 1000) - day * 24);
        min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
        second = diff/1000;
        // System.out.println("day="+day+" hour="+hour+" min="+min+" ss="+second%60+" SSS="+diff%1000);
        String daystr = day%30+"天";
        String hourStr = hour%24+"小时";
        String minStr = min%60+"分";
        String secondStr = second%60+"秒";
        if (day!=0){
            result = result + daystr;
        }
        if (hour!=0){
            result = result + hourStr;
        }
        if (min!=0){
            result = result + minStr;
        }
        if (second!=0){
            result = result + secondStr;
        }
        return result;
    }
    public static Date fromLocalDateTime(LocalDateTime ldt){
        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zdt = ldt.atZone(zoneId);
        Date date = Date.from(zdt.toInstant());
        return date ;
    }
    public static void main(String[] args) throws ParseException {
    @SuppressWarnings("static-access")
    public static Date addSecond(Date date, int second) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.SECOND, second);// 把日期往后增加一天.整数往后推,负数往前移动
        return calendar.getTime(); // 这个时间就是日期往后推一天的结果
    }
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE,-1);
        calendar.add(Calendar.HOUR,-6);
        calendar.add(Calendar.MINUTE,-5);
        calendar.add(Calendar.SECOND,-4);
        calendar.add(Calendar.MILLISECOND, -30);
        Date date = calendar.getTime();
        Date today = new Date();
        // System.out.println(getDistanceDateTime(date,today));
    }
    /**
     * 统计两个时间的时间差
     * two-one
     * 相差几秒几毫秒
     */
    public static String getDistanceDateTime(Date one, Date two) {
        long day = 0;//天数差
        long hour = 0;//小时数差
        long min = 0;//分钟数差
        long second = 0;//秒数差
        long diff = 0;//毫秒差
        String result = "";
        final Calendar c = Calendar.getInstance();
        c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
        c.setTime(one);
        long time1 = one.getTime();
        long time2 = two.getTime();
        diff = time2 - time1;
        day = diff / (24 * 60 * 60 * 1000);
        hour = (diff / (60 * 60 * 1000) - day * 24);
        min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
        second = diff / 1000;
        // System.out.println("day="+day+" hour="+hour+" min="+min+" ss="+second%60+" SSS="+diff%1000);
        String daystr = day % 30 + "天";
        String hourStr = hour % 24 + "小时";
        String minStr = min % 60 + "分";
        String secondStr = second % 60 + "秒";
        if (day != 0) {
            result = result + daystr;
        }
        if (hour != 0) {
            result = result + hourStr;
        }
        if (min != 0) {
            if (day == 0) {
                result = result + minStr;
            }
        }
        if (second != 0) {
            if (day == 0 && hour == 0) {
                result = result + secondStr;
            }
        }
        return result;
    }
    public static Date fromLocalDateTime(LocalDateTime ldt) {
        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zdt = ldt.atZone(zoneId);
        Date date = Date.from(zdt.toInstant());
        return date;
    }
    public static void main(String[] args) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        calendar.add(Calendar.HOUR, -6);
        calendar.add(Calendar.MINUTE, -5);
        calendar.add(Calendar.SECOND, -4);
        calendar.add(Calendar.MILLISECOND, -30);
        Date date = calendar.getTime();
        Date today = new Date();
        // System.out.println(getDistanceDateTime(date,today));
    }
}
ycl-platform/src/main/java/com/ycl/entity/caseHandler/DispatchInfo.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -106,6 +107,7 @@
     * 创建时间
     */
    @TableField("create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java
@@ -1,6 +1,8 @@
package com.ycl.service.caseHandler.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.common.util.UtilNumber;
import com.ycl.dto.video.HKAlarmParam;
@@ -124,6 +126,12 @@
                    imageResources.setBelongToId(baseCase.getId());
                    imageResources.setUrl(videoAlarmReport.getPicData());
                    imageResources.setCreateTime(LocalDateTime.now());
                    ImageResources imageResources1 = new ImageResources();
                    BeanUtil.copyProperties(imageResources,imageResources1);
                    imageResources1.setType("01");
                    imageResourcesService.save(imageResources1);
                    imageResourcesService.save(imageResources);
                } catch (Exception ex) {
                    System.out.println("海康推送保存异常:" + ex.getMessage());
@@ -191,8 +199,13 @@
                imageResources.setBelongToId(baseCase.getId());
                imageResources.setUrl(imgs[i]);
                imageResources.setCreateTime(LocalDateTime.now());
                imageResourcesService.save(imageResources);
                ImageResources imageResources1 = new ImageResources();
                BeanUtil.copyProperties(imageResources,imageResources1);
                imageResources1.setType("01");
                imageResourcesService.save(imageResources1);
                imageResourcesService.save(imageResources);
            }
        } catch (Exception ex) {
ycl-platform/src/main/java/com/ycl/service/message/IMessageService.java
@@ -18,6 +18,7 @@
 */
public interface IMessageService extends IService<Message> {
    void sendSMS(Message message);
    void sendMessage(Message message);
    Page<MessageVO> list(MessageParam messageParam);
ycl-platform/src/main/java/com/ycl/service/message/impl/MessageServiceImpl.java
@@ -82,18 +82,37 @@
    RestTemplate restTemplate;
    @Override
    @SneakyThrows
    @Transactional(rollbackFor = Exception.class)
    public void sendSMS(Message message) {
        Integer messageStatus = sendMessages(message);
        if (messageStatus == 2) {
            message.setStatus(2);
            message.setRespondResult("发送成功");
        }
        if (messageStatus == 3) {
            message.setStatus(3);
            message.setRespondResult("发送失败");
        }
        message.setUpdateTime(new Date());
        message.setSendTime(new Date());
        messageMapper.updateById(message);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void sendMessage(Message message) {
        Message savedMessage = messageMapper.selectOne(new LambdaQueryWrapper<Message>()
                .eq(Message::getTargetTo, message.getTargetTo())
                .eq(Message::getTargetFrom, message.getTargetFrom())
                .eq(Message::getBody, message.getBody())
                .eq(Message::getStatus, 1)
                .eq(Message::getHead, message.getHead()));
        if (savedMessage != null) {
            messageMapper.deleteById(savedMessage);
        }
//        Message savedMessage = messageMapper.selectOne(new LambdaQueryWrapper<Message>()
//                .eq(Message::getTargetTo, message.getTargetTo())
//                .eq(Message::getTargetFrom, message.getTargetFrom())
//                .eq(Message::getBody, message.getBody())
//                .eq(Message::getStatus, 1)
//                .eq(Message::getHead, message.getHead()));
//        if (savedMessage != null) {
//            messageMapper.deleteById(savedMessage);
//        }
        ArrayList<Message> ids = new ArrayList<>();
        message.setTargetFrom(umsAdminMapper.selectById(message.getCreateUser()).getUsername());
@@ -114,20 +133,20 @@
                ids.add(sendMessage);
            }
        }
        switch (message.getChannelCode()) {
            //邮件发送
            case ChannelCode.SMS:
                sendSMS(message, ids);
                break;
            //短信发送
            case ChannelCode.MAIL:
                sendMail(message);
                break;
            case ChannelCode.INNER:
                break;
            default:
                throw new ApiException("未匹配到该类型");
        }
//        switch (message.getChannelCode()) {
//            //短信发送
//            case ChannelCode.SMS:
//                sendSMS(message, ids);
//                break;
//            //邮件发送
//            case ChannelCode.MAIL:
//                sendMail(message);
//                break;
//            case ChannelCode.INNER:
//                break;
//            default:
//                throw new ApiException("未匹配到该类型");
//        }
    }
    @SneakyThrows
ycl-platform/src/main/java/com/ycl/timer/SendMsg.java
New file
@@ -0,0 +1,36 @@
package com.ycl.timer;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ycl.service.message.IMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.ycl.entity.message.Message;
import java.util.List;
@Slf4j
@Component
public class SendMsg {
    @Value("${spring.profiles.active}")
    private String env;
    @Autowired
    IMessageService messageService;
    @Scheduled(cron = "0 0/2 * * * ?")
    public void runAction() {
        if ("online".equals(env)) {
            List<Message> messages = messageService.list(new LambdaQueryWrapper<Message>()
                    .eq(Message::getStatus, 0));
            for (Message msg : messages) {
                messageService.sendSMS(msg);
            }
        }
    }
}