| | |
| | | import java.lang.Exception; |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.yeshi.makemoney.app.entity.SystemEnum; |
| | | import com.yeshi.makemoney.app.entity.config.SystemConfigKey; |
| | | import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType; |
| | | import com.yeshi.makemoney.app.entity.goldcorn.GoldCornPriceCountType; |
| | | import com.yeshi.makemoney.app.entity.user.UserInfo; |
| | | import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetPriceException; |
| | | import com.yeshi.makemoney.app.service.inter.config.SystemConfigService; |
| | | import com.yeshi.makemoney.app.service.inter.team.TeamInviteRelationService; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import org.yeshi.utils.bean.BeanUtil; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.yeshi.makemoney.app.dao.goldcorn.GoldCornGetPriceDao; |
| | | import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetPrice; |
| | |
| | | @Resource |
| | | private GoldCornGetPriceDao goldCornGetPriceDao; |
| | | |
| | | @Resource |
| | | private SystemConfigService systemConfigService; |
| | | |
| | | @Resource |
| | | private TeamInviteRelationService teamInviteRelationService; |
| | | |
| | | @Override |
| | | public List<GoldCornGetPrice> list(GoldCornGetPriceQuery goldCornGetPriceQuery, int page, int pageSize) { |
| | | DaoQuery daoQuery = new DaoQuery(); |
| | | daoQuery.type = goldCornGetPriceQuery.getType(); |
| | | if (!StringUtil.isNullOrEmpty(goldCornGetPriceQuery.getStartTime())) { |
| | | daoQuery.minValidateTime = new Date(TimeUtil.convertToTimeTemp(goldCornGetPriceQuery.getStartTime(), "yyyy-MM-dd")); |
| | | } |
| | | if (!StringUtil.isNullOrEmpty(goldCornGetPriceQuery.getEndTime())) { |
| | | daoQuery.maxValidateTime = new Date(TimeUtil.convertToTimeTemp(goldCornGetPriceQuery.getEndTime(), "yyyy-MM-dd") + 1000 * 60 * 60 * 24L); |
| | | } |
| | | daoQuery.minValidateTime = goldCornGetPriceQuery.toStartTime(); |
| | | daoQuery.maxValidateTime = goldCornGetPriceQuery.toEndTime(); |
| | | |
| | | |
| | | daoQuery.start = (page - 1) * pageSize; |
| | |
| | | public long count(GoldCornGetPriceQuery goldCornGetPriceQuery) { |
| | | DaoQuery daoQuery = new DaoQuery(); |
| | | daoQuery.type = goldCornGetPriceQuery.getType(); |
| | | if (!StringUtil.isNullOrEmpty(goldCornGetPriceQuery.getStartTime())) { |
| | | daoQuery.minValidateTime = new Date(TimeUtil.convertToTimeTemp(goldCornGetPriceQuery.getStartTime(), "yyyy-MM-dd")); |
| | | } |
| | | if (!StringUtil.isNullOrEmpty(goldCornGetPriceQuery.getEndTime())) { |
| | | daoQuery.maxValidateTime = new Date(TimeUtil.convertToTimeTemp(goldCornGetPriceQuery.getEndTime(), "yyyy-MM-dd") + 1000 * 60 * 60 * 24L); |
| | | } |
| | | daoQuery.minValidateTime = goldCornGetPriceQuery.toStartTime(); |
| | | daoQuery.maxValidateTime = goldCornGetPriceQuery.toEndTime(); |
| | | return goldCornGetPriceDao.count(daoQuery); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public GoldCornGetPrice getPrice(SystemEnum system, GoldCornGetType type, Date date) { |
| | | DaoQuery daoQuery = new DaoQuery(); |
| | | daoQuery.maxValidateTime = date; |
| | | daoQuery.system = system; |
| | | daoQuery.type = type; |
| | | daoQuery.sortList = Arrays.asList(new Sort.Order[]{Sort.Order.desc("validateTime")}); |
| | | daoQuery.count = 1; |
| | | |
| | | List<GoldCornGetPrice> list = goldCornGetPriceDao.list(daoQuery); |
| | | if (list != null && list.size() > 0) { |
| | | return list.get(0); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public Integer getPriceCornNum(SystemEnum system, GoldCornGetType type, Date date, boolean hasBoss) { |
| | | GoldCornGetPrice price = getPrice(system, type, date); |
| | | if (price == null) { |
| | | return null; |
| | | } |
| | | return new BigDecimal(price.getCornNum()).multiply(new BigDecimal(1).add(price.getTeamGainRate())).intValue(); |
| | | } |
| | | |
| | | @Override |
| | | public Integer getSingInPrice(SystemEnum system, int continueDay) { |
| | | List<Integer> list = getSingInPriceList(system); |
| | | if (list == null) { |
| | | return null; |
| | | } |
| | | |
| | | if (continueDay >= list.size()) { |
| | | return list.get(list.size() - 1); |
| | | } |
| | | |
| | | if (continueDay <= 0) { |
| | | return list.get(0); |
| | | } |
| | | |
| | | return list.get(continueDay - 1); |
| | | } |
| | | |
| | | @Override |
| | | public List<Integer> getSingInPriceList(SystemEnum system) { |
| | | String value = systemConfigService.getValueCache(system, SystemConfigKey.signInGoldCorn); |
| | | if (StringUtil.isNullOrEmpty(value)) { |
| | | return null; |
| | | } |
| | | Type type = new TypeToken<List<Integer>>() { |
| | | }.getType(); |
| | | return new Gson().fromJson(value, type); |
| | | } |
| | | |
| | | @Override |
| | | public Integer getCountPrice(GoldCornGetType type, UserInfo user, SystemEnum system, Date date, long eventCount) throws GoldCornGetPriceException { |
| | | GoldCornGetPrice getPrice = getPrice(system, type, date); |
| | | if (getPrice == null) { |
| | | throw new GoldCornGetPriceException(GoldCornGetPriceException.CODE_NOT_EXIST, "价格信息缺失"); |
| | | } |
| | | |
| | | int goldCorn; |
| | | if (getPrice.getCountType() == GoldCornPriceCountType.time) { |
| | | goldCorn = (int) (eventCount * getPrice.getCornNum() / 60.0f); |
| | | |
| | | } else { |
| | | goldCorn = (int) (eventCount * getPrice.getCornNum()); |
| | | } |
| | | |
| | | //加上团队增益比例 |
| | | if (user != null && teamInviteRelationService.getBossUid(user.getId()) != null) { |
| | | goldCorn = new BigDecimal(goldCorn).multiply(new BigDecimal(1).add(getPrice.getTeamGainRate())).intValue(); |
| | | } |
| | | return goldCorn; |
| | | } |
| | | |
| | | @Override |
| | | public Map<GoldCornGetType, GoldCornGetPrice> getCountPrice(List<GoldCornGetType> typeList, UserInfo user, SystemEnum system, Date date) { |
| | | Map<GoldCornGetType, GoldCornGetPrice> map = new HashMap(); |
| | | for (GoldCornGetType type : typeList) { |
| | | GoldCornGetPrice getPrice = getPrice(system, type, date); |
| | | if (getPrice == null) { |
| | | continue; |
| | | } |
| | | int goldCorn = getPrice.getCornNum(); |
| | | //加上团队增益比例 |
| | | if (user != null && teamInviteRelationService.getBossUid(user.getId()) != null) { |
| | | goldCorn = new BigDecimal(goldCorn).multiply(new BigDecimal(1).add(getPrice.getTeamGainRate())).intValue(); |
| | | } |
| | | getPrice.setCornNum(goldCorn); |
| | | map.put(type, getPrice); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public GoldCornGetPrice getCountPrice(GoldCornGetType type, UserInfo user, SystemEnum system, Date date) { |
| | | |
| | | Map<GoldCornGetType, GoldCornGetPrice> map = getCountPrice(Arrays.asList(new GoldCornGetType[]{type}), user, system, date); |
| | | |
| | | return map.get(type); |
| | | } |
| | | |
| | | |
| | | } |