From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/service/impl/lable/BoutiqueAutoRuleServiceImpl.java | 606 ++++++++++++++++++++++++++++++------------------------ 1 files changed, 336 insertions(+), 270 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..fcf92a0 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,270 +1,336 @@ -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 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.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; - -@Service -public class BoutiqueAutoRuleServiceImpl implements BoutiqueAutoRuleService { - - @Resource - private BoutiqueAutoRuleService boutiqueAutoRuleService; - @Resource - private BoutiqueAutoRuleMapper boutiqueAutoRuleMapper; - - @Resource - private Scheduler scheduler; - - @Override - public int insertSelective(BoutiqueAutoRule record) throws BoutiqueAutoRuleException { - return boutiqueAutoRuleMapper.insertSelective(record); - } - - @Override - public int updateByPrimaryKey(BoutiqueAutoRule record) throws BoutiqueAutoRuleException { - return boutiqueAutoRuleMapper.updateByPrimaryKey(record); - } - - @Override - public int updateByPrimaryKeySelective(BoutiqueAutoRule record) throws BoutiqueAutoRuleException { - return boutiqueAutoRuleMapper.updateByPrimaryKeySelective(record); - } - - @Override - @Transactional - public void deleteByPrimaryKey(Long id) throws BoutiqueAutoRuleException { - boutiqueAutoRuleMapper.deleteByPrimaryKey(id); - } - - @Override - @Transactional - public void deleteBatchByPrimaryKey(List<Long> ids) throws BoutiqueAutoRuleException { - for (Long id : ids) { - // 鍒犻櫎 - boutiqueAutoRuleMapper.deleteByPrimaryKey(id); - } - } - - @Override - public BoutiqueAutoRule selectByPrimaryKey(Long id) throws BoutiqueAutoRuleException { - return boutiqueAutoRuleMapper.selectByPrimaryKey(id); - } - - @Override - public List<BoutiqueAutoRule> query(int pageIndex, int pageSize, Integer source, String key, - Integer state,Integer sort) throws BoutiqueAutoRuleException { - return boutiqueAutoRuleMapper.query(pageIndex, pageSize, source, key, state, sort); - } - - @Override - public long queryCount(Integer source, String key, Integer state) throws BoutiqueAutoRuleException { - return boutiqueAutoRuleMapper.queryCount(source, key, state); - } - - @Override - public List<BoutiqueAutoRule> queryStart() throws BoutiqueAutoRuleException { - return boutiqueAutoRuleMapper.queryStart(); - } - - /** - * 璁剧疆鍑哄彂鍣� - * - * @param boutiqueAutoRule - */ - @Override - public void setScheduler(BoutiqueAutoRule boutiqueAutoRule, String type) { - - if (boutiqueAutoRule == null) { - return; - } - - Long id = boutiqueAutoRule.getId(); - if (id == null) - return; - - Integer source = boutiqueAutoRule.getSource(); - String cronTime = boutiqueAutoRule.getCronTime(); - - // 涓嶈兘涓虹┖: 瑙﹀彂鏃堕棿銆佽姹傛簮銆佺被鐩� - 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()+""); - - // 浠诲姟鍚� - String JobName = "JOB_" + source + "_" + id; - - try { - - /* 鏂板缓浠诲姟 */ - if ("add".equalsIgnoreCase(type)) { - QuartzManager.addJob(scheduler,QualityFactoryJob.class, JobName, cronTime, params); - } - - /* 淇敼浠诲姟 */ - if ("modify".equalsIgnoreCase(type)) { - QuartzManager.modifyJob(scheduler, QualityFactoryJob.class, JobName, cronTime, params); - } - - /* 鍒犻櫎浠诲姟 */ - if ("delete".equalsIgnoreCase(type)) { - QuartzManager.removeJob(scheduler, JobName); - } - - } catch (Exception e) { - - try { - LogHelper.errorDetailInfo(e); - } catch (Exception e1) { - e1.printStackTrace(); - } - e.printStackTrace(); - } - - } - - @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(":"); - // 灏忔椂 - 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 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); - } - - - - // 0 34 3 1/5 * ? - // 绉� 灏忔椂 鍒� 鐩搁殧澶╂暟 - cronTime = 0 + " " + minute + " " + hour + " " + "1/" + day.replace("澶�", "") + " * ?"; - - } - - - - return cronTime; - } - - /** - * 绯荤粺鍚姩鏃讹紝娣诲姞浠诲姟鍒癝cheduler - */ - @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) { - boutiqueAutoRuleService.setScheduler(boutiqueAutoRule, "add"); - } - } - } - } - - /** - * 鍏抽棴鎵�鏈変换鍔� - */ - @Override - public void shutdownJobs() throws Exception { - - /* 鍋滄浠诲姟 */ - QuartzManager.shutdownJobs(scheduler); - - } - - @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; - - } - - public static void main(String[] args) { - String t = "3灏忔椂"; - System.out.println(t.replace("灏忔椂", "")); - } - -} +package com.yeshi.fanli.service.impl.lable; + +import java.util.Date; +import java.util.List; + +import javax.annotation.Resource; + +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.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 { + + @Resource + private BoutiqueAutoRuleService boutiqueAutoRuleService; + @Resource + private BoutiqueAutoRuleMapper boutiqueAutoRuleMapper; + + @Resource + private Scheduler scheduler; + + @Override + public int insertSelective(BoutiqueAutoRule record) throws BoutiqueAutoRuleException { + return boutiqueAutoRuleMapper.insertSelective(record); + } + + @Override + public int updateByPrimaryKey(BoutiqueAutoRule record) throws BoutiqueAutoRuleException { + return boutiqueAutoRuleMapper.updateByPrimaryKey(record); + } + + @Override + public int updateByPrimaryKeySelective(BoutiqueAutoRule record) throws BoutiqueAutoRuleException { + return boutiqueAutoRuleMapper.updateByPrimaryKeySelective(record); + } + + @Override + @Transactional(rollbackFor=Exception.class) + public void deleteByPrimaryKey(Long id) throws BoutiqueAutoRuleException { + boutiqueAutoRuleMapper.deleteByPrimaryKey(id); + } + + @Override + @Transactional(rollbackFor=Exception.class) + public void deleteBatchByPrimaryKey(List<Long> ids) throws BoutiqueAutoRuleException { + for (Long id : ids) { + boutiqueAutoRuleMapper.deleteByPrimaryKey(id); + } + } + + @Override + public BoutiqueAutoRule selectByPrimaryKey(Long id) throws BoutiqueAutoRuleException { + return boutiqueAutoRuleMapper.selectByPrimaryKey(id); + } + + @Override + public List<BoutiqueAutoRule> query(int pageIndex, int pageSize, Integer source, String key, + Integer state,Integer sort) throws BoutiqueAutoRuleException { + return boutiqueAutoRuleMapper.query(pageIndex, pageSize, source, key, state, sort); + } + + @Override + public long queryCount(Integer source, String key, Integer state) throws BoutiqueAutoRuleException { + return boutiqueAutoRuleMapper.queryCount(source, key, state); + } + + @Override + public List<BoutiqueAutoRule> queryStart() throws BoutiqueAutoRuleException { + return boutiqueAutoRuleMapper.queryStart(); + } + + /** + * 璁剧疆鍑哄彂鍣� + * + * @param boutiqueAutoRule + */ + @Override + public void setScheduler(BoutiqueAutoRule boutiqueAutoRule, String type) { + + if (boutiqueAutoRule == null) { + return; + } + + Long id = boutiqueAutoRule.getId(); + if (id == null) + return; + + Integer source = boutiqueAutoRule.getSource(); + String cronTime = boutiqueAutoRule.getCronTime(); + // 涓嶈兘涓虹┖: 瑙﹀彂鏃堕棿銆佽姹傛簮銆佺被鐩� + if (source == null || StringUtil.isNullOrEmpty(cronTime)) + return; + + jsonTransformString(boutiqueAutoRule); + + // 浠诲姟鍚� + String JobName = "JOB_" + source + "_" + id; + try { + /* 鏂板缓浠诲姟 */ + if ("add".equalsIgnoreCase(type)) { + QuartzManager.addJob(scheduler,QualityFactoryJob.class, JobName, cronTime, boutiqueAutoRule); + } + + /* 淇敼浠诲姟 */ + if ("modify".equalsIgnoreCase(type)) { + QuartzManager.modifyJob(scheduler, QualityFactoryJob.class, JobName, cronTime, boutiqueAutoRule); + } + + /* 鍒犻櫎浠诲姟 */ + if ("delete".equalsIgnoreCase(type)) { + QuartzManager.removeJob(scheduler, JobName); + } + } catch (Exception e) { + 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(":"); + // 灏忔椂 + 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 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); + } + + // 0 34 3 1/5 * ? + // 绉� 灏忔椂 鍒� 鐩搁殧澶╂暟 + cronTime = 0 + " " + minute + " " + hour + " " + "1/" + day.replace("澶�", "") + " * ?"; + } + return cronTime; + } + + /** + * 绯荤粺鍚姩鏃讹紝娣诲姞浠诲姟鍒癝cheduler + */ + @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"); + } + } + } + } + + /** + * 鍏抽棴鎵�鏈変换鍔� + */ + @Override + public void shutdownJobs() throws Exception { + /* 鍋滄浠诲姟 */ + QuartzManager.shutdownJobs(scheduler); + + } + + @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")); + } + } +} -- Gitblit v1.8.0