package com.xzx.gc.user.service; import cn.hutool.core.collection.CollUtil; import com.xzx.gc.entity.ConfigInfo; import com.xzx.gc.entity.CoreSetMoney; import com.xzx.gc.user.mapper.AccountMapper; import com.xzx.gc.user.mapper.ConfigMapper; import com.xzx.gc.user.mapper.OtherUserMapper; import com.xzx.gc.util.DoubleUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.List; import java.util.Map; @Service @Transactional public class ConfigService { @Autowired private ConfigMapper configMapper; @Autowired private OtherUserMapper otherUserMapper; @Autowired private AccountMapper accountMapper; public ConfigInfo findByCode(String typeCode) { ConfigInfo configInfo=new ConfigInfo(); configInfo.setConfigTypeCode(typeCode); List list = configMapper.select(configInfo); if(CollUtil.isNotEmpty(list)){ return list.get(0); } return null; } public List findByGroup(String group) { ConfigInfo configInfo=new ConfigInfo(); configInfo.setConfigGroup(group); List select = configMapper.select(configInfo); return select; } public void updateMoneySetting(CoreSetMoney money) { if (!StringUtils.isEmpty(money.getAgentPrice())) { configMapper.updateAgentPrice(money); } if (!StringUtils.isEmpty(money.getTimeInterval())) { configMapper.updateTimeInterval(money); } if (!StringUtils.isEmpty(money.getStartTime())) { configMapper.updateStratTime(money); } if (!StringUtils.isEmpty(money.getEndTime())) { configMapper.updateEndTime(money); } if (!StringUtils.isEmpty(money.getOverdrawPrice())) { Map m = configMapper.queryOverdrawPrice(); //String limitPrice = m.get("configValue").toString(); if(null!=m){ List orderIds = otherUserMapper.queryRKOrderIds(m.get("configValue").toString(), "1"); if (null != orderIds && orderIds.size() > 0) { if (money.getOverdrawPrice().equals(m.get("configValue").toString())) { // 需要更新所有account表的透支额度,但是不更新已经修改过的用户额度 if(null!=money.getWarehousingPrice()){ money.setWarehousingPrice(DoubleUtil.roundTwo(money.getWarehousingPrice())); } if(null!=money.getOverdrawPrice()){ money.setOverdrawPrice(DoubleUtil.roundTwo(money.getOverdrawPrice())); } configMapper.updateOverdrawPrice(money); accountMapper.updateAccountOverdrawPrice(money.getOverdrawPrice(), m.get("configValue").toString(), orderIds, null); } else { money.setWarehousingPrice(DoubleUtil.roundTwo(money.getWarehousingPrice())); money.setOverdrawPrice(DoubleUtil.roundTwo(money.getOverdrawPrice())); configMapper.updateOverdrawPrice(money); accountMapper.updateAccountOverdrawPrice(money.getOverdrawPrice(), m.get("configValue").toString(), orderIds, "1"); } } } } if (!StringUtils.isEmpty(money.getWarehousingPrice())) { Map m = configMapper.queryWarehousingPrice(); List orderIds = otherUserMapper.queryRKOrderIds(m.get("configValue").toString(), null); if (null != orderIds && orderIds.size() > 0) { if (money.getOverdrawPrice().equals(m.get("configValue").toString())) { money.setWarehousingPrice(DoubleUtil.roundTwo(money.getWarehousingPrice())); money.setOverdrawPrice(DoubleUtil.roundTwo(money.getOverdrawPrice())); configMapper.updateWarehousingPrice(money); accountMapper.updateAccountWarehousingPrice(money.getWarehousingPrice(), m.get("configValue").toString(), orderIds, null); } else { money.setWarehousingPrice(DoubleUtil.roundTwo(money.getWarehousingPrice())); money.setOverdrawPrice(DoubleUtil.roundTwo(money.getOverdrawPrice())); configMapper.updateWarehousingPrice(money); accountMapper.updateAccountWarehousingPrice(money.getWarehousingPrice(), m.get("configValue").toString(), orderIds, "1"); } } } if (!StringUtils.isEmpty(money.getRechargePrice())) { configMapper.updateRechargePrice(money); } if (!StringUtils.isEmpty(money.getOrderTimeout())) { configMapper.updateOrderTimeout(money); } if (!StringUtils.isEmpty(money.getOrderTotal())) { configMapper.updateOrderTotal(money); } if (!StringUtils.isEmpty(money.getOrderViewNum())) { BigDecimal ovN = new BigDecimal(money.getOrderViewNum()); if(ovN.compareTo(BigDecimal.ZERO)==0){ configMapper.updateOrderViewNum(money); }else if(ovN.compareTo(BigDecimal.ZERO)==1){ if(null!=money.getOrderTotal()&&!"".equals(money.getOrderTotal())){ money.setOrderViewNum(money.getOrderTotal()); configMapper.updateOrderViewNum(money); } } } } }