Selaa lähdekoodia

增加应用授权记录

marxjaw 3 kuukautta sitten
vanhempi
commit
7a19d7800c

+ 7 - 0
yt-common/src/main/java/com/ytpm/agent/model/YtPlatformUserApp.java

@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 @EqualsAndHashCode(callSuper = true)
@@ -32,4 +33,10 @@ public class YtPlatformUserApp extends BaseParam {
     private String wxAppId;
     @ApiModelProperty("微信访问secret")
     private String wxSecret;
+    @ApiModelProperty("售价")
+    private BigDecimal salePrice;
+    @ApiModelProperty("授权类型 1-直营 2-分销")
+    private Integer grantType;
+    @ApiModelProperty("缴费状态")
+    private Integer chargeStatus;
 }

+ 41 - 0
yt-common/src/main/java/com/ytpm/middle/model/YtAppGrantRecord.java

@@ -0,0 +1,41 @@
+package com.ytpm.middle.model;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author Marx
+ * @date 2025/8/5 17:34
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@ApiModel("应用授权记录表")
+public class YtAppGrantRecord {
+    @ApiModelProperty("记录ID")
+    private String recordId;
+    @ApiModelProperty("应用ID")
+    private String appId;
+    @ApiModelProperty("用户ID")
+    private String userId;
+    @ApiModelProperty("售价")
+    private BigDecimal salePrice;
+    @ApiModelProperty("授权类型")
+    private Integer grantType;
+    @ApiModelProperty("比例")
+    private BigDecimal ratio;
+    @ApiModelProperty("流量费")
+    private BigDecimal dataCharge;
+    @ApiModelProperty("授权时间")
+    private Date grantTime;
+    @ApiModelProperty("操作人ID")
+    private String operatorId;
+    @ApiModelProperty("操作人姓名")
+    private Date operateTime;
+}

+ 5 - 0
yt-common/src/main/java/com/ytpm/middle/param/AppForm.java

@@ -8,6 +8,7 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 @EqualsAndHashCode(callSuper = true)
@@ -36,4 +37,8 @@ public class AppForm extends BaseParam {
     private String wxAppId;
     @ApiModelProperty("微信开发应用ID")
     private String wxSecret;
+    @ApiModelProperty("售价")
+    private BigDecimal salePrice;
+    @ApiModelProperty("授权类型")
+    private Integer grantType;
 }

+ 8 - 0
yt-common/src/main/java/com/ytpm/middle/param/GrantAppParam.java

@@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.math.BigDecimal;
+
 @Data
 @NoArgsConstructor
 @AllArgsConstructor
@@ -20,4 +22,10 @@ public class GrantAppParam {
     /** 操作用户ID */
     @ApiModelProperty(value = "操作用户ID", hidden = true)
     private String userId;
+    @ApiModelProperty(value = "授权类型", required = true)
+    private Integer grantType;
+    @ApiModelProperty("比例")
+    private BigDecimal ratio;
+    @ApiModelProperty("流量费")
+    private BigDecimal dataCharge;
 }

+ 2 - 0
yt-common/src/main/java/com/ytpm/middle/view/AppListVO.java

@@ -57,4 +57,6 @@ public class AppListVO {
     /** Taku访问key */
     @ApiModelProperty("Taku访问key")
     private String takuPublicKey;
+    @ApiModelProperty(value = "售价",hidden = true)
+    private String salePrice;
 }

+ 6 - 0
yt-middle/middle-platform/src/main/java/com/ytpm/middle/dao/AppMapper.java

@@ -1,6 +1,7 @@
 package com.ytpm.middle.dao;
 
 import com.ytpm.agent.model.YtPlatformUserApp;
+import com.ytpm.middle.model.YtAppGrantRecord;
 import com.ytpm.middle.param.AppListParam;
 import com.ytpm.middle.view.AppListVO;
 import com.ytpm.middle.view.DropDownVO;
@@ -48,4 +49,9 @@ public interface AppMapper {
      * 根据上级应用获取apk包
      */
     List<DropDownVO> getApkList(@Param("appId") String appId);
+
+    /**
+     * 授权应用记录
+     */
+    void addGrantRecord(YtAppGrantRecord grantRecord);
 }

+ 6 - 2
yt-middle/middle-platform/src/main/java/com/ytpm/middle/service/impl/AgentServiceImpl.java

@@ -14,6 +14,7 @@ import com.ytpm.middle.model.YtMiddleEnterprise;
 import com.ytpm.middle.param.AgentBaseInfoParam;
 import com.ytpm.middle.param.AgentForm;
 import com.ytpm.middle.service.AgentService;
+import com.ytpm.middle.util.RedisUtil;
 import com.ytpm.middle.util.TencentSmsUtil;
 import com.ytpm.middle.view.AgentBaseInfoListVO;
 import com.ytpm.oauth.model.YtPlatformUser;
@@ -41,6 +42,8 @@ public class AgentServiceImpl implements AgentService {
     private EnterpriseMapper enterpriseMapper;
     @Resource
     private TencentSmsUtil smsUtil;
+    @Resource
+    private RedisUtil redisUtil;
 
     @Value("${tencent.sms.registryTemplateId}")
     private String registryTemplateId;
@@ -147,7 +150,7 @@ public class AgentServiceImpl implements AgentService {
         user.setNickName(form.getEnterpriseName());
         user.setLoginName(form.getLoginName());
         String generatedPassword = RandomPasswordGenerator.generatePassword(8);
-        System.err.println("创建用户成功,您本次的登录密码为:"+generatedPassword);
+        log.error("创建用户成功,您本次的登录密码为:{}", generatedPassword);
         user.setEncryptPwd(new BCryptPasswordEncoder().encode(generatedPassword));
         user.setPhone(form.getConcatPhone());
         user.setLastLoginTime(new Date());
@@ -156,7 +159,8 @@ public class AgentServiceImpl implements AgentService {
         user.setUserId(accountId);
         user.setAccountStatus(1);
         agentMapper.addOneUser(user);
-        //短信通知企业负责人 账号密码,邀请其登录代理商管理系统
+        //缓存企业负责人电话:账号密码
+        redisUtil.setTimeOutMinutesStr(form.getConcatPhone(), generatedPassword, 30);
         try {
             smsUtil.sendLoginPwd(form.getConcatPhone(), generatedPassword,registryTemplateId);
         } catch (TencentCloudSDKException e) {

+ 27 - 0
yt-middle/middle-platform/src/main/java/com/ytpm/middle/service/impl/AppServiceImpl.java

@@ -9,6 +9,7 @@ import com.ytpm.general.Result;
 import com.ytpm.general.ResultTable;
 import com.ytpm.middle.dao.AppMapper;
 import com.ytpm.middle.dao.EnterpriseMapper;
+import com.ytpm.middle.model.YtAppGrantRecord;
 import com.ytpm.middle.model.YtMiddleEnterprise;
 import com.ytpm.middle.param.AppForm;
 import com.ytpm.middle.param.AppListParam;
@@ -16,8 +17,10 @@ import com.ytpm.middle.param.GrantAppParam;
 import com.ytpm.middle.service.AppService;
 import com.ytpm.middle.view.AppListVO;
 import com.ytpm.middle.view.DropDownVO;
+import com.ytpm.util.IDUtil;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.Date;
@@ -53,6 +56,7 @@ public class AppServiceImpl implements AppService {
         app.setCreateTime(new Date());
         app.setCreateUserId(form.getCreateUserId());
         app.setAvailable(1);
+        app.setChargeStatus(0);
         appMapper.insertOne(app);
         return Result.resultOk(RepMessage.SAVE_SUCCESS);
     }
@@ -70,6 +74,7 @@ public class AppServiceImpl implements AppService {
      * 应用授权企业
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Result<String> grantApp(GrantAppParam param) {
         //查询企业是否存在
         YtMiddleEnterprise enterprise = enterpriseMapper.getByCode(param.getCreditCode());
@@ -86,10 +91,32 @@ public class AppServiceImpl implements AppService {
         app.setAppId(param.getAppId());
         app.setUpdateParam(param.getUserId());
         app.setUserId(enterprise.getUserId());
+        app.setGrantType(param.getGrantType());
+        app.setChargeStatus(1);
         appMapper.updateById(app);
+        //增加授权记录
+        addGrantAppRecord(param, app);
         return Result.resultOk(RepMessage.GRANT_SUCCESS);
     }
 
+    /**
+     * 授权应用记录
+     */
+    private void addGrantAppRecord(GrantAppParam param, YtPlatformUserApp app) {
+        YtAppGrantRecord grantRecord = new YtAppGrantRecord();
+        grantRecord.setRecordId(IDUtil.generateFlowID("grant"));
+        grantRecord.setAppId(app.getAppId());
+        grantRecord.setUserId(app.getUserId());
+        grantRecord.setGrantType(param.getGrantType());
+        grantRecord.setSalePrice(app.getSalePrice());
+        grantRecord.setRatio(param.getRatio());
+        grantRecord.setDataCharge(param.getDataCharge());
+        grantRecord.setGrantTime(new Date());
+        grantRecord.setOperateTime(new Date());
+        grantRecord.setOperatorId(param.getUserId());
+        appMapper.addGrantRecord(grantRecord);
+    }
+
     /**
      * 修改上架应用信息
      */

+ 43 - 2
yt-middle/middle-platform/src/main/resources/mapper/AppMapper.xml

@@ -14,6 +14,7 @@
          issued_time,
          wx_app_id,
          wx_secret,
+         sale_price,
          create_user_id,
          create_time,
          available
@@ -30,11 +31,40 @@
          #{issuedTime},
          #{wxAppId},
          #{wxSecret},
+         #{salePrice},
          #{createUserId},
          #{createTime},
          #{available}
         )
     </insert>
+    <insert id="addGrantRecord">
+        insert into yt_app_grant_record
+        (
+         record_id,
+         app_id,
+         user_id,
+         sale_price,
+         grant_type,
+         ratio,
+         data_charge,
+         grant_time,
+         operator_id,
+         operator_time
+        )
+        values
+        (
+         #{recordId},
+         #{appId},
+         #{userId},
+         #{salePrice},
+         #{grantType},
+         #{ratio},
+         #{dataCharge},
+         #{grantTime},
+         #{operatorId},
+         #{operateTime}
+        );
+    </insert>
     <update id="updateById">
         update yt_platform_user_app
         <set>
@@ -71,6 +101,15 @@
             <if test="updateTime != null">
                 update_time = #{updateTime},
             </if>
+            <if test="salePrice != null">
+                sale_price = #{salePrice},
+            </if>
+            <if test="chargeStatus != null">
+                charge_status = #{chargeStatus},
+            </if>
+            <if test="grantType != null">
+                grant_type = #{grantType},
+            </if>
             <if test="available != null">
                 available = #{available}
             </if>
@@ -90,6 +129,8 @@
             pua.detail_url,
             pua.package_name,
             pua.domain,
+            pua.sale_price,
+            pua.grant_type,
             pua.issued_time,
             pua.wx_app_id,
             pua.wx_secret,
@@ -114,13 +155,13 @@
     </select>
     <select id="getByPackName" resultType="com.ytpm.agent.model.YtPlatformUserApp">
         select
-            app_id, app_name, user_id, app_type, detail_url, package_name, domain, issued_time, wx_app_id, wx_secret
+            app_id, app_name, user_id,sale_price,grant_type, app_type, detail_url, package_name, domain, issued_time, wx_app_id, wx_secret
         from yt_platform_user_app
         where package_name = #{packageName}
     </select>
     <select id="getByPrimary" resultType="com.ytpm.agent.model.YtPlatformUserApp">
         select
-            app_id, app_name, user_id, app_type, detail_url, package_name, domain, issued_time, wx_app_id,wx_secret
+            app_id, app_name, user_id,sale_price,grant_type, app_type, detail_url, package_name, domain, issued_time, wx_app_id,wx_secret
         from yt_platform_user_app
         where app_id = #{appId}
     </select>