王先生 2 gadi atpakaļ
vecāks
revīzija
e10029d3cf

+ 53 - 49
eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/CardRecordTask.java

@@ -24,6 +24,7 @@ import me.zhengjie.repository.LogRepository;
 import me.zhengjie.utils.BeanMapUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
+import org.springframework.util.ObjectUtils;
 
 import java.io.IOException;
 import java.math.BigDecimal;
@@ -258,59 +259,62 @@ public class CardRecordTask {
                      * 对方未有dept字段 需要手动去数据库中查询  根据卡号查对应的 用户
                      */
                     DmUser dmUser = dmUserService.queryUserByCardId(attendance.getString("card"));
-                    dmSettlement.setDmUser(dmUser);
-                    dmExpenseCalendar.setDept(dmUser.getDept());
-                    String bh = UUID.randomUUID().toString();
-                    dmExpenseCalendar.setBh(bh);//UUID 生成 与dm_order_item关联编号
-                    dmSettlement.setBh(bh);
-                    JSONArray item = attendance.getJSONArray("details");
-                    /**
-                     * 生成个map来统计数量
-                     */
-                    Map<String,Integer> map = new HashMap<>();
-                    for (int q = 0; q < item.size(); q++) {
-                        JSONObject userData = item.getJSONObject(q);
-                        String name = userData.getString("name");
-                        Integer num = map.get(name) == null ?map.put(name,1):map.put(name, map.get(name)+1);
-                    }
-                    for (int m = 0; m < item.size(); m++) {
-                        JSONObject userData = item.getJSONObject(m);
-                        DmOrderItem dmOrderItem = new DmOrderItem();
+                    if (!ObjectUtils.isEmpty(dmUser)){
+                        dmSettlement.setDmUser(dmUser);
+                        dmExpenseCalendar.setDept(dmUser.getDept());
+                        String bh = UUID.randomUUID().toString();
+                        dmExpenseCalendar.setBh(bh);//UUID 生成 与dm_order_item关联编号
+                        dmSettlement.setBh(bh);
+                        JSONArray item = attendance.getJSONArray("details");
+                        /**
+                         * 生成个map来统计数量
+                         */
+                        Map<String,Integer> map = new HashMap<>();
+                        for (int q = 0; q < item.size(); q++) {
+                            JSONObject userData = item.getJSONObject(q);
+                            String name = userData.getString("name");
+                            Integer num = map.get(name) == null ?map.put(name,1):map.put(name, map.get(name)+1);
+                        }
+                        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(userData.getLong("pid"));//商品id
-                        dmOrderItem.setBh(bh);//uuid生成 与 dm_order_record关联编号
-                        dmOrderItem.setName(userData.getString("name"));//商品名称
-                        dmOrderItem.setPrice(userData.getString("price")); //单价
-                        dmOrderItem.setAmt(userData.getDouble("amt"));//商品售价
-                        dmOrderItem.setMoney(String.valueOf(userData.getDouble("amt")));//小计
-                        dmOrderItem.setPjType("0");
-                        dmOrderItem.setNum(map.get(dmOrderItem.getName()));
-                         String foodName = dmSettlement.getFoodName() == null?"":","; //结算管理的
-                         Integer foodNum = dmSettlement.getFoodNum() == null?0:dmSettlement.getFoodNum();
-                         String foodPrice = dmSettlement.getFoodPrice() == null?"":",";
-                        BigDecimal totalPrice = dmSettlement.getTotalPrice() == null?BigDecimal.ZERO:dmSettlement.getTotalPrice();
-                        dmSettlement.setFoodName(foodName+dmOrderItem.getName());//结算管理 商品名称
-                        dmSettlement.setFoodNum(foodNum+dmOrderItem.getNum());//结算管理 商品数量
-                        dmSettlement.setTotalPrice(totalPrice.add(BigDecimal.valueOf(Double.valueOf(dmOrderItem.getPrice()))));//结算管理总价格
-                        dmSettlement.setFoodPrice(foodPrice+dmOrderItem.getPrice());//结算管理 单价
-                        dmOrderItemService.create(dmOrderItem);
-                    }
-                    JSONArray payment = attendance.getJSONArray("payments");
+                            dmOrderItem.setSeq(attendance.getLong("seq")); //序列号  流水号
+                            dmOrderItem.setFood(userData.getLong("pid"));//商品id
+                            dmOrderItem.setBh(bh);//uuid生成 与 dm_order_record关联编号
+                            dmOrderItem.setName(userData.getString("name"));//商品名称
+                            dmOrderItem.setPrice(userData.getString("price")); //单价
+                            dmOrderItem.setAmt(userData.getDouble("amt"));//商品售价
+                            dmOrderItem.setMoney(String.valueOf(userData.getDouble("amt")));//小计
+                            dmOrderItem.setPjType("0");
+                            dmOrderItem.setNum(map.get(dmOrderItem.getName()));
+                            String foodName = dmSettlement.getFoodName() == null?"":","; //结算管理的
+                            Integer foodNum = dmSettlement.getFoodNum() == null?0:dmSettlement.getFoodNum();
+                            String foodPrice = dmSettlement.getFoodPrice() == null?"":",";
+                            BigDecimal totalPrice = dmSettlement.getTotalPrice() == null?BigDecimal.ZERO:dmSettlement.getTotalPrice();
+                            dmSettlement.setFoodName(foodName+dmOrderItem.getName());//结算管理 商品名称
+                            dmSettlement.setFoodNum(foodNum+dmOrderItem.getNum());//结算管理 商品数量
+                            dmSettlement.setTotalPrice(totalPrice.add(BigDecimal.valueOf(Double.valueOf(dmOrderItem.getPrice()))));//结算管理总价格
+                            dmSettlement.setFoodPrice(foodPrice+dmOrderItem.getPrice());//结算管理 单价
+                            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);
+                        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);
+                        dmSettlementService.create(dmSettlement);
                     }
-                    dmOrderRecordService.create(dmExpenseCalendar);
-                    dmSettlementService.create(dmSettlement);
+                    log.info("dmUser IS NULL");
                 }else {
                     log.info("dmOrderRecord is not null. seq:"+seq);
                 }