Pārlūkot izejas kodu

修改同步用户+部门,排菜+消费rabbit

he.dujuan 3 gadi atpakaļ
vecāks
revīzija
22e6058707

+ 35 - 2
eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java

@@ -31,8 +31,8 @@ import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.Arrays;
-import java.util.List;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * 获取当前登录的用户
@@ -125,4 +125,37 @@ public class SecurityUtils {
             }
         }
     }
+
+    /**
+     * 根据key获取token
+     */
+    public static Map<String,Object> getToken(String key){
+        //获取11位随机数
+        double rand = Math.random();
+        String randStr = String.valueOf(rand).replace("0.", "");
+        String nonce = randStr.substring(0, 11);
+        System.out.println("nonce:"+nonce);
+        //获取当前时间
+        SimpleDateFormat sdf = new SimpleDateFormat();
+        sdf.applyPattern("yyyy-MM-dd HH:mm");
+        Date date = new Date();
+        String timestamp =sdf.format(date);
+        System.out.println("timestamp:"+timestamp);
+        //排序
+        String[] arr = {key, timestamp, nonce};
+        Arrays.sort(arr);
+        //获取token
+        String str = "";
+        for (int i = 0; i < arr.length; i++) {
+            str += arr[i];
+        }
+        String token = EncryptUtils.sha1(str);
+        System.out.println("token:"+token);
+        Map<String,Object> data = new HashMap<String, Object>(1) {{
+            put("nonce", nonce);
+            put("timestamp", timestamp);
+            put("token", token);
+        }};
+        return data;
+    }
 }

+ 111 - 111
eladmin-system/src/main/java/me/zhengjie/modules/dm/daypc/rest/ReceiveMsg.java

@@ -1,114 +1,114 @@
-package me.zhengjie.modules.dm.daypc.rest;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.rabbitmq.client.*;
-import com.rabbitmq.client.Connection;
-import lombok.SneakyThrows;
-import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
-import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
-import me.zhengjie.modules.dm.food.domain.DmFood;
-import me.zhengjie.modules.dm.food.service.DmFoodService;
-import me.zhengjie.utils.ConnectionUtil;
-import org.springframework.amqp.rabbit.core.RabbitTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-
-import java.io.*;
-import java.sql.*;
-import java.text.*;
-import java.util.*;
-
-@Component
-//@RabbitListener(queues = "schedule_produce")
-public class ReceiveMsg {
-//    private final static String SCHEDULE_PRODUCE = "schedule_produce";
-    @Autowired
-    private DmDayPcService dmDayPcService;
-    @Autowired
-    private DmFoodService dmFoodService;
-    @Autowired
-    RabbitTemplate rabbitTemplate;
-    private static String isEable = "0";
-
-    //每天10点执行
-    @Scheduled(cron = "0 0 10 * * ?")
-    //异步执行,指定线程池(配置类里配置)
-    @Async("threadPoolTaskExecutor1")
-    public void timer(){
-        isEable = "1";
-    }
-
-    //每五分钟执行一次
-    @Scheduled(cron = "0 */5 * * * ?")
-    @Async("threadPoolTaskExecutor2")
-    public void timer2(){
-        if(isEable!=null&&isEable=="1"){
-            receive();
-            isEable = "0";
-        }
-    }
-
-    /**
-     * 消费者
-     */
-    public void receive(){
-        Connection connection = ConnectionUtil.getConnection();
-        try {
-            Channel channel = connection.createChannel();
-            //通过consumer来处理数据
-            Consumer consumer = new DefaultConsumer(channel){
-                @SneakyThrows
-                @Override
-                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
-                    //body就是从队列中获取的数据
-                    String str = new String(body);
-                    List<DmDayPc>  list = JSONArray.parseArray(str,DmDayPc.class);
-//                    Map<String,Object> map = null;
-                    for (DmDayPc dmDayPc : list) {
-//                        map = new HashMap<>();
-//                        map.put("food",dmDayPc.getFood());
-                        dmDayPc.setPcdate(new Timestamp(System.currentTimeMillis()));
-                        dmDayPcService.create(dmDayPc);
-                        System.out.println("新增food==="+dmDayPc.getFood());
-                        dmFoodService.create(dmDayPc.getFood());
-                    }
-//                    Map<String,Object> map = JSONObject.parseObject(str);
-//                    for (Map.Entry<String, Object> entry : map.entrySet()) {
-//                        dmFoodService.create((DmFood) entry);
-//                        System.out.println("key====>" + entry.getKey() + ",value===>" + entry.getValue());
+//package me.zhengjie.modules.dm.daypc.rest;
+//
+//import com.alibaba.fastjson.JSON;
+//import com.alibaba.fastjson.JSONArray;
+//import com.alibaba.fastjson.JSONObject;
+//import com.fasterxml.jackson.databind.ObjectMapper;
+//import com.rabbitmq.client.*;
+//import com.rabbitmq.client.Connection;
+//import lombok.SneakyThrows;
+//import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
+//import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
+//import me.zhengjie.modules.dm.food.domain.DmFood;
+//import me.zhengjie.modules.dm.food.service.DmFoodService;
+//import me.zhengjie.utils.ConnectionUtil;
+//import org.springframework.amqp.rabbit.core.RabbitTemplate;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.scheduling.annotation.Async;
+//import org.springframework.scheduling.annotation.Scheduled;
+//import org.springframework.stereotype.Component;
+//
+//import java.io.*;
+//import java.sql.*;
+//import java.text.*;
+//import java.util.*;
+//
+//@Component
+////@RabbitListener(queues = "schedule_produce")
+//public class ReceiveMsg {
+////    private final static String SCHEDULE_PRODUCE = "schedule_produce";
+//    @Autowired
+//    private DmDayPcService dmDayPcService;
+//    @Autowired
+//    private DmFoodService dmFoodService;
+//    @Autowired
+//    RabbitTemplate rabbitTemplate;
+//    private static String isEable = "0";
+//
+//    //每天10点执行
+//    @Scheduled(cron = "0 0 10 * * ?")
+//    //异步执行,指定线程池(配置类里配置)
+//    @Async("threadPoolTaskExecutor1")
+//    public void timer(){
+//        isEable = "1";
+//    }
+//
+//    //每五分钟执行一次
+//    @Scheduled(cron = "0 */5 * * * ?")
+//    @Async("threadPoolTaskExecutor2")
+//    public void timer2(){
+//        if(isEable!=null&&isEable=="1"){
+//            receive();
+//            isEable = "0";
+//        }
+//    }
+//
+//    /**
+//     * 消费者
+//     */
+//    public void receive(){
+//        Connection connection = ConnectionUtil.getConnection();
+//        try {
+//            Channel channel = connection.createChannel();
+//            //通过consumer来处理数据
+//            Consumer consumer = new DefaultConsumer(channel){
+//                @SneakyThrows
+//                @Override
+//                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
+//                    //body就是从队列中获取的数据
+//                    String str = new String(body);
+//                    List<DmDayPc>  list = JSONArray.parseArray(str,DmDayPc.class);
+////                    Map<String,Object> map = null;
+//                    for (DmDayPc dmDayPc : list) {
+////                        map = new HashMap<>();
+////                        map.put("food",dmDayPc.getFood());
+//                        dmDayPc.setPcdate(new Timestamp(System.currentTimeMillis()));
+//                        dmDayPcService.create(dmDayPc);
+//                        System.out.println("新增food==="+dmDayPc.getFood());
+//                        dmFoodService.create(dmDayPc.getFood());
 //                    }
-
-                }
-            };
-            //参数1:接收哪个队列的数据
-            //参数2:消息确认 是否应答,收到消息是否回复
-            //参数3:
-            channel.basicConsume("schedule_produce",true,consumer);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-//    public List<DmDayPc> getDmDayPc(){
-//        return JSONObject.parseArray(getDmDayPc(),DmDayPc.class);
+////                    Map<String,Object> map = JSONObject.parseObject(str);
+////                    for (Map.Entry<String, Object> entry : map.entrySet()) {
+////                        dmFoodService.create((DmFood) entry);
+////                        System.out.println("key====>" + entry.getKey() + ",value===>" + entry.getValue());
+////                    }
+//
+//                }
+//            };
+//            //参数1:接收哪个队列的数据
+//            //参数2:消息确认 是否应答,收到消息是否回复
+//            //参数3:
+//            channel.basicConsume("schedule_produce",true,consumer);
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
 //    }
-
-    public  Object getObjectFromBytes(byte[] objBytes) throws Exception {
-        if (objBytes == null || objBytes.length == 0) {
-            return null;
-        }
-        ByteArrayInputStream bi = new ByteArrayInputStream(objBytes);
-        ObjectInputStream oi = new ObjectInputStream(bi);
-        return oi.readObject();
-    }
-
-//    @RabbitHandler
-//    public void process(DmDayPc dmDayPc) {
-//        dmDayPcService.create(dmDayPc);
+//
+////    public List<DmDayPc> getDmDayPc(){
+////        return JSONObject.parseArray(getDmDayPc(),DmDayPc.class);
+////    }
+//
+//    public  Object getObjectFromBytes(byte[] objBytes) throws Exception {
+//        if (objBytes == null || objBytes.length == 0) {
+//            return null;
+//        }
+//        ByteArrayInputStream bi = new ByteArrayInputStream(objBytes);
+//        ObjectInputStream oi = new ObjectInputStream(bi);
+//        return oi.readObject();
 //    }
-}
+//
+////    @RabbitHandler
+////    public void process(DmDayPc dmDayPc) {
+////        dmDayPcService.create(dmDayPc);
+////    }
+//}

+ 91 - 91
eladmin-system/src/main/java/me/zhengjie/modules/dm/daypc/rest/SendMsg.java

@@ -1,92 +1,92 @@
-package me.zhengjie.modules.dm.daypc.rest;
-
-import com.alibaba.fastjson.JSON;
-import com.rabbitmq.client.BuiltinExchangeType;
-import com.rabbitmq.client.Channel;
-import com.rabbitmq.client.Connection;
-import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
-import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
-import me.zhengjie.modules.dm.daypc.service.dto.DmDayPcDto;
-import me.zhengjie.utils.ConnectionUtil;
-import org.springframework.amqp.core.AmqpTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeoutException;
-
-@Component
-public class SendMsg {
-    @Autowired
-    private AmqpTemplate amqpTemplate;
-    @Autowired
-    private DmDayPcService dmDayPcService;
-    private static String isEable = "0";
-
-    //每天10点执行
-    @Scheduled(cron = "0 0 10 * * ?")
-    //异步执行,指定线程池(配置类里配置)
-    @Async("threadPoolTaskExecutor1")
-    public void timer(){
-        isEable = "1";
-    }
-
-    //每五分钟执行一次
-    @Scheduled(cron = "0 */5 * * * ?")
-    @Async("threadPoolTaskExecutor2")
-    public void timer2(){
-        if(isEable!=null&&isEable=="1"){
-            send();
-            isEable = "0";
-        }
-    }
-
-    public void send(){
-//        String msg = "Hello,rabbit";
-        //获取连接
-        Connection connection = ConnectionUtil.getConnection();
-        try {
-            List<DmDayPc> dmDayPc = dmDayPcService.foodRepository();
-            String userString = JSON.toJSONString(dmDayPc);
-            Channel channel = connection.createChannel();
-            String exchangeName = "schedule_produce";//交换机
-            channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
-            String queue1Name = "schedule_produce";//队列名称
-            channel.queueDeclare(queue1Name, true, false, false, null);
-            channel.queueBind(queue1Name, exchangeName, "schedule_produce");// 队列绑定hello路由
-            channel.basicPublish(exchangeName, "schedule_produce", null, userString.getBytes());
-            System.out.println("sned排菜:"+dmDayPc);
-            //            Boy boy=new Boy(15,"tom");
-            //对象转化为字节码 把对象转化为字节码后,把字节码传输过去再转化为对象
-//            byte[] bytes=getBytesFromObject(dmDayPc);
-//            amqpTemplate.convertAndSend("exchange","topic.messages",bytes);
-
-//            List<DmDayPcDto> dmDayPc = dmDayPcService.queryAll(null);
+//package me.zhengjie.modules.dm.daypc.rest;
+//
+//import com.alibaba.fastjson.JSON;
+//import com.rabbitmq.client.BuiltinExchangeType;
+//import com.rabbitmq.client.Channel;
+//import com.rabbitmq.client.Connection;
+//import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
+//import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
+//import me.zhengjie.modules.dm.daypc.service.dto.DmDayPcDto;
+//import me.zhengjie.utils.ConnectionUtil;
+//import org.springframework.amqp.core.AmqpTemplate;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.scheduling.annotation.Async;
+//import org.springframework.scheduling.annotation.Scheduled;
+//import org.springframework.stereotype.Component;
+//
+//import java.io.ByteArrayOutputStream;
+//import java.io.IOException;
+//import java.io.ObjectOutputStream;
+//import java.io.Serializable;
+//import java.util.HashMap;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.concurrent.TimeoutException;
+//
+//@Component
+//public class SendMsg {
+//    @Autowired
+//    private AmqpTemplate amqpTemplate;
+//    @Autowired
+//    private DmDayPcService dmDayPcService;
+//    private static String isEable = "0";
+//
+//    //每天10点执行
+//    @Scheduled(cron = "0 0 10 * * ?")
+//    //异步执行,指定线程池(配置类里配置)
+//    @Async("threadPoolTaskExecutor1")
+//    public void timer(){
+//        isEable = "1";
+//    }
+//
+//    //每五分钟执行一次
+//    @Scheduled(cron = "0 */5 * * * ?")
+//    @Async("threadPoolTaskExecutor2")
+//    public void timer2(){
+//        if(isEable!=null&&isEable=="1"){
+//            send();
+//            isEable = "0";
+//        }
+//    }
+//
+//    public void send(){
+////        String msg = "Hello,rabbit";
+//        //获取连接
+//        Connection connection = ConnectionUtil.getConnection();
+//        try {
+//            List<DmDayPc> dmDayPc = dmDayPcService.foodRepository();
 //            String userString = JSON.toJSONString(dmDayPc);
-//            amqpTemplate.convertAndSend(exchangeName,queue1Name,userString);
-            channel.close();
-            connection.close();
-        } catch (IOException | TimeoutException e) {
-            e.printStackTrace();
-        }
-    }
-
-    //对象转化为字节码
-    public  byte[] getBytesFromObject(Serializable obj) throws Exception {
-        if (obj == null) {
-            return null;
-        }
-        ByteArrayOutputStream bo = new ByteArrayOutputStream();
-        ObjectOutputStream oo = new ObjectOutputStream(bo);
-        oo.writeObject(obj);
-        return bo.toByteArray();
-    }
-}
+//            Channel channel = connection.createChannel();
+//            String exchangeName = "schedule_produce";//交换机
+//            channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
+//            String queue1Name = "schedule_produce";//队列名称
+//            channel.queueDeclare(queue1Name, true, false, false, null);
+//            channel.queueBind(queue1Name, exchangeName, "schedule_produce");// 队列绑定hello路由
+//            channel.basicPublish(exchangeName, "schedule_produce", null, userString.getBytes());
+//            System.out.println("sned排菜:"+dmDayPc);
+//            //            Boy boy=new Boy(15,"tom");
+//            //对象转化为字节码 把对象转化为字节码后,把字节码传输过去再转化为对象
+////            byte[] bytes=getBytesFromObject(dmDayPc);
+////            amqpTemplate.convertAndSend("exchange","topic.messages",bytes);
+//
+////            List<DmDayPcDto> dmDayPc = dmDayPcService.queryAll(null);
+////            String userString = JSON.toJSONString(dmDayPc);
+////            amqpTemplate.convertAndSend(exchangeName,queue1Name,userString);
+//            channel.close();
+//            connection.close();
+//        } catch (IOException | TimeoutException e) {
+//            e.printStackTrace();
+//        }
+//    }
+//
+//    //对象转化为字节码
+//    public  byte[] getBytesFromObject(Serializable obj) throws Exception {
+//        if (obj == null) {
+//            return null;
+//        }
+//        ByteArrayOutputStream bo = new ByteArrayOutputStream();
+//        ObjectOutputStream oo = new ObjectOutputStream(bo);
+//        oo.writeObject(obj);
+//        return bo.toByteArray();
+//    }
+//}

+ 89 - 89
eladmin-system/src/main/java/me/zhengjie/modules/dm/order/rest/OrderReceiveMsg.java

@@ -1,89 +1,89 @@
-package me.zhengjie.modules.dm.order.rest;
-
-import com.alibaba.fastjson.JSONArray;
-import com.rabbitmq.client.*;
-import lombok.SneakyThrows;
-import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
-import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
-import me.zhengjie.modules.dm.order.domain.DmOrderItem;
-import me.zhengjie.modules.dm.order.domain.DmOrderRecord;
-import me.zhengjie.modules.dm.order.service.DmOrderItemService;
-import me.zhengjie.modules.dm.order.service.DmOrderRecordService;
-import me.zhengjie.modules.dm.order.service.dto.DmExpenseCalendar;
-import me.zhengjie.modules.dm.order.service.dto.DmOrderItemDto;
-import me.zhengjie.utils.ConnectionUtil;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.sql.Timestamp;
-import java.util.List;
-
-@Component
-public class OrderReceiveMsg {
-    @Autowired
-    private DmOrderRecordService dmOrderRecordService;
-    private static String isEable = "0";
-
-    //每天10点执行
-    @Scheduled(cron = "0 0 10 * * ?")
-    //异步执行,指定线程池(配置类里配置)
-    @Async("threadPoolTaskExecutor1")
-    public void timer(){
-        isEable = "1";
-    }
-
-    //每五分钟执行一次
-    @Scheduled(cron = "0 */5 * * * ?")
-    @Async("threadPoolTaskExecutor2")
-    public void timer2(){
-        if(isEable!=null&&isEable=="1"){
-            receive();
-            isEable = "0";
-        }
-    }
-
-    /**
-     * 消费者
-     */
-    public void receive(){
-        Connection connection = ConnectionUtil.getConnection();
-        try {
-            Channel channel = connection.createChannel();
-            //通过consumer来处理数据
-            Consumer consumer = new DefaultConsumer(channel){
-                @SneakyThrows
-                @Override
-                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
-                    //body就是从队列中获取的数据
-                    String str = new String(body);
-                    List<DmExpenseCalendar> dmOrderItem = JSONArray.parseArray(str,DmExpenseCalendar.class);
-//                    DmOrderRecord dmOrderRecord = (DmOrderRecord) getObjectFromBytes(body);
-//                    dmOrderItemService.create(dmOrderItem);
-//                    dmOrderRecordService.create(dmOrderRecord);
-                    for (DmExpenseCalendar dmExpenseCalendar : dmOrderItem) {
-//                        dmExpenseCalendar.setCreateDate(new Timestamp(System.currentTimeMillis()));
-                        dmOrderRecordService.createOrderItem(dmExpenseCalendar);
-                        dmOrderRecordService.createOrderRecord(dmExpenseCalendar);
-                    }
-                }
-            };
-            channel.basicConsume("dish_trade_produce",true,consumer);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-    public  Object getObjectFromBytes(byte[] objBytes) throws Exception {
-        if (objBytes == null || objBytes.length == 0) {
-            return null;
-        }
-        ByteArrayInputStream bi = new ByteArrayInputStream(objBytes);
-        ObjectInputStream oi = new ObjectInputStream(bi);
-        return oi.readObject();
-    }
-}
+//package me.zhengjie.modules.dm.order.rest;
+//
+//import com.alibaba.fastjson.JSONArray;
+//import com.rabbitmq.client.*;
+//import lombok.SneakyThrows;
+//import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
+//import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
+//import me.zhengjie.modules.dm.order.domain.DmOrderItem;
+//import me.zhengjie.modules.dm.order.domain.DmOrderRecord;
+//import me.zhengjie.modules.dm.order.service.DmOrderItemService;
+//import me.zhengjie.modules.dm.order.service.DmOrderRecordService;
+//import me.zhengjie.modules.dm.order.service.dto.DmExpenseCalendar;
+//import me.zhengjie.modules.dm.order.service.dto.DmOrderItemDto;
+//import me.zhengjie.utils.ConnectionUtil;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.scheduling.annotation.Async;
+//import org.springframework.scheduling.annotation.Scheduled;
+//import org.springframework.stereotype.Component;
+//
+//import java.io.ByteArrayInputStream;
+//import java.io.IOException;
+//import java.io.ObjectInputStream;
+//import java.sql.Timestamp;
+//import java.util.List;
+//
+//@Component
+//public class OrderReceiveMsg {
+//    @Autowired
+//    private DmOrderRecordService dmOrderRecordService;
+//    private static String isEable = "0";
+//
+//    //每天10点执行
+//    @Scheduled(cron = "0 0 10 * * ?")
+//    //异步执行,指定线程池(配置类里配置)
+//    @Async("threadPoolTaskExecutor1")
+//    public void timer(){
+//        isEable = "1";
+//    }
+//
+//    //每五分钟执行一次
+//    @Scheduled(cron = "0 */5 * * * ?")
+//    @Async("threadPoolTaskExecutor2")
+//    public void timer2(){
+//        if(isEable!=null&&isEable=="1"){
+//            receive();
+//            isEable = "0";
+//        }
+//    }
+//
+//    /**
+//     * 消费者
+//     */
+//    public void receive(){
+//        Connection connection = ConnectionUtil.getConnection();
+//        try {
+//            Channel channel = connection.createChannel();
+//            //通过consumer来处理数据
+//            Consumer consumer = new DefaultConsumer(channel){
+//                @SneakyThrows
+//                @Override
+//                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
+//                    //body就是从队列中获取的数据
+//                    String str = new String(body);
+//                    List<DmExpenseCalendar> dmOrderItem = JSONArray.parseArray(str,DmExpenseCalendar.class);
+////                    DmOrderRecord dmOrderRecord = (DmOrderRecord) getObjectFromBytes(body);
+////                    dmOrderItemService.create(dmOrderItem);
+////                    dmOrderRecordService.create(dmOrderRecord);
+//                    for (DmExpenseCalendar dmExpenseCalendar : dmOrderItem) {
+////                        dmExpenseCalendar.setCreateDate(new Timestamp(System.currentTimeMillis()));
+//                        dmOrderRecordService.createOrderItem(dmExpenseCalendar);
+//                        dmOrderRecordService.createOrderRecord(dmExpenseCalendar);
+//                    }
+//                }
+//            };
+//            channel.basicConsume("dish_trade_produce",true,consumer);
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//    }
+//
+//    public  Object getObjectFromBytes(byte[] objBytes) throws Exception {
+//        if (objBytes == null || objBytes.length == 0) {
+//            return null;
+//        }
+//        ByteArrayInputStream bi = new ByteArrayInputStream(objBytes);
+//        ObjectInputStream oi = new ObjectInputStream(bi);
+//        return oi.readObject();
+//    }
+//}

+ 91 - 91
eladmin-system/src/main/java/me/zhengjie/modules/dm/order/rest/OrderSendMsg.java

@@ -1,91 +1,91 @@
-package me.zhengjie.modules.dm.order.rest;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.rabbitmq.client.BuiltinExchangeType;
-import com.rabbitmq.client.Channel;
-import com.rabbitmq.client.Connection;
-import me.zhengjie.modules.dm.order.service.DmOrderRecordService;
-import me.zhengjie.modules.dm.order.service.dto.DmExpenseCalendar;
-import me.zhengjie.utils.ConnectionUtil;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeoutException;
-
-@Component
-public class OrderSendMsg {
-    @Autowired
-    private DmOrderRecordService dmOrderRecordService;
-    private static String isEable = "0";
-
-    //每天10点执行
-    @Scheduled(cron = "0 0 10 * * ?")
-    //异步执行,指定线程池(配置类里配置)
-    @Async("threadPoolTaskExecutor1")
-    public void timer(){
-        isEable = "1";
-    }
-
-    //每五分钟执行一次
-    @Scheduled(cron = "0 */5 * * * ?")
-    @Async("threadPoolTaskExecutor2")
-    public void timer2(){
-        if(isEable!=null&&isEable=="1"){
-            send();
-            isEable = "0";
-        }
-    }
-
-    public void send(){
-        //获取连接
-        Connection connection = ConnectionUtil.getConnection();
-        try {
-//            String userString1 = JSON.toJSONString(dmOrderItemService.queryAll(null));
-//            String userString2 = JSON.toJSONString(dmOrderRecordService.selectOrderRecord());
-            List<Map<String,Object>> map = dmOrderRecordService.selectOrderRecord();
-            JSONArray jsonArray = new JSONArray();
-            jsonArray.addAll(map);
-            List<DmExpenseCalendar> list = jsonArray.toJavaList(DmExpenseCalendar.class);
-            String userString2 = JSON.toJSONString(list);
-            Channel channel = connection.createChannel();
-            String exchangeName = "dish_trade_produce";//交换机
-            channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
-            String queue1Name = "dish_trade_produce";//队列名称
-            channel.queueDeclare(queue1Name, true, false, false, null);
-            channel.queueBind(queue1Name, exchangeName, "dish_trade_produce");// 队列绑定hello路由
-
-//            byte[] bytes = new byte[2];
-//            bytes = userString1.getBytes();
-//            bytes[1] = (Byte)
-//            channel.basicPublish(exchangeName, "dish_trade_produce", null, userString1.getBytes());
-            channel.basicPublish(exchangeName, "dish_trade_produce", null, userString2.getBytes());
-//            System.out.println("userString1"+userString1);
-            System.out.println("消费记录:"+userString2);
-
-            channel.close();
-            connection.close();
-        } catch (IOException | TimeoutException e) {
-            e.printStackTrace();
-        }
-    }
-
-    //对象转化为字节码
-    public  byte[] getBytesFromObject(Serializable obj) throws Exception {
-        if (obj == null) {
-            return null;
-        }
-        ByteArrayOutputStream bo = new ByteArrayOutputStream();
-        ObjectOutputStream oo = new ObjectOutputStream(bo);
-        oo.writeObject(obj);
-        return bo.toByteArray();
-    }
-}
+//package me.zhengjie.modules.dm.order.rest;
+//
+//import com.alibaba.fastjson.JSON;
+//import com.alibaba.fastjson.JSONArray;
+//import com.rabbitmq.client.BuiltinExchangeType;
+//import com.rabbitmq.client.Channel;
+//import com.rabbitmq.client.Connection;
+//import me.zhengjie.modules.dm.order.service.DmOrderRecordService;
+//import me.zhengjie.modules.dm.order.service.dto.DmExpenseCalendar;
+//import me.zhengjie.utils.ConnectionUtil;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.scheduling.annotation.Async;
+//import org.springframework.scheduling.annotation.Scheduled;
+//import org.springframework.stereotype.Component;
+//
+//import java.io.ByteArrayOutputStream;
+//import java.io.IOException;
+//import java.io.ObjectOutputStream;
+//import java.io.Serializable;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.concurrent.TimeoutException;
+//
+//@Component
+//public class OrderSendMsg {
+//    @Autowired
+//    private DmOrderRecordService dmOrderRecordService;
+//    private static String isEable = "0";
+//
+//    //每天10点执行
+//    @Scheduled(cron = "0 0 10 * * ?")
+//    //异步执行,指定线程池(配置类里配置)
+//    @Async("threadPoolTaskExecutor1")
+//    public void timer(){
+//        isEable = "1";
+//    }
+//
+//    //每五分钟执行一次
+//    @Scheduled(cron = "0 */5 * * * ?")
+//    @Async("threadPoolTaskExecutor2")
+//    public void timer2(){
+//        if(isEable!=null&&isEable=="1"){
+//            send();
+//            isEable = "0";
+//        }
+//    }
+//
+//    public void send(){
+//        //获取连接
+//        Connection connection = ConnectionUtil.getConnection();
+//        try {
+////            String userString1 = JSON.toJSONString(dmOrderItemService.queryAll(null));
+////            String userString2 = JSON.toJSONString(dmOrderRecordService.selectOrderRecord());
+//            List<Map<String,Object>> map = dmOrderRecordService.selectOrderRecord();
+//            JSONArray jsonArray = new JSONArray();
+//            jsonArray.addAll(map);
+//            List<DmExpenseCalendar> list = jsonArray.toJavaList(DmExpenseCalendar.class);
+//            String userString2 = JSON.toJSONString(list);
+//            Channel channel = connection.createChannel();
+//            String exchangeName = "dish_trade_produce";//交换机
+//            channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
+//            String queue1Name = "dish_trade_produce";//队列名称
+//            channel.queueDeclare(queue1Name, true, false, false, null);
+//            channel.queueBind(queue1Name, exchangeName, "dish_trade_produce");// 队列绑定hello路由
+//
+////            byte[] bytes = new byte[2];
+////            bytes = userString1.getBytes();
+////            bytes[1] = (Byte)
+////            channel.basicPublish(exchangeName, "dish_trade_produce", null, userString1.getBytes());
+//            channel.basicPublish(exchangeName, "dish_trade_produce", null, userString2.getBytes());
+////            System.out.println("userString1"+userString1);
+//            System.out.println("消费记录:"+userString2);
+//
+//            channel.close();
+//            connection.close();
+//        } catch (IOException | TimeoutException e) {
+//            e.printStackTrace();
+//        }
+//    }
+//
+//    //对象转化为字节码
+//    public  byte[] getBytesFromObject(Serializable obj) throws Exception {
+//        if (obj == null) {
+//            return null;
+//        }
+//        ByteArrayOutputStream bo = new ByteArrayOutputStream();
+//        ObjectOutputStream oo = new ObjectOutputStream(bo);
+//        oo.writeObject(obj);
+//        return bo.toByteArray();
+//    }
+//}

+ 112 - 0
eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/DayPcDataTask.java

@@ -0,0 +1,112 @@
+package me.zhengjie.modules.quartz.task;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.rabbitmq.client.*;
+import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
+import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
+import me.zhengjie.modules.dm.food.service.DmFoodService;
+import me.zhengjie.utils.ConnectionUtil;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.sql.Timestamp;
+import java.util.List;
+import java.util.concurrent.TimeoutException;
+
+@Slf4j
+@RequiredArgsConstructor
+@Component
+public class DayPcDataTask {
+    private final DmFoodService dmFoodService;
+    private final DmDayPcService dmDayPcService;
+    private static String isEable = "0";
+
+    public void runSend1(){
+        isEable = "1";
+    }
+
+    public void runSend2(){
+        if(isEable!=null&&isEable=="1"){
+            send();
+            isEable = "0";
+        }
+    }
+
+    public void runReceive1(){
+        isEable = "1";
+    }
+
+    public void runReceive2(){
+        if(isEable!=null&&isEable=="1"){
+            receive();
+            isEable = "0";
+        }
+    }
+
+    /**
+     * 生产者
+     */
+    public void send(){
+        //获取连接
+        Connection connection = ConnectionUtil.getConnection();
+        try {
+            List<DmDayPc> dmDayPc = dmDayPcService.foodRepository();
+            String userString = JSON.toJSONString(dmDayPc);
+            Channel channel = connection.createChannel();
+            String exchangeName = "schedule_produce";//交换机
+            channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
+            String queue1Name = "schedule_produce";//队列名称
+            channel.queueDeclare(queue1Name, true, false, false, null);
+            channel.queueBind(queue1Name, exchangeName, "schedule_produce");// 队列绑定hello路由
+            channel.basicPublish(exchangeName, "schedule_produce", null, userString.getBytes());
+            System.out.println("sned排菜:"+dmDayPc);
+            channel.close();
+            connection.close();
+        } catch (IOException | TimeoutException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 消费者
+     */
+    public void receive(){
+        Connection connection = ConnectionUtil.getConnection();
+        try {
+            Channel channel = connection.createChannel();
+            //通过consumer来处理数据
+            Consumer consumer = new DefaultConsumer(channel){
+                @SneakyThrows
+                @Override
+                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
+                    //body就是从队列中获取的数据
+                    String str = new String(body);
+                    List<DmDayPc>  list = JSONArray.parseArray(str,DmDayPc.class);
+                    for (DmDayPc dmDayPc : list) {
+                        dmDayPc.setPcdate(new Timestamp(System.currentTimeMillis()));
+                        dmDayPcService.create(dmDayPc);
+                        System.out.println("新增food==="+dmDayPc.getFood());
+                        dmFoodService.create(dmDayPc.getFood());
+                    }
+                }
+            };
+            //参数1:接收哪个队列的数据
+            //参数2:消息确认 是否应答,收到消息是否回复
+            //参数3:
+            channel.basicConsume("schedule_produce",true,consumer);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 108 - 0
eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/OrderDataTask.java

@@ -0,0 +1,108 @@
+package me.zhengjie.modules.quartz.task;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.rabbitmq.client.*;
+import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import me.zhengjie.modules.dm.order.service.DmOrderRecordService;
+import me.zhengjie.modules.dm.order.service.dto.DmExpenseCalendar;
+import me.zhengjie.utils.ConnectionUtil;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeoutException;
+
+@Slf4j
+@RequiredArgsConstructor
+@Component
+public class OrderDataTask {
+    private final DmOrderRecordService dmOrderRecordService;
+    private static String isEable = "0";
+
+    public void runSend1(){
+        isEable = "1";
+    }
+
+    public void runSend2(){
+        if(isEable!=null&&isEable=="1"){
+            send();
+            isEable = "0";
+        }
+    }
+
+    public void runReceive1(){
+        isEable = "1";
+    }
+
+    public void runReceive2(){
+        if(isEable!=null&&isEable=="1"){
+            receive();
+            isEable = "0";
+        }
+    }
+
+    /**
+     * 生产者
+     */
+    public void send(){
+        //获取连接
+        Connection connection = ConnectionUtil.getConnection();
+        try {
+            List<Map<String,Object>> map = dmOrderRecordService.selectOrderRecord();
+            JSONArray jsonArray = new JSONArray();
+            jsonArray.addAll(map);
+            List<DmExpenseCalendar> list = jsonArray.toJavaList(DmExpenseCalendar.class);
+            String userString2 = JSON.toJSONString(list);
+            Channel channel = connection.createChannel();
+            String exchangeName = "dish_trade_produce";//交换机
+            channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
+            String queue1Name = "dish_trade_produce";//队列名称
+            channel.queueDeclare(queue1Name, true, false, false, null);
+            channel.queueBind(queue1Name, exchangeName, "dish_trade_produce");// 队列绑定hello路由
+            channel.basicPublish(exchangeName, "dish_trade_produce", null, userString2.getBytes());
+            System.out.println("消费记录:"+userString2);
+
+            channel.close();
+            connection.close();
+        } catch (IOException | TimeoutException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 消费者
+     */
+    public void receive(){
+        Connection connection = ConnectionUtil.getConnection();
+        try {
+            Channel channel = connection.createChannel();
+            //通过consumer来处理数据
+            Consumer consumer = new DefaultConsumer(channel){
+                @SneakyThrows
+                @Override
+                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
+                    //body就是从队列中获取的数据
+                    String str = new String(body);
+                    List<DmExpenseCalendar> dmOrderItem = JSONArray.parseArray(str,DmExpenseCalendar.class);
+//                    DmOrderRecord dmOrderRecord = (DmOrderRecord) getObjectFromBytes(body);
+//                    dmOrderItemService.create(dmOrderItem);
+//                    dmOrderRecordService.create(dmOrderRecord);
+                    for (DmExpenseCalendar dmExpenseCalendar : dmOrderItem) {
+//                        dmExpenseCalendar.setCreateDate(new Timestamp(System.currentTimeMillis()));
+                        dmOrderRecordService.createOrderItem(dmExpenseCalendar);
+                        dmOrderRecordService.createOrderRecord(dmExpenseCalendar);
+                    }
+                }
+            };
+            channel.basicConsume("dish_trade_produce",true,consumer);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 188 - 157
eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/ZkDataSyncTask.java

@@ -21,22 +21,19 @@ import com.alibaba.fastjson.JSONObject;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.modules.dm.user.domain.DmUser;
-import me.zhengjie.modules.dm.user.service.DmUserService;
-import me.zhengjie.modules.dm.user.service.dto.DmUserDto;
+import me.zhengjie.modules.dm.user.repository.DmUserRepository;
 import me.zhengjie.modules.system.domain.Dept;
 import me.zhengjie.modules.system.domain.Job;
 import me.zhengjie.modules.system.domain.Role;
 import me.zhengjie.modules.system.domain.User;
+import me.zhengjie.modules.system.repository.DeptRepository;
+import me.zhengjie.modules.system.repository.UserRepository;
 import me.zhengjie.modules.system.service.DeptService;
-import me.zhengjie.modules.system.service.UserService;
-import me.zhengjie.modules.system.service.dto.DeptDto;
-import me.zhengjie.modules.system.service.dto.UserDto;
 import me.zhengjie.utils.SecurityUtils;
-import me.zhengjie.utils.StringUtils;
-import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Component;
-import org.springframework.util.ObjectUtils;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 /**
@@ -48,100 +45,122 @@ import java.util.*;
 @Component
 public class ZkDataSyncTask {
 
-    private final String erpApiUrl = "http://121.31.41.88:29312";
-    private final String sign = "e34b2f59-0e9d-45ed-a32a-f4abd4381000";
-    private final String header_key = "X_AUTO_USER_INFO_HEAD";
-    private final String header_value = "{\"id\":\"anonymous\",\"tenantId\":\"caih\"}";
     private final String key = "DMERPYT!@#$QWER2021+{:>";
+    private final String zkApiUrl = "http://192.168.1.14:6112";
+    private final String header_key = "X_YT_ACCESS_TOKEN";
 
-    private final DeptService deptService;
-    private final UserService userService;
-    private final DmUserService dmUserService;
-    private final PasswordEncoder passwordEncoder;
+    private final UserRepository userRepository;
+    private final DmUserRepository dmUserRepository;
+    private final DeptRepository deptRepository;
 
-    public void run() {
+    public void run(){
         log.info("deptsync 执行开始");
-        deptsync();
+        deptSync();
         log.info("deptsync 执行结束");
 
         log.info("usersync 执行开始");
-        usersync();
+        userSync();
         log.info("usersync 执行结束");
     }
 
-    private JSONObject getDatas(String api, int pagenum, int pagesize) {
-        String res = HttpRequest.get(erpApiUrl + api)
-                .header(header_key, header_value)
-                .body("{\n" +
-                        "    \"formData\":{\n" +
-                        "        \"pageNum\":" + pagenum + ",\n" +
-                        "        \"pageSize\":" + pagesize + "\n" +
-                        "    },\n" +
-                        "    \"product\":\"17\",\n" +
-                        "    \"sign\":\"" + sign + "\"\n" +
-                        "}").execute().body();
+    public void runDept(){
+        log.info("deptsync 执行开始");
+        deptSyncAll();
+        log.info("deptsync 执行结束");
+    }
+
+    public void runUser(){
+        log.info("usersync 执行开始");
+        userSyncAll();
+        log.info("usersync 执行结束");
+    }
+
+    private JSONObject getDatas(String api,JSONArray time, int pageNum, int pageSize,int type) {
+        Map<String,Object> tokenData = SecurityUtils.getToken(key);
+        JSONObject body = new JSONObject();
+        body.put("timestamp",tokenData.get("timestamp"));
+        body.put("nonce",tokenData.get("nonce"));
+        JSONObject query = new JSONObject();
+        if(type == 1){
+            query.put("updateTime",time);
+        }
+        body.put("query",query);
+
+        String res = HttpRequest.get(zkApiUrl + api+"?page="+pageNum+"&size="+pageSize)
+                .header(header_key, tokenData.get("token").toString())
+                .body(body.toString()).execute().body();
         JSONObject json = JSONObject.parseObject(res);
+        log.info("json:"+json);
         return json;
     }
 
-    private int gettotal(String api) {
-        JSONObject json = getDatas(api, 0, 100);
-        return json.getJSONObject("page").getInteger("totalCount");
+    /**
+     * 部门数据同步
+     */
+    private void deptSync() {
+        String api = "/api/thirdparty/v1/user/getzkdeps";
+
+        JSONArray createTme = new JSONArray();
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.HOUR_OF_DAY,-24);
+        String yesterdayDate = dateFormat.format(calendar.getTime());
+
+        String todayDate = dateFormat.format(new Date());
+
+        createTme.add(yesterdayDate);
+        createTme.add(todayDate);
+
+        //计算总页数
+        int total = getDatas(api,createTme,0,100,1).getJSONObject("data").getInteger("totalElements");
+        int pageSize = 100;
+        int pageTotal = (total / pageSize);
+        if (total % pageSize != 0) {
+            pageTotal++;
+        }
+        log.info("pageTotal:"+pageTotal);
+
+        //按页获取
+        for (int k = 0; k < pageTotal; k++) {
+            JSONObject json = getDatas(api, createTme,k,pageSize,1);
+            JSONObject data = json.getJSONObject("data");
+            JSONArray content = data.getJSONArray("content");
+            for (int i = 0; i < content.size(); i++) {
+                Dept dept = JSONObject.parseObject(content.getString(i), Dept.class);
+                deptRepository.save(dept);
+//                DeptDto deptDto = deptService.findById(dept.getId());
+//                if (deptDto != null) {
+//                    deptService.update(dept);
+//                } else {
+//                    deptService.create(dept);
+//                }
+            }
+        }
     }
 
     /**
-     * 部门数据同步
+     * 部门数据同步(全量)
      */
-    private void deptsync() {
-        String api = "/api-third-party/busi/comm/usky/queryGroup";
+    private void deptSyncAll() {
+        String api = "/api/thirdparty/v1/user/getzkdeps";
 
         //计算总页数
-        int total = gettotal(api);
-        int pagesize = 100;
-        int pagetotal = (total / pagesize);
-        if (total % pagesize != 0) {
-            pagetotal++;
+        int total = getDatas(api,null,0,100,2).getJSONObject("data").getInteger("totalElements");
+        int pageSize = 100;
+        int pageTotal = (total / pageSize);
+        if (total % pageSize != 0) {
+            pageTotal++;
         }
+        log.info("pageTotal:"+pageTotal);
 
         //按页获取
-        for (int k = 0; k < pagetotal; k++) {
-            JSONObject json = getDatas(api, k, pagesize);
-            JSONArray datas = json.getJSONArray("data");
-            JSONObject item;
-            Dept dept;
-            for (int i = 0; i < datas.size(); i++) {
-                item = datas.getJSONObject(i);
-                dept = new Dept();
-
-                if (StringUtils.isBlank(item.getString("groupId"))) {
-                    dept.setId(UUID.randomUUID().toString());
-                } else {
-                    dept.setId(item.getString("groupId"));
-                }
-                dept.setName(item.getString("groupName"));
-
-                if (item.getString("parentId").equals("~")) {
-                    dept.setPid(null);
-                } else {
-                    dept.setPid(item.getString("parentId"));
-                }
-                dept.setDeptSort(item.getInteger("sort"));
-                dept.setEnabled(item.getBoolean("groupStatus"));
-//                dept.setTreeNames(item.getString("groupNamePath"));
-//                dept.setTreeIds(item.getString("groupIdPath"));
-//                dept.setDeptType(item.getInteger("groupType"));
-                dept.setDescription(item.getString("groupName"));
-
-                try {
-                    DeptDto deptDto = deptService.findById(item.getString("groupId"));
-                    if (deptDto != null) {
-                        deptService.update(dept);
-                    } else {
-                        deptService.create(dept);
-                    }
-                } catch (Exception ex) {
-                    System.out.println(JSONObject.toJSON(dept));
-                }
+        for (int k = 0; k < pageTotal; k++) {
+            JSONObject json = getDatas(api,null,k,pageSize,2);
+            JSONObject data = json.getJSONObject("data");
+            JSONArray content = data.getJSONArray("content");
+            for (int i = 0; i < content.size(); i++) {
+                Dept dept = JSONObject.parseObject(content.getString(i), Dept.class);
+                deptRepository.save(dept);
             }
         }
     }
@@ -149,99 +168,111 @@ public class ZkDataSyncTask {
     /**
      * 人员数据同步
      */
-    private void usersync() {
+    private void userSync() {
+
+        String api = "/api/thirdparty/v1/user/getzkusers";
 
-        String api = "/api-third-party/busi/comm/usky/queryUser";
+        JSONArray createTme = new JSONArray();
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.HOUR_OF_DAY,-24);
+        String yesterdayDate = dateFormat.format(calendar.getTime());
+
+        String todayDate = dateFormat.format(new Date());
+
+        createTme.add(yesterdayDate);
+        createTme.add(todayDate);
 
         //计算总页数
-        int total = gettotal(api);
-        int pagesize = 100;
-        int pagetotal = (total / pagesize);
-        if (total % pagesize != 0) {
-            pagetotal++;
+        int total = getDatas(api,createTme,0,100,1).getJSONObject("data").getInteger("totalElements");
+        int pageSize = 100;
+        int pageTotal = (total / pageSize);
+        if (total % pageSize != 0) {
+            pageTotal++;
         }
+        log.info("pageTotal:"+pageTotal);
 
         //按页获取
-        for (int k = 0; k < pagetotal; k++) {
-            JSONObject json = getDatas(api, k, pagesize);
-            JSONArray datas = json.getJSONArray("data");
-            JSONObject item;
-            User user;
-            UserDto userDto;
-            Dept dept;
-            DmUser dmUser;
-            DmUserDto dmUserDto;
-            for (int i = 0; i < datas.size(); i++) {
-                item = datas.getJSONObject(i);
-                user = new User();
-                user.setId(item.getString("userId"));
-//                user.setUsercode(item.getString("usercode"));
-                user.setNickName(item.getString("userName"));
-                user.setUsername(item.getString("userAccount"));
-
-                if(StringUtils.isBlank(item.getString("sex"))){
-                    user.setGender("");
-                }else{
-                    user.setGender(item.getString("sex").equals("m") ? "男" : "女");
-                }
-
-                user.setEmail(item.getString("email"));
-                user.setPhone(item.getString("mobile"));
-                user.setPassword(passwordEncoder.encode("12345678"));
-                user.setEnabled(item.getInteger("userStatus") == 1);
-                user.setIsAdmin(false);
-                user.setOrgPassword("12345678");
-                dept = new Dept();
-                dept.setId(item.getString("userGroupId"));
-                if (StringUtils.isBlank(dept.getId())) {
-                    dept.setId("0001T110000000000UKL");
-                }
-                user.setDept(dept);
-
-                Set<Job> jobs = new HashSet<Job>();
-                Job job = new Job();
-                job.setId("10");
-                jobs.add(job);
+        for (int k = 0; k < pageTotal; k++) {
+            JSONObject json = getDatas(api, createTme,k,pageSize,1);
+            JSONObject data = json.getJSONObject("data");
+            JSONArray content = data.getJSONArray("content");
+            for (int i = 0; i < content.size(); i++) {
+                User user = new User();
+                JSONObject userData = content.getJSONObject(i);
+
+                user.setId(userData.getString("id"));
+                Set<Job> jobs = new HashSet<>(JSONArray.parseArray(userData.getString("jobs"),Job.class));
                 user.setJobs(jobs);
+                Set<Role> roles = new HashSet<>(JSONArray.parseArray(userData.getString("roles"),Role.class));
+                user.setRoles(roles);
+                user.setGender(userData.getString("sex"));
+                user.setDept(JSONObject.parseObject(userData.getString("dept"),Dept.class));
+                user.setEmail(userData.getString("email"));
+                user.setNickName(userData.getString("name"));
+                user.setPhone(userData.getString("contacts"));
+
+                DmUser dmUser = new DmUser();
+                dmUser.setDept(user.getDept());
+                dmUser.setId(user.getId());
+                dmUser.setEmail(user.getEmail());
+                dmUser.setContacts(user.getPhone());
+                dmUser.setName(user.getNickName());
+                dmUser.setSex(user.getGender());
+                DmUser newDmUser = dmUserRepository.save(dmUser);
+                user.setDmUser(newDmUser);
+                userRepository.save(user);
+            }
+        }
+    }
+
+
+    /**
+     * 人员数据同步(全量)
+     */
+    private void userSyncAll() {
+
+        String api = "/api/thirdparty/v1/user/getzkusers";
 
-                Set<Role> roles = new HashSet<Role>();
+        //计算总页数
+        int total = getDatas(api,null,0,100,2).getJSONObject("data").getInteger("totalElements");
+        int pageSize = 100;
+        int pageTotal = (total / pageSize);
+        if (total % pageSize != 0) {
+            pageTotal++;
+        }
+        log.info("pageTotal:"+pageTotal);
+
+        //按页获取
+        for (int k = 0; k < pageTotal; k++) {
+            JSONObject json = getDatas(api,null,k,pageSize,2);
+            JSONObject data = json.getJSONObject("data");
+            JSONArray content = data.getJSONArray("content");
+            for (int i = 0; i < content.size(); i++) {
+                User user = new User();
+                JSONObject userData = content.getJSONObject(i);
 
-                Role role = new Role();
-                role.setId("2");//普通用户
-                roles.add(role);
+                user.setId(userData.getString("id"));
+                Set<Job> jobs = new HashSet<>(JSONArray.parseArray(userData.getString("jobs"),Job.class));
+                user.setJobs(jobs);
+                Set<Role> roles = new HashSet<>(JSONArray.parseArray(userData.getString("roles"),Role.class));
                 user.setRoles(roles);
-                dmUser = new DmUser();
-                dmUser.setDept(dept);
+                user.setGender(userData.getString("sex"));
+                user.setDept(JSONObject.parseObject(userData.getString("dept"),Dept.class));
+                user.setEmail(userData.getString("email"));
+                user.setNickName(userData.getString("name"));
+                user.setPhone(userData.getString("contacts"));
+
+                DmUser dmUser = new DmUser();
+                dmUser.setDept(user.getDept());
                 dmUser.setId(user.getId());
                 dmUser.setEmail(user.getEmail());
                 dmUser.setContacts(user.getPhone());
                 dmUser.setName(user.getNickName());
                 dmUser.setSex(user.getGender());
-//                dmUser.setUsercode(user.getUsercode());
-                dmUser.setJobs(jobs);
-                dmUser.setRoles(roles);
-
-                try {
-                    //1、入用户库
-                    dmUserDto = dmUserService.findById(dmUser.getId());
-
-                    if (dmUserDto != null) {
-                        dmUserService.update(dmUser);
-                    } else {
-                        dmUserService.create(dmUser);
-                    }
-                    user.setDmUser(dmUser);
-
-                    //2、入账户库并与用户库关联
-                    userDto = userService.findById(user.getId());
-                    if (userDto != null) {
-                        userService.update(user);
-                    } else {
-                        userService.create(user);
-                    }
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
+                DmUser newDmUser = dmUserRepository.save(dmUser);
+                user.setDmUser(newDmUser);
+                userRepository.save(user);
             }
         }
     }