| | |
| | | package com.ks.goldcorn.service.remote; |
| | | |
| | | import com.ks.goldcorn.exception.GoldAppException; |
| | | import com.ks.goldcorn.mapper.GoldCornAppInfoMapper; |
| | | import com.ks.goldcorn.mapper.GoldCornBalanceMapper; |
| | | import com.ks.goldcorn.pojo.DO.GoldCornAppInfo; |
| | | import com.ks.goldcorn.pojo.DO.GoldCornBalance; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ks.goldcorn.service.GoldCornAppManager; |
| | | import org.apache.dubbo.config.annotation.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @Service(version = "1.0") |
| | | public class GoldCornBalanceServiceImpl implements GoldCornBalanceService { |
| | | |
| | | @Resource |
| | | private GoldCornBalanceMapper goldCornBalanceMapper; |
| | | |
| | | @Resource |
| | | private GoldCornAppInfoMapper goldCornAppInfoMapper; |
| | | private GoldCornAppManager goldCornAppManager; |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void init(String appCode, String uid) throws GoldAppException { |
| | | GoldCornAppInfo app = goldCornAppInfoMapper.selectByAppCode(appCode); |
| | | if (app == null) { |
| | | throw new GoldAppException(GoldAppException.CODE_NOT_EXIST, "应用不存在"); |
| | | } |
| | | |
| | | GoldCornBalance balance = goldCornBalanceMapper.selectByAppIdAndUid(app.getId(), uid); |
| | | Long appId = goldCornAppManager.getAppId(appCode); |
| | | GoldCornBalance balance = goldCornBalanceMapper.selectByAppIdAndUid(appId, uid); |
| | | if (balance == null) { |
| | | balance = new GoldCornBalance(); |
| | | balance.setAppId(app.getId()); |
| | | balance.setAppId(appId); |
| | | balance.setBalance(0L); |
| | | balance.setCreateTime(new Date()); |
| | | balance.setUid(uid); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Long getBalance(Long appId, String uid) { |
| | | public Long getBalance(String appCode, String uid) throws GoldAppException { |
| | | Long appId = goldCornAppManager.getAppId(appCode); |
| | | GoldCornBalance balance = goldCornBalanceMapper.selectByAppIdAndUid(appId, uid); |
| | | if (balance != null) { |
| | | return balance.getBalance(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<GoldCornBalance> getBalanceList(Long appId, List<String> uidList) { |
| | | public List<GoldCornBalance> getBalanceList(String appCode, List<String> uidList) throws GoldAppException { |
| | | Long appId = goldCornAppManager.getAppId(appCode); |
| | | return goldCornBalanceMapper.listByUids(appId, uidList); |
| | | } |
| | | |