From 9d35ba657fa5e3add766405d76e3ff8c4dcd4ad4 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 04 七月 2020 15:38:00 +0800
Subject: [PATCH] 多系统兼容优化

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java |  379 ++++++++++++++++++++++++++---------------------------
 1 files changed, 187 insertions(+), 192 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java
index d4b2da9..8558b4c 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java
@@ -7,6 +7,7 @@
 
 import javax.annotation.Resource;
 
+import com.yeshi.fanli.entity.SystemEnum;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -28,111 +29,105 @@
 @Service
 public class PushCouponServiceImpl implements PushCouponService {
 
-	@Resource
-	private PushService pushService;
+    @Resource
+    private PushService pushService;
 
-	@Resource
-	private ConfigService configService;
+    @Resource
+    private PushCouponMapper pushCouponMapper;
 
-	@Resource
-	private PushCouponMapper pushCouponMapper;
-	
-	@Resource
-	private PushCouponRecordService pushCouponRecordService;
-	
-	@Resource
-	private UserSystemCouponService userSystemCouponService;
-	
-	@Override
-	public int deleteByPrimaryKey(Long id) {
-		return pushCouponMapper.deleteByPrimaryKey(id);
-	}
+    @Resource
+    private PushCouponRecordService pushCouponRecordService;
 
-	@Override
-	public int insert(PushCoupon record) {
-		return pushCouponMapper.insert(record);
-	}
+    @Override
+    public int deleteByPrimaryKey(Long id) {
+        return pushCouponMapper.deleteByPrimaryKey(id);
+    }
 
-	@Override
-	public int insertSelective(PushCoupon record) {
-		return pushCouponMapper.insertSelective(record);
-	}
+    @Override
+    public int insert(PushCoupon record) {
+        return pushCouponMapper.insert(record);
+    }
 
-	@Override
-	public PushCoupon selectByPrimaryKey(Long id) {
-		return pushCouponMapper.selectByPrimaryKey(id);
-	}
+    @Override
+    public int insertSelective(PushCoupon record) {
+        return pushCouponMapper.insertSelective(record);
+    }
 
-	@Override
-	public int updateByPrimaryKeySelective(PushCoupon record) {
-		return pushCouponMapper.updateByPrimaryKeySelective(record);
-	}
+    @Override
+    public PushCoupon selectByPrimaryKey(Long id) {
+        return pushCouponMapper.selectByPrimaryKey(id);
+    }
 
-	@Override
-	public int updateByPrimaryKey(PushCoupon record) {
-		return pushCouponMapper.updateByPrimaryKey(record);
-	}
+    @Override
+    public int updateByPrimaryKeySelective(PushCoupon record) {
+        return pushCouponMapper.updateByPrimaryKeySelective(record);
+    }
+
+    @Override
+    public int updateByPrimaryKey(PushCoupon record) {
+        return pushCouponMapper.updateByPrimaryKey(record);
+    }
 
 
-	@Override
-	public List<PushCoupon> listQuery(long start, int count, String key, Integer state) {
-		return pushCouponMapper.listQuery(start, count, key, state);
-	}
+    @Override
+    public List<PushCoupon> listQuery(long start, int count, String key, Integer state, SystemEnum system) {
+        return pushCouponMapper.listQuery(start, count, key, state, system);
+    }
 
-	@Override
-	public long countQuery(String key, Integer state) {
-		return pushCouponMapper.countQuery(key, state);
-	}
+    @Override
+    public long countQuery(String key, Integer state, SystemEnum system) {
+        return pushCouponMapper.countQuery(key, state, system);
+    }
 
-	@Override
-	@Transactional(rollbackFor=Exception.class)
-	public void save(PushCoupon record) throws PushCouponException,Exception {
-		if (record == null) {
-			throw new PushCouponException(1, "鍙傛暟涓嶆纭�");
-		}
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void save(PushCoupon record) throws PushCouponException, Exception {
+        if (record == null) {
+            throw new PushCouponException(1, "鍙傛暟涓嶆纭�");
+        }
 
-		String uids = record.getUids();
-		if (StringUtil.isNullOrEmpty(uids)) {
-			throw new PushCouponException(1, "鍙戞斁鐢ㄦ埛涓嶈兘涓虹┖");
-		}
-		
-		Integer amount = record.getAmount();
-		if (amount == null) {
-			throw new PushCouponException(1, "鍒告暟閲忎笉鑳戒负绌�");
-		} else if (amount < 1 || amount > 5) {
-			throw new PushCouponException(1, "鍒告暟閲忚寖鍥存槸 1~5");
-		}
-		
+        String uids = record.getUids();
+        if (StringUtil.isNullOrEmpty(uids)) {
+            throw new PushCouponException(1, "鍙戞斁鐢ㄦ埛涓嶈兘涓虹┖");
+        }
 
-		Long id = record.getId();
-		if (id == null) {
-			// 鏂板
-			record.setCreateTime(new Date());
-			record.setUpdateTime(new Date());
-			// 鎻掑叆鏁版嵁
-			pushCouponMapper.insert(record);
-			
-			String[] uidArray = uids.split(",");
-			
-			if (uidArray != null) {
-				for (int i = 0; i < uidArray.length; i++) {
+        Integer amount = record.getAmount();
+        if (amount == null) {
+            throw new PushCouponException(1, "鍒告暟閲忎笉鑳戒负绌�");
+        } else if (amount < 1 || amount > 5) {
+            throw new PushCouponException(1, "鍒告暟閲忚寖鍥存槸 1~5");
+        }
 
-					Long uid = Long.parseLong(uidArray[i]);
-					// 鎻掑叆璁板綍
-					PushCouponRecord pushCouponRecord = new PushCouponRecord();
-					pushCouponRecord.setPushCoupon(record);
-					pushCouponRecord.setUid(uid);
-					pushCouponRecord.setCreateTime(new Date());
-				
-					// 鎻掑叆棰嗗彇璁板綍
-					//pushCouponRecordService.insertSelective(pushCouponRecord);
-					// 鐩存帴鍙戦�佸埜
-					//userSystemCouponService.randomRewardCoupon(amount, uid, UserSystemCoupon.SOURCE_SYSTEM_PUSH);
-				}
-			}
-			
-			
-		} else {
+
+        Long id = record.getId();
+        if (id == null) {
+            // 鏂板
+            record.setCreateTime(new Date());
+            record.setUpdateTime(new Date());
+            // 鎻掑叆鏁版嵁
+            pushCouponMapper.insert(record);
+
+            String[] uidArray = uids.split(",");
+
+            if (uidArray != null) {
+                for (int i = 0; i < uidArray.length; i++) {
+
+                    Long uid = Long.parseLong(uidArray[i]);
+                    // 鎻掑叆璁板綍
+                    PushCouponRecord pushCouponRecord = new PushCouponRecord();
+                    pushCouponRecord.setPushCoupon(record);
+                    pushCouponRecord.setUid(uid);
+                    pushCouponRecord.setCreateTime(new Date());
+
+                    // 鎻掑叆棰嗗彇璁板綍
+                    //pushCouponRecordService.insertSelective(pushCouponRecord);
+                    // 鐩存帴鍙戦�佸埜
+                    //userSystemCouponService.randomRewardCoupon(amount, uid, UserSystemCoupon.SOURCE_SYSTEM_PUSH);
+                }
+            }
+
+
+        } else {
 //			
 //			// 淇敼
 //			PushCoupon current = selectByPrimaryKey(id);
@@ -149,110 +144,110 @@
 //			current.setUpdateTime(new Date());
 //			// 鏇存柊鏁版嵁
 //			updateByPrimaryKey(current);
-		}
-	}
+        }
+    }
 
-	@Override
-	@Transactional(rollbackFor=Exception.class)
-	public void executePush(Long id) throws Exception, PushCouponException, PushException {
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void executePush(Long id) throws Exception, PushCouponException, PushException {
 
-		PushCoupon pushCoupon = selectByPrimaryKey(id);
-		if (pushCoupon == null) {
-			throw new PushCouponException(1, "鎺ㄩ�佷俊鎭凡涓嶅瓨鍦�");
-		}
-		
-		if(pushCoupon.isPushed()) {
-			throw new PushCouponException(1, "璇ヤ俊鎭笉鑳介噸澶嶆帹閫�");
-		}
-		String versions = pushCoupon.getVersions();
-		if (versions == null || versions.trim().length() == 0 ) {
-			throw new PushCouponException(1, "鎺ㄩ�佺増鏈笉鑳戒负绌�");
-		}
-		
+        PushCoupon pushCoupon = selectByPrimaryKey(id);
+        if (pushCoupon == null) {
+            throw new PushCouponException(1, "鎺ㄩ�佷俊鎭凡涓嶅瓨鍦�");
+        }
 
-		String title = pushCoupon.getTitle();
-		String content = pushCoupon.getContent();
-		if (title == null || title.trim().length() == 0 || content == null || content.trim().length() == 0) {
-			throw new PushCouponException(1, "鏍囬鎴栧唴瀹逛笉鑳戒负绌�");
-		}
-		
-		
-		List<String> listuid = null;
-		String uids = pushCoupon.getUids();
-		if (uids != null && uids.trim().length() > 0) {
-			listuid = Arrays.asList(uids.split(","));
-			if (listuid == null || listuid.size() == 0) {
-				throw new PushCouponException(1, "鐢ㄦ埛id鏍煎紡涓嶆纭�");
-			}
-		}
-		
-		List<String> listIOS = new ArrayList<String>();
-		JSONObject json = JSONObject.fromObject(versions);
-		String versionsIOS = json.getString("IOS");
-		if (versionsIOS != null && versionsIOS.trim().length() > 0) {
-			if (versionsIOS.contains("鍏ㄦ帹")) {
-				listIOS = null;
-			} else {
-				listIOS = Arrays.asList(versionsIOS.split(","));
-			}
-		}
-		
-		List<String> listAndroid = new ArrayList<String>();
-		String versionsAndroid  = json.getString("Android");
-		if (versionsAndroid != null && versionsAndroid.trim().length() > 0) {
-			if (versionsAndroid.contains("鍏ㄦ帹")) {
-				listAndroid = null;
-			} else {
-				listAndroid = Arrays.asList(versionsAndroid.split(","));
-			}
-		}
-		
-		
-		if (listuid == null) {
-			// 鍏ㄦ帹
-			pushService.pushWelfareCenter(null, title, content, listIOS, listAndroid);
-			
-		} else {
-			// 鎸囧畾鐢ㄦ埛鎺ㄩ��
-			for (String str_uid: listuid) {
-				if (str_uid != null && str_uid.trim().length() > 0) {
-					pushService.pushWelfareCenter(Long.parseLong(str_uid), title, content, listIOS, listAndroid);
-				}
-			}
-		}
-		
-		// 宸叉帹閫�
-		pushCoupon.setPushed(true);
-		// 鎺ㄩ�佹椂闂�
-		pushCoupon.setPushTime(new Date());
-		// 鏇存柊鏃堕棿
-		pushCoupon.setUpdateTime(new Date());
-		
-		updateByPrimaryKeySelective(pushCoupon);
-	}
-	
+        if (pushCoupon.isPushed()) {
+            throw new PushCouponException(1, "璇ヤ俊鎭笉鑳介噸澶嶆帹閫�");
+        }
+        String versions = pushCoupon.getVersions();
+        if (versions == null || versions.trim().length() == 0) {
+            throw new PushCouponException(1, "鎺ㄩ�佺増鏈笉鑳戒负绌�");
+        }
 
-	@Override
-	@Transactional
-	public void deleteBatchByPrimaryKey(List<Long> list) {
-		if (list == null || list.size() == 0) {
-			return;
-		}
-		
-		for (Long id: list) {
-			long receivedCount = pushCouponRecordService.countByPushId(id);
-			// 棰嗗彇鏁伴噺
-			if (receivedCount > 0) {
-				continue;
-			}
-			
-			pushCouponMapper.deleteByPrimaryKey(id);
-		}
-	}
 
-	@Override
-	public List<PushCoupon> listQueryEffective() {
-		return pushCouponMapper.listQueryEffective();
-	}
-	
+        String title = pushCoupon.getTitle();
+        String content = pushCoupon.getContent();
+        if (title == null || title.trim().length() == 0 || content == null || content.trim().length() == 0) {
+            throw new PushCouponException(1, "鏍囬鎴栧唴瀹逛笉鑳戒负绌�");
+        }
+
+
+        List<String> listuid = null;
+        String uids = pushCoupon.getUids();
+        if (uids != null && uids.trim().length() > 0) {
+            listuid = Arrays.asList(uids.split(","));
+            if (listuid == null || listuid.size() == 0) {
+                throw new PushCouponException(1, "鐢ㄦ埛id鏍煎紡涓嶆纭�");
+            }
+        }
+
+        List<String> listIOS = new ArrayList<String>();
+        JSONObject json = JSONObject.fromObject(versions);
+        String versionsIOS = json.getString("IOS");
+        if (versionsIOS != null && versionsIOS.trim().length() > 0) {
+            if (versionsIOS.contains("鍏ㄦ帹")) {
+                listIOS = null;
+            } else {
+                listIOS = Arrays.asList(versionsIOS.split(","));
+            }
+        }
+
+        List<String> listAndroid = new ArrayList<String>();
+        String versionsAndroid = json.getString("Android");
+        if (versionsAndroid != null && versionsAndroid.trim().length() > 0) {
+            if (versionsAndroid.contains("鍏ㄦ帹")) {
+                listAndroid = null;
+            } else {
+                listAndroid = Arrays.asList(versionsAndroid.split(","));
+            }
+        }
+
+
+        if (listuid == null) {
+            // 鍏ㄦ帹
+            pushService.pushWelfareCenter(null, title, content, listIOS, listAndroid, pushCoupon.getSystem());
+
+        } else {
+            // 鎸囧畾鐢ㄦ埛鎺ㄩ��
+            for (String str_uid : listuid) {
+                if (str_uid != null && str_uid.trim().length() > 0) {
+                    pushService.pushWelfareCenter(Long.parseLong(str_uid), title, content, listIOS, listAndroid, pushCoupon.getSystem());
+                }
+            }
+        }
+
+        // 宸叉帹閫�
+        pushCoupon.setPushed(true);
+        // 鎺ㄩ�佹椂闂�
+        pushCoupon.setPushTime(new Date());
+        // 鏇存柊鏃堕棿
+        pushCoupon.setUpdateTime(new Date());
+
+        updateByPrimaryKeySelective(pushCoupon);
+    }
+
+
+    @Override
+    @Transactional
+    public void deleteBatchByPrimaryKey(List<Long> list) {
+        if (list == null || list.size() == 0) {
+            return;
+        }
+
+        for (Long id : list) {
+            long receivedCount = pushCouponRecordService.countByPushId(id);
+            // 棰嗗彇鏁伴噺
+            if (receivedCount > 0) {
+                continue;
+            }
+
+            pushCouponMapper.deleteByPrimaryKey(id);
+        }
+    }
+
+    @Override
+    public List<PushCoupon> listQueryEffective(SystemEnum system) {
+        return pushCouponMapper.listQueryEffective(system);
+    }
+
 }

--
Gitblit v1.8.0