From 5e54f329dfe0220ae6ca878f6502a00ba95c774c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 14 十一月 2020 16:38:42 +0800
Subject: [PATCH] admin

---
 service-goldcorn/src/main/java/com/ks/goldcorn/service/remote/GoldCornTradeServiceImpl.java |   55 ++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/service-goldcorn/src/main/java/com/ks/goldcorn/service/remote/GoldCornTradeServiceImpl.java b/service-goldcorn/src/main/java/com/ks/goldcorn/service/remote/GoldCornTradeServiceImpl.java
index b8a2a08..d30a846 100644
--- a/service-goldcorn/src/main/java/com/ks/goldcorn/service/remote/GoldCornTradeServiceImpl.java
+++ b/service-goldcorn/src/main/java/com/ks/goldcorn/service/remote/GoldCornTradeServiceImpl.java
@@ -9,13 +9,14 @@
 import com.ks.goldcorn.mapper.GoldCornConsumeSourceMapper;
 import com.ks.goldcorn.mapper.GoldCornGetSourceMapper;
 import com.ks.goldcorn.pojo.DO.*;
+import com.ks.goldcorn.service.GoldCornBalanceManager;
 import com.ks.goldcorn.service.GoldCornRecordManager;
-import org.springframework.stereotype.Service;
+import org.apache.dubbo.config.annotation.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 
-@Service
+@Service(version = "1.0")
 public class GoldCornTradeServiceImpl implements GoldCornTradeService {
 
     @Resource
@@ -45,7 +46,7 @@
      * @throws GoldAppException
      * @throws GoldUserException
      */
-    private GoldCornAppInfo validateAppAndUser(String appCode, String uid) throws GoldAppException, GoldUserException {
+    private Long validateAppAndUser(String appCode, String uid) throws GoldAppException, GoldUserException {
         GoldCornAppInfo appInfo = goldCornAppInfoMapper.selectByAppCode(appCode);
         if (appInfo == null) {
             throw new GoldAppException(GoldAppException.CODE_NOT_EXIST, "app is not exist");
@@ -56,55 +57,79 @@
             throw new GoldUserException(GoldUserException.CODE_NOT_EXIST, "uid is not exist");
         }
 
-        return appInfo;
+        return appInfo.getId();
     }
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public void addGoldCorn(String appCode, String uid, GoldCornGetSource source) throws GoldAppException, GoldUserException, GoldTradeException {
-        GoldCornAppInfo app = validateAppAndUser(appCode, uid);
-        source = goldCornGetSourceMapper.selectByPrimaryKey(source.getId());
+    public void addGoldCorn(String appCode, String uid, String sourceCode, String title, String desc) throws GoldAppException, GoldUserException, GoldTradeException {
+        Long appId = validateAppAndUser(appCode, uid);
+        GoldCornGetSource source = goldCornGetSourceMapper.selectByAppIdAndSourceCode(appId, sourceCode);
         if (source == null) {
             throw new GoldUserException(GoldTradeException.CODE_NOT_EXIST, "source is not exist");
         }
 
         //鍔犺褰�
         GoldCornRecord record = new GoldCornRecord();
-        record.setAppId(app.getId());
+        record.setAppId(appId);
         record.setGoldCorn(source.getGoldCorn());
         record.setSourceId(source.getId());
         record.setType(GoldCornRecord.TYPE_GET);
         record.setUid(uid);
+        if (title != null) {
+            record.setTitle(title);
+        } else {
+            record.setTitle(source.getSourceName());
+        }
+        if (desc != null) {
+            record.setDesc(desc);
+        } else {
+            record.setDesc(source.getSourceDesc());
+        }
         try {
             goldCornRecordManager.addRecord(record);
         } catch (GoldRecordException e) {
             throw new GoldTradeException(GoldTradeException.CODE_ADD_RECORD_FAIL, "娣诲姞璁板綍澶辫触");
         }
         //鍔犱綑棰�
-        goldCornBalanceManager.addMoney(app.getId(), uid, source.getGoldCorn());
+        goldCornBalanceManager.addMoney(appId, uid, source.getGoldCorn());
     }
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public void consumeGoldCorn(String appCode, String uid, GoldCornConsumeSource source) throws GoldAppException, GoldUserException, GoldTradeException {
-        GoldCornAppInfo app = validateAppAndUser(appCode, uid);
-        source = goldCornConsumeSourceMapper.selectByPrimaryKey(source.getId());
+    public void consumeGoldCorn(String appCode, String uid, String sourceCode, String title, String desc) throws GoldAppException, GoldUserException, GoldTradeException {
+        Long appId = validateAppAndUser(appCode, uid);
+        GoldCornConsumeSource source = goldCornConsumeSourceMapper.selectByAppIdAndSourceCode(appId, sourceCode);
         if (source == null) {
             throw new GoldUserException(GoldTradeException.CODE_NOT_EXIST, "source is not exist");
         }
+
+        //鍑忎綑棰�
+        goldCornBalanceManager.subMoney(appId, uid, source.getGoldCorn());
+
         //鍔犺褰�
         GoldCornRecord record = new GoldCornRecord();
-        record.setAppId(app.getId());
+        record.setAppId(appId);
         record.setGoldCorn(source.getGoldCorn());
         record.setSourceId(source.getId());
         record.setType(GoldCornRecord.TYPE_CONSUME);
         record.setUid(uid);
+        if (title != null) {
+            record.setTitle(title);
+        } else {
+            record.setTitle(source.getSourceName());
+        }
+        if (desc != null) {
+            record.setDesc(desc);
+        } else {
+            record.setDesc(source.getSourceDesc());
+        }
         try {
             goldCornRecordManager.addRecord(record);
         } catch (GoldRecordException e) {
             throw new GoldTradeException(GoldTradeException.CODE_ADD_RECORD_FAIL, "娣诲姞璁板綍澶辫触");
         }
-        //鍑忎綑棰�
-        goldCornBalanceManager.subMoney(app.getId(), uid, source.getGoldCorn());
+
+
     }
 }

--
Gitblit v1.8.0