Browse Source

lime修改同步idiom

hidewnd 1 tháng trước cách đây
mục cha
commit
fcd7084bf5

+ 12 - 3
yt-idiom/idiom-feign/src/main/java/com/ytpm/idiom/feign/IdiomFeign.java

@@ -1,5 +1,6 @@
 package com.ytpm.idiom.feign;
 
+import com.ytpm.agent.param.AdRecordListParam;
 import com.ytpm.agent.param.AuditCheckParam;
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
@@ -49,7 +50,15 @@ public interface IdiomFeign {
     @PostMapping("/user/updateUserInfo")
     Result<?> updateUserInfo(@RequestBody YtDyzUser dyzUser);
     @GetMapping("/user/adRecords")
-    ResultTable<YtDyzAdRecord> adRecords(@RequestParam(name = "userId",required = true) String userId,@RequestParam(name = "adsourceType",required = false)Integer adsourceType);
+    ResultTable<YtDyzAdRecord> adRecords(@RequestParam(name = "userId",required = true) String userId, @RequestParam(name = "adsourceType",required = false)Integer adsourceType);
+
+    @PostMapping("/user/adRecords/page")
+    ResultTable<YtDyzAdRecord> adRecordsPage(@RequestBody AdRecordListParam param);
+
+    @GetMapping("/user/adRecords/count/month")
+    Result<Integer> queryRecordMonthCount(@RequestParam(name = "userId") String userId,
+                                          @RequestParam(name = "adSourceType", required = false) Integer adSourceType,
+                                          @RequestParam(name = "startTime", required = false) String startTime);
 
     @PostMapping("/user/queryUserByTime")
     List<YtDyzUser> queryUserByTime(@RequestBody AppUserQueryParam appUserQueryParam);
@@ -58,7 +67,7 @@ public interface IdiomFeign {
     int[] queryUserByTodayTime(@RequestBody AppQueryUserTodayTimeParam appQueryUserTodayTimeParam);
 
     @PostMapping("/user/queryLoginRecords")
-     List<String> queryLoginRecords(@RequestBody AppUserQueryParam appUserQueryParam);
+    List<String> queryLoginRecords(@RequestBody AppUserQueryParam appUserQueryParam);
 
     @GetMapping("/user/queryByOpenid")
     List<YtDyzUser> queryByOpenid(@RequestParam("openid") String openid);
@@ -82,7 +91,7 @@ public interface IdiomFeign {
     AgentTopCountView getAppTopCount(@RequestParam(name = "appIds")String appIds);
 
     @GetMapping("/ad/getAppRankingList")
-    DashboardRankingListVO queryRankingList(@RequestParam(name = "sortBy") Integer sortBy,@RequestParam(name = "limit") Integer limit);
+    DashboardRankingListVO queryRankingList(@RequestParam(name = "sortBy") Integer sortBy, @RequestParam(name = "limit") Integer limit);
 
     @GetMapping("/ad/revenueStatics")
     DashboardRevenueVO revenueStatics(@RequestParam(name = "apkIds") String apkIds);

+ 33 - 0
yt-idiom/idiom-service/src/main/java/com/ytpm/idiom/controller/UserController.java

@@ -7,6 +7,7 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
+import com.ytpm.agent.param.AdRecordListParam;
 import com.ytpm.agent.param.AuditCheckParam;
 import com.ytpm.agent.param.AuditUserParam;
 import com.ytpm.agent.view.AgentAuditCheckVO;
@@ -47,6 +48,7 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -72,6 +74,7 @@ public class UserController {
 
     @Autowired
     private RiskFeign riskFeign;
+
     /**
      * 根据应用ID查询当月注册用户
      */
@@ -198,6 +201,36 @@ public class UserController {
         return ResultTable.resultTableOk(new PageInfo<YtDyzAdRecord>(result));
     }
 
+    @PostMapping("/adRecords/page")
+    public ResultTable<YtDyzAdRecord> adRecordsPage(@RequestBody AdRecordListParam param) {
+        PageHelper.startPage(param.getPage(), param.getLimit());
+        List<YtDyzAdRecord> adrecords = adRecordMapper.getByUserByParam(param);
+        return ResultTable.resultTableOk(new PageInfo<>(adrecords));
+    }
+
+    /**
+     * 查询广告记录统计数
+     */
+    @GetMapping("/adRecords/count/month")
+    public Result<Integer> queryRecordMonthCount(@RequestParam(name = "userId") String userId,
+                                                 @RequestParam(name = "adSourceType", required = false) Integer adSourceType,
+                                                 @RequestParam(name = "startTime", required = false) String startTime) {
+        Date time;
+        // 统计起始时间为空,则默认查询当月信息
+        if (StrUtil.isEmpty(startTime)) {
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(new Date());
+            calendar.set(Calendar.DAY_OF_MONTH, 1);
+            calendar.set(Calendar.HOUR_OF_DAY, 0);
+            calendar.set(Calendar.MINUTE, 0);
+            calendar.set(Calendar.SECOND, 0);
+            time = calendar.getTime();
+        } else {
+            time = DateUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss");
+        }
+        return Result.resultObjOk(adRecordMapper.getRecordMonthCount(userId, adSourceType, time));
+    }
+
     @PostMapping("/queryUserByTime")
     public List<YtDyzUser> queryUserByTime(@RequestBody AppUserQueryParam appUserQueryParam) {
         List<YtDyzUser> ytDyzUsers = appUserMapper.queryAllByTime(appUserQueryParam.getStartTime(), appUserQueryParam.getEndTime(),appUserQueryParam.getAppIdList());

+ 13 - 3
yt-idiom/idiom-service/src/main/java/com/ytpm/idiom/dao/AdRecordMapper.java

@@ -1,5 +1,6 @@
 package com.ytpm.idiom.dao;
 
+import com.ytpm.agent.param.AdRecordListParam;
 import com.ytpm.app.model.YtDyzAdRecord;
 import com.ytpm.app.param.YtAppUserListParam;
 import com.ytpm.middle.view.AppRevenueHourVO;
@@ -7,6 +8,7 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 
 @Mapper
@@ -21,10 +23,13 @@ public interface AdRecordMapper {
      */
     void addOneVisitor(YtDyzAdRecord adRecord);
 
+
     /**
      * 查询用户的广告记录
      */
-    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId, @Param("adsourceType") Integer adsourceType);
+    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId,@Param("adsourceType") Integer adsourceType);
+
+    List<YtDyzAdRecord> getByUserByParam(AdRecordListParam param);
 
     /**
      * 查询激励视频记录
@@ -51,8 +56,13 @@ public interface AdRecordMapper {
      */
     List<YtDyzAdRecord> getTodayRecord(@Param("appIds")String appIds,@Param("firstDay")String firstDay,@Param("lastDay")String lastDay);
 
+    List<YtDyzAdRecord> selectRecordByIds(@Param("loginStatus") Integer loginStatus, @Param("ids") List<String> adRecordIds);
+
     /**
-     * 查询指定广告记录
+     * 查询用户广告记录统计数
      */
-    List<YtDyzAdRecord> selectRecordByIds(@Param("loginStatus") Integer loginStatus, @Param("ids") List<String> adRecordIds);
+    Integer getRecordMonthCount(@Param("userId") String userId,
+                                @Param("adSourceType") Integer adSourceType,
+                                @Param("startTime") Date startTime);
+
 }

+ 2 - 0
yt-idiom/idiom-service/src/main/java/com/ytpm/idiom/dao/AppUserMapper.java

@@ -208,4 +208,6 @@ public interface AppUserMapper {
     YtDyzUser getByDeviceAndDitch(@Param("deviceId") String deviceId,@Param("ditchId")Long ditchId);
 
     String getPlatformByDeviceId(@Param("deviceId")String deviceId);
+
+    void updateTotal(@Param("userId") String userId, @Param("videoCount") int videoCount, @Param("revenue") BigDecimal revenue);
 }

+ 13 - 8
yt-idiom/idiom-service/src/main/java/com/ytpm/idiom/service/impl/AdServiceImpl.java

@@ -252,11 +252,12 @@ public class AdServiceImpl implements AdService {
         cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),actualMaximum,23,59,59);
         String lastDay = sdf.format(cal.getTime());
         List<YtDyzAdRecord> dyzMonthRecords = adRecordMapper.getTodayRecord(appIds,firstDay,lastDay);
+
         if(CollUtil.isNotEmpty(dyzMonthRecords)){monthRecords.addAll(dyzMonthRecords);}
         records = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),new Date())).collect(Collectors.toList());
 
-        cal = Calendar.getInstance(); // 获取当前日期时间
+        cal = Calendar.getInstance();
         cal.add(Calendar.DATE, -1); // 昨天的日期时间
         Date yest = cal.getTime();
         yestRecords = monthRecords.stream().filter(
@@ -304,12 +305,15 @@ public class AdServiceImpl implements AdService {
      * 保存记录
      *  始终创建新的事务以保障子方法的独立事务
      */
-//    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
     @Override
+//    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
     public String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user) {
         //增加广告记录
         YtDyzAdRecord adRecord = new YtDyzAdRecord();
-        if(Objects.isNull(param.getBeginTime())){
+        if(Objects.isNull(param.getBeginTime()) || "null".equals(param.getBeginTime())){
+            if ("null".equals(param.getBeginTime())) {
+                log.warn("param beginTime is null !");
+            }
             param.setBeginTime(param.getFinishTime());
         }
         BeanUtils.copyProperties(param, adRecord);
@@ -328,11 +332,10 @@ public class AdServiceImpl implements AdService {
         }
         if (updateUserTotal) {
             //修改用户信息, 广告次数+1  总收益 + revenue
-            YtDyzUser dyzUser = new YtDyzUser();
-            dyzUser.setUserId(user.getUserId());
-            dyzUser.setTotalVideo(Objects.isNull(user.getTotalVideo()) ? 1 : (user.getTotalVideo() + 1));
-            dyzUser.setTotalIncome(user.getTotalIncome().add(param.getRevenue()));
-            appUserMapper.updateUser(dyzUser);
+            if (param.getRevenue() == null) {
+                param.setRevenue(BigDecimal.ZERO);
+            }
+            appUserMapper.updateTotal(user.getUserId(), 1, param.getRevenue());
         }
         return adRecord.getRecordId();
     }
@@ -343,3 +346,5 @@ public class AdServiceImpl implements AdService {
     }
 
 }
+
+

+ 39 - 1
yt-idiom/idiom-service/src/main/resources/mapper/AdRecordMapper.xml

@@ -93,8 +93,26 @@
     </select>
     <select id="getByUserId" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name,
+        network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
+        where user_id = #{userId} and DATE_FORMAT(finish_time, '%Y-%m-%d') = DATE_FORMAT(now(), '%Y-%m-%d')
+        <if test="adsourceType != null and adsourceType!=888">
+            and ad_source_type = #{adsourceType}
+        </if>
+        order by finish_time desc
+    </select>
+    <select id="getByUserByParam" resultType="com.ytpm.app.model.YtDyzAdRecord">
+        select
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name,
+        network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm,
+        ifnull(#{loginStatus}, 2) as loginStatus
+        <if test="loginStatus != null and loginStatus == 1">
+            from yt_dyz_ad_record_visitor
+        </if>
+        <if test="loginStatus == null or loginStatus != 1">
+            from yt_dyz_ad_record
+        </if>
         where user_id = #{userId}
         <if test="adsourceType != null and adsourceType!=888">
             and ad_source_type = #{adsourceType}
@@ -109,6 +127,14 @@
         <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
             #{item}
         </foreach>
+        union
+        select
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        from yt_dyz_ad_record_visitor
+        where ad_source_type != 1 and user_id in
+        <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
+            #{item}
+        </foreach>
         order by finish_time
     </select>
     <select id="getHourRevenue" resultType="com.ytpm.middle.view.AppRevenueHourVO">
@@ -191,4 +217,16 @@
         </if>
         where record_id in <foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach>
     </select>
+    <select id="getRecordMonthCount" resultType="java.lang.Integer">
+        SELECT count(record_id) as counts
+        FROM yt_dyz_ad_record
+        where user_id= #{userId} and revenue > 0
+        <if test="adSourceType != null and adSourceType!=888">
+            and ad_source_type = #{adSourceType}
+        </if>
+        <if test="startTime != null">
+            and finish_time > #{startTime}
+        </if>
+    </select>
+
 </mapper>

+ 6 - 0
yt-idiom/idiom-service/src/main/resources/mapper/AppUserMapper.xml

@@ -782,4 +782,10 @@
             #{item}
         </foreach>
     </update>
+    <update id="updateTotal">
+        UPDATE yt_dyz_user
+        SET total_video = COALESCE(total_video, 0) + #{videoCount},
+            total_income = COALESCE(total_income, 0) + #{revenue}
+        WHERE user_id = #{userId}
+    </update>
 </mapper>