From f4a0f2acc63d7785eab108419a4e16f5f688cb95 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期六, 18 一月 2020 12:06:27 +0800 Subject: [PATCH] 用户注册信息 --- fanli/src/main/java/com/yeshi/fanli/service/impl/lable/BoutiqueAutoRuleServiceImpl.java | 218 +++++++++++++++++++++++++++++++++++------------------- 1 files changed, 142 insertions(+), 76 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/lable/BoutiqueAutoRuleServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/lable/BoutiqueAutoRuleServiceImpl.java index 1a74d8b..83c5da9 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/lable/BoutiqueAutoRuleServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/lable/BoutiqueAutoRuleServiceImpl.java @@ -1,24 +1,24 @@ package com.yeshi.fanli.service.impl.lable; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.annotation.Resource; -import javax.transaction.Transactional; import org.quartz.Scheduler; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import com.yeshi.fanli.dao.mybatis.lable.BoutiqueAutoRuleMapper; import com.yeshi.fanli.entity.bus.lable.BoutiqueAutoRule; -import com.yeshi.fanli.exception.BoutiqueAutoRuleException; +import com.yeshi.fanli.exception.goods.quality.BoutiqueAutoRuleException; import com.yeshi.fanli.job.QualityFactoryJob; import com.yeshi.fanli.job.QuartzManager; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.lable.BoutiqueAutoRuleService; import com.yeshi.fanli.util.StringUtil; + +import net.sf.json.JSONObject; @Service public class BoutiqueAutoRuleServiceImpl implements BoutiqueAutoRuleService { @@ -47,16 +47,15 @@ } @Override - @Transactional + @Transactional(rollbackFor=Exception.class) public void deleteByPrimaryKey(Long id) throws BoutiqueAutoRuleException { boutiqueAutoRuleMapper.deleteByPrimaryKey(id); } @Override - @Transactional + @Transactional(rollbackFor=Exception.class) public void deleteBatchByPrimaryKey(List<Long> ids) throws BoutiqueAutoRuleException { for (Long id : ids) { - // 鍒犻櫎 boutiqueAutoRuleMapper.deleteByPrimaryKey(id); } } @@ -100,61 +99,41 @@ Integer source = boutiqueAutoRule.getSource(); String cronTime = boutiqueAutoRule.getCronTime(); - // 涓嶈兘涓虹┖: 瑙﹀彂鏃堕棿銆佽姹傛簮銆佺被鐩� - if (source == null || StringUtil.isNullOrEmpty(cronTime)) { + if (source == null || StringUtil.isNullOrEmpty(cronTime)) return; - } - - Map<String, String> params = new HashMap<String, String>(); - params.put("source", source+""); - params.put("searchContent", boutiqueAutoRule.getSearchContent()); - params.put("ruleId", boutiqueAutoRule.getId()+""); + jsonTransformString(boutiqueAutoRule); // 浠诲姟鍚� String JobName = "JOB_" + source + "_" + id; - try { - /* 鏂板缓浠诲姟 */ if ("add".equalsIgnoreCase(type)) { - QuartzManager.addJob(scheduler,QualityFactoryJob.class, JobName, cronTime, params); + QuartzManager.addJob(scheduler,QualityFactoryJob.class, JobName, cronTime, boutiqueAutoRule); } /* 淇敼浠诲姟 */ if ("modify".equalsIgnoreCase(type)) { - QuartzManager.modifyJob(scheduler, QualityFactoryJob.class, JobName, cronTime, params); + QuartzManager.modifyJob(scheduler, QualityFactoryJob.class, JobName, cronTime, boutiqueAutoRule); } /* 鍒犻櫎浠诲姟 */ if ("delete".equalsIgnoreCase(type)) { QuartzManager.removeJob(scheduler, JobName); } - } catch (Exception e) { - - try { - LogHelper.errorDetailInfo(e); - } catch (Exception e1) { - e1.printStackTrace(); - } - e.printStackTrace(); + LogHelper.errorDetailInfo(e); } } @Override public String setCronTime(String day, String time) { - if (StringUtil.isNullOrEmpty(day) || StringUtil.isNullOrEmpty(time)) { return null; } - String cronTime = null; - - - if (day.contains("灏忔椂")) { String[] sts = time.split(":"); @@ -174,44 +153,31 @@ if ("0".equals(minNumOne)) { minute = minute.substring(1, 2); } - // 0 11 2/12 * * ? cronTime = 0 + " " + minute + " " + hour + "/" + day.replace("灏忔椂", "") + " * * ? "; - } - - if (day.contains("澶�")) { + String[] sts = time.split(":"); + // 灏忔椂 + String hour = sts[0]; + // 鍒� + String minute = sts[1]; + // 娓呴櫎鍓嶉潰鐨�0 + String hourNumOne = hour.substring(0, 1); + if ("0".equals(hourNumOne)) { + hour = hour.substring(1, 2); + } + // 娓呴櫎鍓嶉潰鐨�0 + String minNumOne = minute.substring(0, 1); + if ("0".equals(minNumOne)) { + minute = minute.substring(1, 2); + } - String[] sts = time.split(":"); - // 灏忔椂 - String hour = sts[0]; - // 鍒� - String minute = sts[1]; - - // 娓呴櫎鍓嶉潰鐨�0 - String hourNumOne = hour.substring(0, 1); - if ("0".equals(hourNumOne)) { - hour = hour.substring(1, 2); - } - - // 娓呴櫎鍓嶉潰鐨�0 - String minNumOne = minute.substring(0, 1); - if ("0".equals(minNumOne)) { - minute = minute.substring(1, 2); - } - - - - // 0 34 3 1/5 * ? - // 绉� 灏忔椂 鍒� 鐩搁殧澶╂暟 - cronTime = 0 + " " + minute + " " + hour + " " + "1/" + day.replace("澶�", "") + " * ?"; - + // 0 34 3 1/5 * ? + // 绉� 灏忔椂 鍒� 鐩搁殧澶╂暟 + cronTime = 0 + " " + minute + " " + hour + " " + "1/" + day.replace("澶�", "") + " * ?"; } - - - return cronTime; } @@ -220,13 +186,12 @@ */ @Override public void startScheduler() { - List<BoutiqueAutoRule> listStart = boutiqueAutoRuleMapper.queryStart(); - if (listStart != null && listStart.size() > 0) { for (BoutiqueAutoRule boutiqueAutoRule : listStart) { boolean validateDate = boutiqueAutoRuleService.validateDate(boutiqueAutoRule); if (validateDate) { + jsonTransformString(boutiqueAutoRule); boutiqueAutoRuleService.setScheduler(boutiqueAutoRule, "add"); } } @@ -238,7 +203,6 @@ */ @Override public void shutdownJobs() throws Exception { - /* 鍋滄浠诲姟 */ QuartzManager.shutdownJobs(scheduler); @@ -246,25 +210,127 @@ @Override public boolean validateDate(BoutiqueAutoRule boutiqueAutoRule) { - long nowTime = new Date().getTime(); - Date endTime = boutiqueAutoRule.getEndTime(); if (endTime != null) { - long end = endTime.getTime(); if (end - nowTime <= 0) { return false; // 缁撴潫鏃堕棿宸茶繃 } } - return true; + } + + + /** + * json 杞崲鏈猄tring + * @param boutiqueAutoRule + */ + public void jsonTransformString(BoutiqueAutoRule boutiqueAutoRule){ + String searchContent = boutiqueAutoRule.getSearchContent(); + if (StringUtil.isNullOrEmpty(searchContent)) { + return; + } + + JSONObject jsonData = JSONObject.fromObject(searchContent); + + if (jsonData.get("key") != null){ + // 鎼滅储鍏抽敭璇� + boutiqueAutoRule.setKey(jsonData.get("key").toString()); + } + + if (jsonData.get("cateIds") != null){ + // 瀹樻柟鎺ㄨ崘鍟嗗搧搴撴姇鏀綢D;娣樺疂绫荤洰id闆嗗悎 + boutiqueAutoRule.setCateIds(jsonData.get("cateIds").toString()); + } + + if (jsonData.get("startTkRate") != null){ + // 浣i噾鑼冨洿灏忓�糄ouble.valueOf(itoString()); + boutiqueAutoRule.setStartTkRate(Double.valueOf(jsonData.get("startTkRate").toString())); + } + + if (jsonData.get("endTkRate") != null){ + // 浣i噾鑼冨洿澶у�� + boutiqueAutoRule.setEndTkRate(Double.valueOf(jsonData.get("endTkRate").toString())); + } + + if (jsonData.get("startSales") != null){ + // 閿�閲忓皬鍊� + boutiqueAutoRule.setStartSales((int)jsonData.get("startSales")); + } + + if (jsonData.get("endSales") != null){ + // 閿�閲忓ぇ鍊� + boutiqueAutoRule.setEndSales((int)jsonData.get("endSales")); + } + + if (jsonData.get("startZkPrice") != null){ + // 鍦ㄥ敭浠疯寖鍥村皬鍊� + boutiqueAutoRule.setStartZkPrice(Double.valueOf(jsonData.get("startZkPrice").toString())); + } + + if (jsonData.get("endZkPrice") != null){ + // 鍦ㄥ敭浠疯寖鍥村ぇ鍊� + boutiqueAutoRule.setEndZkPrice(Double.valueOf(jsonData.get("endZkPrice").toString())); + } + + if (jsonData.get("startPrice") != null){ + // 鍒稿悗浠疯寖鍥村皬鍊� + boutiqueAutoRule.setStartPrice(Double.valueOf(jsonData.get("startPrice").toString())); + } + + if (jsonData.get("endPrice") != null){ + // 鍒稿悗浠疯寖鍥村ぇ鍊� + boutiqueAutoRule.setEndPrice(Double.valueOf(jsonData.get("endPrice").toString())); + } + if (jsonData.get("isTmall") != null){ + // 鏄惁澶╃尗 + boutiqueAutoRule.setIsTmall((int)jsonData.get("isTmall")); + } + + if (jsonData.get("hasCoupon") != null){ + // 鏄惁鏈夊埜锛�1 鏈� 0 鏃� + boutiqueAutoRule.setHasCoupon((int)jsonData.get("hasCoupon")); + } + + if (jsonData.get("freeShipment") != null){ + // 鏄惁鍖呴偖锛�1 鏈� 0 鏃� + boutiqueAutoRule.setFreeShipment((int)jsonData.get("freeShipment")); + } + + if (jsonData.get("needPrepay") != null){ + // 鏄惁娑堣垂淇濋殰锛�1鏈� 0 鏃� + boutiqueAutoRule.setNeedPrepay((int)jsonData.get("needPrepay")); + } + + if (jsonData.get("npxLevel") != null){ + // 鐗涚毊鐧g▼搴︼紝鍙栧�硷細1:涓嶉檺锛�2:鏃狅紝3:杞诲井 + boutiqueAutoRule.setNpxLevel((int)jsonData.get("npxLevel")); + } + + if (jsonData.get("includePayRate30") != null){ + // 鎴愪氦杞寲鏄惁楂樹簬琛屼笟鍧囧�� 1 鏈� 0 鏃� + boutiqueAutoRule.setIncludePayRate30((int)jsonData.get("includePayRate30")); + } + + if (jsonData.get("includeGoodRate") != null){ + // 濂借瘎鐜囨槸鍚﹂珮浜庤涓氬潎鍊� 1 鏈� 0 鏃� + boutiqueAutoRule.setIncludeGoodRate((int)jsonData.get("includeGoodRate")); + } + + if (jsonData.get("includeRfdRate") != null){ + // 閫�娆剧巼鏄惁浣庝簬琛屼笟鍧囧�� 1 鏈� 0 鏃� + boutiqueAutoRule.setIncludeRfdRate((int)jsonData.get("includeRfdRate")); + } + + if (jsonData.get("lableNames") != null){ + boutiqueAutoRule.setLableNames(jsonData.get("lableNames").toString()); + } + + if (jsonData.get("maxPage") != null){ + // 鏄惁鍖呴偖锛�1 鏈� 0 鏃� + boutiqueAutoRule.setMaxPage((int)jsonData.get("maxPage")); + } } - - public static void main(String[] args) { - String t = "3灏忔椂"; - System.out.println(t.replace("灏忔椂", "")); - } - } -- Gitblit v1.8.0