@@ -80,7 +80,6 @@ public class CallbackSmController extends BaseController { | |||||
userMouldVideoService.updateById(videoUnd); | userMouldVideoService.updateById(videoUnd); | ||||
} | } | ||||
userMouldVideoService.uploadVideo(videoUnd); | userMouldVideoService.uploadVideo(videoUnd); | ||||
return new ResultData(); | return new ResultData(); | ||||
} | } | ||||
@@ -188,7 +187,7 @@ public class CallbackSmController extends BaseController { | |||||
imgList.add(data.get("img_1")); | imgList.add(data.get("img_1")); | ||||
imgList.add(data.get("img_2")); | imgList.add(data.get("img_2")); | ||||
imgList.add(data.get("img_3")); | imgList.add(data.get("img_3")); | ||||
userDigitalAvatarOrderService.handlePhoto(userDigitalAvatarOrder,imgList); | |||||
userDigitalAvatarPhotoService.handlePhoto(userDigitalAvatarOrder,imgList); | |||||
}else{ | }else{ | ||||
UserDigitalAvatarOrder updOrder = new UserDigitalAvatarOrder(); | UserDigitalAvatarOrder updOrder = new UserDigitalAvatarOrder(); | ||||
updOrder.setId(userDigitalAvatarOrder.getId()); | updOrder.setId(userDigitalAvatarOrder.getId()); | ||||
@@ -449,7 +449,7 @@ public enum ErrorCode{ | |||||
MEM_MONTH_IS_USED(13105, "该用户本月已领取或未到领取条件"), | MEM_MONTH_IS_USED(13105, "该用户本月已领取或未到领取条件"), | ||||
GLOD_NOT_ENOUGH(13200, "金币不足"), | |||||
GLOD_NOT_UPDATE(13200, "金币修改失败"), | |||||
/** | /** | ||||
@@ -30,6 +30,9 @@ public class UserBasicProperty extends TenantEntity { | |||||
@TableField(exist = false) | @TableField(exist = false) | ||||
private Integer addGlod; | private Integer addGlod; | ||||
@TableField(exist = false) | |||||
private Integer addSumGlod; | |||||
@TableField(exist = false) | @TableField(exist = false) | ||||
private Integer reduceGlod; | private Integer reduceGlod; | ||||
@@ -2,6 +2,7 @@ package com.iformall.mapper; | |||||
import com.iformall.common.CommonMapper; | import com.iformall.common.CommonMapper; | ||||
import com.iformall.domain.po.UserBasicGlodConfig; | import com.iformall.domain.po.UserBasicGlodConfig; | ||||
import org.apache.ibatis.annotations.Param; | |||||
import java.util.List; | import java.util.List; | ||||
@@ -9,4 +10,6 @@ public interface UserBasicGlodConfigMapper extends CommonMapper<UserBasicGlodCon | |||||
List<UserBasicGlodConfig> findList(UserBasicGlodConfig record); | List<UserBasicGlodConfig> findList(UserBasicGlodConfig record); | ||||
UserBasicGlodConfig selectGlodConfig(@Param("projectType")Integer projectType, @Param("type")Integer type); | |||||
} | } |
@@ -9,8 +9,8 @@ public interface UserBasicPropertyMapper extends CommonMapper<UserBasicProperty, | |||||
List<UserBasicProperty> findList(UserBasicProperty record); | List<UserBasicProperty> findList(UserBasicProperty record); | ||||
int addGlod(UserBasicProperty record); | |||||
int addDigitalAvatarGlod(UserBasicProperty record); | |||||
int reduceGlod(UserBasicProperty record); | |||||
int reduceDigitalAvatarGlod(UserBasicProperty record); | |||||
} | } |
@@ -19,24 +19,14 @@ public interface UserBasicPropertyService { | |||||
PageInfo<UserBasicProperty> listAsPage(UserBasicProperty record, Integer pageIndex, Integer pageSize); | PageInfo<UserBasicProperty> listAsPage(UserBasicProperty record, Integer pageIndex, Integer pageSize); | ||||
/** | /** | ||||
* 充值 | |||||
* @param userId | |||||
* @param projectType | |||||
* @param extraId | |||||
* @param glod | |||||
*/ | |||||
void addRechargeGlod(Long userId, Integer projectType, Long extraId, Integer glod); | |||||
/** | |||||
* 消费 | |||||
* | |||||
* @param userId | * @param userId | ||||
* @param projectType | * @param projectType | ||||
* @param propertyLogType | * @param propertyLogType | ||||
* @param glod | |||||
* @param extraId | * @param extraId | ||||
* @param now | |||||
* @param glod | |||||
*/ | */ | ||||
void consumptionGlod(Long userId, Integer projectType, Integer propertyLogType, Integer glod, Long extraId, Date now); | |||||
void updUserGlod(Long userId, Integer projectType,Integer propertyLogType, Long extraId, Integer glod, Date now); | |||||
UserBasicProperty findById(Long id); | UserBasicProperty findById(Long id); | ||||
} | } |
@@ -179,24 +179,27 @@ public class ProductOrderServiceImpl implements ProductOrderService { | |||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
public void handleProductOrderSuccess(ProductOrder productOrder, PayQueryAdapterResult result) { | public void handleProductOrderSuccess(ProductOrder productOrder, PayQueryAdapterResult result) { | ||||
String lockKey = "productOrder:success:"+productOrder.getId(); | String lockKey = "productOrder:success:"+productOrder.getId(); | ||||
long time = System.currentTimeMillis() + 30000; | |||||
long time = System.currentTimeMillis() + 5000; | |||||
String timeStr = String.valueOf(time); | String timeStr = String.valueOf(time); | ||||
try{ | try{ | ||||
while (!redisLock.lock2(lockKey, timeStr)){ | |||||
Thread.sleep(1000); | |||||
// while (!redisLock.lock2(lockKey, timeStr)){ | |||||
// Thread.sleep(1000); | |||||
// } | |||||
if(!redisLock.lock2(lockKey, timeStr)){ | |||||
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请稍后重试"); | |||||
} | } | ||||
ProductOrder order = this.getById(productOrder.getId()); | ProductOrder order = this.getById(productOrder.getId()); | ||||
if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(order.getOrderStatus())){ | if(!EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode().equals(order.getOrderStatus())){ | ||||
return; | return; | ||||
} | } | ||||
Date now = new Date(); | |||||
order.setOpenId(result.getOpenId()); | order.setOpenId(result.getOpenId()); | ||||
order.setTransactionId(result.getTransactionId()); | order.setTransactionId(result.getTransactionId()); | ||||
order.setPaymentTime(result.getPayTime()); | order.setPaymentTime(result.getPayTime()); | ||||
order.setPayWay(result.getWay()); | order.setPayWay(result.getWay()); | ||||
order.setOrderStatus(result.getCode()); | order.setOrderStatus(result.getCode()); | ||||
order.setUpdateDate(new Date()); | |||||
order.setUpdateDate(now); | |||||
order.setIsOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | order.setIsOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | ||||
int num = productOrderMapper.orderPayUpdStatus(order); | int num = productOrderMapper.orderPayUpdStatus(order); | ||||
if(num == 0){ | if(num == 0){ | ||||
@@ -206,7 +209,8 @@ public class ProductOrderServiceImpl implements ProductOrderService { | |||||
} | } | ||||
Product product = productMapper.selectById(order.getProductId()); | Product product = productMapper.selectById(order.getProductId()); | ||||
if(EnumProductType.product_1.getCode().equals(product.getType())){ | if(EnumProductType.product_1.getCode().equals(product.getType())){ | ||||
userBasicPropertyService.addRechargeGlod(order.getUserId(),product.getProjectType(),order.getId(),product.getGlod()); | |||||
userBasicPropertyService.updUserGlod(order.getUserId(),product.getProjectType(),EnumPropertyLogType.RECHARGE.getCode(), | |||||
order.getId(),product.getGlod(),now); | |||||
} | } | ||||
}catch(Exception e){ | }catch(Exception e){ | ||||
throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | ||||
@@ -4,14 +4,19 @@ import com.github.pagehelper.PageHelper; | |||||
import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
import com.iformall.domain.po.UserBasicFrom; | import com.iformall.domain.po.UserBasicFrom; | ||||
import com.iformall.domain.po.UserBasicGlodConfig; | |||||
import com.iformall.domain.po.UserBasicPropertyLog; | import com.iformall.domain.po.UserBasicPropertyLog; | ||||
import com.iformall.domain.po.WxCUserBasicInfo; | import com.iformall.domain.po.WxCUserBasicInfo; | ||||
import com.iformall.enums.EnumGlodConfigType; | |||||
import com.iformall.enums.EnumProject; | |||||
import com.iformall.enums.EnumPropertyLogType; | import com.iformall.enums.EnumPropertyLogType; | ||||
import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
import com.iformall.mapper.UserBasicFromMapper; | import com.iformall.mapper.UserBasicFromMapper; | ||||
import com.iformall.mapper.UserBasicGlodConfigMapper; | |||||
import com.iformall.mapper.UserBasicPropertyLogMapper; | import com.iformall.mapper.UserBasicPropertyLogMapper; | ||||
import com.iformall.mapper.WxCUserBasicInfoMapper; | import com.iformall.mapper.WxCUserBasicInfoMapper; | ||||
import com.iformall.service.UserBasicFromService; | import com.iformall.service.UserBasicFromService; | ||||
import com.iformall.service.UserBasicPropertyService; | |||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
@@ -41,6 +46,12 @@ public class UserBasicFromServiceImpl implements UserBasicFromService { | |||||
@Autowired | @Autowired | ||||
WxCUserBasicInfoMapper wxCUserBasicInfoMapper; | WxCUserBasicInfoMapper wxCUserBasicInfoMapper; | ||||
@Autowired | |||||
UserBasicGlodConfigMapper userBasicGlodConfigMapper; | |||||
@Autowired | |||||
UserBasicPropertyService userBasicPropertyService; | |||||
@Override | @Override | ||||
public PageInfo<UserBasicFrom> listAsPage(UserBasicFrom record, Integer pageIndex, Integer pageSize) { | public PageInfo<UserBasicFrom> listAsPage(UserBasicFrom record, Integer pageIndex, Integer pageSize) { | ||||
PageInfo<UserBasicFrom> pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> userBasicFromMapper.findList(record)); | PageInfo<UserBasicFrom> pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> userBasicFromMapper.findList(record)); | ||||
@@ -83,16 +94,18 @@ public class UserBasicFromServiceImpl implements UserBasicFromService { | |||||
@Override | @Override | ||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
public void saveForm(UserBasicFrom from) { | public void saveForm(UserBasicFrom from) { | ||||
Date now = new Date(); | |||||
if(from.getId() == null){ | if(from.getId() == null){ | ||||
return; | return; | ||||
} | } | ||||
from.setCreateDate(new Date()); | |||||
from.setCreateDate(now); | |||||
try{ | try{ | ||||
int insert = userBasicFromMapper.insert(from); | int insert = userBasicFromMapper.insert(from); | ||||
if(insert == 1){ | if(insert == 1){ | ||||
logger.info("邀请加积分{}"+from.getFromUserId()); | logger.info("邀请加积分{}"+from.getFromUserId()); | ||||
//todo 邀请逻辑 | //todo 邀请逻辑 | ||||
userBasicPropertyService.updUserGlod(from.getFromUserId(),from.getFromProject(),EnumPropertyLogType.INVITE.getCode(), | |||||
from.getId(),null,now); | |||||
} | } | ||||
}catch(Exception e){ | }catch(Exception e){ | ||||
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR); | throw new MallinkException(ErrorCode.SYS_SERVER_ERROR); | ||||
@@ -5,17 +5,13 @@ import com.github.pagehelper.PageInfo; | |||||
import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
import com.iformall.enums.EnumProductOrderStatus; | |||||
import com.iformall.enums.EnumProductType; | |||||
import com.iformall.enums.EnumProject; | |||||
import com.iformall.enums.EnumPropertyLogType; | |||||
import com.iformall.enums.*; | |||||
import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
import com.iformall.mapper.ProductMapper; | |||||
import com.iformall.mapper.UserBasicPropertyLogMapper; | |||||
import com.iformall.mapper.UserBasicPropertyMapper; | |||||
import com.iformall.mapper.WxCUserBasicInfoMapper; | |||||
import com.iformall.mapper.*; | |||||
import com.iformall.service.UserBasicPropertyService; | import com.iformall.service.UserBasicPropertyService; | ||||
import com.iformall.utils.RedisLock; | |||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.flowable.bpmn.converter.EndEventXMLConverter; | |||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
@@ -43,6 +39,12 @@ public class UserBasicPropertyServiceImpl implements UserBasicPropertyService { | |||||
@Autowired | @Autowired | ||||
UserBasicPropertyLogMapper userBasicPropertyLogMapper; | UserBasicPropertyLogMapper userBasicPropertyLogMapper; | ||||
@Autowired | |||||
UserBasicGlodConfigMapper userBasicGlodConfigMapper; | |||||
@Autowired | |||||
RedisLock redisLock; | |||||
@Override | @Override | ||||
public PageInfo<UserBasicProperty> listAsPage(UserBasicProperty record, Integer pageIndex, Integer pageSize) { | public PageInfo<UserBasicProperty> listAsPage(UserBasicProperty record, Integer pageIndex, Integer pageSize) { | ||||
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> userBasicPropertyMapper.findList(record)); | return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> userBasicPropertyMapper.findList(record)); | ||||
@@ -50,83 +52,126 @@ public class UserBasicPropertyServiceImpl implements UserBasicPropertyService { | |||||
@Override | @Override | ||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
public void addRechargeGlod(Long userId, Integer projectType, Long extraId, Integer glod) { | |||||
public void updUserGlod(Long userId, Integer projectType,Integer propertyLogType, Long extraId, Integer glod, Date now) { | |||||
WxCUserBasicInfo basicInfo = wxCUserBasicInfoMapper.selectById(userId); | WxCUserBasicInfo basicInfo = wxCUserBasicInfoMapper.selectById(userId); | ||||
if(basicInfo == null){ | if(basicInfo == null){ | ||||
throw new MallinkException(ErrorCode.USER_IS_EMPTY); | throw new MallinkException(ErrorCode.USER_IS_EMPTY); | ||||
} | } | ||||
Date now = new Date(); | |||||
UserBasicProperty userBasicProperty = userBasicPropertyMapper.selectById(userId); | |||||
Integer befourGold = 0; | |||||
if(EnumProject.PROJECT_5.getCode().equals(projectType)){ | |||||
if(userBasicProperty == null){ | |||||
userBasicProperty = new UserBasicProperty(); | |||||
userBasicProperty.setId(userId); | |||||
userBasicProperty.setDigitalAvatarGlod(glod); | |||||
userBasicProperty.setDigitalAvatarResidueGlod(glod); | |||||
userBasicProperty.setUpdateDate(now); | |||||
userBasicPropertyMapper.insert(userBasicProperty); | |||||
}else{ | |||||
befourGold = userBasicProperty.getDigitalAvatarResidueGlod(); | |||||
userBasicProperty.setAddGlod(glod); | |||||
userBasicProperty.setUpdateDate(now); | |||||
userBasicPropertyMapper.addGlod(userBasicProperty); | |||||
} | |||||
UserBasicPropertyLog userBasicPropertyLog = new UserBasicPropertyLog(); | |||||
final IdWorker idWorker = IdWorker.get(); | |||||
userBasicPropertyLog.setId(idWorker.nextId()); | |||||
userBasicPropertyLog.setUserId(userId); | |||||
userBasicPropertyLog.setProjectType(projectType); | |||||
userBasicPropertyLog.setType(EnumPropertyLogType.RECHARGE.getCode()); | |||||
userBasicPropertyLog.setBefourGold(befourGold); | |||||
userBasicPropertyLog.setGoldNum(glod); | |||||
userBasicPropertyLog.setAfterGold(befourGold+glod); | |||||
userBasicPropertyLog.setExtraId(extraId); | |||||
userBasicPropertyLog.setCreateDate(now); | |||||
userBasicPropertyLogMapper.insert(userBasicPropertyLog); | |||||
} | |||||
Integer glodNum = handGlodNum(projectType,propertyLogType,glod); | |||||
if(glodNum == 0){ | |||||
throw new MallinkException(ErrorCode.GLOD_NOT_UPDATE.getCode(),"金币变动值为0"); | |||||
} | |||||
String lockKey = "userProperty:glod:"+userId; | |||||
long time = System.currentTimeMillis() + 5000; | |||||
String timeStr = String.valueOf(time); | |||||
try{ | |||||
while (!redisLock.lock2(lockKey, timeStr)){ | |||||
Thread.sleep(1000); | |||||
} | |||||
UserBasicProperty userBasicProperty = userBasicPropertyMapper.selectById(userId); | |||||
Integer befourGold = getUserGlod(userBasicProperty,projectType); | |||||
Integer afterGold = befourGold + glodNum; | |||||
if(afterGold < 0){ | |||||
throw new MallinkException(ErrorCode.GLOD_NOT_UPDATE.getCode(),"金币不足"); | |||||
} | |||||
Integer count = handUserProPery(userId,userBasicProperty,projectType,glodNum,now); | |||||
if(count != 1){ | |||||
throw new MallinkException(ErrorCode.GLOD_NOT_UPDATE.getCode(),"金币不足"); | |||||
} | |||||
UserBasicPropertyLog userBasicPropertyLog = new UserBasicPropertyLog(); | |||||
final IdWorker idWorker = IdWorker.get(); | |||||
userBasicPropertyLog.setId(idWorker.nextId()); | |||||
userBasicPropertyLog.setUserId(userId); | |||||
userBasicPropertyLog.setProjectType(projectType); | |||||
userBasicPropertyLog.setType(propertyLogType); | |||||
userBasicPropertyLog.setBefourGold(befourGold); | |||||
userBasicPropertyLog.setGoldNum(glodNum); | |||||
userBasicPropertyLog.setAfterGold(afterGold); | |||||
userBasicPropertyLog.setExtraId(extraId); | |||||
userBasicPropertyLog.setCreateDate(now); | |||||
userBasicPropertyLogMapper.insert(userBasicPropertyLog); | |||||
}catch(Exception e){ | |||||
throw new MallinkException(ErrorCode.GLOD_NOT_UPDATE); | |||||
}finally { | |||||
redisLock.unlock(lockKey, timeStr); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
public void consumptionGlod(Long userId, Integer projectType, Integer propertyLogType, Integer glod, Long extraId, Date now) { | |||||
WxCUserBasicInfo basicInfo = wxCUserBasicInfoMapper.selectById(userId); | |||||
if(basicInfo == null){ | |||||
throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||||
public UserBasicProperty findById(Long id) { | |||||
return userBasicPropertyMapper.selectById(id); | |||||
} | |||||
private Integer handGlodNum(Integer projectType, Integer propertyLogType, Integer glod){ | |||||
if(EnumPropertyLogType.REGISTER.getCode().equals(propertyLogType)){ | |||||
UserBasicGlodConfig glodConfig = userBasicGlodConfigMapper.selectGlodConfig(projectType, EnumGlodConfigType.register.getCode()); | |||||
if(glodConfig != null && glodConfig.getGlodNum() != null && glodConfig.getGlodNum() != 0){ | |||||
return glodConfig.getGlodNum(); | |||||
} | |||||
return 0; | |||||
}else if(EnumPropertyLogType.INVITE.getCode().equals(propertyLogType)){ | |||||
UserBasicGlodConfig glodConfig = userBasicGlodConfigMapper.selectGlodConfig(projectType, EnumGlodConfigType.invite.getCode()); | |||||
if(glodConfig != null && glodConfig.getGlodNum() != null && glodConfig.getGlodNum() != 0){ | |||||
return glodConfig.getGlodNum(); | |||||
} | |||||
return 0; | |||||
}else if(EnumPropertyLogType.RECHARGE.getCode().equals(propertyLogType)){ | |||||
return glod; | |||||
}else if(EnumPropertyLogType.CONSUMPTION_10.getCode().equals(propertyLogType)){ | |||||
if(glod > 0){ | |||||
return -glod; | |||||
} | |||||
return glod; | |||||
}else if(EnumPropertyLogType.CONSUMPTION_11.getCode().equals(propertyLogType)){ | |||||
if(glod > 0){ | |||||
return -glod; | |||||
} | |||||
return glod; | |||||
} | } | ||||
UserBasicProperty userBasicProperty = userBasicPropertyMapper.selectById(userId); | |||||
if(userBasicProperty == null || userBasicProperty.getDigitalAvatarResidueGlod() < glod){ | |||||
throw new MallinkException(ErrorCode.GLOD_NOT_ENOUGH); | |||||
return 0; | |||||
} | |||||
private Integer getUserGlod(UserBasicProperty userBasicProperty,Integer projectType){ | |||||
if(userBasicProperty == null){ | |||||
return 0; | |||||
} | } | ||||
UserBasicProperty updProperty = new UserBasicProperty(); | |||||
updProperty.setId(userId); | |||||
updProperty.setReduceGlod(glod); | |||||
updProperty.setUpdateDate(now); | |||||
int count = userBasicPropertyMapper.reduceGlod(updProperty); | |||||
if(count != 1){ | |||||
throw new MallinkException(ErrorCode.GLOD_NOT_ENOUGH.getCode(),"扣减异常"); | |||||
if(EnumProject.PROJECT_5.getCode().equals(projectType)){ | |||||
return userBasicProperty.getDigitalAvatarResidueGlod(); | |||||
} | } | ||||
UserBasicPropertyLog userBasicPropertyLog = new UserBasicPropertyLog(); | |||||
final IdWorker idWorker = IdWorker.get(); | |||||
userBasicPropertyLog.setId(idWorker.nextId()); | |||||
userBasicPropertyLog.setUserId(userId); | |||||
userBasicPropertyLog.setProjectType(projectType); | |||||
userBasicPropertyLog.setType(propertyLogType); | |||||
userBasicPropertyLog.setBefourGold(userBasicProperty.getDigitalAvatarResidueGlod()); | |||||
userBasicPropertyLog.setGoldNum(glod); | |||||
userBasicPropertyLog.setAfterGold(userBasicProperty.getDigitalAvatarResidueGlod()-glod); | |||||
userBasicPropertyLog.setExtraId(extraId); | |||||
userBasicPropertyLog.setCreateDate(now); | |||||
userBasicPropertyLogMapper.insert(userBasicPropertyLog); | |||||
return 0; | |||||
} | } | ||||
@Override | |||||
public UserBasicProperty findById(Long id) { | |||||
return userBasicPropertyMapper.selectById(id); | |||||
private Integer handUserProPery(Long userId, UserBasicProperty userBasicProperty, Integer projectType, Integer glodNum, Date now){ | |||||
int count = 0; | |||||
if(EnumProject.PROJECT_5.getCode().equals(projectType)){ | |||||
if(userBasicProperty == null){ | |||||
userBasicProperty = new UserBasicProperty(); | |||||
userBasicProperty.setId(userId); | |||||
userBasicProperty.setDigitalAvatarGlod(glodNum); | |||||
userBasicProperty.setDigitalAvatarResidueGlod(glodNum); | |||||
userBasicProperty.setUpdateDate(now); | |||||
count = userBasicPropertyMapper.insert(userBasicProperty); | |||||
}else{ | |||||
if(glodNum > 0){ | |||||
//余额和总金额都会增加 | |||||
Integer addSumGlod = glodNum; | |||||
userBasicProperty.setAddGlod(glodNum); | |||||
userBasicProperty.setAddSumGlod(addSumGlod); | |||||
userBasicProperty.setUpdateDate(now); | |||||
count = userBasicPropertyMapper.addDigitalAvatarGlod(userBasicProperty); | |||||
}else if(glodNum < 0){ | |||||
userBasicProperty.setReduceGlod(glodNum); | |||||
userBasicProperty.setUpdateDate(now); | |||||
count = userBasicPropertyMapper.reduceDigitalAvatarGlod(userBasicProperty); | |||||
} | |||||
} | |||||
} | |||||
return count; | |||||
} | } | ||||
@@ -60,6 +60,5 @@ public interface UserDigitalAvatarOrderService { | |||||
void createPhoto(UserDigitalAvatarOrder record); | void createPhoto(UserDigitalAvatarOrder record); | ||||
void handlePhoto(UserDigitalAvatarOrder record,List<String> imgList); | |||||
} | } |
@@ -20,4 +20,6 @@ public interface UserDigitalAvatarPhotoService { | |||||
void handleSuperPhoto(UserDigitalAvatarPhoto record, String img); | void handleSuperPhoto(UserDigitalAvatarPhoto record, String img); | ||||
void updateById(UserDigitalAvatarPhoto updPhoto); | void updateById(UserDigitalAvatarPhoto updPhoto); | ||||
void handlePhoto(UserDigitalAvatarOrder record,List<String> imgList); | |||||
} | } |
@@ -142,14 +142,14 @@ public class UserDigitalAvatarOrderServiceImpl implements UserDigitalAvatarOrder | |||||
if(record.getPrice() > 0){ | if(record.getPrice() > 0){ | ||||
UserBasicProperty userBasicProperty = userBasicPropertyMapper.selectById(record.getUserId()); | UserBasicProperty userBasicProperty = userBasicPropertyMapper.selectById(record.getUserId()); | ||||
if(userBasicProperty == null || userBasicProperty.getDigitalAvatarResidueGlod() < record.getPrice()){ | if(userBasicProperty == null || userBasicProperty.getDigitalAvatarResidueGlod() < record.getPrice()){ | ||||
return new ResultData(ErrorCode.GLOD_NOT_ENOUGH); | |||||
return new ResultData(ErrorCode.GLOD_NOT_UPDATE.getCode(),"金币余不足"); | |||||
} | } | ||||
} | } | ||||
try{ | try{ | ||||
UserDigitalAvatarOrderServiceImpl proxy = (UserDigitalAvatarOrderServiceImpl) AopContext.currentProxy(); | UserDigitalAvatarOrderServiceImpl proxy = (UserDigitalAvatarOrderServiceImpl) AopContext.currentProxy(); | ||||
proxy.handleOrder(record); | proxy.handleOrder(record); | ||||
this.createPhoto(record); | |||||
proxy.createPhoto(record); | |||||
return new ResultData(record); | return new ResultData(record); | ||||
}catch(MallinkException e){ | }catch(MallinkException e){ | ||||
return new ResultData(e.getErrorCode(),e.getMessage()); | return new ResultData(e.getErrorCode(),e.getMessage()); | ||||
@@ -207,8 +207,8 @@ public class UserDigitalAvatarOrderServiceImpl implements UserDigitalAvatarOrder | |||||
public void handleOrder(UserDigitalAvatarOrder record) { | public void handleOrder(UserDigitalAvatarOrder record) { | ||||
Date now = new Date(); | Date now = new Date(); | ||||
if(record.getPrice() > 0){ | if(record.getPrice() > 0){ | ||||
userBasicPropertyService.consumptionGlod(record.getUserId(),EnumProject.PROJECT_5.getCode(), EnumPropertyLogType.CONSUMPTION_10.getCode(), | |||||
record.getPrice(),record.getId(),now); | |||||
userBasicPropertyService.updUserGlod(record.getUserId(),EnumProject.PROJECT_5.getCode(), EnumPropertyLogType.CONSUMPTION_10.getCode(), | |||||
record.getId(),record.getPrice(),now); | |||||
} | } | ||||
final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
record.setId(idWorker.nextId()); | record.setId(idWorker.nextId()); | ||||
@@ -266,7 +266,7 @@ public class UserDigitalAvatarOrderServiceImpl implements UserDigitalAvatarOrder | |||||
DigitalAvatarResult result = AiDigitalAvatarHelper.digitalAvatarPhoto(param,record.getId()); | DigitalAvatarResult result = AiDigitalAvatarHelper.digitalAvatarPhoto(param,record.getId()); | ||||
if(result.isSuccess()){ | if(result.isSuccess()){ | ||||
UserDigitalAvatarOrderServiceImpl proxy = (UserDigitalAvatarOrderServiceImpl) AopContext.currentProxy(); | |||||
UserDigitalAvatarPhotoServiceImpl proxy = (UserDigitalAvatarPhotoServiceImpl) AopContext.currentProxy(); | |||||
proxy.handlePhoto(record,result.getImgList()); | proxy.handlePhoto(record,result.getImgList()); | ||||
}else{ | }else{ | ||||
updOrder.setStatus(EnumDigitalAvatarOrderStatus.fail.getCode()); | updOrder.setStatus(EnumDigitalAvatarOrderStatus.fail.getCode()); | ||||
@@ -288,56 +288,4 @@ public class UserDigitalAvatarOrderServiceImpl implements UserDigitalAvatarOrder | |||||
} | } | ||||
@Override | |||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
public void handlePhoto(UserDigitalAvatarOrder record,List<String> imgList){ | |||||
String lockKey = "digitalAvatar:handlePhoto:"+record.getId(); | |||||
long time = System.currentTimeMillis() + 5000; | |||||
String timeStr = String.valueOf(time); | |||||
try{ | |||||
while (!redisLock.lock2(lockKey, timeStr)){ | |||||
Thread.sleep(2000); | |||||
} | |||||
UserDigitalAvatarOrder userDigitalAvatarOrder = userDigitalAvatarOrderMapper.selectById(record.getId()); | |||||
if(EnumDigitalAvatarOrderStatus.finish.getCode().equals(userDigitalAvatarOrder.getStatus())){ | |||||
return; | |||||
} | |||||
Date now = new Date(); | |||||
UserDigitalAvatarOrder updOrder = new UserDigitalAvatarOrder(); | |||||
updOrder.setId(record.getId()); | |||||
updOrder.setStatus(EnumDigitalAvatarOrderStatus.finish.getCode()); | |||||
updOrder.setMsg("success"); | |||||
updOrder.setUpdateDate(now); | |||||
userDigitalAvatarOrderMapper.updateById(updOrder); | |||||
try{ | |||||
final IdWorker idWorker = IdWorker.get(); | |||||
for (String img: imgList) { | |||||
InputStream inputStream = Base64Util.base2InputStream(img); | |||||
String img_url = aliyunOSS.upload(record.getTenantId(), ".png", inputStream); | |||||
UserDigitalAvatarPhoto userDigitalAvatarPhoto = new UserDigitalAvatarPhoto(); | |||||
userDigitalAvatarPhoto.setId(idWorker.nextId()); | |||||
userDigitalAvatarPhoto.setOrderId(record.getId()); | |||||
userDigitalAvatarPhoto.setUserId(record.getUserId()); | |||||
userDigitalAvatarPhoto.setImage(img_url); | |||||
userDigitalAvatarPhoto.setStatus(EnumDigitalAvatarPhotoStatus.def.getCode()); | |||||
userDigitalAvatarPhoto.setCreateDate(now); | |||||
userDigitalAvatarPhoto.setUpdateDate(now); | |||||
userDigitalAvatarPhotoMapper.insert(userDigitalAvatarPhoto); | |||||
} | |||||
}catch(Exception e){ | |||||
throw new MallinkException(ErrorCode.PICTURE_ANALYZING_ERROR.getCode(),"上传图片异常"); | |||||
} | |||||
} catch(MallinkException e){ | |||||
throw e; | |||||
} catch(Exception e){ | |||||
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR); | |||||
}finally { | |||||
redisLock.unlock(lockKey, timeStr); | |||||
} | |||||
} | |||||
} | } |
@@ -7,6 +7,7 @@ import com.iformall.domain.po.sm.*; | |||||
import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
import com.iformall.file.aliyun.AliyunOSS; | import com.iformall.file.aliyun.AliyunOSS; | ||||
import com.iformall.mapper.UserDigitalAvatarOrderMapper; | |||||
import com.iformall.mapper.UserDigitalAvatarPhotoMapper; | import com.iformall.mapper.UserDigitalAvatarPhotoMapper; | ||||
import com.iformall.service.UserBasicPropertyService; | import com.iformall.service.UserBasicPropertyService; | ||||
import com.iformall.service.sm.*; | import com.iformall.service.sm.*; | ||||
@@ -33,6 +34,9 @@ public class UserDigitalAvatarPhotoServiceImpl implements UserDigitalAvatarPhoto | |||||
@Autowired | @Autowired | ||||
UserDigitalAvatarPhotoMapper userDigitalAvatarPhotoMapper; | UserDigitalAvatarPhotoMapper userDigitalAvatarPhotoMapper; | ||||
@Autowired | |||||
UserDigitalAvatarOrderMapper userDigitalAvatarOrderMapper; | |||||
@Autowired | @Autowired | ||||
UserBasicPropertyService userBasicPropertyService; | UserBasicPropertyService userBasicPropertyService; | ||||
@@ -75,8 +79,8 @@ public class UserDigitalAvatarPhotoServiceImpl implements UserDigitalAvatarPhoto | |||||
Integer price = 0; | Integer price = 0; | ||||
record.setPrice(price); | record.setPrice(price); | ||||
if(price > 0){ | if(price > 0){ | ||||
userBasicPropertyService.consumptionGlod(record.getUserId(),EnumProject.PROJECT_5.getCode(), EnumPropertyLogType.CONSUMPTION_11.getCode(), | |||||
price,record.getId(),now); | |||||
userBasicPropertyService.updUserGlod(record.getUserId(),EnumProject.PROJECT_5.getCode(), EnumPropertyLogType.CONSUMPTION_11.getCode(), | |||||
record.getId(),price,now); | |||||
} | } | ||||
UserDigitalAvatarPhoto updPhoto = new UserDigitalAvatarPhoto(); | UserDigitalAvatarPhoto updPhoto = new UserDigitalAvatarPhoto(); | ||||
@@ -126,11 +130,11 @@ public class UserDigitalAvatarPhotoServiceImpl implements UserDigitalAvatarPhoto | |||||
@Override | @Override | ||||
public void handleSuperPhoto(UserDigitalAvatarPhoto record, String img) { | public void handleSuperPhoto(UserDigitalAvatarPhoto record, String img) { | ||||
String lockKey = "digitalAvatar:superPhoto:"+record.getId(); | String lockKey = "digitalAvatar:superPhoto:"+record.getId(); | ||||
long time = System.currentTimeMillis() + 5000; | |||||
long time = System.currentTimeMillis() + 10000; | |||||
String timeStr = String.valueOf(time); | String timeStr = String.valueOf(time); | ||||
try{ | try{ | ||||
while (!redisLock.lock2(lockKey, timeStr)){ | |||||
Thread.sleep(2000); | |||||
if(!redisLock.lock2(lockKey, timeStr)){ | |||||
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请稍后重试"); | |||||
} | } | ||||
UserDigitalAvatarPhoto userDigitalAvatarPhoto = userDigitalAvatarPhotoMapper.selectById(record.getId()); | UserDigitalAvatarPhoto userDigitalAvatarPhoto = userDigitalAvatarPhotoMapper.selectById(record.getId()); | ||||
if(EnumDigitalAvatarPhotoStatus.finish.getCode().equals(userDigitalAvatarPhoto.getStatus())){ | if(EnumDigitalAvatarPhotoStatus.finish.getCode().equals(userDigitalAvatarPhoto.getStatus())){ | ||||
@@ -162,4 +166,55 @@ public class UserDigitalAvatarPhotoServiceImpl implements UserDigitalAvatarPhoto | |||||
userDigitalAvatarPhotoMapper.updateById(updPhoto); | userDigitalAvatarPhotoMapper.updateById(updPhoto); | ||||
} | } | ||||
@Override | |||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
public void handlePhoto(UserDigitalAvatarOrder record,List<String> imgList){ | |||||
String lockKey = "digitalAvatar:handlePhoto:"+record.getId(); | |||||
long time = System.currentTimeMillis() + 10000; | |||||
String timeStr = String.valueOf(time); | |||||
try{ | |||||
if (!redisLock.lock2(lockKey, timeStr)){ | |||||
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请稍后重试"); | |||||
} | |||||
UserDigitalAvatarOrder userDigitalAvatarOrder = userDigitalAvatarOrderMapper.selectById(record.getId()); | |||||
if(EnumDigitalAvatarOrderStatus.finish.getCode().equals(userDigitalAvatarOrder.getStatus())){ | |||||
return; | |||||
} | |||||
Date now = new Date(); | |||||
UserDigitalAvatarOrder updOrder = new UserDigitalAvatarOrder(); | |||||
updOrder.setId(record.getId()); | |||||
updOrder.setStatus(EnumDigitalAvatarOrderStatus.finish.getCode()); | |||||
updOrder.setMsg("success"); | |||||
updOrder.setUpdateDate(now); | |||||
userDigitalAvatarOrderMapper.updateById(updOrder); | |||||
try{ | |||||
final IdWorker idWorker = IdWorker.get(); | |||||
for (String img: imgList) { | |||||
InputStream inputStream = Base64Util.base2InputStream(img); | |||||
String img_url = aliyunOSS.upload(record.getTenantId(), ".png", inputStream); | |||||
UserDigitalAvatarPhoto userDigitalAvatarPhoto = new UserDigitalAvatarPhoto(); | |||||
userDigitalAvatarPhoto.setId(idWorker.nextId()); | |||||
userDigitalAvatarPhoto.setOrderId(record.getId()); | |||||
userDigitalAvatarPhoto.setUserId(record.getUserId()); | |||||
userDigitalAvatarPhoto.setImage(img_url); | |||||
userDigitalAvatarPhoto.setStatus(EnumDigitalAvatarPhotoStatus.def.getCode()); | |||||
userDigitalAvatarPhoto.setCreateDate(now); | |||||
userDigitalAvatarPhoto.setUpdateDate(now); | |||||
userDigitalAvatarPhotoMapper.insert(userDigitalAvatarPhoto); | |||||
} | |||||
}catch(Exception e){ | |||||
throw new MallinkException(ErrorCode.PICTURE_ANALYZING_ERROR.getCode(),"上传图片异常"); | |||||
} | |||||
} catch(MallinkException e){ | |||||
throw e; | |||||
} catch(Exception e){ | |||||
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR); | |||||
}finally { | |||||
redisLock.unlock(lockKey, timeStr); | |||||
} | |||||
} | |||||
} | } |
@@ -158,7 +158,7 @@ public class AiDigitalAvatarHelper { | |||||
// log.info("生成照片start request:" + param.getBg_img()); | // log.info("生成照片start request:" + param.getBg_img()); | ||||
String response = HttpUtil.doAiVideoPost(digital_avatar + "/logo_img", JSONObject.toJSONString(param)); | String response = HttpUtil.doAiVideoPost(digital_avatar + "/logo_img", JSONObject.toJSONString(param)); | ||||
log.info("照片超分end response:"+response); | |||||
log.info("生成照片end response:"+response); | |||||
ShareImgResult result = new ShareImgResult(); | ShareImgResult result = new ShareImgResult(); | ||||
@@ -198,14 +198,16 @@ public class AiDigitalAvatarHelper { | |||||
// System.out.println(result); | // System.out.println(result); | ||||
DigitalAvatarParam param = new DigitalAvatarParam(); | |||||
param.setBg_img("素白"); | |||||
String img = Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/capi/2023-08-31/91f69a7fdac146159d2408baaad26619.jpg?x-oss-process=image/resize,w_10000/quality,q_60"); | |||||
param.setImg_lift(img); | |||||
param.setImg_middle("None"); | |||||
param.setImg_right("None"); | |||||
DigitalAvatarResult result = AiDigitalAvatarHelper.digitalAvatarPhoto(param,100001l); | |||||
System.out.println(result); | |||||
// DigitalAvatarParam param = new DigitalAvatarParam(); | |||||
// param.setBg_img("素白"); | |||||
// String img = Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/capi/2023-08-31/91f69a7fdac146159d2408baaad26619.jpg?x-oss-process=image/resize,w_10000/quality,q_60"); | |||||
// param.setImg_lift(img); | |||||
// param.setImg_middle("None"); | |||||
// param.setImg_right("None"); | |||||
// DigitalAvatarResult result = AiDigitalAvatarHelper.digitalAvatarPhoto(param,100001l); | |||||
// System.out.println(result); | |||||
} | } | ||||
@@ -45,4 +45,12 @@ | |||||
<include refid="dynamicWhereConditions" /> | <include refid="dynamicWhereConditions" /> | ||||
</select> | </select> | ||||
<select id="selectGlodConfig" parameterType="java.util.HashMap" resultMap="BaseResultMap"> | |||||
select <include refid="allColumns" /> | |||||
from user_basic_glod_config | |||||
where `project_type` = #{projectType} | |||||
and `type` = #{type} | |||||
</select> | |||||
</mapper> | </mapper> |
@@ -41,15 +41,17 @@ | |||||
<include refid="dynamicWhereConditions" /> | <include refid="dynamicWhereConditions" /> | ||||
</select> | </select> | ||||
<update id="addGlod" parameterType="com.iformall.domain.po.UserBasicProperty"> | |||||
<update id="addDigitalAvatarGlod" parameterType="com.iformall.domain.po.UserBasicProperty"> | |||||
update user_basic_property | update user_basic_property | ||||
set `update_date` = #{updateDate} | set `update_date` = #{updateDate} | ||||
,`digital_avatar_glod` = digital_avatar_glod+#{addGlod} | |||||
<if test=" null != addSumGlod "> | |||||
,`digital_avatar_glod` = digital_avatar_glod+#{addSumGlod} | |||||
</if> | |||||
,`digital_avatar_residue_glod` = digital_avatar_residue_glod+#{addGlod} | ,`digital_avatar_residue_glod` = digital_avatar_residue_glod+#{addGlod} | ||||
where id = #{id} | where id = #{id} | ||||
</update> | </update> | ||||
<update id="reduceGlod" parameterType="com.iformall.domain.po.UserBasicProperty"> | |||||
<update id="reduceDigitalAvatarGlod" parameterType="com.iformall.domain.po.UserBasicProperty"> | |||||
update user_basic_property | update user_basic_property | ||||
set `update_date` = #{updateDate} | set `update_date` = #{updateDate} | ||||
,`digital_avatar_residue_glod` = digital_avatar_residue_glod-#{reduceGlod} | ,`digital_avatar_residue_glod` = digital_avatar_residue_glod-#{reduceGlod} | ||||