Parcourir la source

Merge remote-tracking branch 'origin/master'

syh il y a 4 ans
Parent
commit
def6aeeb44

+ 11 - 11
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AdvertiserController.java

@@ -117,13 +117,13 @@ public class AdvertiserController {
         Result<IPage<Advertiser>> result = new Result<>();
         String roleCode = sysRoleService.getRoleCodeByUserId(advertiser.getUserId());
         String userId = advertiser.getUserId();
-        if (CtopRoleCodeConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode) || "kuaishouOperationManager".equals(roleCode) || "touTiaoOperationManager".equals(roleCode) || "sale".equals(roleCode) || "saleDirector".equals(roleCode)) {
+        if (CtopRoleCodeConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode) || "kuaishouOperationManager".equals(roleCode) || "touTiaoOperationManager".equals(roleCode) || roleCode.contains("sale") || "meidaManager".equals(roleCode)) {
             advertiser.setUserId(null);
         }
         String industryId = advertiser.getIndustryId();
         advertiser.setIndustryId(null);
         QueryWrapper<Advertiser> queryWrapper = QueryGenerator.initQueryWrapper(advertiser, req.getParameterMap());
-        if ("kuaishouOperationManager".equals(roleCode)) {
+        if ("kuaishouOperationManager".equals(roleCode) || "touTiaoOperationManager".equals(roleCode)) {
             QueryWrapper<UserCompany> userCompanyQueryWrapper = new QueryWrapper<>();
             userCompanyQueryWrapper.eq("user_id", userId);
             userCompanyQueryWrapper.orderByDesc("create_time");
@@ -133,10 +133,10 @@ public class AdvertiserController {
                 queryWrapper.eq("company_id", userCompany.getCompanyId());
             }
         }
-        if(null!=industryId&&!"".equals(industryId.trim())){
+        if (null != industryId && !"".equals(industryId.trim())) {
             SysCategory category = sysCategoryService.getById(industryId);
-            if(null!=category){
-                queryWrapper.likeRight("industry_code",category.getCode());
+            if (null != category) {
+                queryWrapper.likeRight("industry_code", category.getCode());
             }
         }
         Page<Advertiser> page = new Page<>(pageNo, pageSize);
@@ -180,9 +180,9 @@ public class AdvertiserController {
                 advertiser.setCompanyId(userCompany.getCompanyId());
             }
             String industryId = advertiser.getIndustryId();
-            if(null!=industryId&&!"".equals(industryId.trim())){
+            if (null != industryId && !"".equals(industryId.trim())) {
                 SysCategory category = sysCategoryService.getById(industryId);
-                if(null!=category){
+                if (null != category) {
                     advertiser.setIndustryId(category.getId());
                     advertiser.setIndustryCode(category.getCode());
                 }
@@ -215,9 +215,9 @@ public class AdvertiserController {
             result.error500("未找到对应实体");
         } else {
             String industryId = advertiser.getIndustryId();
-            if(null!=industryId&&!"".equals(industryId.trim())){
+            if (null != industryId && !"".equals(industryId.trim())) {
                 SysCategory category = sysCategoryService.getById(industryId);
-                if(null!=category){
+                if (null != category) {
                     advertiser.setIndustryId(category.getId());
                     advertiser.setIndustryCode(category.getCode());
                 }
@@ -386,7 +386,7 @@ public class AdvertiserController {
                 }
             }
         }
-        List<UserAllocation> allocations = userAllocationService.getByParams(projectId, systemType,null);
+        List<UserAllocation> allocations = userAllocationService.getByParams(projectId, systemType, null);
         if (null != allocations && !allocations.isEmpty()) {
             for (UserAllocation allocation : allocations) {
                 SheetInfoVo vo = advertiserService.getXxlStatisticInfo(projectId, systemType, allocation.getAccountId(), allocation.getAuthName());
@@ -421,7 +421,7 @@ public class AdvertiserController {
                 }
             }
         }
-        List<UserAllocation> allocations = userAllocationService.getByParams(projectId, systemType,null);
+        List<UserAllocation> allocations = userAllocationService.getByParams(projectId, systemType, null);
         if (null != allocations && !allocations.isEmpty()) {
             for (UserAllocation allocation : allocations) {
                 SheetInfoVo vo = advertiserService.getXxlStatisticInfo(projectId, systemType, allocation.getAccountId(), allocation.getAuthName());

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ProjectController.java

@@ -246,7 +246,7 @@ public class ProjectController {
         Page<Project> page = new Page<>(pageNo, pageSize);
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         String roleCode = sysRoleService.getRoleCodeByUserId(sysUser.getId());
-        if (!(CtopRoleCodeConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode) || "sale".equals(roleCode) || "saleDirector".equals(roleCode))) {
+        if (!(CtopRoleCodeConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode) || roleCode.contains("sale") || "meidaManager".equals(roleCode))) {
             queryWrapper.eq("user_id", sysUser.getId());
             queryWrapper.orderByDesc("create_time");
         }

+ 2 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ProjectMemberController.java

@@ -88,7 +88,7 @@ public class ProjectMemberController {
         try {
             QueryWrapper<ProjectMember> queryWrapper = new QueryWrapper<>();
             String roleCode = sysRoleService.getRoleCodeByUserId(userId);
-            if (!"admin".equals(roleCode) && !"sale".equals(roleCode) && !"saleDirector".equals(roleCode)) {
+            if (!"admin".equals(roleCode) && !roleCode.contains("sale") && !"meidaManager".equals(roleCode)) {
                 queryWrapper.eq("user_id", userId);
             }
             queryWrapper.groupBy("project_id");
@@ -145,7 +145,7 @@ public class ProjectMemberController {
         QueryWrapper<ProjectMember> queryWrapper = QueryGenerator.initQueryWrapper(projectMember, req.getParameterMap());
 
         String roleCode = sysRoleService.getRoleCodeByUserId(userId);
-        if (!"admin".equals(roleCode) && !"sale".equals(roleCode) && !"saleDirector".equals(roleCode)) {
+        if (!"admin".equals(roleCode) && !roleCode.contains("sale") && !"meidaManager".equals(roleCode)) {
             queryWrapper.eq("user_id", userId);
         }
         if (!Check.isNull(projectName)) {

+ 5 - 6
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -859,8 +859,6 @@ public class TestController {
     }
 
 
-
-
     @GetMapping(value = "/getOperationRecord")
     public Result getOperationRecord(@Param("accountId")Long accountId, @Param("operationTarget")Integer operationTarget, @Param("startDate")String startDate, @Param("endDate")String endDate){
         Result result = new Result();
@@ -890,15 +888,15 @@ public class TestController {
                     return result;
                 }
 
-                executorService = Executors.newFixedThreadPool(3);
+                executorService = Executors.newFixedThreadPool(8);
                 tokens.forEach(token -> {
                     executorService.submit(new Runnable() {
                         @Override
                         public void run() {
                             log.info("获取操作记录开始:accountId:{},startDate:{},endDate:{}", token.getAccountId(), startDate, endDate);
                             kuaishouInterfaceService2.getOperationRecord(token.getAccountId(), token.getAccessToken(), operationTarget, startDate, endDate);
-                            log.info("获取操作记录开始:accountId:{}", token.getAccountId());
-                     }
+                            log.info("获取操作记录结束:accountId:{}", token.getAccountId());
+                        }
                     });
                 });
             }else{
@@ -911,8 +909,9 @@ public class TestController {
                     result.setMessage("定时获取快手操作记录数据异常:未获取到可用的toke");
                     return result;
                 }
+                log.info("获取快手操作记录开始:accountId:{},startDate:{},endDate:{}", token.getAccountId(), startDate, endDate);
                 kuaishouInterfaceService2.getOperationRecord(token.getAccountId(), token.getAccessToken(), operationTarget, startDate, endDate);
-
+                log.info("获取快手操作记录结束:accountId:{},startDate:{},endDate:{}", token.getAccountId(), startDate, endDate);
             }
 
 

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ProjectMemberServiceImpl.java

@@ -40,7 +40,7 @@ public class ProjectMemberServiceImpl extends ServiceImpl<ProjectMemberMapper, P
     @Autowired
     private UserAllocationMapper userAllocationMapper;
 
-    private static final String[] PERMISSION_VIEW_PROJECT = {"admin", "saleDirector", "sale", "saleAssistant", "saleAm"};
+    private static final String[] PERMISSION_VIEW_PROJECT = {"admin", "saleDirector", "sale", "saleAssistant", "saleAm", "meidaManager"};
 
     @Override
     public void addMember(SysUser sysUser, Project project) {

+ 76 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouOperationRecordJob.java

@@ -0,0 +1,76 @@
+package cn.com.ctop.job.kuaishou.handler;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService2;
+import cn.com.ctop.kuaishou.modules.material.service.IKuaishouBidWarningService;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import com.xxl.job.core.log.XxlJobLogger;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Component
+public class KuaishouOperationRecordJob {
+    @Autowired
+    private IKuaishouInterfaceService2 kuaishouInterfaceService2;
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+
+    static ExecutorService executorService = Executors.newFixedThreadPool(4);
+
+    @XxlJob("kuaishouOperationRecord")
+    public ReturnT<String> execute(String param) throws Exception {
+        Date getDate = DateUtils.addDay(new Date(), -1);
+        String date = DateUtils.formatDate(getDate);
+        //1:查询当日数据
+        List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
+        if (null == tokens || tokens.size() <= 0) {
+            XxlJobLogger.log("定时获取快手操作记录数据异常:未获取到可用的token");
+            return ReturnT.FAIL;
+        }
+        tokens.forEach(token -> {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 1 + "时间:" + date + "~" + date);
+                    kuaishouInterfaceService2.getOperationRecord(token.getAccountId(), token.getAccessToken(), 1, date, date);
+                    XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 1 + "时间:" + date + "~" + date);
+
+                    XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 2+ "时间:" + date + "~" + date);
+                    kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),2, date, date);
+                    XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 2+ "时间:" + date + "~" + date);
+
+                    XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 3+ "时间:" + date + "~" + date);
+                    kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),3, date, date);
+                    XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 3+ "时间:" + date + "~" + date);
+
+                    XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 4+ "时间:" + date + "~" + date);
+                    kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),4, date, date);
+                    XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 4+ "时间:" + date + "~" + date);
+
+                    XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 5+ "时间:" + date + "~" + date);
+                    kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),5, date, date);
+                    XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 5+ "时间:" + date + "~" + date);
+
+                    XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 6+ "时间:" + date + "~" + date);
+                    kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),6, date, date);
+                    XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 6+ "时间:" + date + "~" + date);
+
+                    XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 7+ "时间:" + date + "~" + date);
+                    kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),7, date, date);
+                    XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 7+ "时间:" + date + "~" + date);
+                }
+            });
+        });
+        return ReturnT.SUCCESS;
+    }
+
+}

+ 97 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouInterfaceController.java

@@ -0,0 +1,97 @@
+package cn.com.ctop.kuaishou.modules.batch.controller;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService2;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.ibatis.annotations.Param;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+
+@Slf4j
+@Api(tags = "快手对接接口类")
+@RestController
+@RequestMapping("/kuaishou/interface")
+public class KuaiShouInterfaceController {
+    @Autowired
+    private IKuaishouInterfaceService2 kuaishouInterfaceService2;
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+
+    @GetMapping(value = "/getOperationRecord")
+    public Result getOperationRecord(@Param("accountId")Long accountId, @Param("operationTarget")Integer operationTarget, @Param("startDate")String startDate, @Param("endDate")String endDate){
+        Result result = new Result();
+        try {
+            if(StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)){
+                result.setSuccess(false);
+                result.setMessage("时间参数不能为空");
+                return result;
+            }
+
+            if(operationTarget == null){
+                result.setSuccess(false);
+                result.setMessage("类型不能为空");
+                return result;
+            }
+
+            if(accountId == null){
+                //1:查询当日数据
+                QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("media_id", 2);
+                queryWrapper.orderByDesc("create_time");
+                List<CtopOauthToken> tokens = tokenService.list(queryWrapper);
+                if (null == tokens || tokens.size() <= 0) {
+                    log.error("定时获取快手操作记录数据异常:未获取到可用的token");
+                    result.setSuccess(false);
+                    result.setMessage("定时获取快手操作记录数据异常:未获取到可用的toke");
+                    return result;
+                }
+
+                executorService = Executors.newFixedThreadPool(8);
+                tokens.forEach(token -> {
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            log.info("获取操作记录开始:accountId:{},startDate:{},endDate:{}", token.getAccountId(), startDate, endDate);
+                            kuaishouInterfaceService2.getOperationRecord(token.getAccountId(), token.getAccessToken(), operationTarget, startDate, endDate);
+                            log.info("获取操作记录结束:accountId:{}", token.getAccountId());
+                        }
+                    });
+                });
+            }else{
+                QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("account_id", accountId);
+                CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(accountId));
+                if (null == token) {
+                    log.error("定时获取快手操作记录数据异常:未获取到可用的token");
+                    result.setSuccess(false);
+                    result.setMessage("定时获取快手操作记录数据异常:未获取到可用的toke");
+                    return result;
+                }
+                log.info("获取快手操作记录开始:accountId:{},startDate:{},endDate:{}", token.getAccountId(), startDate, endDate);
+                kuaishouInterfaceService2.getOperationRecord(token.getAccountId(), token.getAccessToken(), operationTarget, startDate, endDate);
+                log.info("获取快手操作记录结束:accountId:{},startDate:{},endDate:{}", token.getAccountId(), startDate, endDate);
+            }
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return result;
+    }
+
+
+}

+ 7 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl2.java

@@ -30,11 +30,11 @@ public class KuaishouInterfaceServiceImpl2 implements IKuaishouInterfaceService2
         Long days = DateUtils.getDiscrepantDays(startDate, endDate);
         String start = null;
         String end = null;
-        for (int i = 0; i <= days; i++) {
-            start = DateUtils.addDay(startDate, i);
-            end = start;
-            getOperationRecordByPage(advertiserId, accessToken,1, 500, operationTarget, start, end);
-        }
+        //for (int i = 0; i <= days; i++) {
+        //    start = DateUtils.addDay(startDate, i);
+        //    end = start;
+        getOperationRecordByPage(advertiserId, accessToken,1, 500, operationTarget, startDate, endDate);
+        //}
     }
 
     private void getOperationRecordByPage(Long advertiserId, String accessToken, Integer page, Integer pageSize, Integer operationTarget, String startDate, String endDate) {
@@ -67,6 +67,7 @@ public class KuaishouInterfaceServiceImpl2 implements IKuaishouInterfaceService2
                         if (!Check.isNull(dataJson)) {
 
                             Date operationTime = dataJson.getDate("operation_time");
+                            //Date operationDate = DateUtils.parseDate()
                             Integer operationType = dataJson.getInteger("operation_type");
                             operationTarget = dataJson.getInteger("operation_target");
                             Integer roleType = dataJson.getInteger("role_type");
@@ -94,7 +95,7 @@ public class KuaishouInterfaceServiceImpl2 implements IKuaishouInterfaceService2
 
                             KuaishouOperationRecord record = new KuaishouOperationRecord();
                             record.setAccountId(advertiserId);
-                            record.setStatDate(startDate);
+                            record.setStatDate(DateUtils.formatDate(operationTime));
                             record.setOperationTime(operationTime);
                             record.setOperationType(operationType);
                             record.setRoleType(roleType);