Pārlūkot izejas kodu

消费记录调整

linfei.luo 3 gadi atpakaļ
vecāks
revīzija
42e311f047

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/config/rabbitmq/test/ListenerTemplate.java

@@ -87,7 +87,7 @@ public class ListenerTemplate {
         }
     }
 
-    @RabbitListener(queues = OrderProduce.NAME_ORDER, containerFactory = OrderProduce.LISTENER_ORDER)
+//    @RabbitListener(queues = OrderProduce.NAME_ORDER, containerFactory = OrderProduce.LISTENER_ORDER)
     public void dealDeclareOrderMessage(Message message) throws UnsupportedEncodingException {
         System.out.println("messageOrder"+message);
         String str = new String(message.getBody(),"utf-8");

+ 7 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/order/repository/DmOrderRecordRepository.java

@@ -66,6 +66,13 @@ public interface DmOrderRecordRepository extends JpaRepository<DmOrderRecord, Lo
             "WHERE date_format(create_date,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d') ",nativeQuery = true)
     List<Map<String,Object>> selectOrderRecord();
 
+    /**
+     * 通过seq流水号查询消费记录
+     *
+     * */
+    @Query(value = "SELECT id, seq, bh from dm_order_record where seq = :seq",nativeQuery = true)
+    List<Map<String, Object>> selectOrderRecordBySeq(@Param("seq") Long seq);
+
     @Modifying
     @Query(value = "INSERT INTO `dm_order_record`(`bh`, `money`, `mob`, `user_code`, `user_name`, `dept_id`, `user_type`, `phone`, `create_date`, " +
             "`total_money`, `zk_money`, `seq`, `card`, `card_no`, `part`, `term`, `shop`, `term_name`, `shop_name`, `amt`, `balance`, `account`, `type`) " +

+ 351 - 0
eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/CardRecordTask.java

@@ -0,0 +1,351 @@
+package me.zhengjie.modules.quartz.task;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import me.zhengjie.modules.dm.food.domain.DmFood;
+import me.zhengjie.modules.dm.order.domain.DmOrderItem;
+import me.zhengjie.modules.dm.order.domain.DmOrderPayment;
+import me.zhengjie.modules.dm.order.domain.DmOrderRecord;
+import me.zhengjie.modules.dm.order.repository.DmOrderRecordRepository;
+import me.zhengjie.modules.dm.order.service.DmOrderItemService;
+import me.zhengjie.modules.dm.order.service.DmOrderPaymentService;
+import me.zhengjie.modules.dm.order.service.DmOrderRecordService;
+import me.zhengjie.utils.BeanMapUtils;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ObjectUtils;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@Slf4j
+@Component
+@RequiredArgsConstructor
+public class CardRecordTask {
+
+    private final DmOrderRecordService dmOrderRecordService;
+    private final DmOrderItemService dmOrderItemService;
+    private final DmOrderPaymentService dmOrderPaymentService;
+
+    private final DmOrderRecordRepository dmOrderRecordRepository;
+//    private final DmExpenseCalendarService dmExpenseCalendarService;
+
+//    public void run() throws ParseException, IOException {
+//        log.info("run 执行开始");
+//        asyncRecharge();
+//        log.info("run 执行结束");
+//    }
+//
+//    public void run2() throws ParseException, IOException {
+//        log.info("run2 执行开始");
+//        asyncRechargeAll();
+//        log.info("run2 执行结束");
+//    }
+
+    public void runExpense() throws ParseException, IOException {
+        log.info("runExpense 执行开始");
+        asyncExpense();
+        log.info("runExpense 执行结束");
+    }
+
+    public void runExpenseAll() throws ParseException, IOException {
+        log.info("runExpenseAll 执行开始");
+        asyncExpenseAll();
+        log.info("runExpenseAll 执行结束");
+    }
+
+    public JSONObject getData(String url , JSONObject param) throws IOException {
+//        Map<String,String> formDataParam = new HashMap<>();
+//        System.out.println("formDataParam:"+param.toJSONString());
+//        formDataParam.put("date",param.toJSONString());
+        log.info("param:"+param);
+        String data = BeanMapUtils.sendPost(url, param.toString());
+        System.out.println("historyRecord:"+data);
+        JSONObject dataJSON = JSONObject.parseObject(data);
+        return dataJSON;
+    }
+
+//    public void asyncRecharge() throws IOException, ParseException {
+//        String url = "https://smartpark.caih.com/dxapi/dxtop/charge/page";
+//
+//        JSONObject data = new JSONObject();
+//        int limit = 100;//页数
+//        SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
+//        SimpleDateFormat formater2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//        Calendar calendar = Calendar.getInstance();
+//        Date start = formater2.parse(formater.format(calendar.getTime())+ " 00:00:00");
+//        Date end = formater2.parse(formater.format(calendar.getTime())+ " 23:59:59");
+//        data.put("startTime",formater2.format(start));
+//        data.put("endTime",formater2.format(end));
+//        data.put("current",1);//当前页数
+//        data.put("size",limit);
+//
+//        JSONObject generateProcDataJson = getData(url,data);
+//        System.out.println(generateProcDataJson);
+//
+//        Integer total = generateProcDataJson.getJSONObject("data").getInteger("total");//总条数
+//        int pageTotal = (total / limit);
+//        if (total % limit != 0) {
+//            pageTotal++;
+//        }
+//
+//        for(int i = 1;i<=pageTotal;i++){//循环总页数
+//            //获取当前页数
+//            data.put("current",i);//当前页数
+//            JSONObject newGenerateProcDataJson = getData(url,data);
+//            JSONObject dataJSON = newGenerateProcDataJson.getJSONObject("data");//第二层
+//            JSONArray arr2 = dataJSON.getJSONArray("records");//第三层集合数据
+//            for (int j = 0;j<arr2.size();j++){//
+//                JSONObject attendance = arr2.getJSONObject(j);
+//                String seq = attendance.getString("seq");
+//                DmRechargeRecord dmRechargeRecord = dmRechargeRecordService.findBySeq(seq);
+//                if(dmRechargeRecord == null) {
+//                    //组装返回数据
+//                    JSONObject acc = new JSONObject();
+//                    acc.put("seq", seq);
+//                    acc.put("userName", attendance.getString("userName"));
+//                    acc.put("userPhone", attendance.getString("userPhone"));
+//                    acc.put("cardNumber", attendance.getString("cardNo"));
+//                    acc.put("rechargeAmount", attendance.getString("amt"));
+//                    acc.put("amountAfterRecharge", attendance.getString("balance"));
+//                    acc.put("rechargeTime", attendance.getString("createTime"));
+//
+//                    dmRechargeRecordService.create(JSON.toJavaObject(acc, DmRechargeRecord.class));
+//                } else {
+//                    System.out.println("dmRechargeRecord is null. seq:"+seq);
+//                }
+//            }
+//        }
+//    }
+//
+//    public void asyncRechargeAll() throws IOException, ParseException {
+//        String url = "https://smartpark.caih.com/dxapi/dxtop/charge/page";
+//
+//        JSONObject data = new JSONObject();
+//        int limit = 100;//页数
+//        data.put("current",1);//当前页数
+//        data.put("size",limit);
+//
+//        JSONObject generateProcDataJson = getData(url,data);
+//        System.out.println(generateProcDataJson);
+//
+//        Integer total = generateProcDataJson.getJSONObject("data").getInteger("total");//总条数
+//        int pageTotal = (total / limit);
+//        if (total % limit != 0) {
+//            pageTotal++;
+//        }
+//
+//        for(int i = 1;i<=pageTotal;i++){//循环总页数
+//            //获取当前页数
+//            data.put("current",i);//当前页数
+//            JSONObject newGenerateProcDataJson = getData(url,data);
+//            JSONObject dataJSON = newGenerateProcDataJson.getJSONObject("data");//第二层
+//            JSONArray arr2 = dataJSON.getJSONArray("records");//第三层集合数据
+//            for (int j = 0;j<arr2.size();j++){//
+//                JSONObject attendance = arr2.getJSONObject(j);
+//                String seq = attendance.getString("seq");
+//                DmRechargeRecord dmRechargeRecord = dmRechargeRecordService.findBySeq(seq);
+//                if(dmRechargeRecord == null) {
+//                    //组装返回数据
+//                    JSONObject acc = new JSONObject();
+//                    acc.put("seq", seq);
+//                    acc.put("userName", attendance.getString("userName"));
+//                    acc.put("userPhone", attendance.getString("userPhone"));
+//                    acc.put("cardNumber", attendance.getString("cardNo"));
+//                    acc.put("rechargeAmount", attendance.getString("amt"));
+//                    acc.put("amountAfterRecharge", attendance.getString("balance"));
+//                    acc.put("rechargeTime", attendance.getString("createTime"));
+//
+//                    dmRechargeRecordService.create(JSON.toJavaObject(acc, DmRechargeRecord.class));
+//                } else {
+//                    System.out.println("dmRechargeRecord is null. seq:"+seq);
+//                }
+//            }
+//        }
+//    }
+
+    public void asyncExpense() throws IOException, ParseException {
+        String url = "https://smartpark.caih.com/dxapi/dxtop/dish/page";
+
+        JSONObject data = new JSONObject();
+        int limit = 100;//页数
+        SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
+        SimpleDateFormat formater2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar calendar = Calendar.getInstance();
+        Date start = formater2.parse(formater.format(calendar.getTime())+ " 00:00:00");
+        Date end = formater2.parse(formater.format(calendar.getTime())+ " 23:59:59");
+        data.put("startTime",formater2.format(start));
+        data.put("endTime",formater2.format(end));
+        data.put("current",1);//当前页数
+        data.put("size",limit);
+
+        JSONObject generateProcDataJson = getData(url,data);
+        System.out.println(generateProcDataJson);
+
+        Integer total = generateProcDataJson.getJSONObject("data").getInteger("total");//总条数
+        int pageTotal = (total / limit);
+        if (total % limit != 0) {
+            pageTotal++;
+        }
+
+        for(int i = 1;i<=pageTotal;i++){//循环总页数
+            //获取当前页数
+            data.put("current",i);//当前页数
+            JSONObject newGenerateProcDataJson = getData(url,data);
+            JSONObject dataJSON = newGenerateProcDataJson.getJSONObject("data");//第二层
+            JSONArray arr2 = dataJSON.getJSONArray("records");//第三层集合数据
+            for (int j = 0;j<arr2.size();j++){//
+                JSONObject attendance = arr2.getJSONObject(j);
+                Long seq = attendance.getLong("seq");
+                List<Map<String, Object>> list = dmOrderRecordRepository.selectOrderRecordBySeq(seq);
+
+                if(list.size() == 0) {
+                    DmOrderRecord dmExpenseCalendar = new DmOrderRecord();
+
+                    dmExpenseCalendar.setSeq(attendance.getLong("seq"));
+                    dmExpenseCalendar.setCreateDate(attendance.getTimestamp("create_date"));
+                    dmExpenseCalendar.setCard(attendance.getString("card"));
+                    dmExpenseCalendar.setCardNo(attendance.getString("card_no"));
+                    dmExpenseCalendar.setType(attendance.getInteger("type"));
+                    dmExpenseCalendar.setPart(attendance.getInteger("part"));
+                    dmExpenseCalendar.setTerm(attendance.getInteger("term"));
+                    dmExpenseCalendar.setShop(attendance.getInteger("shop"));
+                    dmExpenseCalendar.setTermName(attendance.getString("term_name"));
+                    dmExpenseCalendar.setShopName(attendance.getString("shop_name"));
+                    dmExpenseCalendar.setAmt(attendance.getDouble("amt"));
+                    dmExpenseCalendar.setMoney(String.valueOf(attendance.getDouble("amt")));
+                    dmExpenseCalendar.setBalance(attendance.getDouble("balance"));
+                    dmExpenseCalendar.setAccount(attendance.getInteger("account"));
+                    dmExpenseCalendar.setUserName(attendance.getString("name"));
+                    dmExpenseCalendar.setMob(attendance.getString("mob"));
+                    dmExpenseCalendar.setUserCode(attendance.getString("mob"));
+                    dmExpenseCalendar.setTel(attendance.getString("tel"));
+                    dmExpenseCalendar.setCardProfile(attendance.getInteger("card_profile"));
+
+                    String bh = UUID.randomUUID().toString();
+                    dmExpenseCalendar.setBh(bh);//关联编号
+                    JSONArray item = attendance.getJSONArray("details");
+                    for (int m = 0; m < item.size(); m++) {
+                        JSONObject userData = item.getJSONObject(m);
+                        DmOrderItem dmOrderItem = new DmOrderItem();
+                        DmFood dmFood = new DmFood();
+                        dmFood.setId(userData.getLong("pid"));
+                        dmOrderItem.setSeq(attendance.getLong("seq"));
+                        dmOrderItem.setFood(dmFood);
+                        dmOrderItem.setBh(bh);
+                        dmOrderItem.setName(userData.getString("name"));
+                        dmOrderItem.setPrice(userData.getString("price"));
+                        dmOrderItem.setAmt(userData.getDouble("amt"));
+                        dmOrderItem.setMoney(String.valueOf(userData.getDouble("amt")));
+                        dmOrderItemService.create(dmOrderItem);
+                    }
+                    JSONArray payment = attendance.getJSONArray("payments");
+                    for (int n = 0; n < payment.size(); n++) {
+                        JSONObject userData = payment.getJSONObject(i);
+                        DmOrderPayment dmOrderPayment = new DmOrderPayment();
+                        dmOrderPayment.setBh(bh);
+                        dmOrderPayment.setType(userData.getString("type"));
+                        dmOrderPayment.setAmt(userData.getDouble("amt"));
+                        dmOrderPayment.setBalance(userData.getDouble("balance"));
+                        dmOrderPayment.setUid(userData.getString("uid"));
+                        dmOrderPaymentService.create(dmOrderPayment);
+                    }
+                    dmOrderRecordService.create(dmExpenseCalendar);
+                }else {
+                    System.out.println("dmOrderRecord is null. seq:"+seq);
+                }
+            }
+        }
+    }
+
+    public void asyncExpenseAll() throws IOException, ParseException {
+        String url = "https://smartpark.caih.com/dxapi/dxtop/dish/page";
+
+        JSONObject data = new JSONObject();
+        int limit = 100;//页数
+        data.put("current",1);//当前页数
+        data.put("size",limit);
+
+        JSONObject generateProcDataJson = getData(url,data);
+        System.out.println(generateProcDataJson);
+
+        Integer total = generateProcDataJson.getJSONObject("data").getInteger("total");//总条数
+        int pageTotal = (total / limit);
+        if (total % limit != 0) {
+            pageTotal++;
+        }
+
+        for(int i = 1;i<=pageTotal;i++){//循环总页数
+            //获取当前页数
+            data.put("current",i);//当前页数
+            JSONObject newGenerateProcDataJson = getData(url,data);
+            JSONObject dataJSON = newGenerateProcDataJson.getJSONObject("data");//第二层
+            JSONArray arr2 = dataJSON.getJSONArray("records");//第三层集合数据
+            for (int j = 0;j<arr2.size();j++){//
+                JSONObject attendance = arr2.getJSONObject(j);
+                Long seq = attendance.getLong("seq");
+                List<Map<String, Object>> list = dmOrderRecordRepository.selectOrderRecordBySeq(seq);
+
+                if(list.size() == 0) {
+                    DmOrderRecord dmExpenseCalendar = new DmOrderRecord();
+
+                    dmExpenseCalendar.setSeq(attendance.getLong("seq"));
+                    dmExpenseCalendar.setCreateDate(attendance.getTimestamp("create_date"));
+                    dmExpenseCalendar.setCard(attendance.getString("card"));
+                    dmExpenseCalendar.setCardNo(attendance.getString("card_no"));
+                    dmExpenseCalendar.setType(attendance.getInteger("type"));
+                    dmExpenseCalendar.setPart(attendance.getInteger("part"));
+                    dmExpenseCalendar.setTerm(attendance.getInteger("term"));
+                    dmExpenseCalendar.setShop(attendance.getInteger("shop"));
+                    dmExpenseCalendar.setTermName(attendance.getString("term_name"));
+                    dmExpenseCalendar.setShopName(attendance.getString("shop_name"));
+                    dmExpenseCalendar.setAmt(attendance.getDouble("amt"));
+                    dmExpenseCalendar.setMoney(String.valueOf(attendance.getDouble("amt")));
+                    dmExpenseCalendar.setBalance(attendance.getDouble("balance"));
+                    dmExpenseCalendar.setAccount(attendance.getInteger("account"));
+                    dmExpenseCalendar.setUserName(attendance.getString("name"));
+                    dmExpenseCalendar.setMob(attendance.getString("mob"));
+                    dmExpenseCalendar.setUserCode(attendance.getString("mob"));
+                    dmExpenseCalendar.setTel(attendance.getString("tel"));
+                    dmExpenseCalendar.setCardProfile(attendance.getInteger("card_profile"));
+
+                    String bh = UUID.randomUUID().toString();
+                    dmExpenseCalendar.setBh(bh);//关联编号
+                    JSONArray item = attendance.getJSONArray("details");
+                    for (int m = 0; m < item.size(); m++) {
+                        JSONObject userData = item.getJSONObject(m);
+                        DmOrderItem dmOrderItem = new DmOrderItem();
+                        DmFood dmFood = new DmFood();
+                        dmFood.setId(userData.getLong("pid"));
+                        dmOrderItem.setSeq(attendance.getLong("seq"));
+                        dmOrderItem.setFood(dmFood);
+                        dmOrderItem.setBh(bh);
+                        dmOrderItem.setName(userData.getString("name"));
+                        dmOrderItem.setPrice(userData.getString("price"));
+                        dmOrderItem.setAmt(userData.getDouble("amt"));
+                        dmOrderItem.setMoney(String.valueOf(userData.getDouble("amt")));
+                        dmOrderItemService.create(dmOrderItem);
+                    }
+                    JSONArray payment = attendance.getJSONArray("payments");
+                    for (int n = 0; n < payment.size(); n++) {
+                        JSONObject userData = payment.getJSONObject(n);
+                        DmOrderPayment dmOrderPayment = new DmOrderPayment();
+                        dmOrderPayment.setBh(bh);
+                        dmOrderPayment.setType(userData.getString("type"));
+                        dmOrderPayment.setAmt(userData.getDouble("amt"));
+                        dmOrderPayment.setBalance(userData.getDouble("balance"));
+                        dmOrderPayment.setUid(userData.getString("uid"));
+                        dmOrderPaymentService.create(dmOrderPayment);
+                    }
+                    dmOrderRecordService.create(dmExpenseCalendar);
+                }else {
+                    System.out.println("dmOrderRecord is null. seq:"+seq);
+                }
+            }
+        }
+    }
+}

+ 1 - 0
eladmin-system/src/main/java/me/zhengjie/modules/test/TestController.java

@@ -35,6 +35,7 @@ public class TestController {
         map.put("seq",Long.valueOf(timestamp));
         map.put("date",dateNowStr);
         map.put("shopname","餐厅");
+//        map.put("date", "2021-12-07");
         JSONObject jsonObject = new JSONObject(map);
         sendTemplate.sendMessage(jsonObject);
         System.out.println("消息發送成功success"+jsonObject);