Commit 974e16e5 by guojuxing

Merge remote-tracking branch 'origin/developer' into developer

parents d6b8b717 87378aba
......@@ -9,7 +9,8 @@ package com.gic.enterprise.constant;
public enum AccountStandardEnum {
SMS(2, "短信"),
VOICE(3, "语音"),
CALL(4, "双向呼叫")
CALL(4, "双向呼叫"),
INTERNATIONAL_SMS(4, "海外短信")
;
private Integer code;
private String msg;
......
......@@ -56,6 +56,8 @@ public interface Constants {
*/
String ENTERPRISE_BILLING_SMS_PACKAGE_COUNT = "enterprise_billing_sms_package_count";
String ENTERPRISE_BILLING_SMS_PACKAGE_COUNT_LOCK = "enterprise_billing_sms_package_count_lock";
/**
* 审批的url
*/
......
......@@ -12,6 +12,17 @@ import com.gic.enterprise.dto.InternationalSmsRecordDTO;
public interface InternationalSmsRecordApiService {
/**
* @Title: verifySendInternationalSms
* @Description: 发送海外短信
* @author zhiwj
* @param enterpriseId
* @param sendCount
* @return com.gic.api.base.commons.ServiceResponse<java.lang.Void>
* @throws
*/
ServiceResponse<Void> verifySendInternationalSms(Integer enterpriseId, Integer sendCount);
/**
* 保存明细
* @Title: saveInternationalSmsRecord
* @Description:
......
......@@ -2,6 +2,7 @@ package com.gic.enterprise.service;
import com.gic.enterprise.dto.BillingEnterpriseSmsPackageDTO;
import com.gic.enterprise.entity.TabBillingEnterpriseSmsPackage;
import org.redisson.api.RAtomicLong;
import java.util.List;
/**
......@@ -41,6 +42,7 @@ public interface BillingEnterpriseSmsPackageService {
/**
* 查询该商户套餐包里全部拥有的可用短信条数
* @return
*/
Integer getTotalSmsInPackageByEnterpriseId(Integer enterpriseId);
RAtomicLong getTotalSmsInPackageByEnterpriseId(Integer enterpriseId);
}
package com.gic.enterprise.service.impl;
import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.constant.Constants;
import com.gic.enterprise.dao.mapper.TabBillingEnterpriseSmsPackageMapper;
import com.gic.enterprise.dto.BillingEnterpriseSmsPackageDTO;
import com.gic.enterprise.entity.TabBillingEnterpriseSmsPackage;
import com.gic.enterprise.service.BillingEnterpriseSmsPackageService;
import com.gic.redis.data.util.RedisUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -15,6 +21,8 @@ import java.util.List;
@Service("billingEnterpriseSmsPackageService")
public class BillingEnterpriseSmsPackageServiceImpl implements BillingEnterpriseSmsPackageService {
private Logger logger = LogManager.getLogger(BillingEnterpriseSmsPackageServiceImpl.class);
@Autowired
private TabBillingEnterpriseSmsPackageMapper tabBillingEnterpriseSmsPackageMapper;
......@@ -61,7 +69,17 @@ public class BillingEnterpriseSmsPackageServiceImpl implements BillingEnterprise
}
@Override
public Integer getTotalSmsInPackageByEnterpriseId(Integer enterpriseId) {
return tabBillingEnterpriseSmsPackageMapper.getTotalSmsInPackageByEnterpriseId(enterpriseId);
public RAtomicLong getTotalSmsInPackageByEnterpriseId(Integer enterpriseId) {
RedissonClient redisClient = RedisUtil.getRedisClient();
RAtomicLong smsCountR = redisClient.getAtomicLong(Constants.ENTERPRISE_BILLING_SMS_PACKAGE_COUNT + enterpriseId);
long smsPackageCount = smsCountR.get();
if (smsPackageCount == 0) {
RedisUtil.lock(Constants.ENTERPRISE_BILLING_SMS_PACKAGE_COUNT_LOCK + enterpriseId, 30L);
logger.info("redis中没有套餐包 查询数据库:{}", enterpriseId);
Integer totalSms = tabBillingEnterpriseSmsPackageMapper.getTotalSmsInPackageByEnterpriseId(enterpriseId);
smsCountR.set(totalSms);
RedisUtil.unlock(Constants.ENTERPRISE_BILLING_SMS_PACKAGE_COUNT_LOCK + enterpriseId);
}
return smsCountR;
}
}
......@@ -3,13 +3,14 @@ package com.gic.enterprise.service.outer.impl;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.enterprise.constant.AccountStandardEnum;
import com.gic.enterprise.constant.Constants;
import com.gic.enterprise.dto.DictDTO;
import com.gic.enterprise.dto.InternationalSmsRecordDTO;
import com.gic.enterprise.service.BillingAccountService;
import com.gic.enterprise.service.BillingInternationalSmsRecordService;
import com.gic.enterprise.service.DictApiService;
import com.gic.enterprise.service.InternationalSmsRecordApiService;
import com.gic.enterprise.entity.TabBillingAccount;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.response.EnterpriseServiceResponse;
import com.gic.enterprise.service.*;
import com.gic.mq.sdk.GicMQClient;
import com.gic.store.utils.valid.ValidUtil;
import org.apache.logging.log4j.LogManager;
......@@ -36,6 +37,28 @@ public class InternationalSmsRecordApiServiceImpl implements InternationalSmsRec
private BillingInternationalSmsRecordService billingInternationalSmsRecordService;
@Autowired
private DictApiService dictApiService;
@Autowired
private AccountStandardService accountStandardService;
@Override
public ServiceResponse<Void> verifySendInternationalSms(Integer enterpriseId, Integer sendCount) {
if (enterpriseId == null || sendCount == null) {
return EnterpriseServiceResponse.failure(ErrorCode.PARAMETER_ERROR);
}
TabBillingAccount billingAccount = billingAccountService.getByEnterpriseId(enterpriseId);
Double accountBalance = billingAccount.getAccountBalance();
Integer unitFee = accountStandardService.queryUnitFee(enterpriseId, AccountStandardEnum.SMS.getCode());
double needFee = (double) (sendCount * unitFee) / 1000;
if (needFee - accountBalance > 5000d) {
logger.info("enterpriseId:{}, 余额:{}, 发送条数:{}, 不能发送", enterpriseId, accountBalance, sendCount);
return EnterpriseServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "余额不足, 不能发送");
} else {
logger.info("enterpriseId:{}, 余额:{}, 发送条数:{}, 可以发送", enterpriseId, accountBalance, sendCount);
return EnterpriseServiceResponse.success();
}
}
@Override
public ServiceResponse<Void> saveInternationalSmsRecord(InternationalSmsRecordDTO internationalSmsRecordDTO) {
......
......@@ -12,12 +12,10 @@ import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.response.EnterpriseServiceResponse;
import com.gic.enterprise.service.*;
import com.gic.mq.sdk.GicMQClient;
import com.gic.redis.data.util.RedisUtil;
import com.gic.store.utils.valid.ValidUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -50,8 +48,7 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
if (enterpriseId == null || sendCount == null) {
return EnterpriseServiceResponse.failure(ErrorCode.PARAMETER_ERROR);
}
RedissonClient redisClient = RedisUtil.getRedisClient();
RAtomicLong smsCountR = redisClient.getAtomicLong(Constants.ENTERPRISE_BILLING_SMS_PACKAGE_COUNT + enterpriseId);
RAtomicLong smsCountR = billingEnterpriseSmsPackageService.getTotalSmsInPackageByEnterpriseId(enterpriseId);
long smsPackageCount = smsCountR.get();
if (smsPackageCount > sendCount) {
logger.info("enterpriseId:{}, 短信套餐包条数:{}, 发送条数:{}, 可以发送", enterpriseId, smsPackageCount, sendCount);
......@@ -101,8 +98,7 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
SmsRecordDTO smsRecordDTO = JSON.parseObject(arg, SmsRecordDTO.class);
// 判断是扣套餐包还是扣余额
RedissonClient redisClient = RedisUtil.getRedisClient();
RAtomicLong smsCount = redisClient.getAtomicLong(Constants.ENTERPRISE_BILLING_SMS_PACKAGE_COUNT + smsRecordDTO.getEnterpriseId());
RAtomicLong smsCount = billingEnterpriseSmsPackageService.getTotalSmsInPackageByEnterpriseId(smsRecordDTO.getEnterpriseId());
smsRecordDTO.setCacheStatus(0);
smsRecordDTO.setDatabaseStatus(0);
......
......@@ -378,16 +378,14 @@
<include refid="Base_Column_List" />
from tab_billing_sms_record
<where>
and enterprise_id = #{enterpriseId}
and cache_status = 1
and database_status = 1
<if test="enterpriseId != null ">
and enterprise_id = #{enterpriseId}
</if>
<if test="startTime != null and startTime != '' ">
and DATE_FORMAT(deduction_time,'%Y-%m-%d') &gt;= #{startTime}
and deduction_time &gt;= #{startTime}
</if>
<if test="endTime != null and startTime != '' ">
and DATE_FORMAT(deduction_time,'%Y-%m-%d') &lt;= #{endTime}
and deduction_time &lt;= #{endTime}
</if>
<if test="payType != null ">
and pay_type = #{payType}
......
......@@ -11,6 +11,7 @@ import com.gic.enterprise.service.DictApiService;
import com.gic.enterprise.utils.ResultControllerUtils;
import com.gic.enterprise.utils.UserDetailUtils;
import com.gic.enterprise.web.vo.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -91,6 +92,13 @@ public class BillingRecordController {
@RequestMapping("/list-sms")
public RestResponse listSmsRecord(RecordQO recordQO) {
recordQO.setEnterpriseId(UserDetailUtils.getUserDetail().getEnterpriseId());
if (StringUtils.isNotBlank(recordQO.getStartTime())) {
recordQO.setStartTime(recordQO.getStartTime() + " 00:00:00");
}
if (StringUtils.isNotBlank(recordQO.getEndTime())) {
recordQO.setEndTime(recordQO.getEndTime() + " 23:59:59");
}
ServiceResponse<Page<SmsRecordDTO>> serviceResponse = billingRecordApiService.listSmsRecord(recordQO);
if (serviceResponse.isSuccess()) {
Page page = new Page(serviceResponse.getResult().getCurrentPage(), serviceResponse.getResult().getPageSize(), serviceResponse.getResult().getTotalPage(), serviceResponse.getResult().getTotalCount());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment