diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java index 4b45f35bd..b97e44e57 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java @@ -1,163 +1,165 @@ -package com.ruoyi.common.utils; - -import java.lang.management.ManagementFactory; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import org.apache.commons.lang3.time.DateFormatUtils; - -/** - * 时间工具类 - * - * @author ruoyi - */ -public class DateUtils extends org.apache.commons.lang3.time.DateUtils -{ - public static String YYYY = "yyyy"; - - public static String YYYY_MM = "yyyy-MM"; - - public static String YYYY_MM_DD = "yyyy-MM-dd"; - - public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; - - public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; - - private static String[] parsePatterns = { - "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", - "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", - "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; - - /** - * 获取当前Date型日期 - * - * @return Date() 当前日期 - */ - public static Date getNowDate() - { - return new Date(); - } - - /** - * 获取当前日期, 默认格式为yyyy-MM-dd - * - * @return String - */ - public static String getDate() - { - return dateTimeNow(YYYY_MM_DD); - } - - public static final String getTime() - { - return dateTimeNow(YYYY_MM_DD_HH_MM_SS); - } - - public static final String dateTimeNow() - { - return dateTimeNow(YYYYMMDDHHMMSS); - } - - public static final String dateTimeNow(final String format) - { - return parseDateToStr(format, new Date()); - } - - public static final String dateTime(final Date date) - { - return parseDateToStr(YYYY_MM_DD, date); - } - - public static final String parseDateToStr(final String format, final Date date) - { - return new SimpleDateFormat(format).format(date); - } - - public static final Date dateTime(final String format, final String ts) - { - try - { - return new SimpleDateFormat(format).parse(ts); - } - catch (ParseException e) - { - throw new RuntimeException(e); - } - } - - /** - * 日期路径 即年/月/日 如2018/08/08 - */ - public static final String datePath() - { - Date now = new Date(); - return DateFormatUtils.format(now, "yyyy/MM/dd"); - } - - /** - * 日期路径 即年/月/日 如20180808 - */ - public static final String dateTime() - { - Date now = new Date(); - return DateFormatUtils.format(now, "yyyyMMdd"); - } - - /** - * 日期型字符串转化为日期 格式 - */ - public static Date parseDate(Object str) - { - if (str == null) - { - return null; - } - try - { - return parseDate(str.toString(), parsePatterns); - } - catch (ParseException e) - { - return null; - } - } - - /** - * 获取服务器启动时间 - */ - public static Date getServerStartDate() - { - long time = ManagementFactory.getRuntimeMXBean().getStartTime(); - return new Date(time); - } - - /** - * 计算相差天数 - */ - public static int differentDaysByMillisecond(Date date1, Date date2) - { - return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24))); - } - - /** - * 计算两个时间差 - */ - public static String getDatePoor(Date endDate, Date nowDate) - { - long nd = 1000 * 24 * 60 * 60; - long nh = 1000 * 60 * 60; - long nm = 1000 * 60; - // long ns = 1000; - // 获得两个时间的毫秒时间差异 - long diff = endDate.getTime() - nowDate.getTime(); - // 计算差多少天 - long day = diff / nd; - // 计算差多少小时 - long hour = diff % nd / nh; - // 计算差多少分钟 - long min = diff % nd % nh / nm; - // 计算差多少秒//输出结果 - // long sec = diff % nd % nh % nm / ns; - return day + "天" + hour + "小时" + min + "分钟"; - } -} +package com.ruoyi.common.utils; + +import java.lang.management.ManagementFactory; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import org.apache.commons.lang3.time.DateFormatUtils; + +/** + * 时间工具类 + * + * @author ruoyi + */ +public class DateUtils extends org.apache.commons.lang3.time.DateUtils +{ + public static String YYYY = "yyyy"; + + public static String YYYY_MM = "yyyy-MM"; + + public static String YYYY_MM_DD = "yyyy-MM-dd"; + + public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; + + public static String YYYYMMDDHHMMSSS = "yyyyMMddHHmmssSSS"; + + public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; + + private static String[] parsePatterns = { + "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", + "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", + "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; + + /** + * 获取当前Date型日期 + * + * @return Date() 当前日期 + */ + public static Date getNowDate() + { + return new Date(); + } + + /** + * 获取当前日期, 默认格式为yyyy-MM-dd + * + * @return String + */ + public static String getDate() + { + return dateTimeNow(YYYY_MM_DD); + } + + public static final String getTime() + { + return dateTimeNow(YYYY_MM_DD_HH_MM_SS); + } + + public static final String dateTimeNow() + { + return dateTimeNow(YYYYMMDDHHMMSS); + } + + public static final String dateTimeNow(final String format) + { + return parseDateToStr(format, new Date()); + } + + public static final String dateTime(final Date date) + { + return parseDateToStr(YYYY_MM_DD, date); + } + + public static final String parseDateToStr(final String format, final Date date) + { + return new SimpleDateFormat(format).format(date); + } + + public static final Date dateTime(final String format, final String ts) + { + try + { + return new SimpleDateFormat(format).parse(ts); + } + catch (ParseException e) + { + throw new RuntimeException(e); + } + } + + /** + * 日期路径 即年/月/日 如2018/08/08 + */ + public static final String datePath() + { + Date now = new Date(); + return DateFormatUtils.format(now, "yyyy/MM/dd"); + } + + /** + * 日期路径 即年/月/日 如20180808 + */ + public static final String dateTime() + { + Date now = new Date(); + return DateFormatUtils.format(now, "yyyyMMdd"); + } + + /** + * 日期型字符串转化为日期 格式 + */ + public static Date parseDate(Object str) + { + if (str == null) + { + return null; + } + try + { + return parseDate(str.toString(), parsePatterns); + } + catch (ParseException e) + { + return null; + } + } + + /** + * 获取服务器启动时间 + */ + public static Date getServerStartDate() + { + long time = ManagementFactory.getRuntimeMXBean().getStartTime(); + return new Date(time); + } + + /** + * 计算相差天数 + */ + public static int differentDaysByMillisecond(Date date1, Date date2) + { + return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24))); + } + + /** + * 计算两个时间差 + */ + public static String getDatePoor(Date endDate, Date nowDate) + { + long nd = 1000 * 24 * 60 * 60; + long nh = 1000 * 60 * 60; + long nm = 1000 * 60; + // long ns = 1000; + // 获得两个时间的毫秒时间差异 + long diff = endDate.getTime() - nowDate.getTime(); + // 计算差多少天 + long day = diff / nd; + // 计算差多少小时 + long hour = diff % nd / nh; + // 计算差多少分钟 + long min = diff % nd % nh / nm; + // 计算差多少秒//输出结果 + // long sec = diff % nd % nh % nm / ns; + return day + "天" + hour + "小时" + min + "分钟"; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java index e502f5be4..4cd1644f8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java @@ -1,99 +1,103 @@ -package com.ruoyi.system.service; - -import java.util.List; -import com.ruoyi.common.core.domain.Ztree; -import com.ruoyi.common.core.domain.entity.SysDictData; -import com.ruoyi.common.core.domain.entity.SysDictType; - -/** - * 字典 业务层 - * - * @author ruoyi - */ -public interface ISysDictTypeService -{ - /** - * 根据条件分页查询字典类型 - * - * @param dictType 字典类型信息 - * @return 字典类型集合信息 - */ - public List selectDictTypeList(SysDictType dictType); - - /** - * 根据所有字典类型 - * - * @return 字典类型集合信息 - */ - public List selectDictTypeAll(); - - /** - * 根据字典类型查询字典数据 - * - * @param dictType 字典类型 - * @return 字典数据集合信息 - */ - public List selectDictDataByType(String dictType); - - /** - * 根据字典类型ID查询信息 - * - * @param dictId 字典类型ID - * @return 字典类型 - */ - public SysDictType selectDictTypeById(Long dictId); - - /** - * 根据字典类型查询信息 - * - * @param dictType 字典类型 - * @return 字典类型 - */ - public SysDictType selectDictTypeByType(String dictType); - - /** - * 批量删除字典类型 - * - * @param ids 需要删除的数据 - * @return 结果 - * @throws Exception 异常 - */ - public int deleteDictTypeByIds(String ids); - - /** - * 清空缓存数据 - */ - public void clearCache(); - - /** - * 新增保存字典类型信息 - * - * @param dictType 字典类型信息 - * @return 结果 - */ - public int insertDictType(SysDictType dictType); - - /** - * 修改保存字典类型信息 - * - * @param dictType 字典类型信息 - * @return 结果 - */ - public int updateDictType(SysDictType dictType); - - /** - * 校验字典类型称是否唯一 - * - * @param dictType 字典类型 - * @return 结果 - */ - public String checkDictTypeUnique(SysDictType dictType); - - /** - * 查询字典类型树 - * - * @param dictType 字典类型 - * @return 所有字典类型 - */ - public List selectDictTree(SysDictType dictType); -} +package com.ruoyi.system.service; + +import java.util.List; +import java.util.Map; + +import com.ruoyi.common.core.domain.Ztree; +import com.ruoyi.common.core.domain.entity.SysDictData; +import com.ruoyi.common.core.domain.entity.SysDictType; + +/** + * 字典 业务层 + * + * @author ruoyi + */ +public interface ISysDictTypeService +{ + /** + * 根据条件分页查询字典类型 + * + * @param dictType 字典类型信息 + * @return 字典类型集合信息 + */ + public List selectDictTypeList(SysDictType dictType); + + /** + * 根据所有字典类型 + * + * @return 字典类型集合信息 + */ + public List selectDictTypeAll(); + + Map selectDictMapByType(String dictType); + + /** + * 根据字典类型查询字典数据 + * + * @param dictType 字典类型 + * @return 字典数据集合信息 + */ + public List selectDictDataByType(String dictType); + + /** + * 根据字典类型ID查询信息 + * + * @param dictId 字典类型ID + * @return 字典类型 + */ + public SysDictType selectDictTypeById(Long dictId); + + /** + * 根据字典类型查询信息 + * + * @param dictType 字典类型 + * @return 字典类型 + */ + public SysDictType selectDictTypeByType(String dictType); + + /** + * 批量删除字典类型 + * + * @param ids 需要删除的数据 + * @return 结果 + * @throws Exception 异常 + */ + public int deleteDictTypeByIds(String ids); + + /** + * 清空缓存数据 + */ + public void clearCache(); + + /** + * 新增保存字典类型信息 + * + * @param dictType 字典类型信息 + * @return 结果 + */ + public int insertDictType(SysDictType dictType); + + /** + * 修改保存字典类型信息 + * + * @param dictType 字典类型信息 + * @return 结果 + */ + public int updateDictType(SysDictType dictType); + + /** + * 校验字典类型称是否唯一 + * + * @param dictType 字典类型 + * @return 结果 + */ + public String checkDictTypeUnique(SysDictType dictType); + + /** + * 查询字典类型树 + * + * @param dictType 字典类型 + * @return 所有字典类型 + */ + public List selectDictTree(SysDictType dictType); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java index 642c8469b..daa5311a0 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java @@ -1,241 +1,252 @@ -package com.ruoyi.system.service.impl; - -import java.util.ArrayList; -import java.util.List; -import javax.annotation.PostConstruct; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import com.ruoyi.common.constant.UserConstants; -import com.ruoyi.common.core.domain.Ztree; -import com.ruoyi.common.core.domain.entity.SysDictData; -import com.ruoyi.common.core.domain.entity.SysDictType; -import com.ruoyi.common.core.text.Convert; -import com.ruoyi.common.exception.BusinessException; -import com.ruoyi.common.utils.DictUtils; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.system.mapper.SysDictDataMapper; -import com.ruoyi.system.mapper.SysDictTypeMapper; -import com.ruoyi.system.service.ISysDictTypeService; - -/** - * 字典 业务层处理 - * - * @author ruoyi - */ -@Service -public class SysDictTypeServiceImpl implements ISysDictTypeService -{ - @Autowired - private SysDictTypeMapper dictTypeMapper; - - @Autowired - private SysDictDataMapper dictDataMapper; - - /** - * 项目启动时,初始化字典到缓存 - */ - @PostConstruct - public void init() - { - List dictTypeList = dictTypeMapper.selectDictTypeAll(); - for (SysDictType dictType : dictTypeList) - { - List dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType()); - DictUtils.setDictCache(dictType.getDictType(), dictDatas); - } - } - - /** - * 根据条件分页查询字典类型 - * - * @param dictType 字典类型信息 - * @return 字典类型集合信息 - */ - @Override - public List selectDictTypeList(SysDictType dictType) - { - return dictTypeMapper.selectDictTypeList(dictType); - } - - /** - * 根据所有字典类型 - * - * @return 字典类型集合信息 - */ - @Override - public List selectDictTypeAll() - { - return dictTypeMapper.selectDictTypeAll(); - } - - /** - * 根据字典类型查询字典数据 - * - * @param dictType 字典类型 - * @return 字典数据集合信息 - */ - @Override - public List selectDictDataByType(String dictType) - { - List dictDatas = DictUtils.getDictCache(dictType); - if (StringUtils.isNotEmpty(dictDatas)) - { - return dictDatas; - } - dictDatas = dictDataMapper.selectDictDataByType(dictType); - if (StringUtils.isNotEmpty(dictDatas)) - { - DictUtils.setDictCache(dictType, dictDatas); - return dictDatas; - } - return null; - } - - /** - * 根据字典类型ID查询信息 - * - * @param dictId 字典类型ID - * @return 字典类型 - */ - @Override - public SysDictType selectDictTypeById(Long dictId) - { - return dictTypeMapper.selectDictTypeById(dictId); - } - - /** - * 根据字典类型查询信息 - * - * @param dictType 字典类型 - * @return 字典类型 - */ - @Override - public SysDictType selectDictTypeByType(String dictType) - { - return dictTypeMapper.selectDictTypeByType(dictType); - } - - /** - * 批量删除字典类型 - * - * @param ids 需要删除的数据 - * @return 结果 - */ - @Override - public int deleteDictTypeByIds(String ids) - { - Long[] dictIds = Convert.toLongArray(ids); - for (Long dictId : dictIds) - { - SysDictType dictType = selectDictTypeById(dictId); - if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) - { - throw new BusinessException(String.format("%1$s已分配,不能删除", dictType.getDictName())); - } - } - int count = dictTypeMapper.deleteDictTypeByIds(dictIds); - if (count > 0) - { - DictUtils.clearDictCache(); - } - return count; - } - - /** - * 清空缓存数据 - */ - @Override - public void clearCache() - { - DictUtils.clearDictCache(); - } - - /** - * 新增保存字典类型信息 - * - * @param dictType 字典类型信息 - * @return 结果 - */ - @Override - public int insertDictType(SysDictType dictType) - { - int row = dictTypeMapper.insertDictType(dictType); - if (row > 0) - { - DictUtils.clearDictCache(); - } - return row; - } - - /** - * 修改保存字典类型信息 - * - * @param dictType 字典类型信息 - * @return 结果 - */ - @Override - @Transactional - public int updateDictType(SysDictType dictType) - { - SysDictType oldDict = dictTypeMapper.selectDictTypeById(dictType.getDictId()); - dictDataMapper.updateDictDataType(oldDict.getDictType(), dictType.getDictType()); - int row = dictTypeMapper.updateDictType(dictType); - if (row > 0) - { - DictUtils.clearDictCache(); - } - return row; - } - - /** - * 校验字典类型称是否唯一 - * - * @param dict 字典类型 - * @return 结果 - */ - @Override - public String checkDictTypeUnique(SysDictType dict) - { - Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId(); - SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType()); - if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) - { - return UserConstants.DICT_TYPE_NOT_UNIQUE; - } - return UserConstants.DICT_TYPE_UNIQUE; - } - - /** - * 查询字典类型树 - * - * @param dictType 字典类型 - * @return 所有字典类型 - */ - @Override - public List selectDictTree(SysDictType dictType) - { - List ztrees = new ArrayList(); - List dictList = dictTypeMapper.selectDictTypeList(dictType); - for (SysDictType dict : dictList) - { - if (UserConstants.DICT_NORMAL.equals(dict.getStatus())) - { - Ztree ztree = new Ztree(); - ztree.setId(dict.getDictId()); - ztree.setName(transDictName(dict)); - ztree.setTitle(dict.getDictType()); - ztrees.add(ztree); - } - } - return ztrees; - } - - public String transDictName(SysDictType dictType) - { - StringBuffer sb = new StringBuffer(); - sb.append("(" + dictType.getDictName() + ")"); - sb.append("   " + dictType.getDictType()); - return sb.toString(); - } -} +package com.ruoyi.system.service.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.PostConstruct; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.core.domain.Ztree; +import com.ruoyi.common.core.domain.entity.SysDictData; +import com.ruoyi.common.core.domain.entity.SysDictType; +import com.ruoyi.common.core.text.Convert; +import com.ruoyi.common.exception.BusinessException; +import com.ruoyi.common.utils.DictUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.mapper.SysDictDataMapper; +import com.ruoyi.system.mapper.SysDictTypeMapper; +import com.ruoyi.system.service.ISysDictTypeService; + +/** + * 字典 业务层处理 + * + * @author ruoyi + */ +@Service +public class SysDictTypeServiceImpl implements ISysDictTypeService +{ + @Autowired + private SysDictTypeMapper dictTypeMapper; + + @Autowired + private SysDictDataMapper dictDataMapper; + + /** + * 项目启动时,初始化字典到缓存 + */ + @PostConstruct + public void init() + { + List dictTypeList = dictTypeMapper.selectDictTypeAll(); + for (SysDictType dictType : dictTypeList) + { + List dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType()); + DictUtils.setDictCache(dictType.getDictType(), dictDatas); + } + } + + /** + * 根据条件分页查询字典类型 + * + * @param dictType 字典类型信息 + * @return 字典类型集合信息 + */ + @Override + public List selectDictTypeList(SysDictType dictType) + { + return dictTypeMapper.selectDictTypeList(dictType); + } + + /** + * 根据所有字典类型 + * + * @return 字典类型集合信息 + */ + @Override + public List selectDictTypeAll() + { + return dictTypeMapper.selectDictTypeAll(); + } + + /** + * 根据字典类型查询字典数据 + * + * @param dictType 字典类型 + * @return 字典数据集合信息 + */ + @Override + public Map selectDictMapByType(String dictType) { + Map map = new HashMap<>(); + List sysDictData = selectDictDataByType(dictType); + for (SysDictData dict : sysDictData) { + map.put(dict.getDictValue(), dict); + } + return map; + } + @Override + public List selectDictDataByType(String dictType) + { + List dictDatas = DictUtils.getDictCache(dictType); + if (StringUtils.isNotEmpty(dictDatas)) + { + return dictDatas; + } + dictDatas = dictDataMapper.selectDictDataByType(dictType); + if (StringUtils.isNotEmpty(dictDatas)) + { + DictUtils.setDictCache(dictType, dictDatas); + return dictDatas; + } + return null; + } + + /** + * 根据字典类型ID查询信息 + * + * @param dictId 字典类型ID + * @return 字典类型 + */ + @Override + public SysDictType selectDictTypeById(Long dictId) + { + return dictTypeMapper.selectDictTypeById(dictId); + } + + /** + * 根据字典类型查询信息 + * + * @param dictType 字典类型 + * @return 字典类型 + */ + @Override + public SysDictType selectDictTypeByType(String dictType) + { + return dictTypeMapper.selectDictTypeByType(dictType); + } + + /** + * 批量删除字典类型 + * + * @param ids 需要删除的数据 + * @return 结果 + */ + @Override + public int deleteDictTypeByIds(String ids) + { + Long[] dictIds = Convert.toLongArray(ids); + for (Long dictId : dictIds) + { + SysDictType dictType = selectDictTypeById(dictId); + if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) + { + throw new BusinessException(String.format("%1$s已分配,不能删除", dictType.getDictName())); + } + } + int count = dictTypeMapper.deleteDictTypeByIds(dictIds); + if (count > 0) + { + DictUtils.clearDictCache(); + } + return count; + } + + /** + * 清空缓存数据 + */ + @Override + public void clearCache() + { + DictUtils.clearDictCache(); + } + + /** + * 新增保存字典类型信息 + * + * @param dictType 字典类型信息 + * @return 结果 + */ + @Override + public int insertDictType(SysDictType dictType) + { + int row = dictTypeMapper.insertDictType(dictType); + if (row > 0) + { + DictUtils.clearDictCache(); + } + return row; + } + + /** + * 修改保存字典类型信息 + * + * @param dictType 字典类型信息 + * @return 结果 + */ + @Override + @Transactional + public int updateDictType(SysDictType dictType) + { + SysDictType oldDict = dictTypeMapper.selectDictTypeById(dictType.getDictId()); + dictDataMapper.updateDictDataType(oldDict.getDictType(), dictType.getDictType()); + int row = dictTypeMapper.updateDictType(dictType); + if (row > 0) + { + DictUtils.clearDictCache(); + } + return row; + } + + /** + * 校验字典类型称是否唯一 + * + * @param dict 字典类型 + * @return 结果 + */ + @Override + public String checkDictTypeUnique(SysDictType dict) + { + Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId(); + SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType()); + if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) + { + return UserConstants.DICT_TYPE_NOT_UNIQUE; + } + return UserConstants.DICT_TYPE_UNIQUE; + } + + /** + * 查询字典类型树 + * + * @param dictType 字典类型 + * @return 所有字典类型 + */ + @Override + public List selectDictTree(SysDictType dictType) + { + List ztrees = new ArrayList(); + List dictList = dictTypeMapper.selectDictTypeList(dictType); + for (SysDictType dict : dictList) + { + if (UserConstants.DICT_NORMAL.equals(dict.getStatus())) + { + Ztree ztree = new Ztree(); + ztree.setId(dict.getDictId()); + ztree.setName(transDictName(dict)); + ztree.setTitle(dict.getDictType()); + ztrees.add(ztree); + } + } + return ztrees; + } + + public String transDictName(SysDictType dictType) + { + StringBuffer sb = new StringBuffer(); + sb.append("(" + dictType.getDictName() + ")"); + sb.append("   " + dictType.getDictType()); + return sb.toString(); + } +} diff --git a/sino-act-web/pom.xml b/sino-act-web/pom.xml index cf28999cd..3b1539f4e 100644 --- a/sino-act-web/pom.xml +++ b/sino-act-web/pom.xml @@ -79,6 +79,10 @@ mysql-connector-java + + com.ruoyi + ruoyi-system + com.ruoyi sino-activity diff --git a/sino-act-web/src/main/java/com/ruoyi/ActWebApplication.java b/sino-act-web/src/main/java/com/ruoyi/ActWebApplication.java index bb93b5ccf..71c2e06e5 100644 --- a/sino-act-web/src/main/java/com/ruoyi/ActWebApplication.java +++ b/sino-act-web/src/main/java/com/ruoyi/ActWebApplication.java @@ -16,7 +16,6 @@ public class ActWebApplication { // System.setProperty("spring.devtools.restart.enabled", "false"); SpringApplication.run(ActWebApplication.class, args); - System.out.println("(♥◠‿◠)ノ゙ 活动前端服务启动成功 ლ(´ڡ`ლ)゙ \n" + - " ''-' `'-' `-..-' "); + System.out.println("Activity Server Running Successful"); } } \ No newline at end of file diff --git a/sino-act-web/src/main/java/com/ruoyi/config/ShiroConfig.java b/sino-act-web/src/main/java/com/ruoyi/config/ShiroConfig.java new file mode 100644 index 000000000..cd1af5d34 --- /dev/null +++ b/sino-act-web/src/main/java/com/ruoyi/config/ShiroConfig.java @@ -0,0 +1,69 @@ +package com.ruoyi.config; + +import com.ruoyi.common.utils.StringUtils; +import org.apache.commons.io.IOUtils; +import org.apache.shiro.cache.ehcache.EhCacheManager; +import org.apache.shiro.config.ConfigurationException; +import org.apache.shiro.io.ResourceUtils; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * 权限配置加载 + * + * @author ruoyi + */ +@Configuration +public class ShiroConfig +{ + + /** + * 缓存管理器 使用Ehcache实现 + */ + @Bean + public EhCacheManager getEhCacheManager() + { + net.sf.ehcache.CacheManager cacheManager = net.sf.ehcache.CacheManager.getCacheManager("ruoyi"); + EhCacheManager em = new EhCacheManager(); + if (StringUtils.isNull(cacheManager)) + { + em.setCacheManager(new net.sf.ehcache.CacheManager(getCacheManagerConfigFileInputStream())); + return em; + } + else + { + em.setCacheManager(cacheManager); + return em; + } + } + + /** + * 返回配置文件流 避免ehcache配置文件一直被占用,无法完全销毁项目重新部署 + */ + protected InputStream getCacheManagerConfigFileInputStream() + { + String configFile = "classpath:ehcache/ehcache-shiro.xml"; + InputStream inputStream = null; + try + { + inputStream = ResourceUtils.getInputStreamForPath(configFile); + byte[] b = IOUtils.toByteArray(inputStream); + InputStream in = new ByteArrayInputStream(b); + return in; + } + catch (IOException e) + { + throw new ConfigurationException( + "Unable to obtain input stream for cacheManagerConfigFile [" + configFile + "]", e); + } + finally + { + IOUtils.closeQuietly(inputStream); + } + } + +} diff --git a/sino-act-web/src/main/java/com/ruoyi/dto/DrawActivityRequest.java b/sino-act-web/src/main/java/com/ruoyi/dto/DrawActivityRequest.java new file mode 100644 index 000000000..c77ac3f2a --- /dev/null +++ b/sino-act-web/src/main/java/com/ruoyi/dto/DrawActivityRequest.java @@ -0,0 +1,134 @@ +package com.ruoyi.dto; + +import java.io.Serializable; + +public class DrawActivityRequest implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -426397448496644788L; + + private String serialNo; + + private String drawCode; + + private String userId; + + private String userType; + + private String drawTime; + + private String merchantCode; + + private String merchantSysCode; + + private String channel; + + private String userName; + + private String businessArea; + + private String source; + + private String phone; + + public String getSerialNo() { + return serialNo; + } + + public void setSerialNo(String serialNo) { + this.serialNo = serialNo; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getDrawCode() { + return drawCode; + } + + public void setDrawCode(String drawCode) { + this.drawCode = drawCode; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getUserType() { + return userType; + } + + public void setUserType(String userType) { + this.userType = userType; + } + + public String getDrawTime() { + return drawTime; + } + + public void setDrawTime(String drawTime) { + this.drawTime = drawTime; + } + + public String getMerchantCode() { + return merchantCode; + } + + public void setMerchantCode(String merchantCode) { + this.merchantCode = merchantCode; + } + + public String getMerchantSysCode() { + return merchantSysCode; + } + + public void setMerchantSysCode(String merchantSysCode) { + this.merchantSysCode = merchantSysCode; + } + + public String getChannel() { + return channel; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getBusinessArea() { + return businessArea; + } + + public void setBusinessArea(String businessArea) { + this.businessArea = businessArea; + } + + + +} diff --git a/sino-act-web/src/main/java/com/ruoyi/dto/DrawActivityResponse.java b/sino-act-web/src/main/java/com/ruoyi/dto/DrawActivityResponse.java new file mode 100644 index 000000000..38d4652b6 --- /dev/null +++ b/sino-act-web/src/main/java/com/ruoyi/dto/DrawActivityResponse.java @@ -0,0 +1,117 @@ +package com.ruoyi.dto; + +import java.io.Serializable; + +public class DrawActivityResponse implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 2898381019555914194L; + private String drawCode; + private String userId; + private String userType; + private String gateWayTime; + private String result; + private String prizeCode; + private String prizeName; + private String prizeType; + private String displayOrder; + private String prizeLevel; + private String gatewayFolw; + private String available; + private String extId; + private String source; + + public String getGatewayFolw() { + return gatewayFolw; + } + public void setGatewayFolw(String gatewayFolw) { + this.gatewayFolw = gatewayFolw; + } + public String getPrizeLevel() { + return prizeLevel; + } + public void setPrizeLevel(String prizeLevel) { + this.prizeLevel = prizeLevel; + } + private String cue; + public String getDrawCode() { + return drawCode; + } + public void setDrawCode(String drawCode) { + this.drawCode = drawCode; + } + public String getUserId() { + return userId; + } + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserType() { + return userType; + } + public void setUserType(String userType) { + this.userType = userType; + } + public String getGateWayTime() { + return gateWayTime; + } + public void setGateWayTime(String gateWayTime) { + this.gateWayTime = gateWayTime; + } + public String getResult() { + return result; + } + public void setResult(String result) { + this.result = result; + } + public String getPrizeCode() { + return prizeCode; + } + public void setPrizeCode(String prizeCode) { + this.prizeCode = prizeCode; + } + public String getPrizeName() { + return prizeName; + } + public void setPrizeName(String prizeName) { + this.prizeName = prizeName; + } + public String getPrizeType() { + return prizeType; + } + public void setPrizeType(String prizeType) { + this.prizeType = prizeType; + } + public String getDisplayOrder() { + return displayOrder; + } + public void setDisplayOrder(String displayOrder) { + this.displayOrder = displayOrder; + } + public String getCue() { + return cue; + } + public void setCue(String cue) { + this.cue = cue; + } + public String getAvailable() { + return available; + } + public void setAvailable(String available) { + this.available = available; + } + public String getExtId() { + return extId; + } + public void setExtId(String extId) { + this.extId = extId; + } + public String getSource() { + return source; + } + public void setSource(String source) { + this.source = source; + } +} diff --git a/sino-act-web/src/main/java/com/ruoyi/dto/DrawActivityResult.java b/sino-act-web/src/main/java/com/ruoyi/dto/DrawActivityResult.java new file mode 100644 index 000000000..e1181c7fc --- /dev/null +++ b/sino-act-web/src/main/java/com/ruoyi/dto/DrawActivityResult.java @@ -0,0 +1,62 @@ +package com.ruoyi.dto; + +import java.util.HashMap; +import java.util.Map; + +public class DrawActivityResult { + /**成功**/ + public static final String SUCCESS = "0000"; + /**系统繁忙,请稍后重试**/ + public final static String EXCEPTION = "GT00000"; + /**参数错误**/ + public static final String EXCEPTION_000001="GT00001"; + /**抽奖失败[{0}]**/ + public static final String EXCEPTION_000002="GT00002"; + /**奖品信息**/ + public static final String EXCEPTION_000003="GT00003"; + /**查询中奖纪录**/ + public static final String EXCEPTION_000004="GT00004"; + /**奖品发放通知**/ + public static final String EXCEPTION_000005="GT00005"; + /**增加抽奖机会失败**/ + public static final String EXCEPTION_000006="GT00006"; + /**可用抽奖次数不足**/ + public static final String EXCEPTION_000007="GT00007"; + /**查询抽奖可用次数失败*/ + public static final String EXCEPTION_000008="GT00008"; + /**积分账户不存在**/ + public static final String EXCEPTION_000009="GT00009"; + /**积分账户余额不足**/ + public static final String EXCEPTION_000010="GT00010"; + public static final String EXCEPTION_000011="GT00011"; + public static final String EXCEPTION_000012="GT00012"; + public static final Map ERROR = new HashMap(); + static { + ERROR.put(SUCCESS, "成功"); + ERROR.put(EXCEPTION, "系统繁忙,请稍后重试"); + ERROR.put(EXCEPTION_000001, "参数错误[{0}]"); + ERROR.put(EXCEPTION_000002, "抽奖失败[{0}]"); + ERROR.put(EXCEPTION_000003, "查询奖品信息失败[{0}]"); + ERROR.put(EXCEPTION_000004, "查询中奖纪录失败[{0}]"); + ERROR.put(EXCEPTION_000005, "奖品发放通知[{0}]"); + ERROR.put(EXCEPTION_000006, "增加抽奖机会失败[{0}]"); + ERROR.put(EXCEPTION_000007, "可用抽奖次数不足"); + ERROR.put(EXCEPTION_000008, "查询抽奖可用次数失败[{0}]"); + ERROR.put(EXCEPTION_000009, "积分账户不存在"); + ERROR.put(EXCEPTION_000010, "积分账户余额不足"); + ERROR.put(EXCEPTION_000011, "活动未开启"); + } + + public static String getMsg(String code, Object... params) { + String message = ERROR.get(code); + if (message == null) { + return null; + } + for (int i = 0; i < params.length; i++) { + message = message.replaceAll("\\{" + i + "\\}", String.valueOf(params[i])); + } + + return message; + } + +} diff --git a/sino-act-web/src/main/java/com/ruoyi/service/AwardService.java b/sino-act-web/src/main/java/com/ruoyi/service/AwardService.java new file mode 100644 index 000000000..871f6ec28 --- /dev/null +++ b/sino-act-web/src/main/java/com/ruoyi/service/AwardService.java @@ -0,0 +1,13 @@ +package com.ruoyi.service; + +import com.ruoyi.dto.DrawActivityRequest; +import com.ruoyi.thread.AwardThread; +import com.ruoyi.thread.ThreadPool; +import com.sinosoft.activity.domain.DrawInfo; +import com.sinosoft.activity.domain.DrawRecord; + +public class AwardService { + public void award(DrawRecord gtDrawRecord, DrawActivityRequest request, DrawInfo gtDrawInfo, String mobile, String awardMethod) { + ThreadPool.awardExecutorService.submit(new AwardThread(gtDrawRecord, request,mobile,awardMethod)); + } +} diff --git a/sino-act-web/src/main/java/com/ruoyi/service/DrawService.java b/sino-act-web/src/main/java/com/ruoyi/service/DrawService.java index 9f4a5dc5b..a9b6ae410 100644 --- a/sino-act-web/src/main/java/com/ruoyi/service/DrawService.java +++ b/sino-act-web/src/main/java/com/ruoyi/service/DrawService.java @@ -2,24 +2,31 @@ package com.ruoyi.service; import com.ruoyi.cache.Cache; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.dto.DrawActivityRequest; +import com.ruoyi.dto.DrawActivityResult; import com.ruoyi.dto.GtPrizeConfigTemp; +import com.ruoyi.thread.DrawActivityThread; +import com.ruoyi.thread.ThreadPool; import com.ruoyi.web.vo.Const; +import com.ruoyi.web.vo.draw.DrawResult; import com.sinosoft.activity.domain.DrawConfig; +import com.sinosoft.activity.domain.DrawInfo; import com.sinosoft.activity.domain.DrawPrizeInfo; import com.sinosoft.activity.domain.DrawRule; import com.sinosoft.activity.service.IDrawConfigService; +import com.sinosoft.activity.service.IDrawInfoService; import com.sinosoft.activity.service.IDrawPrizeInfoService; import com.sinosoft.activity.service.IDrawRuleService; import com.sinosoft.activity.vo.PrizeInfo; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; public class DrawService { @@ -30,6 +37,85 @@ public class DrawService { private IDrawConfigService drawConfigService; @Autowired private IDrawPrizeInfoService drawPrizeInfoService; + @Autowired + private IDrawInfoService drawInfoService; + + /** + * 抽奖实现主方法 + */ + public DrawResult drawActivity(DrawActivityRequest request) { + long start = System.currentTimeMillis(); + long end = 0; + long proct = 0; + String exception = ""; + DrawResult drawResult = new DrawResult(); + long point = System.currentTimeMillis(); + logger.info("抽奖开始时间:" + request.getSerialNo() + ":" + point); + try { + // 校验体信息 + String drawCode = request.getDrawCode(); + if(StringUtils.isBlank(drawCode)){ + return processResp(request, DrawActivityResult.EXCEPTION_000001, + DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000001, "drawCode参数为空")); + } + long point1 = System.currentTimeMillis(); + logger.info("抽奖检查点1:" + request.getSerialNo() + ":" + point1 + "与前一个检查点时间差" + (point1 - point)); + // 查询活动信息 + DrawInfo queryInfo = new DrawInfo(); + queryInfo.setDRAWCODE(drawCode); + queryInfo.setSTATUS(Const.DRAW_STATUS_EFFECTIVE); + List drawInfos = drawInfoService.selectDrawInfoList(queryInfo); + if (drawInfos == null || drawInfos.size() == 0) { + drawResult.setRespCode("-3"); + drawResult.setRespMsg("活动未开启"); + return processResp(request, DrawActivityResult.EXCEPTION_000011, + DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000011)); + } + DrawInfo drawInfo = drawInfos.get(0); + Date starttime = drawInfo.getSTARTTIME(); + Date endtime = drawInfo.getENDTIME(); + Date currDate = new Date(); + if (currDate.before(starttime) || currDate.after(endtime)) { + return processResp(request, DrawActivityResult.EXCEPTION_000011, + DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000011)); + } + long point2 = System.currentTimeMillis(); + logger.info("抽奖检查点2:" + request.getSerialNo() + ":" + point2 + "与前一个检查点时间差" + (point2 - point1)); + String currentDateStr = DateUtils.dateTime(); + DrawInfo gtDrawInfo = null; + if ("1".equals(gtDrawInfo.getUPDATEFLAG()) || Cache.get("_" + drawCode + "_currentDateStr_") == null + || Cache.get("_" + drawCode + "_" + currentDateStr + "_rule_") == null + || Cache.get("_" + drawCode + "_" + currentDateStr + "_config_") == null + || Cache.get("_" + drawCode + "_blank_") == null || Cache.get("_" + drawCode + "_blankConfig_") == null + || Cache.get("_" + drawCode + "_" + currentDateStr + "_gtDrawConfigList_") == null + || Cache.get("_" + drawCode + "_" + currentDateStr + "_baseNumber_") == null) { + // 刷新缓存 + loadDrawRule(drawCode); + gtDrawInfo.setUPDATEFLAG("0"); + drawInfoService.updateDrawInfo(gtDrawInfo); + } + long point3 = System.currentTimeMillis(); + logger.info("抽奖检查点3:" + request.getSerialNo() + ":" + point3 + "与前一个检查点时间差" + (point3 - point2)); + DrawRule gtDrawRule = (DrawRule) Cache.get("_" + drawCode + "_" + currentDateStr + "_rule_"); + Future resFuture = ThreadPool.drawActivityExecutorService.submit(new DrawActivityThread(request, gtDrawInfo, gtDrawRule, drawResult)); + drawResult = resFuture.get(15 * 1000, TimeUnit.SECONDS); + end = System.currentTimeMillis(); + logger.info("抽奖接口返回:" + request.getSerialNo() + "&返回时间" + end + "总时间" + (end - point)); + return drawResult; + } catch (Exception e) { + drawResult = processResp(request, DrawActivityResult.EXCEPTION, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION)); + logger.error("抽奖接口异常,异常原因:", e); + return drawResult; + } + } + + private DrawResult processResp(DrawActivityRequest request, String resultCode, String resultInfo) { + DrawResult response = new DrawResult(); + response.setRespCode(resultCode); + response.setRespMsg(resultInfo); + return response; + } + /** * 刷新抽奖需要的缓存信息 * @@ -59,7 +145,7 @@ public class DrawService { // gtDrawConfigQueryRule.addAscOrder("prizeLevel"); DrawConfig drawConfigParams = new DrawConfig(); drawConfigParams.setDRAWCODE(drawCode); - drawConfigParams.setSTATUS(Const.STATUS_VALID); + drawConfigParams.setSTATUS(Const.DRAW_CONFIG_STATUS_EFFECTIVE); List drawConfigs = drawConfigService.selectDrawConfigList(drawConfigParams); cacheAdd("_" + drawCode + "_" + currentDateStr + "_config_", drawConfigs, "_" + drawCode + "_" + yesterdayDateStr + "_config_", timeOut); // 空奖奖项配置 diff --git a/sino-act-web/src/main/java/com/ruoyi/service/SequenceService.java b/sino-act-web/src/main/java/com/ruoyi/service/SequenceService.java new file mode 100644 index 000000000..8e0a29cf2 --- /dev/null +++ b/sino-act-web/src/main/java/com/ruoyi/service/SequenceService.java @@ -0,0 +1,58 @@ +package com.ruoyi.service; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/*** + * + * @ClassName: SequenceService + * @Description: к + * @author liuyaoyao + * @date 201828 4:24:32 + * + */ +public class SequenceService { + + private static Logger logger = LoggerFactory.getLogger(SequenceService.class); + + public synchronized String getPrizeSequence(){ + try{ + String sql = "select lpad(sequenec_prize.nextval,8,0) from dual"; + return null; + }catch(Exception e){ + logger.error("ͨݿлȡʻIDԭ", e); + return null; + } + } + + public String getDrawActivirtSeq(){ + try{ + String sql = "select lpad(gt_draw_activity_seq.nextval,7,0) from dual"; + return null; + }catch(Exception e){ + logger.error("ͨݿлȡʻIDԭ", e); + return null; + } + } + public String getDrawActivirtTradeOrderSeq(){ + try{ + String sql = "select lpad(gt_draw_activity_tradeorder.nextval,10,0) from dual"; + return null; + }catch(Exception e){ + logger.error("ͨݿлȡʻIDԭ", e); + return null; + } + } + + public String getGtReqFlagSeq(){ + try{ + String sql = "select lpad(gt_req_flag_seq.nextval,10,0) from dual"; + return null; + }catch(Exception e){ + logger.error("ͨݿлȡʻIDԭ", e); + return null; + } + } + +} diff --git a/sino-act-web/src/main/java/com/ruoyi/thread/AwardThread.java b/sino-act-web/src/main/java/com/ruoyi/thread/AwardThread.java new file mode 100644 index 000000000..64a13a9b3 --- /dev/null +++ b/sino-act-web/src/main/java/com/ruoyi/thread/AwardThread.java @@ -0,0 +1,379 @@ +package com.ruoyi.thread; + +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.dto.DrawActivityRequest; +import com.ruoyi.system.service.ISysDictDataService; +import com.ruoyi.web.vo.Const; +import com.sinosoft.activity.domain.DrawRecord; +import com.sinosoft.activity.service.IDrawAwardRecordService; +import com.sinosoft.activity.service.IDrawPrizeInfoService; +import com.sinosoft.activity.service.IDrawRecordService; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AwardThread implements Runnable { + protected static Logger logger = LoggerFactory.getLogger(AwardThread.class); + private String mobile; + private DrawActivityRequest request; + private IDrawPrizeInfoService gtPrizeInfoService; + private IDrawAwardRecordService gtAwardRecordService; + private ISysDictDataService inCodeService; + private DrawRecord gtDrawRecord; + private String awardMethod; + private IDrawRecordService gtDrawRecordService; +/** + * ߼ + */ + @Override + public void run() { + String prizeType = gtDrawRecord.getPRIZETYPE(); + try { + //ཱƷ + if (prizeType.equals(Const.PRIZE_TYPE_INTEGRAL)) { +// GetIntegralResponse getIntegralResponse = getIntegral(gtDrawRecord); +// if (getIntegralResponse == null) { +// throw new Exception("ַŽӿ쳣"); +// } +// GtAwardRecord gtAwardRecord = new GtAwardRecord(); +// gtAwardRecord.setUserName(gtDrawRecord.getUserName()); +// gtAwardRecord.setUserId(gtDrawRecord.getUserId()); +// gtAwardRecord.setCreateTimeStamp(new Date()); +// gtAwardRecord.setDrawCode(gtDrawRecord.getDrawCode()); +// gtAwardRecord.setDrawRecordId(gtDrawRecord.getDrawRecordId()); +// gtAwardRecord.setLastUpdateTimeStamp(new Date()); +// gtAwardRecord.setPrizeCode(gtDrawRecord.getPrizeCode()); +// gtAwardRecord.setPrizeType(gtDrawRecord.getPrizeType()); +// gtAwardRecord.setPrizeLevel(gtDrawRecord.getPrizeLevel()); +// gtAwardRecord.setReturnCode(getIntegralResponse.getResultCode()); +// gtAwardRecord.setReturnMessage(getIntegralResponse.getResultInfo()); +// gtAwardRecord.setMerchantCode(request.getBody().getMerchantCode()); +// gtAwardRecord.setMerchantSysCode(request.getBody().getMerchantSysCode()); +// gtAwardRecord.setChannel(request.getBody().getChannel()); +// gtAwardRecord.setBusinessArea(request.getBody().getBusinessArea()); +// gtAwardRecord.setDrawTranseqNo(gtDrawRecord.getDrawTranseqNo()); +// gtAwardRecord.setExtId(gtDrawRecord.getProjectCode()); +// if (getIntegralResponse.getResultCode().endsWith(WebServiceResult.SUCCESS)) { +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_SUCCESS); +// gtAwardRecord.setAwardTime(new Date()); +// }else{ +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_FAIL); +// logger.info("ƽַ̨ʧܣ"+gtDrawRecord.getDrawTranseqNo()+"&ʧԭ"+getIntegralResponse.getResultInfo()); +// } +// gtAwardRecordService.addGtAwardRecord(gtAwardRecord); + } else if (prizeType.equals(Const.PRIZE_TYPE_CASH)) { + //1654 һֽͨ +// getCash(); + } else if (prizeType.equals(Const.PRIZE_TYPE_VOCHER)) { +// QueryRule queryRule=QueryRule.getInstance(); +// queryRule.addEqual("prizeCode", gtDrawRecord.getPrizeCode()); +// GtPrizeInfo gtPrizeInfo=gtPrizeInfoService.queryUniqueGtPrizeInfo(queryRule); +// Map coupon_config=inCodeService.findAllCodeAndName("INTERFACE_COUPON"); +// if(coupon_config==null||gtPrizeInfo==null){ +// throw new Exception("ȯò쳣"); +// } +// StringBuffer param = new StringBuffer(); +// param.append("service_id=" + PropertiesUtil.getProperties("sysConfig.properties", "INTERFACE_COUPON_SERVICE_ID")); +// param.append("&accessToken="+coupon_config.get("ACCESS_TOKEN")); +// Map dataMap=new HashMap(); +// Map requestMap=new HashMap(); +// requestMap.put("oldUserId", gtDrawRecord.getUserId()); +// requestMap.put("bonusCode", gtPrizeInfo.getIntegralProjectCode()); +// requestMap.put("channelType", "3"); +// requestMap.put("platformLimit", "3"); +// dataMap.put("request", requestMap); +// JSONObject jsonObject=JSONObject.fromObject(dataMap); +// param.append("&data="+jsonObject.toString()); +// long iemallStart= System.currentTimeMillis(); +// logger.info("һͨȯ:"+gtDrawRecord.getDrawTranseqNo()+"&Ͳ:"+param.toString()+"&ʱ:"+iemallStart); +// String responseStr=HttpRequestUtil.sendHttpPostRequest(PropertiesUtil.getProperties("sysConfig.properties", "INTERFACE_COUPON_URL"), param.toString()); +// long iemallEnd= System.currentTimeMillis(); +// long iemallProct=iemallEnd-iemallStart; +// logger.info("һͨȯӦ:" +gtDrawRecord.getDrawTranseqNo()+"&Ӧ:"+responseStr+"&Ӧʱ:"+ System.currentTimeMillis()+"&ʱ:"+iemallProct); +// JSONObject responseJson=JSONObject.fromObject(responseStr); +// GtAwardRecord gtAwardRecord = new GtAwardRecord(); +// gtAwardRecord.setUserName(gtDrawRecord.getUserName()); +// gtAwardRecord.setUserId(gtDrawRecord.getUserId()); +// gtAwardRecord.setCreateTimeStamp(new Date()); +// gtAwardRecord.setDrawCode(gtDrawRecord.getDrawCode()); +// gtAwardRecord.setDrawRecordId(gtDrawRecord.getDrawRecordId()); +// gtAwardRecord.setLastUpdateTimeStamp(new Date()); +// gtAwardRecord.setPrizeCode(gtDrawRecord.getPrizeCode()); +// gtAwardRecord.setPrizeType(gtDrawRecord.getPrizeType()); +// gtAwardRecord.setPrizeLevel(gtDrawRecord.getPrizeLevel()); +// gtAwardRecord.setReturnCode(responseJson.getJSONObject("response").get("errorCode").toString()); +// gtAwardRecord.setReturnMessage(responseJson.getJSONObject("response").get("errorMsg").toString()); +// gtAwardRecord.setDrawTranseqNo(gtDrawRecord.getDrawTranseqNo()); +// gtAwardRecord.setExtId(gtDrawRecord.getProjectCode()); +// gtAwardRecord.setAwardTranseqNo(responseJson.getJSONObject("response").get("batchNo").toString()); +// if (responseJson.getJSONObject("response").get("errorCode").toString().endsWith(WebServiceResult.SUCCESS)) { +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_SUCCESS); +// gtAwardRecord.setAwardTime(new Date()); +// } else{ +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_FAIL); +// logger.info("һͨȯʧ"+gtDrawRecord.getDrawTranseqNo()+"&ʧԭ"+responseJson.getJSONObject("response").get("errorCode")+responseJson.getJSONObject("response").get("errorMsg")); +// } +// gtAwardRecord.setReturnCode(responseJson.getJSONObject("response").get("errorCode").toString()); +// gtAwardRecord.setReturnMessage(responseJson.getJSONObject("response").get("errorMsg").toString()); +// gtAwardRecord.setDrawTranseqNo(gtDrawRecord.getDrawTranseqNo()); +// gtAwardRecordService.addGtAwardRecord(gtAwardRecord); +// InPortalTransmessage message = new InPortalTransmessage(); +// message.setTransCode("EXT00001"); +// message.setTransRefGuid(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); +// message.setRequestTime(new Date()); +// message.setResponseTime(new Date()); +// message.setRequestMessage(jsonObject.toString()); +// message.setResponseMessage(responseStr); +// message.setProct(iemallProct); +// transRecordService.offer(message); + }else if(prizeType.equals(Const.PRIZE_TYPE_IEMALL)){ + if(StringUtils.isNotBlank(mobile)){ + //i +// QueryRule queryRule=QueryRule.getInstance(); +// queryRule.addEqual("prizeCode", gtDrawRecord.getPrizeCode()); +// GtPrizeInfo gtPrizeInfo=gtPrizeInfoService.queryUniqueGtPrizeInfo(queryRule); +// Map iemall_config=inCodeService.findAllCodeAndName("iemallConfig"); +// if(iemall_config==null||gtPrizeInfo==null){ +// throw new Exception("ȯò쳣"); +// } +// String key=iemall_config.get("key"); +// String timestamp=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()); +// long voucherId= Long.parseLong(gtPrizeInfo.getIntegralProjectCode()); +// Md5 md5 = new Md5(); +// String str="mobile="+mobile+"×tamp="+timestamp+"&voucherId="+voucherId+"&key="+key; +// String sign=md5.toMD5(str); +// int source=8; +// String request="mobile="+mobile+"&voucherId="+voucherId+"×tamp="+timestamp+"&source="+source+"&sign="+sign; +// URL url = new URL(PropertiesUtil.getProperties("sysConfig.properties", "INTERFACE_IEMALL_URL")+"?"+request); +// long start1= System.currentTimeMillis(); +// logger.info("Iȯȯ:"+gtDrawRecord.getDrawTranseqNo()+"&Ͳ:"+url.toString()+"&ʱ:"+start1); +// InetSocketAddress addr=new InetSocketAddress(iemall_config.get("proxy"), Integer.parseInt(iemall_config.get("port"))); +// HttpURLConnection conn=null; +// if(iemall_config.get("isProxy").equals("1")){ +// Proxy proxy=new Proxy(Proxy.Type.HTTP, addr); +// logger.info("ôiIP"+proxy.address()); +// conn = (HttpURLConnection) url.openConnection(proxy); +// }else{ +// conn = (HttpURLConnection) url.openConnection(); +// } +// conn.setRequestProperty("contentType", "utf-8"); +// conn.setConnectTimeout(5 * 1000); +// conn.setRequestMethod("POST"); +// InputStream inStream = conn.getInputStream(); +// BufferedReader in = new BufferedReader(new InputStreamReader(inStream, "utf-8")); +// StringBuffer buffer = new StringBuffer(); +// String line = ""; +// while ((line = in.readLine()) != null) { +// buffer.append(line); +// } +// String responseStr = buffer.toString(); +// logger.info("IȯȯӦ:" +gtDrawRecord.getDrawTranseqNo()+"&Ӧ:"+responseStr+"&Ӧʱ:"+ System.currentTimeMillis()+"&ʱ:"+(System.currentTimeMillis()-start1)); +// JSONObject responseJson=JSONObject.fromObject(responseStr); +// GtAwardRecord gtAwardRecord = new GtAwardRecord(); +// gtAwardRecord.setUserName(gtDrawRecord.getUserName()); +// gtAwardRecord.setUserId(gtDrawRecord.getUserId()); +// gtAwardRecord.setCreateTimeStamp(new Date()); +// gtAwardRecord.setDrawCode(gtDrawRecord.getDrawCode()); +// gtAwardRecord.setPhone(mobile); +// gtAwardRecord.setDrawRecordId(gtDrawRecord.getDrawRecordId()); +// gtAwardRecord.setLastUpdateTimeStamp(new Date()); +// gtAwardRecord.setPrizeCode(gtDrawRecord.getPrizeCode()); +// gtAwardRecord.setPrizeType(gtDrawRecord.getPrizeType()); +// gtAwardRecord.setPrizeLevel(gtDrawRecord.getPrizeLevel()); +// gtAwardRecord.setExtId(gtDrawRecord.getProjectCode()); +// boolean result=responseJson.getBoolean("success"); +// String awawrState="1"; +// if(result){ +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_SUCCESS); +// gtAwardRecord.setAwardTime(new Date()); +// gtAwardRecord.setReturnCode("0000"); +// awawrState="2"; +// }else{ +// logger.info("Iȯȯʧ:"+gtDrawRecord.getDrawTranseqNo()+"&ʧԭ:"+responseJson.getString("message").toString()); +// gtAwardRecord.setReturnCode(String.valueOf(result)); +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_FAIL); +// } +// gtAwardRecord.setReturnMessage(responseJson.get("message").toString()); +// gtAwardRecord.setDrawTranseqNo(gtDrawRecord.getDrawTranseqNo()); +// gtAwardRecordService.addGtAwardRecord(gtAwardRecord); +// +// if(awardMethod.equals(Const.AWARD_METHOD_MANAL)){ +// gtDrawRecord.setDrawResult(awawrState); +// gtDrawRecordService.updateGtDrawRecord(gtDrawRecord); +// } +// +// InPortalTransmessage message = new InPortalTransmessage(); +// message.setTransCode("EXT00002"); +// message.setTransRefGuid(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); +// message.setRequestTime(new Date()); +// message.setResponseTime(new Date()); +// message.setRequestMessage(request); +// message.setResponseMessage(responseStr); +// transRecordService.offer(message); + } + } + } catch (Exception e) { + e.printStackTrace(); + logger.error("첽쳣쳣ԭ:", e); + } + } + + + /** + * һֽͨŽӿ + * @author huayue + * @since 2020-08-11 + * @version 1654 + * @throws Exception + */ +// private void getCash() throws Exception { +// String url= PropertiesUtil.getProperties("sysConfig.properties", "ecUrl"); +// String isProxyStr=PropertiesUtil.getProperties("sysConfig.properties", "isProxy"); +// String serviceCode=PropertiesUtil.getProperties("sysConfig.properties", "cashServiceCode"); +// String partnerId=PropertiesUtil.getProperties("sysConfig.properties", "partnerId"); +// String key=PropertiesUtil.getProperties("sysConfig.properties", "key"); +// boolean isProxy = false; +// if("1".equals(isProxyStr)){ +// isProxy = true; +// } +// String currentTime = DateUtil.getCurrentDate("yyyyMMddHHmmss"); +// String userId = gtDrawRecord.getUserId(); +// //ȯid +// String bonusCode = gtDrawRecord.getProjectCode(); +// //Ϲapp˴1΢Ŷ˴2 +// String type = "2"; +// if ("APP".equals(gtDrawRecord.getChannel())) { +// type = "1"; +// } +// StringBuffer params = new StringBuffer(); +// params.append("serviceCode=").append(serviceCode).append("&"); +// params.append("type=").append(type).append("&"); +// params.append("ecNo=").append(userId).append("&"); +// params.append("bonusCode=").append(bonusCode).append("&"); +// params.append("currentTime=").append(currentTime).append("&"); +// params.append("partnerId=").append(partnerId).append("&"); +// //ǩַ= md5(type + ecNo + currentTime + partnerId + key) +// params.append("sign=").append(Md5Util.digestByMd5(type+userId+currentTime+partnerId+key)); +// logger.info("һֽͨŽӿΣ" + params); +// long start = System.currentTimeMillis(); +// String responseStr= HttpRequestUtil.sendPost(url, params.toString(), isProxy); +// long proct = System.currentTimeMillis()-start; +// logger.info("һֽͨŽӿӦ" + responseStr + "ʱ"+proct); +// JSONObject respJson = JSONObject.fromObject(responseStr); +// String errorCode = respJson.optString("errorCode"); +// String errorMsg = respJson.optString("errorMsg"); +// if ("0".equals(errorCode)) { +// errorCode = WebServiceResult.SUCCESS; +// } +// saveAwardRecord(errorCode, errorMsg); +// saveTransRecord("EXT00004", params.toString(), responseStr, proct); +// } + /** + * 洢ױ + * @author huayue + * @since 2020-08-11 + * @version 1654 + */ +// private void saveTransRecord(String transCode, String reqMsg, String respMsg, long proct) { +// InPortalTransmessage message = new InPortalTransmessage(); +// message.setTransCode(transCode); +// message.setTransRefGuid(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); +// message.setRequestTime(new Date()); +// message.setResponseTime(new Date()); +// message.setRequestMessage(reqMsg); +// message.setProct(proct); +// message.setResponseMessage(respMsg); +// transRecordService.offer(message); +// } + /** + * 洢н¼ + * @author huayue + * @since 2020-08-11 + * @version 1654 + */ +// private void saveAwardRecord(String returnCode, String returnInfo) { +// GtAwardRecord gtAwardRecord = new GtAwardRecord(); +// gtAwardRecord.setUserName(gtDrawRecord.getUserName()); +// gtAwardRecord.setUserId(gtDrawRecord.getUserId()); +// gtAwardRecord.setCreateTimeStamp(new Date()); +// gtAwardRecord.setDrawCode(gtDrawRecord.getDrawCode()); +// gtAwardRecord.setDrawRecordId(gtDrawRecord.getDrawRecordId()); +// gtAwardRecord.setLastUpdateTimeStamp(new Date()); +// gtAwardRecord.setPrizeCode(gtDrawRecord.getPrizeCode()); +// gtAwardRecord.setPrizeType(gtDrawRecord.getPrizeType()); +// gtAwardRecord.setPrizeLevel(gtDrawRecord.getPrizeLevel()); +// gtAwardRecord.setReturnCode(returnCode); +// gtAwardRecord.setReturnMessage(returnInfo); +// gtAwardRecord.setMerchantCode(request.getBody().getMerchantCode()); +// gtAwardRecord.setMerchantSysCode(request.getBody().getMerchantSysCode()); +// gtAwardRecord.setChannel(request.getBody().getChannel()); +// gtAwardRecord.setBusinessArea(request.getBody().getBusinessArea()); +// gtAwardRecord.setDrawTranseqNo(gtDrawRecord.getDrawTranseqNo()); +// gtAwardRecord.setExtId(gtDrawRecord.getProjectCode()); +// if (WebServiceResult.SUCCESS.equals(returnCode)) { +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_SUCCESS); +// gtAwardRecord.setAwardTime(new Date()); +// }else{ +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_FAIL); +// logger.error("ƽַ̨ʧܣ"+gtDrawRecord.getDrawTranseqNo()+"&ʧԭ"+returnInfo); +// } +// gtAwardRecordService.addGtAwardRecord(gtAwardRecord); +// } + + public AwardThread(DrawRecord gtDrawRecord, DrawActivityRequest request, String mobile, String awardMethod) { + this.mobile=mobile; + this.request = request; + this.gtDrawRecord=gtDrawRecord; + this.awardMethod=awardMethod; + this.gtPrizeInfoService = (IDrawPrizeInfoService) SpringUtils.getBean("drawPrizeInfoService"); + this.gtAwardRecordService = (IDrawAwardRecordService) SpringUtils.getBean("drawAwardRecordService"); + this.inCodeService=(ISysDictDataService) SpringUtils.getBean("inCodeService"); + this.gtDrawRecordService=(IDrawRecordService) SpringUtils.getBean("drawRecordService"); + } + +// public GetIntegralResponse getIntegral(GtDrawRecord gtDrawRecord) throws RemoteException { +// JsonBinder jsonBinder = JsonBinder.buildNormalBinder(); +// DrawActivityRequestBody drawActivityRequestBody = request.getBody(); +// GetIntegralServiceStub getIntegralServiceStub = new GetIntegralServiceStub( +// PropertiesUtil.getProperties("sysConfig.properties", "URL_INTERFACE_INTEGRAL_GETINTEGRALSERVICE")); +// GetIntegralServiceStub.GetIntegral getIntegral = new GetIntegralServiceStub.GetIntegral(); +// GetIntegralServiceStub.GetIntegralRequest getIntegralRequest = new GetIntegralServiceStub.GetIntegralRequest(); +// GetIntegralServiceStub.GetIntegralRequestBody getIntegralRequestBody = new GetIntegralServiceStub.GetIntegralRequestBody(); +// GetIntegralServiceStub.GetIntegralRequestHander getIntegralRequestHander = new GetIntegralServiceStub.GetIntegralRequestHander(); +// getIntegralRequestHander.setUserName(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_USER_HANDER")); +// getIntegralRequestHander.setTransCode(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_TRANSCODE_GETINTEGRALSERVICE")); +// getIntegralRequestHander.setSysName(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_SYS_NAME")); +// getIntegralRequestHander.setPassword(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_PASS_HANDER")); +// getIntegralRequestHander.setChannel(drawActivityRequestBody.getChannel()); +// getIntegralRequestHander.setSysCode(drawActivityRequestBody.getMerchantSysCode()); +// getIntegralRequestHander.setSerialNo(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); +// getIntegralRequest.setHander(getIntegralRequestHander); +// getIntegralRequestBody.setClassCode("A"); +// getIntegralRequestBody.setMerchantCode(drawActivityRequestBody.getMerchantCode()); +// getIntegralRequestBody.setUserId(drawActivityRequestBody.getUserId()); +// getIntegralRequestBody.setUserType(drawActivityRequestBody.getUserType()); +// getIntegralRequestBody.setBusiness(drawActivityRequestBody.getBusinessArea()); +// getIntegralRequestBody.setUserName(drawActivityRequestBody.getUserName()); +// // ѯƷϢ +// QueryRule prizeQueryRule = QueryRule.getInstance(); +// prizeQueryRule.addEqual("prizeCode", gtDrawRecord.getPrizeCode()); +// GtPrizeInfo gtPrizeInfo = gtPrizeInfoService.queryUniqueGtPrizeInfo(prizeQueryRule); +// getIntegralRequestBody.setIntegralProjectCode(gtPrizeInfo.getIntegralProjectCode()); +// getIntegralRequestBody.setFunction(gtPrizeInfo.getIntegralProjectCode()); +// getIntegralRequest.setBody(new GetIntegralServiceStub.GetIntegralRequestBody[] { getIntegralRequestBody }); +// getIntegral.setRequest(getIntegralRequest); +// GetIntegralServiceStub.GetIntegralResponseE responseE = getIntegralServiceStub.getIntegral(getIntegral); +// GetIntegralServiceStub.GetIntegralResponse response = responseE.get_return(); +// InPortalTransmessage message = new InPortalTransmessage(); +// message.setTransCode("IN0001"); +// message.setTransRefGuid(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); +// message.setRequestTime(new Date()); +// message.setResponseTime(new Date()); +// message.setRequestMessage(jsonBinder.toJson(getIntegralRequest)); +// message.setResponseMessage(jsonBinder.toJson(response)); +// transRecordService.offer(message); +// return response; +// } + + +} diff --git a/sino-act-web/src/main/java/com/ruoyi/thread/DrawActivityThread.java b/sino-act-web/src/main/java/com/ruoyi/thread/DrawActivityThread.java new file mode 100644 index 000000000..c4fae90da --- /dev/null +++ b/sino-act-web/src/main/java/com/ruoyi/thread/DrawActivityThread.java @@ -0,0 +1,1411 @@ +package com.ruoyi.thread; + +import com.ruoyi.cache.Cache; +import com.ruoyi.common.core.domain.entity.SysDictData; +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.dto.DrawActivityRequest; +import com.ruoyi.dto.DrawActivityResult; +import com.ruoyi.dto.GtPrizeConfigTemp; +import com.ruoyi.service.AwardService; +import com.ruoyi.service.SequenceService; +import com.ruoyi.system.service.ISysDictDataService; +import com.ruoyi.system.service.ISysDictTypeService; +import com.ruoyi.web.vo.Const; +import com.ruoyi.web.vo.draw.DrawResult; +import com.sinosoft.activity.domain.*; +import com.sinosoft.activity.service.*; +import org.apache.commons.lang3.StringUtils; +import org.dom4j.DocumentException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.math.BigDecimal; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.rmi.RemoteException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.concurrent.Callable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class DrawActivityThread implements Callable { + private static final Logger logger = LoggerFactory.getLogger(DrawActivityThread.class); + private DrawInfo gtDrawInfo; + private DrawRule gtDrawRule; + private IDrawRecordService drawRecordService; + private SequenceService sequenceService; + private DrawResult response; + private DrawActivityRequest request; + private IDrawConfigService drawConfigService; + private IDrawTaskNotifyService drawTaskNotifyService; + private IDrawTaskConsumeService drawTaskConsumeService; + private AwardService awardService; + private ISysDictDataService sysDictDataService; + private ISysDictTypeService sysDictTypeService; + private IDrawAwardRecordService drawAwardRecordService; +// integral +// private List gtIntegralPaymentList = new ArrayList(); +// private GtIntegralPaymentService gtIntegralPaymentService; + + private String bill = null; + + public DrawActivityThread(DrawActivityRequest request, DrawInfo gtDrawInfo, DrawRule gtDrawRule, DrawResult response) { + this.gtDrawInfo = gtDrawInfo; + this.gtDrawRule = gtDrawRule; + this.response = response; + this.request = request; +// this.gtIntegralPaymentService = (GtIntegralPaymentService) SpringUtils.getBean("gtIntegralPaymentService"); + this.drawRecordService = (IDrawRecordService) SpringUtils.getBean("drawRecordService"); + this.sequenceService = (SequenceService) SpringUtils.getBean("sequenceService"); + this.drawConfigService = (IDrawConfigService) SpringUtils.getBean("drawConfigService"); + this.drawTaskNotifyService = (IDrawTaskNotifyService) SpringUtils.getBean("drawTaskNotifyService"); + this.drawTaskConsumeService = (IDrawTaskConsumeService) SpringUtils.getBean("drawTaskConsumeService"); + this.awardService = (AwardService) SpringUtils.getBean("awardService"); + this.sysDictDataService = (ISysDictDataService) SpringUtils.getBean("sysDictDataService"); + this.sysDictTypeService = (ISysDictTypeService) SpringUtils.getBean("sysDictTypeService"); + this.drawAwardRecordService = (IDrawAwardRecordService) SpringUtils.getBean("drawAwardRecordService"); + } + + /** + * 齱߳ʵ + * + * @throws Exception + * @throws RemoteException + */ + @Override + public DrawResult call() throws RemoteException, Exception { + // жϳ齱Ƿ齱 + long point4 = System.currentTimeMillis(); + logger.info("齱4:" + request.getSerialNo() + ":" + point4); + int x = checkRule(request.getUserId()); + logger.info("齱жϷ:" + request.getSerialNo() + "ֵ" + x); + if (x == 10) { + // + return processResp(request, DrawActivityResult.EXCEPTION_000002, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000002, "涨ij齱")); + } + long point5 = System.currentTimeMillis(); + logger.info("齱5:" + request.getSerialNo() + ":" + point5 + "ǰһʱ" + (point5 - point4)); + // жϳ齱 + String expeno = gtDrawInfo.getEXPENO(); + if (Const.DRAW_EXPE_INTEGRAL.equals(expeno)) { + // ѯ˻Ϣ +// GetAccountServiceStub.GetAccountResponse getAccountResopnseService = getIntegralAccount(body); +// if (getAccountResopnseService == null) { +// return processResp(request, DrawActivityResult.EXCEPTION, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION, "ѯ˻쳣")); +// } +// GetAccountServiceStub.GetAccountResopnse get_return = getAccountResopnseService.get_return(); +// if (get_return == null) { +// return processResp(request, DrawActivityResult.EXCEPTION, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION, "ѯ˻쳣")); +// } +// logger.info("getIntegralAccount response: " + get_return.getResultCode()+"|"+get_return.getResultInfo()); +// if (!get_return.getResultCode().equals(DrawActivityResult.SUCCESS)) { +// return processResp(request, DrawActivityResult.EXCEPTION_000009, +// DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000009, get_return.getResultCode() + get_return.getResultInfo())); +// } +// GetAccountServiceStub.ResponseAccoutResult result = get_return.getAccout(); +// String integral = result.getIntegral(); +// Long expeNoValue = gtDrawInfo.getEXPENOVALUE(); +// if (new Long(integral).compareTo(expeNoValue) == -1) { +// return processResp(request, DrawActivityResult.EXCEPTION_000010, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000010)); +// } +// long point6 = System.currentTimeMillis(); +// logger.info("齱6:" + request.getSerialNo() + ":" + point6 + "ǰһʱ" + (point6 - point5)); +// String tranSeqNo = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + sequenceService.getDrawActivirtSeq(); +// DrawRecord gtDrawRecord = addGtDrawActityRecord(tranSeqNo, body); +// String recordId = gtDrawRecord.getDrawRecordId(); +// // ֳ齱ɻ +// InspectIntegralAccountWebServiceStub.InspectPaymentCodeResponse responseService = getIntegralPaymentToken(recordId, body); +// InspectIntegralAccountWebServiceStub.MaInspectIntegralAccountResponse maInspectIntegralAccountResponse = responseService.get_return(); +// if (responseService == null || maInspectIntegralAccountResponse == null) { +// gtIntegralPaymentService.saveGtIntegralPaymentList(gtIntegralPaymentList); +// return processResp(request, DrawActivityResult.EXCEPTION_000002, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000002, "֧ʧܣƴ")); +// } +// if (!maInspectIntegralAccountResponse.getResultCode().equals(DrawActivityResult.SUCCESS)) { +// gtIntegralPaymentService.saveGtIntegralPaymentList(gtIntegralPaymentList); +// return processResp(request, DrawActivityResult.EXCEPTION_000002, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000002, maInspectIntegralAccountResponse.getResultCode() + maInspectIntegralAccountResponse.getResultInfo())); +// } +// String token = maInspectIntegralAccountResponse.getTempToken(); +// logger.info("token___________________" + token); +// bill = token; +// long point7 = System.currentTimeMillis(); +// logger.info("齱7:" + request.getSerialNo() + ":" + point7 + "ǰһʱ" + (point7 - point6)); +// // ֶ +// DealWorkingWebServiceResponse dealWorkingWebServiceResponse = freezeIntegral(recordId, body, token); +// if (!(dealWorkingWebServiceResponse.getResultCode().equals(DrawActivityResult.SUCCESS) || dealWorkingWebServiceResponse == null)) { +// gtIntegralPaymentService.saveGtIntegralPaymentList(gtIntegralPaymentList); +// return processResp(request, DrawActivityResult.EXCEPTION_000002, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000002, dealWorkingWebServiceResponse.getResultCode() + dealWorkingWebServiceResponse.getResultInfo())); +// } +// long point8 = System.currentTimeMillis(); +// logger.info("齱8:" + request.getSerialNo() + ":" + point8 + "ǰһʱ" + (point8 - point7)); +// Object[] awardObject = computingProcess(x); +// // ֧ +// DealWorkingWebServiceResponse deductIntegralCheckResponse = deductIntegralCheck(recordId, body, dealWorkingWebServiceResponse); +// if (!(deductIntegralCheckResponse.getResultCode().equals(DrawActivityResult.SUCCESS) || deductIntegralCheckResponse == null)) { +// gtIntegralPaymentService.saveGtIntegralPaymentList(gtIntegralPaymentList); +// return processResp(request, DrawActivityResult.EXCEPTION_000002, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000002, dealWorkingWebServiceResponse.getResultCode() + dealWorkingWebServiceResponse.getResultInfo())); +// } +// long point9 = System.currentTimeMillis(); +// logger.info("齱9:" + request.getSerialNo() + ":" + point9 + "ǰһʱ" + (point9 - point8)); +// response = processDraw(tranSeqNo, gtDrawRecord, awardObject); +// long point10 = System.currentTimeMillis(); +// logger.info("齱10:" + request.getSerialNo() + ":" + point10 + "ǰһʱ" + (point10 - point9)); +// // ־ +// gtIntegralPaymentService.saveGtIntegralPaymentList(gtIntegralPaymentList); +// // +// long point11 = System.currentTimeMillis(); +// logger.info("齱11:" + request.getSerialNo() + ":" + point11 + "ǰһʱ" + (point11 - point10)); +// // ѯʣ +// GetAccountServiceStub.GetAccountResponse getAvailableAccountResopnseService = getIntegralAccount(body); +// GetAccountServiceStub.GetAccountResopnse getAvailable_return = getAvailableAccountResopnseService.get_return(); +// if (getAvailableAccountResopnseService == null || getAvailable_return == null) { +// return processResp(request, DrawActivityResult.EXCEPTION_000002, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000002, "ѯ˻쳣")); +// } +// if (!getAvailable_return.getResultCode().equals(DrawActivityResult.SUCCESS)) { +// return processResp(request, DrawActivityResult.EXCEPTION_000002, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000002, get_return.getResultCode() + get_return.getResultInfo())); +// } +// GetAccountServiceStub.ResponseAccoutResult availebleResult = getAvailable_return.getAccout(); +// String availebleintegral = availebleResult.getIntegral(); +// long point12 = System.currentTimeMillis(); +// logger.info("齱12:" + request.getSerialNo() + ":" + point12 + "ǰһʱ:" + (point12 - point11)); +// response.setAvailable(availebleintegral); + response = processResp(request, DrawActivityResult.EXCEPTION_000002, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000002, "ݲֳֻ֧齱")); + return response; + } else if (Const.DRAW_EXPE_TASK.equals(expeno)) { + // ۳ + String tranSeqNo = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + sequenceService.getDrawActivirtSeq(); + Object[] awardObject = computingProcess(x); + long point6 = System.currentTimeMillis(); + logger.info("齱6:" + request.getSerialNo() + "_" + tranSeqNo + "&ʱ:" + point6 + "&ǰһʱ:" + (point6 - point5)); + // ϸ + String gtTaskConsumeId = taskPlus(); + if (gtTaskConsumeId == null || "".equals(gtTaskConsumeId)) { + return processResp(request, DrawActivityResult.EXCEPTION_000007, DrawActivityResult.getMsg(DrawActivityResult.EXCEPTION_000007)); + } + long point7 = System.currentTimeMillis(); + logger.info("齱7:" + request.getSerialNo() + "_" + tranSeqNo + "&ʱ:" + point7 + "&ǰһʱ:" + (point7 - point6)); + DrawRecord gtDrawRecord = addGtDrawActityRecord(tranSeqNo, request); + String recordId = gtDrawRecord.getDRAWRECORDID(); + long point8 = System.currentTimeMillis(); + logger.info("齱8:" + request.getSerialNo() + "_" + tranSeqNo + "&ʱ:" + point8 + "&ǰһʱ:" + (point8 - point7)); + // жϷ + response = processDraw(tranSeqNo, gtDrawRecord, awardObject); + long point9 = System.currentTimeMillis(); + logger.info("齱9:" + request.getSerialNo() + "_" + tranSeqNo + "&ʱ:" + point9 + "&ǰһʱ:" + (point9 - point8)); + // 齱 + DrawTaskConsume taskConsume = new DrawTaskConsume(); + taskConsume.setTRANSEQNO(tranSeqNo); + taskConsume.setTRADEORDERID(recordId); + taskConsume.setTASKCONSUMEID(gtTaskConsumeId); + drawTaskConsumeService.updateDrawTaskConsumeState(taskConsume); + long point10 = System.currentTimeMillis(); + logger.info("齱10:" + request.getSerialNo() + "_" + tranSeqNo + "&ʱ:" + point10 + "&ǰһʱ:" + (point10 - point9)); + // ѯʣ齱 + int available = drawTaskNotifyService.selectDrawNumByUserId(request.getUserId(), gtDrawInfo.getDRAWCODE()); + long point11 = System.currentTimeMillis(); + logger.info("齱11:" + request.getSerialNo() + "_" + tranSeqNo + "&ʱ:" + point11 + "&ǰһʱ:" + (point11 - point10)); + response.setAvailable(available+""); + return response; + } + return response; + } + + /** + * ֵȯƷ + * @author huayue + * @since 2020-08-13 + * @version 1656 + * @param gtPrizeInfo + * @param gtDrawRecord + * @return + */ +// public String awardCoupon(DrawPrizeInfo gtPrizeInfo, GtDrawRecord gtDrawRecord) { +// String extId = null; +// try { +// String transCode = PropertiesUtil.getProperties("sysConfig.properties", "URL_INTERFACE_INTEGRAL_AWARD_COUPON_SERVICE"); +// String awardCouponUrl = PropertiesUtil.getProperties("sysConfig.properties", "URL_INTERFACE_INTEGRAL_AWARD_COUPON_SERVICE"); +// AwardCouponServiceStub stub = new AwardCouponServiceStub(awardCouponUrl); +// AwardCouponServiceStub.AwardCoupon awardCoupon = new AwardCouponServiceStub.AwardCoupon(); +// AwardCouponServiceStub.AwardCouponRequest req = new AwardCouponServiceStub.AwardCouponRequest(); +// AwardCouponServiceStub.AwardCouponRequestHander hander = getIntegralHander(AwardCouponServiceStub.AwardCouponRequestHander.class, "INTEGRAL_INTERFACE_TRANSCODE_AWARD_COUPON"); +// req.setHander(hander); +// AwardCouponServiceStub.AwardCouponRequestBody body = new AwardCouponServiceStub.AwardCouponRequestBody(); +// body.setAwardsId(gtPrizeInfo.getIntegralProjectCode()); +// body.setUserId(gtDrawRecord.getUserId()); +// body.setUserType("01"); +// body.setMobile(gtDrawRecord.getPHONE()); +// body.setCHANNEL(request.getChannel()); +// body.setCount("1"); +// body.setBill(bill); +// String hostAddress = InetAddress.getLocalHost().getHostAddress(); +// body.setIp(StringUtils.isBlank(hostAddress)?"127.0.0.1":hostAddress); +// req.setBody(body); +// awardCoupon.setRequest(req); +// long start = System.currentTimeMillis(); +// AwardCouponServiceStub.AwardCouponResponseE awardCouponResponseE = stub.awardCoupon(awardCoupon); +// long proct = System.currentTimeMillis()-start; +// AwardCouponServiceStub.AwardCouponResponse aReturn = awardCouponResponseE.get_return(); +// String resultCode = aReturn.getResultCode(); +// String resultInfo = aReturn.getResultInfo(); +// String startTime = aReturn.getStartTime(); +// String endTime = aReturn.getEndTime(); +// String prizeCode = aReturn.getPRIZECODE(); +// saveAwardRecord(resultCode, resultInfo, gtDrawRecord, prizeCode); +// JsonBinder jsonBinder = JsonBinder.buildNormalBinder(); +// saveTransRecord(transCode, jsonBinder.toJson(req), jsonBinder.toJson(aReturn), proct); +// if ("0000".equals(resultCode)) { +// JSONObject json = new JSONObject(); +// json.put("prizeCode", prizeCode); +// json.put("startTime", startTime); +// json.put("endTime", endTime); +// return json.toString(); +// } +// } catch (Exception e) { +// logger.error("Żֵȯ쳣", e); +// } +// return extId; +// } + + /** + * ȡhander + * @author huayue + * @since 2020-08-13 + * @version 1656 + * @param clazz HanderClass + * @param transCodeKey transCode in sysConfig.properties + * @param + * @return + */ +// private T getIntegralHander(Class clazz, String transCodeKey) { +// T obj = null; +// try { +// String userName = PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_USER_HANDER"); +// String transCode = PropertiesUtil.getProperties("sysConfig.properties", transCodeKey); +// String sysName = PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_SYS_NAME"); +// String pwd = PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_PASS_HANDER"); +// +// obj = clazz.newInstance(); +// +// MethodUtils.invokeMethod(obj, "setTransCode", transCode); +// MethodUtils.invokeMethod(obj, "setSerialNo", DateUtil.getCurrentDate("yyyyMMddHHmmssSSS")); +// MethodUtils.invokeMethod(obj, "setUserName", userName); +// MethodUtils.invokeMethod(obj, "setPassword", pwd); +// MethodUtils.invokeMethod(obj, "setSysName", sysName); +// +// } catch (Exception e) { +// logger.error("װͷ쳣", e); +// } +// return obj; +// } + /** + * 洢ױ + * @author huayue + * @since 2020-08-11 + * @version 1654 + */ +// private void saveTransRecord(String transCode, String reqMsg, String respMsg, long proct) { +// InPortalTransmessage message = new InPortalTransmessage(); +// message.setTransCode(transCode); +// message.setTransRefGuid(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); +// message.setRequestTime(new Date()); +// message.setResponseTime(new Date()); +// message.setRequestMessage(reqMsg); +// message.setProct(proct); +// message.setResponseMessage(respMsg); +// transRecordService.offer(message); +// } + /** + * 洢н¼ + * @author huayue + * @since 2020-08-11 + * @version 1654 + */ + private void saveAwardRecord(String returnCode, String returnInfo, DrawRecord gtDrawRecord, String extId) { + DrawAwardRecord gtAwardRecord = new DrawAwardRecord(); + gtAwardRecord.setUSERNAME(gtDrawRecord.getUSERNAME()); + gtAwardRecord.setUSERID(gtDrawRecord.getUSERID()); + gtAwardRecord.setCREATETIMESTAMP(new Date()); + gtAwardRecord.setDRAWCODE(gtDrawRecord.getDRAWCODE()); + gtAwardRecord.setDRAWRECORDID(gtDrawRecord.getDRAWRECORDID()); + gtAwardRecord.setLASTUPDATETIMESTAMP(new Date()); + gtAwardRecord.setPRIZECODE(gtDrawRecord.getPRIZECODE()); + gtAwardRecord.setPRIZETYPE(gtDrawRecord.getPRIZETYPE()); + gtAwardRecord.setPRIZELEVEL(gtDrawRecord.getPRIZELEVEL()); + gtAwardRecord.setRETURNCODE(returnCode); + gtAwardRecord.setRETURNMESSAGE(returnInfo); + gtAwardRecord.setMERCHANTCODE(request.getMerchantCode()); + gtAwardRecord.setMERCHANTSYSCODE(request.getMerchantSysCode()); + gtAwardRecord.setCHANNEL(request.getChannel()); + gtAwardRecord.setBUSINESSAREA(request.getBusinessArea()); + gtAwardRecord.setDRAWTRANSEQNO(gtDrawRecord.getDRAWTRANSEQNO()); + gtAwardRecord.setEXTID(extId); + if (DrawActivityResult.SUCCESS.equals(returnCode)) { + gtAwardRecord.setAWARDRESULT(Const.AWARD_RESULT_SUCCESS); + gtAwardRecord.setAWARDTIME(new Date()); + }else{ + gtAwardRecord.setAWARDRESULT(Const.AWARD_RESULT_FAIL); + logger.error("saveAwardRecordʧܣ"+gtDrawRecord.getDRAWTRANSEQNO()+"&ʧԭ"+returnInfo); + } + drawAwardRecordService.insertDrawAwardRecord(gtAwardRecord); + } + /** + * һͨ + * @param gtPrizeInfo + * @param gtDrawRecord + * @return + * @throws Exception + */ +// public String getAccount(DrawPrizeInfo gtPrizeInfo, GtDrawRecord gtDrawRecord) throws Exception { +// String extId = null; +// String serviceId=PropertiesUtil.getProperties("sysConfig.properties", "ACCOUNT_SERVICEID"); +// String version=PropertiesUtil.getProperties("sysConfig.properties", "ACCOUNT_VERSION"); +// String url=PropertiesUtil.getProperties("sysConfig.properties", "ACCOUNT_URL"); +// String dev=PropertiesUtil.getProperties("sysConfig.properties", "dev"); +// Map account_config = inCodeService.findAllCodeAndName("accountConfig"); +// String bonusSubType=account_config.get("p_sub_type"); +// String partnerId=account_config.get("PARTNID"); +// String key=account_config.get("p_key"); +// StringBuffer param=new StringBuffer("serviceId="+serviceId+"&partnerId="+partnerId); +// JSONObject jsonRequest = new JSONObject(); +// JSONObject jsonHeader = new JSONObject(); +// JSONObject jsonBody = new JSONObject(); +// jsonHeader.put("version",version); +// jsonHeader.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); +// jsonHeader.put("format", "JSON"); +// jsonBody.put("mobile",gtDrawRecord.getPHONE()); +// jsonBody.put("couponCode", gtPrizeInfo.getIntegralProjectCode()); +// jsonBody.put("bonusSubType", bonusSubType); +// jsonRequest.put("header", jsonHeader); +// jsonRequest.put("request", jsonBody); +// param.append("&data="+jsonRequest.toString()); +// param.append("&sign="+Md5Util.digestByMd5(partnerId+jsonRequest.toString()+key)); +// System.out.println(param); +// boolean dev_flag=false; +// if(dev.equals("1")){ +// dev_flag=true; +// } +// long start = System.currentTimeMillis(); +// logger.info("һͨ:" + request.getSerialNo() + "_" + gtDrawRecord.getDrawTranseqNo() + "&Ͳ:" + param.toString() + "&ʱ:" + start); +// String responseStr=HttpRequestUtil.sendPost(url,param.toString(), dev_flag); +// long end = System.currentTimeMillis(); +// long proct = end - start; +// logger.info("һͨӦ:" + request.getSerialNo() + "_" + gtDrawRecord.getDrawTranseqNo() + "&Ӧ:" + responseStr + "&Ӧʱ:" + System.currentTimeMillis() + "&ʱ:" + proct); +// JSONObject responseJson = JSONObject.fromObject(responseStr); +// GtAwardRecord gtAwardRecord = new GtAwardRecord(); +// gtAwardRecord.setUserName(request.getUserName()); +// gtAwardRecord.setUserId(request.getUserId()); +// gtAwardRecord.setCreateTimeStamp(new Date()); +// gtAwardRecord.setDrawCode(gtDrawInfo.getDRAWCODE()); +// gtAwardRecord.setDrawRecordId(gtDrawRecord.getDrawRecordId()); +// gtAwardRecord.setLastUpdateTimeStamp(new Date()); +// gtAwardRecord.setPrizeCode(gtPrizeInfo.getPRIZECODE()); +// gtAwardRecord.setPRIZETYPE(gtPrizeInfo.getPRIZETYPE()); +// gtAwardRecord.setPRIZELEVEL(gtDrawRecord.getPRIZELEVEL()); +// gtAwardRecord.setReturnCode(responseJson.getJSONObject("header").get("code").toString()); +// gtAwardRecord.setReturnMessage(responseJson.getJSONObject("header").get("msg").toString()); +// gtAwardRecord.setDrawTranseqNo(gtDrawRecord.getDrawTranseqNo()); +// +// if (responseJson.getJSONObject("header").get("code").toString().endsWith("0")&&responseJson.getJSONObject("response").getJSONObject("query").getString("drawStatus").equals("1")) { +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_SUCCESS); +// gtAwardRecord.setAwardTime(new Date()); +// gtDrawRecord.setDrawResult(Const.DRAW_RECORD_RESULT_AWARDS); +// extId = responseJson.getJSONObject("response").getJSONObject("query").getString("bonusAmount"); +// gtAwardRecord.setAwardTranseqNo(extId); +// drawRecordService.updateGtDrawRecord(gtDrawRecord); +// drawAwardRecordService.addGtAwardRecord(gtAwardRecord); +// } else { +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_FAIL); +// } +// InPortalTransmessage message = new InPortalTransmessage(); +// message.setTransCode("EXT00003"); +// message.setTransRefGuid(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); +// message.setRequestTime(new Date()); +// message.setResponseTime(new Date()); +// message.setRequestMessage(param.toString()); +// message.setProct(proct); +// message.setResponseMessage(responseStr); +// transRecordService.offer(message); +// return extId; +// } + + + /** + * ÿȯȯӿ + * + * @return + * @throws Exception + */ +// public String getDiscountCode(DrawPrizeInfo gtPrizeInfo, GtDrawRecord gtDrawRecord) throws Exception { +// String extId = null; +// Map coupon_config = inCodeService.findAllCodeAndName("INTERFACE_COUPON"); +// if (coupon_config == null || gtPrizeInfo == null) { +// throw new Exception("ȯò쳣"); +// } +// StringBuffer param = new StringBuffer(); +// param.append("service_id=" + PropertiesUtil.getProperties("sysConfig.properties", "INTERFACE_COUPON_SERVICE_ID")); +// param.append("&accessToken=" + coupon_config.get("ACCESS_TOKEN")); +// Map dataMap = new HashMap(); +// Map requestMap = new HashMap(); +// requestMap.put("oldUserId", request.getUserId()); +// requestMap.put("bonusCode", gtPrizeInfo.getIntegralProjectCode()); +//// requestMap.put("discountCode", gtPrizeInfo.getIntegralProjectCode()); +// requestMap.put("channelType", "3"); +// requestMap.put("platformLimit", "3"); +// dataMap.put("request", requestMap); +// JSONObject jsonObject = JSONObject.fromObject(dataMap); +// param.append("&data=" + jsonObject.toString()); +// long start = System.currentTimeMillis(); +// logger.info("ȯķȯ:" + request.getSerialNo() + "_" + gtDrawRecord.getDrawTranseqNo() + "&Ͳ:" + param.toString() + "&ʱ:" + start); +// String interfaceCouponUrl = PropertiesUtil.getProperties("sysConfig.properties", "INTERFACE_COUPON_URL"); +// String ecMock = PropertiesUtil.getProperties("sysConfig.properties", "ecMock"); +// String responseStr = null; +// if ("1".equals(ecMock)) { +// responseStr = "{\"response\":{\"errorCode\":\"0000\",\"errorMsg\":\"Żȯȡɹ\",\"status\":\"0\",\"discountCode\":\"31098\",\"bonusUserId\":\"31098\"}}"; +// } else { +// responseStr = HttpRequestUtil.sendHttpPostRequest(interfaceCouponUrl, param.toString()); +// } +// +// long end = System.currentTimeMillis(); +// long proct = end - start; +// logger.info("ȯķȯӦ:" + request.getSerialNo() + "_" + gtDrawRecord.getDrawTranseqNo() + "&Ӧ:" + responseStr + "&Ӧʱ:" + System.currentTimeMillis() + "&ʱ:" + proct); +// if (StringUtils.isBlank(responseStr)) { +// logger.error("ȯķΪ"); +// return extId; +// } +// JSONObject responseJson = JSONObject.fromObject(responseStr); +// GtAwardRecord gtAwardRecord = new GtAwardRecord(); +// gtAwardRecord.setUserName(request.getUserName()); +// gtAwardRecord.setUserId(request.getUserId()); +// gtAwardRecord.setCreateTimeStamp(new Date()); +// gtAwardRecord.setDrawCode(gtDrawInfo.getDRAWCODE()); +// gtAwardRecord.setDrawRecordId(gtDrawRecord.getDrawRecordId()); +// gtAwardRecord.setLastUpdateTimeStamp(new Date()); +// gtAwardRecord.setPrizeCode(gtPrizeInfo.getPRIZECODE()); +// gtAwardRecord.setPRIZETYPE(gtPrizeInfo.getPRIZETYPE()); +// gtAwardRecord.setPRIZELEVEL(gtDrawRecord.getPRIZELEVEL()); +// gtAwardRecord.setReturnCode(responseJson.getJSONObject("response").get("errorCode").toString()); +// gtAwardRecord.setReturnMessage(responseJson.getJSONObject("response").get("errorMsg").toString()); +// gtAwardRecord.setDrawTranseqNo(gtDrawRecord.getDrawTranseqNo()); +// if (responseJson.getJSONObject("response").get("errorCode").toString().endsWith(DrawActivityResult.SUCCESS)) { +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_SUCCESS); +// gtAwardRecord.setAwardTime(new Date()); +// gtDrawRecord.setDrawResult(Const.DRAW_RECORD_RESULT_AWARDS); +// extId = responseJson.getJSONObject("response").get("discountCode").toString(); +// gtAwardRecord.setAwardTranseqNo(extId); +// drawRecordService.updateGtDrawRecord(gtDrawRecord); +// drawAwardRecordService.addGtAwardRecord(gtAwardRecord); +// } else { +// gtAwardRecord.setAwardResult(Const.AWARD_RESULT_FAIL); +// } +// InPortalTransmessage message = new InPortalTransmessage(); +// message.setTransCode("EXT00001"); +// message.setTransRefGuid(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); +// message.setRequestTime(new Date()); +// message.setResponseTime(new Date()); +// message.setRequestMessage(jsonObject.toString()); +// message.setProct(proct); +// message.setResponseMessage(responseStr); +// transRecordService.offer(message); +// return extId; +// } + + // ֻж + private static boolean limitMobile(String mobile, String regex) { + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(mobile); + return m.matches(); + } + /** + * 齱ж + * + * @param tranSeqNo + * @param gtDrawRecord + * @param awardObject + * @return + * @throws Exception + */ + private DrawResult processDraw(String tranSeqNo, DrawRecord gtDrawRecord, Object[] awardObject) throws Exception { + DrawResult responseBody = new DrawResult(); + DrawConfig blankConfig = (DrawConfig) Cache.get("_" + gtDrawInfo.getDRAWCODE() + "_blankConfig_"); + DrawPrizeInfo awardBlankPrize = (DrawPrizeInfo) Cache.get("_" + gtDrawInfo.getDRAWCODE() + "_blank_"); + DrawConfig awardConfig = (DrawConfig) awardObject[0]; + DrawPrizeInfo awardPrize = (DrawPrizeInfo) awardObject[1]; + if (awardConfig != null) { + String phone = gtDrawRecord.getPHONE(); + String drawCode = gtDrawRecord.getDRAWCODE(); + String regex = sysDictDataService.selectDictLabel( "DrawLimit", "mobile_"+drawCode); +// String regex = "^(170|171)\\d{8}$"; + if (StringUtils.isNotBlank(phone) && StringUtils.isNotBlank(regex) && limitMobile(phone, regex)) { + responseBody = parseResponseBody(tranSeqNo, awardBlankPrize, blankConfig, null, gtDrawRecord); + } else if (awardConfig.getAWARDTYPE().equals(Const.AWARD_TYPE_NONE)) { + // ûƣֱжϿ + responseBody = querySotre(tranSeqNo, awardConfig, awardPrize, gtDrawRecord); + logger.info("齱ж:" + request.getSerialNo() + "_" + tranSeqNo + "&,жϿ" + responseBody.getPrizeType()); + } else if (awardConfig.getAWARDTYPE().equals(Const.AWARD_TYPE_DISTINCTION)) { + // ȡƴʱ + Long awardTypeValue = awardConfig.getAWARDTYPEVALUE(); + // ѯλµн + DrawRecord drawRecord = new DrawRecord(); + drawRecord.setUSERID(request.getUserId()); + drawRecord.setDRAWCODE(gtDrawInfo.getDRAWCODE()); + drawRecord.setPRIZECODE(awardConfig.getPRIZECODE()); + Long size = drawRecordService.selectDrawRecordCount(drawRecord); + if (size.compareTo(awardTypeValue) >= 0) { + // ޣս + responseBody = parseResponseBody(tranSeqNo, awardBlankPrize, blankConfig, null, gtDrawRecord); + logger.info("齱ж:" + request.getSerialNo() + "_" + tranSeqNo + "&һҵ,жϿ" + responseBody.getPrizeType()); + } else { + responseBody = querySotre(tranSeqNo, awardConfig, awardPrize, gtDrawRecord); + logger.info("齱ж:" + request.getSerialNo() + "_" + tranSeqNo + "&һδ,жϿ" + responseBody.getPrizeType()); + } + } else if (awardConfig.getAWARDTYPE().equals(Const.AWARD_TYPE_NODISTINCTION)) { + // ȡƴʱ + Long awardTypeValue = awardConfig.getAWARDTYPEVALUE(); + // ѯлµн + DrawRecord drawRecord = new DrawRecord(); + drawRecord.setUSERID(request.getUserId()); + drawRecord.setPRIZECODE(awardConfig.getPRIZECODE()); + Long size = drawRecordService.selectDrawRecordCount(drawRecord); + if (size.compareTo(awardTypeValue) >= 0) { + // ޣս + responseBody = parseResponseBody(tranSeqNo, awardBlankPrize, blankConfig, null, gtDrawRecord); + logger.info("齱ж:" + request.getSerialNo() + "_" + tranSeqNo + "&ǵһҵ,жϿ" + responseBody.getPrizeType()); + } else { + responseBody = querySotre(tranSeqNo, awardConfig, awardPrize, gtDrawRecord); + logger.info("齱ж:" + request.getSerialNo() + "_" + tranSeqNo + "&ǵһδ,жϿ" + responseBody.getPrizeType()); + } + } + } else { + responseBody = parseResponseBody(tranSeqNo, awardBlankPrize, blankConfig, null, gtDrawRecord); + } + if (!Const.PRIZE_TYPE_BLANK.equals(responseBody.getPrizeType())) { + if (awardConfig != null && Const.AWARD_METHOD_AUTO.equals(awardConfig.getAWARDMETHOD())) { + updateGtDrawRecordResult(gtDrawRecord.getDRAWRECORDID(), Const.DRAW_RECORD_RESULT_AWARDS, responseBody.getPrizeCode(), responseBody.getPrizeType(), responseBody.getPrizeLevel(), responseBody.getExtId()); + } else { + updateGtDrawRecordResult(gtDrawRecord.getDRAWRECORDID(), responseBody.getResult(), responseBody.getPrizeCode(), responseBody.getPrizeType(), responseBody.getPrizeLevel(), responseBody.getExtId()); + } + } else { + updateGtDrawRecordResult(gtDrawRecord.getDRAWRECORDID(), responseBody.getResult(), responseBody.getPrizeCode(), responseBody.getPrizeType(), responseBody.getPrizeLevel(), responseBody.getExtId()); + } + response = processResp(request, DrawActivityResult.SUCCESS, DrawActivityResult.getMsg(DrawActivityResult.SUCCESS)); + return response; + } + + /** + * жϽƷ + * + * @param tranSeqNo + * @param awardConfig + * @param awardPrize + * @return + * @throws Exception + */ + private DrawResult querySotre(String tranSeqNo, DrawConfig awardConfig, DrawPrizeInfo awardPrize, DrawRecord gtDrawRecord) throws Exception { + long start = System.currentTimeMillis(); + logger.info("ѯƷ濪ʼ" + tranSeqNo + ":" + start); + DrawResult responseBody = new DrawResult(); + DrawConfig blankConfig = (DrawConfig) Cache.get("_" + gtDrawInfo.getDRAWCODE() + "_blankConfig_"); + DrawPrizeInfo awardBlankPrize = (DrawPrizeInfo) Cache.get("_" + gtDrawInfo.getDRAWCODE() + "_blank_"); + int f = prizeProcess(awardConfig); + long check1 = System.currentTimeMillis(); + logger.info("ɸ¿棺" + tranSeqNo + ":" + check1 + "ʱ" + (check1 - start)); + if (f == 0) { + // ƷûˣΪս + responseBody = parseResponseBody(tranSeqNo, awardBlankPrize, blankConfig, null, gtDrawRecord); + } else { + Map awardNotifyType = sysDictTypeService.selectDictMapByType("AWARDNOTIFYTYPE"); + String syncAward = awardNotifyType.get("SYNC_AWARD_LIST").getDictLabel(); + String awardNeedParam = awardNotifyType.get("GW_AWARD_LIST_FOR_PARAM").getDictLabel(); + List syncAwardList = null; + List awardNeedParamList = null; + if (syncAward != null) { + syncAwardList = Arrays.asList(syncAward.split(",")); + } + if (awardNeedParam != null) { + awardNeedParamList = Arrays.asList(awardNeedParam.split(",")); + } + // жDzͬ + if (syncAwardList.contains(awardPrize.getPRIZETYPE())) { + // ͬ + gtDrawRecord.setPRIZELEVEL(awardConfig.getPRIZELEVEL()); + String extId=null; + if(Const.PRIZE_TYPE_WELFARE.equals(awardPrize.getPRIZETYPE())){ +// extId=getAccount(awardPrize, gtDrawRecord); + } else if (Const.PRIZE_TYPE_VCOUPON.equals(awardPrize.getPRIZETYPE())) { +// extId = awardCoupon(awardPrize, gtDrawRecord); + }else{ +// extId = getDiscountCode(awardPrize, gtDrawRecord); + } + logger.info("ͬȡȯ룺" + tranSeqNo + ":" + check1 + "ʱ" + (System.currentTimeMillis() - start)); + if (StringUtils.isBlank(extId)) { + // ˽Ʒ + int n = rollBackPrizeProcess(awardConfig); + logger.info("Ʒ˷" + n); + responseBody = parseResponseBody(tranSeqNo, awardBlankPrize, blankConfig, null, gtDrawRecord); + } else { + responseBody = parseResponseBody(tranSeqNo, awardPrize, awardConfig, extId, gtDrawRecord); + } + } else if (awardNeedParamList.contains(awardPrize.getPRIZETYPE())) { + // ǰ˷Ҫ + responseBody = parseResponseBody(tranSeqNo, awardPrize, awardConfig, awardPrize.getINTEGRALPROJECTCODE(), gtDrawRecord); + } else { + gtDrawRecord.setPRIZECODE(awardPrize.getPRIZECODE()); + gtDrawRecord.setPRIZETYPE(awardPrize.getPRIZETYPE()); + gtDrawRecord.setPRIZELEVEL(awardConfig.getPRIZELEVEL()); + gtDrawRecord.setPROJECTCODE(awardPrize.getINTEGRALPROJECTCODE()); + awardService.award(gtDrawRecord, request, gtDrawInfo, request.getPhone(), awardConfig.getAWARDMETHOD()); + responseBody = parseResponseBody(tranSeqNo, awardPrize, awardConfig, awardPrize.getINTEGRALPROJECTCODE(), gtDrawRecord); + } + + } + return responseBody; + } + + /** + * 齱 + * + * @return + */ + public String taskPlus() { + DrawTaskNotify taskNotify = new DrawTaskNotify(); + taskNotify.setUSERID(request.getUserId()); + taskNotify.setDRAWCODE(gtDrawInfo.getDRAWCODE()); + return drawTaskNotifyService.updateDrawTaskNotifyNum(taskNotify); + } + + /** + * ˻ѯ + * + * @param body + * @return + * @throws RemoteException + */ +// private GetAccountServiceStub.GetAccountResponse getIntegralAccount(DrawActivityRequestBody body) throws AxisFault, RemoteException { +// String getIntegralAccountUrl = PropertiesUtil.getProperties("sysConfig.properties", "URL_INTERFACE_INTEGRAL_GETACCOUNTSERVICE"); +// logger.info("getIntegralAccountUrl: " + getIntegralAccountUrl); +// GetAccountServiceStub stub = new GetAccountServiceStub(getIntegralAccountUrl); +// GetAccountServiceStub.GetAccount getAccountService = new GetAccountServiceStub.GetAccount(); +// GetAccountServiceStub.GetAccountRequest getAccountRequest = new GetAccountServiceStub.GetAccountRequest(); +// GetAccountServiceStub.GetAccountRequestHander hander = new GetAccountServiceStub.GetAccountRequestHander(); +// GetAccountServiceStub.GetAccountRequestBody getAccountRequestBody = new GetAccountServiceStub.GetAccountRequestBody(); +// hander.setTransCode(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_TRANSCODE_GETACCOUNTSERVICE")); +// hander.setSysName(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_SYS_NAME")); +// hander.setUserName(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_USER_HANDER")); +// hander.setPassword(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_PASS_HANDER")); +// hander.setSerialNo(new SimpleDateFormat(cn.com.chinalife.activity.sys.util.common.DateUtil.FORMAT8).format(new Date())); +// getAccountRequestBody.setUserId(body.getUserId()); +// getAccountRequestBody.setUserType(body.getUserType()); +// getAccountRequest.setHander(hander); +// getAccountRequest.setBody(getAccountRequestBody); +// getAccountService.setRequest(getAccountRequest); +// GetAccountServiceStub.GetAccountResponse getAccountResopnseService = stub.getAccount(getAccountService); +// return getAccountResopnseService; +// } + + /** + * ֧ӿڵ + * + * @param id + * @param body + * @param dealWorkingWebServiceResponse + * @return + * @throws AxisFault + * @throws Exception + * @throws RemoteException + */ +// private DealWorkingWebServiceResponse deductIntegralCheck(String id, DrawActivityRequestBody body, DealWorkingWebServiceResponse dealWorkingWebServiceResponse) throws AxisFault, Exception, RemoteException { +// DealWorkingWebServiceStub dealWorkingWebServiceStub = new DealWorkingWebServiceStub(false, PropertiesUtil.getProperties("sysConfig.properties", "URL_INTERFACE_INTEGRAL_DEALWORKINGWEBSERVICE")); +// DealWorkingWebServiceStub.DeductIntegralCheck deductIntegralCheck = new DealWorkingWebServiceStub.DeductIntegralCheck(); +// String deductXml = parseIntegralPaymentXml(dealWorkingWebServiceResponse.getTrade_order(), dealWorkingWebServiceResponse.getTrade_transNo(), dealWorkingWebServiceResponse.getSerialNum(), gtDrawInfo.getExpeNoValue().toString(), body.getMerchantCode(), body.getUserId(), body.getUserType(), "0", body.getChannel(), body.getMerchantSysCode(), "Y"); +// logger.info("֧ģ" + deductXml); +// String xml = CryptUtil.encrypt(deductXml, PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_PUBLIC_KEY"), "utf-8"); +// deductIntegralCheck.setXmlStr(xml); +// DealWorkingWebServiceStub.DeductIntegralCheckResponse deductIntegralCheckResponse = dealWorkingWebServiceStub.deductIntegralCheck(deductIntegralCheck); +// String deductIntegralCheckResponseXml = deductIntegralCheckResponse.get_return(); +// DealWorkingWebServiceResponse dealWorkingWebServiceResponse2 = null; +// logger.info("֧رģ" + deductIntegralCheckResponseXml); +// if (!(deductIntegralCheckResponseXml == null || "".equals(deductIntegralCheckResponseXml))) { +// dealWorkingWebServiceResponse2 = parseIntegralDealResponse(deductIntegralCheckResponseXml); +// } +// GtIntegralPayment gtIntegralPayment = new GtIntegralPayment(); +// gtIntegralPayment.setCHANNEL(body.getChannel()); +// gtIntegralPayment.setCreateTime(new Date()); +// gtIntegralPayment.setDrawRecordId(id); +// gtIntegralPayment.setGatewayFlow(dealWorkingWebServiceResponse2.getSerialNum()); +// if (!(dealWorkingWebServiceResponse2.getSettleDate() == null || "".equals(dealWorkingWebServiceResponse2.getSettleDate()))) { +// Date settleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dealWorkingWebServiceResponse2.getSettleDate()); +// gtIntegralPayment.setGatewayTime(settleDate); +// } +// gtIntegralPayment.setIntegral(gtDrawInfo.getExpeNoValue()); +// gtIntegralPayment.setLastUpdaeTime(new Date()); +// gtIntegralPayment.setMerchantCode(body.getMerchantCode()); +// gtIntegralPayment.setMerchantSysCode(body.getMerchantSysCode()); +// gtIntegralPayment.setOperationType("Y"); +// gtIntegralPayment.setReturnCode(dealWorkingWebServiceResponse2.getResultCode()); +// gtIntegralPayment.setReturnMessage(dealWorkingWebServiceResponse2.getResultInfo()); +// gtIntegralPayment.setTradeOrder(dealWorkingWebServiceResponse.getTrade_order()); +// gtIntegralPayment.setTradeSeqNo(dealWorkingWebServiceResponse.getTrade_transNo()); +// gtIntegralPayment.setType("payment"); +// gtIntegralPayment.setUserId(body.getUserId()); +// gtIntegralPayment.setUserType(body.getUserType()); +// gtIntegralPaymentList.add(gtIntegralPayment); +// return dealWorkingWebServiceResponse2; +// } + + /** + * ֤֧ ӿڵ + * + * @param id + * @param body + * @return + * @throws AxisFault + * @throws RemoteException + */ +// private InspectIntegralAccountWebServiceStub.InspectPaymentCodeResponse getIntegralPaymentToken(String id, DrawActivityRequestBody body) throws AxisFault, RemoteException { +// InspectIntegralAccountWebServiceStub inspectIntegralAccountWebServiceStub = new InspectIntegralAccountWebServiceStub(PropertiesUtil.getProperties("sysConfig.properties", "URL_INTERFACE_INTEGRAL_INSPECTINTEGRALACCOUNTWEBSERVICE")); +// InspectIntegralAccountWebServiceStub.InspectPaymentCode inspectPaymentCode = new InspectIntegralAccountWebServiceStub.InspectPaymentCode(); +// InspectIntegralAccountWebServiceStub.MaInspectIntegralAccountRequest maInspectIntegralAccountRequest = new InspectIntegralAccountWebServiceStub.MaInspectIntegralAccountRequest(); +// InspectIntegralAccountWebServiceStub.MaInspectIntegralAccountHander maInspectIntegralAccountHander = new InspectIntegralAccountWebServiceStub.MaInspectIntegralAccountHander(); +// InspectIntegralAccountWebServiceStub.MaInspectIntegralAccountBody maInspectIntegralAccountBody = new InspectIntegralAccountWebServiceStub.MaInspectIntegralAccountBody(); +// maInspectIntegralAccountHander.setTransCode(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_TRANSCODE_INSPECTINTEGRALACCOUNTWEBSERVICE")); +// maInspectIntegralAccountHander.setSysName(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_SYS_NAME")); +// maInspectIntegralAccountHander.setUserName(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_USER_HANDER")); +// maInspectIntegralAccountHander.setPassword(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_PASS_HANDER")); +// maInspectIntegralAccountHander.setSerialNo(new SimpleDateFormat(cn.com.chinalife.activity.sys.util.common.DateUtil.FORMAT8).format(new Date())); +// maInspectIntegralAccountHander.setSysCode(body.getMerchantSysCode()); +// maInspectIntegralAccountHander.setCHANNEL(body.getChannel()); +// maInspectIntegralAccountBody.setUserId(body.getUserId()); +// maInspectIntegralAccountBody.setUserType(body.getUserType()); +// maInspectIntegralAccountBody.setPlatform("SINGLESITE"); +// maInspectIntegralAccountBody.setIntegraPayCode("4F607EF6073E513FCF02DFE2E2DFE05A"); +// maInspectIntegralAccountBody.setMerchantCode(body.getMerchantCode()); +// maInspectIntegralAccountRequest.setInspectIntegralAccountHander(maInspectIntegralAccountHander); +// maInspectIntegralAccountRequest.setInspectIntegralAccountBody(maInspectIntegralAccountBody); +// inspectPaymentCode.setRequest(maInspectIntegralAccountRequest); +// InspectIntegralAccountWebServiceStub.InspectPaymentCodeResponse responseService = inspectIntegralAccountWebServiceStub.inspectPaymentCode(inspectPaymentCode); +// GtIntegralPayment gtIntegralPayment = new GtIntegralPayment(); +// gtIntegralPayment.setCHANNEL(body.getChannel()); +// gtIntegralPayment.setCreateTime(new Date()); +// gtIntegralPayment.setDrawRecordId(id); +// gtIntegralPayment.setGatewayFlow(responseService.get_return().getTempToken()); +// gtIntegralPayment.setLastUpdaeTime(new Date()); +// gtIntegralPayment.setMerchantCode(body.getMerchantCode()); +// gtIntegralPayment.setMerchantSysCode(body.getMerchantSysCode()); +// gtIntegralPayment.setReturnCode(responseService.get_return().getResultCode()); +// gtIntegralPayment.setReturnMessage(responseService.get_return().getResultInfo()); +// gtIntegralPayment.setType("getToken"); +// gtIntegralPayment.setUserId(body.getUserId()); +// gtIntegralPayment.setUserType(body.getUserType()); +// gtIntegralPaymentList.add(gtIntegralPayment); +// return responseService; +// } + + /** + * ֶӿڵ + * + * @param id + * @param body + * @param token + * @return + * @throws AxisFault + * @throws Exception + * @throws RemoteException + * @throws DocumentException + */ +// private DealWorkingWebServiceResponse freezeIntegral(String id, DrawActivityRequestBody body, String token) throws AxisFault, Exception, RemoteException, DocumentException { +// DealWorkingWebServiceStub dealWorkingWebServiceStub = new DealWorkingWebServiceStub(false, PropertiesUtil.getProperties("sysConfig.properties", "URL_INTERFACE_INTEGRAL_DEALWORKINGWEBSERVICE")); +// DealWorkingWebServiceStub.FreezIntegralCheck freezIntegralCheck = new DealWorkingWebServiceStub.FreezIntegralCheck(); +// String freezeXml = parseXml(token, gtDrawInfo.getExpeNoValue().toString(), body.getMerchantCode(), body.getUserId(), body.getUserType(), "0", body.getChannel(), body.getMerchantSysCode()); +// logger.info("ֶ" + freezeXml); +// String xml = CryptUtil.encrypt(freezeXml, PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_PUBLIC_KEY"), "utf-8"); +// freezIntegralCheck.setXmlStr(xml); +// DealWorkingWebServiceStub.FreezIntegralCheckResponse freezIntegralCheckResponse = dealWorkingWebServiceStub.freezIntegralCheck(freezIntegralCheck); +// String responseXml = freezIntegralCheckResponse.get_return(); +// DealWorkingWebServiceResponse dealWorkingWebServiceResponse = null; +// logger.info("ֶ᷵" + responseXml); +// if (!(responseXml == null || "".equals(responseXml))) { +// dealWorkingWebServiceResponse = parseIntegralDealResponse(responseXml); +// } +// GtIntegralPayment gtIntegralPayment = new GtIntegralPayment(); +// gtIntegralPayment.setCHANNEL(body.getChannel()); +// gtIntegralPayment.setCreateTime(new Date()); +// gtIntegralPayment.setDrawRecordId(id); +// gtIntegralPayment.setGatewayFlow(dealWorkingWebServiceResponse.getSerialNum()); +// gtIntegralPayment.setIntegral(gtDrawInfo.getExpeNoValue()); +// gtIntegralPayment.setLastUpdaeTime(new Date()); +// gtIntegralPayment.setMerchantCode(body.getMerchantCode()); +// gtIntegralPayment.setMerchantSysCode(body.getMerchantSysCode()); +// gtIntegralPayment.setReturnCode(dealWorkingWebServiceResponse.getResultCode()); +// gtIntegralPayment.setReturnMessage(dealWorkingWebServiceResponse.getResultInfo()); +// gtIntegralPayment.setProductCode(gtDrawInfo.getDRAWCODE()); +// gtIntegralPayment.setProductName(gtDrawInfo.getDrawName()); +// gtIntegralPayment.setProductType(gtDrawInfo.getDrawType()); +// gtIntegralPayment.setTradeOrder(dealWorkingWebServiceResponse.getTrade_order()); +// gtIntegralPayment.setTradeSeqNo(dealWorkingWebServiceResponse.getTrade_transNo()); +// gtIntegralPayment.setUserId(body.getUserId()); +// gtIntegralPayment.setUserType(body.getUserType()); +// gtIntegralPayment.setType("freeze"); +// gtIntegralPaymentList.add(gtIntegralPayment); +// return dealWorkingWebServiceResponse; +// } + + /** + * 齱߼㷨 + * + * @param x + * @return + */ + @SuppressWarnings("unchecked") + public Object[] computingProcess(int x) { + String drawCode = gtDrawInfo.getDRAWCODE(); + String currentDateStr = (String) Cache.get("_" + drawCode + "_currentDateStr_"); + BigDecimal baseNumer = (BigDecimal) Cache.get("_" + drawCode + "_" + currentDateStr + "_baseNumber_"); + // + Random rand = new Random(); + int rand_ = rand.nextInt(baseNumer.intValue()) + 1; + List configList = (List) Cache.get("_" + drawCode + "_" + currentDateStr + "_gtDrawConfigList_"); + DrawConfig awardConfig = null; + DrawPrizeInfo awardPrize = (DrawPrizeInfo) Cache.get("_" + drawCode + "_blank_"); + for (int i = 0; i < configList.size(); i++) { + logger.info("γ齱:" + request.getSerialNo() + ":" + rand_); + DrawConfig gtDrawConfig = configList.get(i); + String prizeLevel = gtDrawConfig.getPRIZELEVEL(); + GtPrizeConfigTemp gtPrizeConfigTemp = (GtPrizeConfigTemp) Cache.get("_cache_" + drawCode + "_" + currentDateStr + "_" + prizeLevel + "_"); + if (x == 0) { + if (gtDrawRule.getFIRSTAWARDPRIZE().equals(gtPrizeConfigTemp.getPrizeInfo().getPRIZECODE())) { + awardPrize = gtPrizeConfigTemp.getPrizeInfo(); + awardConfig = gtDrawConfig; + } + } + if (x == 3 || x == 1) { + if (gtDrawRule.getWILLDRAWAWARDPRIZE().equals(gtPrizeConfigTemp.getPrizeInfo().getPRIZECODE())) { + awardPrize = gtPrizeConfigTemp.getPrizeInfo(); + awardConfig = gtDrawConfig; + } + } + long start = gtPrizeConfigTemp.getStartNumer(); + long end = gtPrizeConfigTemp.getEndNumber(); + logger.info("齱:" + request.getSerialNo() + "&γ齱" + baseNumer.toString() + "&룺" + gtPrizeConfigTemp.getConfig().getPRIZELEVEL() + "&Ʒ룺" + gtPrizeConfigTemp.getConfig().getPRIZECODE() + "&䳤:" + gtPrizeConfigTemp.getWeightLength() + "&ʼ:" + start + "&:" + end); + if (new BigDecimal(rand_).compareTo(new BigDecimal(start)) > -1 && new BigDecimal(rand_).compareTo(new BigDecimal(end)) < 1) { + awardPrize = gtPrizeConfigTemp.getPrizeInfo(); + awardConfig = gtDrawConfig; + break; + } + } + // logger.info("齱:"+request.getSerialNo()+"&н" + // +awardConfig.getPRIZELEVEL()+"ƷΪ"+awardPrize.getPRIZECODE()+awardPrize.getPrizeName()); + return new Object[] { awardConfig, awardPrize }; + } + + /** + * ӳ齱¼ + * + * @param tranSeqNo + * @param body + * @return + * @throws ParseException + * @throws UnknownHostException + */ + private DrawRecord addGtDrawActityRecord(String tranSeqNo, DrawActivityRequest body) throws ParseException, UnknownHostException { + DrawRecord gtDrawRecord = new DrawRecord(); + gtDrawRecord.setUSERID(body.getUserId()); + gtDrawRecord.setCREATETIMESTAMP(new Date()); + gtDrawRecord.setLASTUPDATETIMESTAMP(new Date()); + gtDrawRecord.setDRAWTIME(DateUtils.parseDate(body.getDrawTime(), "yyyyMMddHHmmssSSS")); + gtDrawRecord.setDRAWRESULT(Const.DRAW_RECORD_RESULT_NONE); + gtDrawRecord.setCHECKINGDATE(new Date()); + gtDrawRecord.setCHANNEL(body.getChannel()); + gtDrawRecord.setUSERNAME(body.getUserName()); + gtDrawRecord.setDRAWCODE(gtDrawInfo.getDRAWCODE()); + gtDrawRecord.setSOURCE(body.getSource()); + gtDrawRecord.setPHONE(body.getPhone()); + gtDrawRecord.setDRAWTRANSEQNO(tranSeqNo); + InetAddress addr = InetAddress.getLocalHost(); + String ip = addr.getHostAddress().toString(); // ȡip + gtDrawRecord.setEXTAREA(ip); + drawRecordService.insertDrawRecord(gtDrawRecord); + String drawRecordId = gtDrawRecord.getDRAWRECORDID(); + gtDrawRecord.setDRAWRECORDID(drawRecordId); + return gtDrawRecord; + } + + /*** + * + * @param userId + * @return 0,״αУ2û3ǵNγ齱У10齱 + * @throws ParseException + */ + public int checkRule(String userId) throws ParseException { + if ("1".equals(gtDrawRule.getFIRSTFLAG())) { + // ѯ齱ܴ + DrawRecord drawRecordParams = new DrawRecord(); + drawRecordParams.setDRAWCODE(gtDrawInfo.getDRAWCODE()); + drawRecordParams.setUSERID(userId); + long drawRecordTotalNumber = drawRecordService.selectDrawRecordCount(drawRecordParams); + if (new BigDecimal(drawRecordTotalNumber).compareTo(BigDecimal.ZERO) == 0) { + // ״γ齱Ҫ + return 0; + } + } + if ("1".equals(gtDrawRule.getDAILYFLAG())) { + // ״γ飬ʱγ齱 + Date now = new Date(); + String currentDateStr = DateUtils.getDate(); + String currentStartTimeStr = currentDateStr + " " + gtDrawRule.getDAILYSTARTTIME(); + String currentEndTimeStr = currentDateStr + " " + gtDrawRule.getDAILYENDTIME(); + Date startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(currentStartTimeStr); + Date endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(currentEndTimeStr); + if (now.getTime() > startTime.getTime() && now.getTime() <= endTime.getTime()) { + // ʱнЧ + DrawRecord drawRecordParams = new DrawRecord(); + drawRecordParams.setDRAWCODE(gtDrawInfo.getDRAWCODE()); + drawRecordParams.setUSERID(userId); + Map params = new HashMap<>(); + params.put("startTime", currentStartTimeStr); + params.put("endTime", currentEndTimeStr); + drawRecordParams.setParams(params); + long drawRecordDailyNumber = drawRecordService.selectDrawRecordCount(drawRecordParams); + if (new Long(drawRecordDailyNumber).compareTo(gtDrawRule.getDAILYNUMBER()) != -1) { + // ﵽʱγ齱ޣ齱 + return 10; + } + } + } + //Nγ齱 + if ("1".equals(gtDrawRule.getWILLDRAWFLAG())) { + // ѯܴ + Long willDrawAwardNumber = gtDrawRule.getWILLDRAWAWARDNUMBER(); + if (willDrawAwardNumber.compareTo(new Long(1)) == 0) { + // Ϊ1αУÿζн + return 1; + } else { + DrawRecord drawRecordParams = new DrawRecord(); + drawRecordParams.setDRAWCODE(gtDrawInfo.getDRAWCODE()); + drawRecordParams.setUSERID(userId); + long drawRecordTotalSize = drawRecordService.selectDrawRecordCount(drawRecordParams); + // 齱Ϊ0״γ齱nΪ1ȡ + if (new BigDecimal(drawRecordTotalSize).compareTo(BigDecimal.ZERO) == 1) { + int n = gtDrawRule.getWILLDRAWAWARDNUMBER().intValue(); + long m = drawRecordTotalSize % n; + if (new BigDecimal(m).compareTo(new BigDecimal(n - 1)) == 0) { + // ѯ + DrawRecord queryParams = new DrawRecord(); + queryParams.setDRAWCODE(gtDrawInfo.getDRAWCODE()); + queryParams.setUSERID(userId); + Map params = new HashMap<>(); + params.put("start", 0); + params.put("end", m+1); + queryParams.setParams(params); + List gtDrawRecordList = drawRecordService.selectDrawRecordList(queryParams); + for (DrawRecord gtDrawRecord : gtDrawRecordList) { + if (!Const.DRAW_RECORD_RESULT_NONE.equals(gtDrawRecord.getDRAWRESULT())) { + // nγ齱ѾнҪ + return 2; + } + // Nγ齱 + return 3; + } + } + } + } + } + return 2; + } + + /** + * ֯ӦͷϢ + * + * @param request + * @param resultCode + * @param resultInfo + * @return + */ + private DrawResult processResp(DrawActivityRequest request, String resultCode, String resultInfo) { + DrawResult response = new DrawResult(); + response.setRespCode(resultCode); + response.setRespMsg(resultInfo); + return response; + } + + /** + * ֧ӦxmlĽ + * + * @return + * @throws DocumentException + */ + @SuppressWarnings("unchecked") +// public DealWorkingWebServiceResponse parseIntegralDealResponse(String responseText) throws DocumentException { +// DealWorkingWebServiceResponse response = new DealWorkingWebServiceResponse(); +// Document doc = DocumentHelper.parseText(responseText); +// Element rootElt = doc.getRootElement(); +// Iterator it = rootElt.elementIterator(); +// while (it.hasNext()) { +// Element element = it.next(); +// if (element.getName().equals("resultCode")) { +// response.setResultCode(element.getTextTrim()); +// } +// if (element.getName().equals("resultInfo")) { +// response.setResultInfo(element.getTextTrim()); +// } +// if (element.getName().equals("serialNum")) { +// response.setSerialNum(element.getTextTrim()); +// } +// if (element.getName().equals("trade__order")) { +// response.setTrade_order(element.getTextTrim()); +// } +// if (element.getName().equals("trade__transNo")) { +// response.setTrade_transNo(element.getTextTrim()); +// } +// if (element.getName().equals("merchantCode")) { +// response.setMerchantCode(element.getTextTrim()); +// } +// if (element.getName().equals("result")) { +// response.setResult(element.getTextTrim()); +// } +// if (element.getName().equals("settleDate")) { +// response.setSettleDate(element.getTextTrim()); +// } +// } +// return response; +// } + + /** + * ֶxmlװ + * + * @param billStr + * @param integralStr + * @param merchantCodeStr + * @param userIdStr + * @param userTypeStr + * @param platformStr + * @param channelStr + * @param sysCodeStr + * @return + */ +// public String parseXml(String billStr, String integralStr, String merchantCodeStr, String userIdStr, String userTypeStr, String platformStr, String channelStr, String sysCodeStr) { +// Document document = DocumentHelper.createDocument(); +// Element request = DocumentHelper.createElement("request"); +// Element dealWorkingRequestBody = DocumentHelper.createElement("dealWorkingRequestBody"); +// Element bill = DocumentHelper.createElement("bill"); +// bill.addText(billStr); +// dealWorkingRequestBody.add(bill); +// Element integral = DocumentHelper.createElement("integral"); +// integral.addText(integralStr); +// dealWorkingRequestBody.add(integral); +// Element merchantCode = DocumentHelper.createElement("merchantCode"); +// merchantCode.addText(merchantCodeStr); +// dealWorkingRequestBody.add(merchantCode); +// +// Element platform = DocumentHelper.createElement("platform"); +// platform.addText(platformStr); +// dealWorkingRequestBody.add(platform); +// +// Element productCode = DocumentHelper.createElement("productCode"); +// productCode.addText(gtDrawInfo.getDRAWCODE()); +// dealWorkingRequestBody.add(productCode); +// +// Element productName = DocumentHelper.createElement("productName"); +// productName.addText(gtDrawInfo.getDrawName()); +// dealWorkingRequestBody.add(productName); +// +// Element productType = DocumentHelper.createElement("productType"); +// productType.addText(gtDrawInfo.getDrawType()); +// dealWorkingRequestBody.add(productType); +// +// // ǩ +// Element signature = DocumentHelper.createElement("signature"); +// Md5 md5 = new Md5(); +// String str = md5.toMD5(userIdStr + "_" + userTypeStr + "_" + integralStr + "_" + platformStr); +// signature.addText(str); +// dealWorkingRequestBody.add(signature); +// +// Element trade_order = DocumentHelper.createElement("trade_order"); +// String tradeOrder = new SimpleDateFormat("yyyyMMdd").format(new Date()) + sequenceService.getDrawActivirtTradeOrderSeq(); +// trade_order.addText(tradeOrder); +// dealWorkingRequestBody.add(trade_order); +// +// Element trade_transNo = DocumentHelper.createElement("trade_transNo"); +// trade_transNo.addText(gtDrawInfo.getDRAWCODE() + tradeOrder); +// dealWorkingRequestBody.add(trade_transNo); +// +// Element userId = DocumentHelper.createElement("userId"); +// userId.addText(userIdStr); +// dealWorkingRequestBody.add(userId); +// +// Element userType = DocumentHelper.createElement("userType"); +// userType.addText(userTypeStr); +// dealWorkingRequestBody.add(userType); +// +// Element dealWorkingRequestHander = DocumentHelper.createElement("dealWorkingRequestHander"); +// +// Element channel = DocumentHelper.createElement("channel"); +// channel.addText(channelStr); +// dealWorkingRequestHander.add(channel); +// +// Element password = DocumentHelper.createElement("password"); +// password.addText(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_PASS_HANDER")); +// dealWorkingRequestHander.add(password); +// +// Element serialNo = DocumentHelper.createElement("serialNo"); +// serialNo.addText(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); +// dealWorkingRequestHander.add(serialNo); +// +// Element sysCode = DocumentHelper.createElement("sysCode"); +// sysCode.addText(sysCodeStr); +// dealWorkingRequestHander.add(sysCode); +// +// Element sysName = DocumentHelper.createElement("sysName"); +// sysName.addText(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_SYS_NAME")); +// dealWorkingRequestHander.add(sysName); +// +// Element transCode = DocumentHelper.createElement("transCode"); +// transCode.addText(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_TRANSCODE_DEALWORKINGWEBSERVICE")); +// dealWorkingRequestHander.add(transCode); +// +// Element userName = DocumentHelper.createElement("userName"); +// userName.addText(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_USER_HANDER")); +// dealWorkingRequestHander.add(userName); +// +// request.add(dealWorkingRequestHander); +// request.add(dealWorkingRequestBody); +// document.add(request); +// return document.asXML(); +// } + + /** + * ֧֯xml + * + * @param trade_order_str + * @param trade_seq_no_str + * @param serialNumStr + * @param integralStr + * @param merchantCodeStr + * @param userIdStr + * @param userTypeStr + * @param platformStr + * @param channelStr + * @param sysCodeStr + * @param operationTypeStr + * @return + */ +// public String parseIntegralPaymentXml(String trade_order_str, String trade_seq_no_str, String serialNumStr, String integralStr, String merchantCodeStr, String userIdStr, String userTypeStr, String platformStr, String channelStr, String sysCodeStr, String operationTypeStr) { +// Document document = DocumentHelper.createDocument(); +// Element request = DocumentHelper.createElement("request"); +// Element dealWorkingRequestBody = DocumentHelper.createElement("dealWorkingRequestBody"); +// +// Element userId = DocumentHelper.createElement("userId"); +// userId.addText(userIdStr); +// dealWorkingRequestBody.add(userId); +// +// Element userType = DocumentHelper.createElement("userType"); +// userType.addText(userTypeStr); +// dealWorkingRequestBody.add(userType); +// +// Element operationType = DocumentHelper.createElement("operationType"); +// operationType.addText(operationTypeStr); +// dealWorkingRequestBody.add(operationType); +// +// Element serialNum = DocumentHelper.createElement("serialNum"); +// serialNum.addText(serialNumStr); +// dealWorkingRequestBody.add(serialNum); +// +// Element integral = DocumentHelper.createElement("integral"); +// integral.addText(integralStr); +// dealWorkingRequestBody.add(integral); +// +// Element platform = DocumentHelper.createElement("platform"); +// platform.addText(platformStr); +// dealWorkingRequestBody.add(platform); +// +// Element trade_order = DocumentHelper.createElement("trade_order"); +// trade_order.addText(trade_order_str); +// dealWorkingRequestBody.add(trade_order); +// +// Element trade_transNo = DocumentHelper.createElement("trade_transNo"); +// trade_transNo.addText(trade_seq_no_str); +// dealWorkingRequestBody.add(trade_transNo); +// +// Element tranTime = DocumentHelper.createElement("tranTime"); +// tranTime.addText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); +// dealWorkingRequestBody.add(tranTime); +// +// Element merchantCode = DocumentHelper.createElement("merchantCode"); +// merchantCode.addText(merchantCodeStr); +// dealWorkingRequestBody.add(merchantCode); +// +// // ǩ +// Element signature = DocumentHelper.createElement("signature"); +// Md5 md5 = new Md5(); +// String str = md5.toMD5(userIdStr + "_" + userTypeStr + "_" + operationTypeStr + "_" + channelStr); +// signature.addText(str); +// dealWorkingRequestBody.add(signature); +// +// Element channel = DocumentHelper.createElement("channel"); +// channel.addText(channelStr); +// dealWorkingRequestBody.add(channel); +// +// Element dealWorkingRequestHander = DocumentHelper.createElement("dealWorkingRequestHander"); +// +// Element headerChannel = DocumentHelper.createElement("channel"); +// headerChannel.addText(channelStr); +// dealWorkingRequestHander.add(headerChannel); +// +// Element password = DocumentHelper.createElement("password"); +// password.addText(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_PASS_HANDER")); +// dealWorkingRequestHander.add(password); +// +// Element serialNo = DocumentHelper.createElement("serialNo"); +// serialNo.addText(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); +// dealWorkingRequestHander.add(serialNo); +// +// Element sysCode = DocumentHelper.createElement("sysCode"); +// sysCode.addText(sysCodeStr); +// dealWorkingRequestHander.add(sysCode); +// +// Element sysName = DocumentHelper.createElement("sysName"); +// sysName.addText(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_SYS_NAME")); +// dealWorkingRequestHander.add(sysName); +// +// Element transCode = DocumentHelper.createElement("transCode"); +// transCode.addText(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_TRANSCODE_DEALWORKINGWEBSERVICE")); +// dealWorkingRequestHander.add(transCode); +// +// Element userName = DocumentHelper.createElement("userName"); +// userName.addText(PropertiesUtil.getProperties("sysConfig.properties", "INTEGRAL_INTERFACE_USER_HANDER")); +// dealWorkingRequestHander.add(userName); +// +// request.add(dealWorkingRequestHander); +// request.add(dealWorkingRequestBody); +// document.add(request); +// return document.asXML(); +// } + + /** + * ƷԼ + * + * @param gtDrawConfig + * @return + */ + public int prizeProcess(DrawConfig gtDrawConfig) { + DrawConfig queryParams = new DrawConfig(); + queryParams.setDRAWCODE(gtDrawConfig.getDRAWCODE()); + queryParams.setPRIZELEVEL(gtDrawConfig.getPRIZELEVEL()); + queryParams.setPRIZECODE(gtDrawConfig.getPRIZECODE()); + queryParams.setSTATUS(Const.DRAW_CONFIG_STATUS_EFFECTIVE); + queryParams.setAVAILABLENUMBER(0L); + DrawConfig drawConfig = drawConfigService.selectDrawConfigByDraw(queryParams); + if (drawConfig == null) { + return 0; + } else { + return drawConfigService.updateDrawConfigNumAndStatus(drawConfig); + } + + } + + /** + * ʧܺƷ + * + * @param gtDrawConfig + * @return + */ + public int rollBackPrizeProcess(DrawConfig gtDrawConfig) { + DrawConfig queryParams = new DrawConfig(); + queryParams.setDRAWCODE(gtDrawConfig.getDRAWCODE()); + queryParams.setPRIZELEVEL(gtDrawConfig.getPRIZELEVEL()); + queryParams.setPRIZECODE(gtDrawConfig.getPRIZECODE()); + DrawConfig drawConfig = drawConfigService.selectDrawConfigByDraw(queryParams); + return drawConfigService.updateDrawConfigRollback(drawConfig); + } + + /** + * 齱ӿӦװ + * + * @param gateWayFlow + * @param gtPrizeInfo + * @param gtDrawConfig + * @return + */ + public DrawResult parseResponseBody(String gateWayFlow, DrawPrizeInfo gtPrizeInfo, DrawConfig gtDrawConfig, String extId, DrawRecord gtDrawRecord) { + DrawResult responseBody = new DrawResult(); + responseBody.setUserId(request.getUserId()); + responseBody.setPrizeType(gtPrizeInfo.getPRIZETYPE()); + responseBody.setPrizeName(gtPrizeInfo.getPRIZENAME()); + responseBody.setPrizeCode(gtPrizeInfo.getPRIZECODE()); + responseBody.setGateWayTime(new SimpleDateFormat("yyyyMMddHHmmsssSSS").format(new Date())); + responseBody.setDrawCode(gtDrawInfo.getDRAWCODE()); + responseBody.setDisplayOrder(gtDrawConfig.getDISPLAYORDER()); + if (gtDrawConfig.getCUE() != null) { + responseBody.setCue(gtDrawConfig.getCUE()); + } + responseBody.setGatewayFlow(gateWayFlow); + responseBody.setPrizeLevel(gtDrawConfig.getPRIZELEVEL()); + responseBody.setExtId(extId); + responseBody.setSource(request.getSource()); + if (gtPrizeInfo.getPRIZETYPE().equals("empty")) { + responseBody.setResult("0"); + } else { + responseBody.setResult("1"); + } + //1654 սս + if (Const.PRIZE_LEVEL_BLANK.equals(gtDrawConfig.getPRIZELEVEL())) { + extId = awardBlank(gtPrizeInfo, gtDrawConfig, gtDrawRecord); + responseBody.setExtId(extId); + } + return responseBody; + } + + /** + * սս + * @author huayue + * @since 2020-08-11 + * @param gtPrizeInfo + * @param gtDrawConfig + * @param gtDrawRecord + * @version 1654 + */ + private String awardBlank(DrawPrizeInfo gtPrizeInfo, DrawConfig gtDrawConfig, DrawRecord gtDrawRecord) { + String extId = null; + try { + String prizeType = gtPrizeInfo.getPRIZETYPE(); + if (Const.PRIZE_TYPE_WELFARE.equals(prizeType)) { +// extId = getAccount(gtPrizeInfo, gtDrawRecord); + } else if (Const.PRIZE_TYPE_PCOUPON.equals(prizeType) || Const.PRIZE_TYPE_SCOUPON.equals(prizeType)) { +// extId = getDiscountCode(gtPrizeInfo, gtDrawRecord); + } else if (Const.PRIZE_TYPE_VCOUPON.equals(prizeType)) { +// extId = awardCoupon(gtPrizeInfo, gtDrawRecord); + } else if (Const.PRIZE_TYPE_INTEGRAL.equals(prizeType) || Const.PRIZE_TYPE_IEMALL.equals(prizeType) + || Const.PRIZE_TYPE_VOCHER.equals(prizeType) || Const.PRIZE_TYPE_CASH.equals(prizeType)) { + gtDrawRecord.setPRIZECODE(gtPrizeInfo.getPRIZECODE()); + gtDrawRecord.setPRIZETYPE(prizeType); + gtDrawRecord.setPRIZELEVEL(gtDrawConfig.getPRIZELEVEL()); + gtDrawRecord.setPROJECTCODE(gtPrizeInfo.getINTEGRALPROJECTCODE()); + awardService.award(gtDrawRecord, request, gtDrawInfo, request.getPhone(), gtDrawConfig.getAWARDMETHOD()); + } + } catch (Exception e) { + logger.error("ս쳣", e); + } + return extId; + } + + + /** + * ³齱 + * + * @param id + * @param result + * @param prizeCode + * @param prizeType + * @param prizeLevel + */ + public void updateGtDrawRecordResult(String id, String result, String prizeCode, String prizeType, String prizeLevel, String projectCode) { + DrawRecord record = drawRecordService.selectDrawRecordById(id); + record.setDRAWRESULT(result); + record.setPRIZECODE(prizeCode); + record.setPRIZETYPE(prizeType); + record.setPROJECTCODE(projectCode); + record.setPRIZELEVEL(prizeLevel); + drawRecordService.updateDrawRecord(record); + } +} diff --git a/sino-act-web/src/main/java/com/ruoyi/thread/ThreadPool.java b/sino-act-web/src/main/java/com/ruoyi/thread/ThreadPool.java new file mode 100644 index 000000000..b80002db6 --- /dev/null +++ b/sino-act-web/src/main/java/com/ruoyi/thread/ThreadPool.java @@ -0,0 +1,12 @@ +package com.ruoyi.thread; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class ThreadPool { + // ̳߳--齱߼ + public static final ExecutorService drawActivityExecutorService = Executors.newFixedThreadPool(1000); + public static final ExecutorService awardExecutorService = Executors.newFixedThreadPool(1000); + //ŷ̳߳ + public static final ExecutorService smsExecutorService= Executors.newFixedThreadPool(100); +} diff --git a/sino-act-web/src/main/java/com/ruoyi/web/controller/draw/DrawController.java b/sino-act-web/src/main/java/com/ruoyi/web/controller/draw/DrawController.java index 9620aef26..cb70f545c 100644 --- a/sino-act-web/src/main/java/com/ruoyi/web/controller/draw/DrawController.java +++ b/sino-act-web/src/main/java/com/ruoyi/web/controller/draw/DrawController.java @@ -1,8 +1,11 @@ package com.ruoyi.web.controller.draw; +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.dto.DrawActivityRequest; import com.ruoyi.web.vo.Const; import com.ruoyi.web.vo.Result; import com.ruoyi.web.vo.draw.*; +import com.sinosoft.activity.domain.DrawConfig; import com.sinosoft.activity.domain.*; import com.sinosoft.activity.service.IActPageConfigUserinfoService; import com.sinosoft.activity.service.IDrawConfigService; @@ -28,7 +31,6 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import java.util.ArrayList; -import java.util.Date; import java.util.List; /** @@ -146,62 +148,17 @@ public class DrawController { } String openid = userInfo.getOpenid(); String userName = userInfo.getNickname(); - - DrawInfo queryInfo = new DrawInfo(); - queryInfo.setDRAWCODE(drawCode); - queryInfo.setSTATUS(Const.STATUS_VALID); - List drawInfos = drawInfoService.selectDrawInfoList(queryInfo); - if (drawInfos == null || drawInfos.size() == 0) { - result.setRespCode("-3"); - result.setRespMsg("活动未开启"); - return result; - } - DrawInfo drawInfo = drawInfos.get(0); - Date starttime = drawInfo.getSTARTTIME(); - Date endtime = drawInfo.getENDTIME(); - Date currDate = new Date(); - if (currDate.before(starttime) || currDate.after(endtime)) { - result.setRespCode("-3"); - result.setRespMsg("活动未开始"); - return result; - } -// String userAccount = geUserPersonal.getUserAccount(); -// String mobile = geUserPersonal.getMobliePhone(); -// DrawActivityRequestBody body = new DrawActivityRequestBody(); -// body.setDrawCode(drawCode); -// body.setUserId(openid); -// body.setUserType("01"); -// body.setUserName(StringUtils.isBlank(userName)?userAccount:userName); -// body.setDrawTime(DateUtil.convertDate(new Date(), DateUtil.YYYYMMDDHHMMSSS)); -// body.setMerchantCode("MerchantCode"); -// body.setMerchantSysCode("MerchantSysCode"); -// body.setBusinessArea("6"); -// body.setChannel("WEIXIN"); -// body.setSource("24"); -// body.setPhone(mobile); -// DrawActivityResponse drawActivityResponse = activityService.drawActivityService(body).get_return(); -// DrawActivityResponseHeader header = drawActivityResponse.getHeader(); -// String resultCode = header.getResultCode(); -// if (!WSResult.SUCCESS.equals(resultCode)) { -// result.setRespCode(resultCode); -// result.setRespMsg(WSResult.getMsg(resultCode)); -// return result; -// } -// DrawActivityResponseBody responseBody = drawActivityResponse.getBody(); -// String prizeCode = responseBody.getPrizeCode(); -// result.setPrizeCode(prizeCode); -// String prizeName = responseBody.getPrizeName(); -// result.setPrizeName(prizeName); -// String prizeType = responseBody.getPrizeType(); -// result.setPrizeType(prizeType); -// result.setPrizeLevel(responseBody.getPrizeLevel()); -// result.setDisplayOrder(responseBody.getDisplayOrder()); -// result.setCue(responseBody.getCue()); -// result.setAvailable(responseBody.getAvailable()); -// String extId = responseBody.getExtId(); -// result.setExtId(extId); -// result.setGatewayFlow(responseBody.getGatewayFolw()); -// result.setResult(responseBody.getResult()); + DrawActivityRequest body = new DrawActivityRequest(); + body.setDrawCode(drawCode); + body.setUserId(openid); + body.setUserType("01"); + body.setUserName(userName); + body.setDrawTime(DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSSS)); + body.setMerchantCode("MerchantCode"); + body.setMerchantSysCode("MerchantSysCode"); + body.setBusinessArea("6"); + body.setChannel("WEIXIN"); + body.setSource("24"); } catch (Exception e) { result.setRespCode("-1"); result.setRespMsg("系统异常,请稍后再试"); diff --git a/sino-act-web/src/main/java/com/ruoyi/web/vo/Const.java b/sino-act-web/src/main/java/com/ruoyi/web/vo/Const.java index 037413520..189b9361c 100644 --- a/sino-act-web/src/main/java/com/ruoyi/web/vo/Const.java +++ b/sino-act-web/src/main/java/com/ruoyi/web/vo/Const.java @@ -1,5 +1,9 @@ package com.ruoyi.web.vo; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + /** * * @author Huayue @@ -29,6 +33,95 @@ public interface Const { String STATUS_VALID = "1"; String STATUS_INVALID = "0"; + /** 任务完成通知记录状态 **/ + /** 有效 **/ + public static final String TASK_NOTIFY_RECORD_STATUS_EFFECTIVE = "1"; + /** 失效 **/ + public static final String TASK_NOTIFY_RECORD_STATUS_EXPIRE = "0"; + /** 活动状态 **/ + /** 有效 **/ + public static final String DRAW_STATUS_EFFECTIVE = "1"; + /** 失效 **/ + public static final String DRAW_STATUS_EXPIRE = "0"; + /** 奖项配置状态 **/ + /** 有效 */ + public static final String DRAW_CONFIG_STATUS_EFFECTIVE = "1"; + /** 失效 **/ + public static final String DRAW_CONFIG_STATUS_EXPIRE = "0"; + /** 抽奖类型 **/ + /** 积分抽奖 **/ + public static final String DRAW_EXPE_INTEGRAL = "integral"; + /** 次数抽奖 **/ + public static final String DRAW_EXPE_TASK = "task"; + /** 抽奖记录状态 **/ + /** 没中奖 **/ + public static final String DRAW_RECORD_RESULT_NONE = "0"; + /** 中奖待发奖---发奖失败 **/ + public static final String DRAW_RECORD_RESULT_PRIZE = "1"; + /** 发奖成功 **/ + public static final String DRAW_RECORD_RESULT_AWARDS = "2"; + /** 奖品级别--空奖 1654**/ + public static final String PRIZE_LEVEL_BLANK = "blank"; + /** 奖品类型 ***/ + public static final String PRIZE_TYPE_BLANK = "empty"; + /**一账通**/ + public static final String PRIZE_TYPE_VOCHER = "vocher"; + /**实物**/ + public static final String PRIZE_TYPE_MATERIALOBJECT = "materialObject"; + /**积分**/ + public static final String PRIZE_TYPE_INTEGRAL = "integral"; + /**i购券**/ + public static final String PRIZE_TYPE_IEMALL = "iemall"; + /**公开码电子券**/ + public static final String PRIZE_TYPE_PCOUPON = "pcoupon"; + /**隐藏码电子券**/ + public static final String PRIZE_TYPE_SCOUPON = "scoupon"; + /**1656 积分平台虚拟电子券**/ + public static final String PRIZE_TYPE_VCOUPON = "vcoupon"; + /**服务奖品**/ + public static final String PRIZE_TYPE_SERVICE = "service"; + /**保险奖品**/ + public static final String PRIZE_TYPE_INSURANCE = "insurance"; + /**随机红包**/ + public static final String PRIZE_TYPE_WELFARE = "welfare"; + /**一账通现金红包 1654**/ + public static final String PRIZE_TYPE_CASH = "cash"; + /**发奖结果**/ + public static final String AWARD_RESULT_SUCCESS="1"; + public static final String AWARD_RESULT_FAIL="0"; + /**活动类型-转盘抽奖**/ + public static final String DRAW_TYPE_TURN_TABLE="turnTable"; + /**奖品发放通知类型**/ + public static final List AWARD_TYPE= Arrays.asList("001", "002", "003", "004", "005", "006"); - String PRIZE_LEVEL_BLANK = "blank"; + /**异步发列表**/ + /**请求类型**/ + public static final String TASK_TYPE_VALIDATE="1"; + public static final String TASK_TYPE_SHARE="2"; + public static final String TASK_TYPE_OTHER="3"; + /** + * 1654 + * 一账通支付 + */ + public static final String TASK_TYPE_PAY="9"; + /**一账通验证状态**/ + public static final String TASK_NOTIFY_VSTATE_TRUE="1"; + public static final String TASK_NOTIFY_VSTATE_FALSE="0"; + /**发将限制规则**/ + public static final String AWARD_TYPE_NONE="none"; + /**单个活动限制**/ + public static final String AWARD_TYPE_DISTINCTION="distinction"; + /**不区分活动限制**/ + public static final String AWARD_TYPE_NODISTINCTION="nodistinction"; + /**用户等级**/ + /**一般用户**/ + public static final String USER_LEVEL_ORDINARY="1"; + /**高价值客户**/ + public static final String USER_LEVEL_SENIOR="2"; + + /**领奖方式**/ + /**自动领取**/ + public static final String AWARD_METHOD_AUTO="1"; + /**手动领取**/ + public static final String AWARD_METHOD_MANAL="0"; } diff --git a/sino-act-web/src/main/java/com/ruoyi/web/vo/draw/DrawResult.java b/sino-act-web/src/main/java/com/ruoyi/web/vo/draw/DrawResult.java index 581a4585d..2ed6a50f7 100644 --- a/sino-act-web/src/main/java/com/ruoyi/web/vo/draw/DrawResult.java +++ b/sino-act-web/src/main/java/com/ruoyi/web/vo/draw/DrawResult.java @@ -12,8 +12,44 @@ public class DrawResult extends Result { private String available; private String extId; private String gatewayFlow; + private String gateWayTime; + private String drawCode; + private String source; + private String userId; private String result; + public String getGateWayTime() { + return gateWayTime; + } + + public void setGateWayTime(String gateWayTime) { + this.gateWayTime = gateWayTime; + } + + public String getDrawCode() { + return drawCode; + } + + public void setDrawCode(String drawCode) { + this.drawCode = drawCode; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getPrizeCode() { return prizeCode; } diff --git a/sino-act-web/src/main/resources/public/act/guide.html b/sino-act-web/src/main/resources/public/act/guide.html index a2b7c77f2..c6f0760ad 100644 --- a/sino-act-web/src/main/resources/public/act/guide.html +++ b/sino-act-web/src/main/resources/public/act/guide.html @@ -122,10 +122,11 @@