diff --git a/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/OrderMapper.java b/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/OrderMapper.java index 664a496b1402a8d0f7c971bd8a4ce78b35030972..0a4b6c1d76b14d5206542ed8fc8089cee60e5054 100644 --- a/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/OrderMapper.java +++ b/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/OrderMapper.java @@ -52,8 +52,8 @@ public interface OrderMapper extends BaseMapper<OrderInfo> { /** * æ›´æ®åˆ›å»ºè®¢å•æ—¶é—´èŽ·å–订å•åˆ—表 - * @param createTime 创建订å•æ—¶é—´ + * @param created 创建订å•æ—¶é—´ * @return 订å•åˆ—表 */ - List<OrderInfo> getByCreateTime(@Param("createTime") Date createTime); + List<OrderInfo> getByCreateTime(@Param("created") Date created); } diff --git a/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/TeamPerformanceMapper.java b/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/TeamPerformanceMapper.java index ad8647e5e5b2b60933ec6a28c993644e4e7aa6f3..75b2daf3ed81995251fae0ce87bf5720534a9dc0 100644 --- a/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/TeamPerformanceMapper.java +++ b/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/TeamPerformanceMapper.java @@ -14,6 +14,11 @@ public interface TeamPerformanceMapper extends BaseMapper<TeamPerformance> { int add(TeamPerformance teamPerformance); + /** + * 编辑 + * @param teamPerformance 团队业绩 + * @return 1 + */ int edit(TeamPerformance teamPerformance); int delById(@Param("id") Integer id); diff --git a/wisenergy-mapper/src/main/resources/mapper/MonthManureMapper.xml b/wisenergy-mapper/src/main/resources/mapper/MonthManureMapper.xml index ca9aedf09a597209f5079ad7c7cd5ea48ac26df2..4cc7637876c1ca6593b44a9dbc0881e093b8a869 100644 --- a/wisenergy-mapper/src/main/resources/mapper/MonthManureMapper.xml +++ b/wisenergy-mapper/src/main/resources/mapper/MonthManureMapper.xml @@ -19,7 +19,7 @@ </sql> <sql id="cols_exclude_id"> - year_month,manure_award,create_time,update_time + `year_month`,manure_award,create_time,update_time </sql> <sql id="vals"> @@ -27,14 +27,14 @@ </sql> <sql id="updateCondition"> - <if test="yearMonth != null">year_month =#{yearMonth},</if> + <if test="yearMonth != null">`year_month` =#{yearMonth},</if> <if test="manureAward != null">manure_award = #{manureAward},</if> update_time =now() </sql> <sql id="criteria"> <if test="id != null">id = #{id}</if> - <if test="yearMonth != null">and year_month =#{yearMonth}</if> + <if test="yearMonth != null">and `year_month` =#{yearMonth}</if> <if test="manureAward != null">and manure_award = #{manureAward}</if> <if test="createTime != null">and create_time >= #{createTime}</if> <if test="updateTime != null">and #{updateTime} >= update_time</if> @@ -67,7 +67,7 @@ <include refid="table"/> <where> <if test="yearMonth != null and yearMonth != ''"> - year_month=#{yearMonth} + `year_month`=#{yearMonth} </if> </where> </select> diff --git a/wisenergy-mapper/src/main/resources/mapper/OrderMapper.xml b/wisenergy-mapper/src/main/resources/mapper/OrderMapper.xml index 3e5b8b43afa3a4f4e64fa0b7d0bc2ba7ff14ce43..86a87c0665667890273b9e6ffed07c652677a39b 100644 --- a/wisenergy-mapper/src/main/resources/mapper/OrderMapper.xml +++ b/wisenergy-mapper/src/main/resources/mapper/OrderMapper.xml @@ -146,9 +146,9 @@ from <include refid="table"/> <where> - <if test="successTime != null "> - YEAR(create_time) = YEAR(#{successTime}) - AND MONTH(create_time) = MONTH(#{successTime}) + <if test="created != null "> + YEAR(created) = YEAR(#{created}) + AND MONTH(created) = MONTH(#{created}) </if> </where> </select> diff --git a/wisenergy-mapper/src/main/resources/mapper/TeamPerformanceMapper.xml b/wisenergy-mapper/src/main/resources/mapper/TeamPerformanceMapper.xml index 283bffe29ce62b6025cecd26ee6a35e15987200d..f3d62dc9f8cff771429595a245bf0ae8ba147740 100644 --- a/wisenergy-mapper/src/main/resources/mapper/TeamPerformanceMapper.xml +++ b/wisenergy-mapper/src/main/resources/mapper/TeamPerformanceMapper.xml @@ -21,7 +21,7 @@ </sql> <sql id="cols_exclude_id"> - user_id,user_level,year_month,month_team_performance,create_time,update_time + user_id,user_level,`year_month`,month_team_performance,create_time,update_time </sql> <sql id="vals"> @@ -29,18 +29,18 @@ </sql> <sql id="updateCondition"> - <if test="userId != null">month_manure_total = #{userId},</if> + <if test="userId != null">user_id = #{userId},</if> <if test="userLevel != null">user_level = #{userLevel},</if> - <if test="yearMonth != null">year_month =#{yearMonth},</if> + <if test="yearMonth != null">`year_month` =#{yearMonth},</if> <if test="monthTeamPerformance != null">month_team_performance =#{monthTeamPerformance},</if> update_time =now() </sql> <sql id="criteria"> <if test="id != null">id = #{id}</if> - <if test="userId != null">and month_manure_total = #{userId}</if> + <if test="userId != null">and user_id = #{userId}</if> <if test="userLevel != null">and user_level = #{userLevel}</if> - <if test="yearMonth != null">and year_month =#{yearMonth}</if> + <if test="yearMonth != null">and `year_month` =#{yearMonth}</if> <if test="monthTeamPerformance != null">and month_team_performance =#{monthTeamPerformance}</if> <if test="createTime != null">and create_time >= #{createTime}</if> <if test="updateTime != null">and #{updateTime} >= update_time</if> @@ -82,9 +82,7 @@ user_id = #{userId} </if> <if test="yearMonth != null"> - AND( - YEAR(year_month) = YEAR(#{yearMonth}) - AND MONTH(year_month) = MONTH(#{yearMonth})) + and `year_month`=#{yearMonth} </if> </where> </select> @@ -99,9 +97,7 @@ user_level = #{userLevel} </if> <if test="yearMonth != null"> - AND( - YEAR(year_month) = YEAR(#{yearMonth}) - AND MONTH(year_month) = MONTH(#{yearMonth})) + and `year_month` = #{yearMonth} </if> </where> </select> @@ -113,7 +109,7 @@ <include refid="table"/> <where> <if test="yearMonth != null"> - year_month < #{yearMonth} + `year_month` < #{yearMonth} </if> </where> </select> @@ -125,9 +121,7 @@ <include refid="table"/> <where> <if test="yearMonth != null"> - AND( - YEAR(year_month) = YEAR(#{yearMonth}) - AND MONTH(year_month) = MONTH(#{yearMonth})) + `year_month` = #{yearMonth} </if> </where> </select> @@ -139,9 +133,7 @@ <include refid="table"/> <where> <if test="yearMonth != null"> - AND( - YEAR(year_month) = YEAR(#{yearMonth}) - AND MONTH(year_month) = MONTH(#{yearMonth})) + `year_month` = #{yearMonth} </if> order by month_team_performance desc limit 20 @@ -155,9 +147,7 @@ <include refid="table"/> <where> <if test="yearMonth != null"> - AND( - YEAR(year_month) = YEAR(#{yearMonth}) - AND MONTH(year_month) = MONTH(#{yearMonth})) + `year_month` = #{yearMonth} </if> order by month_team_performance desc limit 20 diff --git a/wisenergy-service/src/main/java/cn/wisenergy/service/Manager/AccountManager.java b/wisenergy-service/src/main/java/cn/wisenergy/service/Manager/AccountManager.java index 41d65e1b159a87a5b8e4f5a770145bd4fa0b23e8..316f579f6bc7905ef71345ce85a0f694009f7c3e 100644 --- a/wisenergy-service/src/main/java/cn/wisenergy/service/Manager/AccountManager.java +++ b/wisenergy-service/src/main/java/cn/wisenergy/service/Manager/AccountManager.java @@ -96,7 +96,7 @@ public class AccountManager { @Transactional(rollbackFor = Exception.class) public void updateAccountPerformanceMonth(List<TeamPerformance> list) { for (TeamPerformance teamPerformance : list) { - teamPerformanceMapper.updateById(teamPerformance); + teamPerformanceMapper.edit(teamPerformance); } } diff --git a/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java b/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java index 64d202145b146d5b5f88b99c686894761b7d4606..42bff9223a0c3935183676ce02c5938365e90132 100644 --- a/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java +++ b/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java @@ -24,6 +24,7 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.*; +import java.util.stream.Collectors; /** @@ -130,59 +131,70 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> //计算当月所有订å•æˆäº¤é¢ BigDecimal totalMoney = new BigDecimal(0); + + //统计出出æ¯ä¸ªç”¨æˆ·å½“月订å•æˆäº¤é¢ key:userId value:用户当月订å•æˆäº¤é¢ + Map<String, Double> map = new HashMap<>(); for (OrderInfo orderInfo : list) { - //判æ–是å¦æ˜¯æœ¬æœˆ - boolean bool = publicManager.isThisMonth(orderInfo.getCreateTime(), PATTERN); - if (bool && orderInfo.getMonthlyTaskStatus() == 0) { - totalMoney = totalMoney.add(orderInfo.getPayment()); + String userId = orderInfo.getBuyerId(); + double payMoney = orderInfo.getPayment().doubleValue(); + + //key å˜åœ¨ ç´¯åŠ è®¢å•é‡‘é¢ åˆ° value + if (map.containsKey(userId)) { + double money = payMoney + map.get(orderInfo.getBuyerId()); + map.put(orderInfo.getBuyerId(), money); + } else { + //key ä¸å˜åœ¨ï¼ŒåŠ å…¥é›†åˆ + map.put(userId, payMoney); } + + //ç´¯åŠ æ‰€ä»¥è®¢å•æˆäº¤é¢ + totalMoney = totalMoney.add(orderInfo.getPayment()); } - //éåŽ†è®¢å• è®¢å•çŠ¶æ€åˆ›å»ºæ—¶é—´ï¼Œå½“月时间å°äºŽå½“å‰æ—¶é—´ - for (OrderInfo orderInfo : list) { - long createTime = orderInfo.getCreated().getTime(); - long time = System.currentTimeMillis(); - if (createTime <= time) { - //获å–ç”¨æˆ·ä¿¡æ¯ - User user = usersMapper.selectById(orderInfo.getBuyerId()); - if (null == user) { - continue; - } - List<TeamPerformance> teamPerformances = new ArrayList<>(); + //éåŽ†è®¢å• + for (Map.Entry<String, Double> entity : map.entrySet()) { + List<TeamPerformance> teamPerformances = new ArrayList<>(); + //获å–ç”¨æˆ·ä¿¡æ¯ + User user = usersMapper.getByUserId(entity.getKey()); + if (null == user) { + continue; + } - //获å–å›¢é˜Ÿä¸šç»©ä¿¡æ¯ - TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth); - if (null == teamPerformance) { - continue; - } + //获å–å›¢é˜Ÿä¸šç»©ä¿¡æ¯ + TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth); + if (null == teamPerformance) { + continue; + } - //1ã€ç»Ÿè®¡å½“å‰ç”¨æˆ·æœˆåº¦ä¸šç»© - BigDecimal userCount = teamPerformance.getMonthTeamPerformance().add(orderInfo.getPayment()); - teamPerformance.setMonthTeamPerformance(userCount); - teamPerformances.add(teamPerformance); + //1ã€ç»Ÿè®¡å½“å‰ç”¨æˆ·æœˆåº¦ä¸šç»© + BigDecimal userCount = BigDecimal.valueOf(entity.getValue()); + teamPerformance.setMonthTeamPerformance(userCount); + teamPerformances.add(teamPerformance); - //2ã€èŽ·å–当å‰ç”¨æˆ·çš„上级用户列表 todo 邀请ç ç‰äºŽä¸€ä¸ªå›ºå®šå€¼ï¼Œåœæ¢ ç‰äºŽä¸¤ä¸ªå€¼ 七ä½XXXXXXX å’Œ 7777777 - List<User> userList = getByList(user.getUserId()); - if (CollectionUtils.isEmpty(userList)) { - continue; - } + //2ã€èŽ·å–当å‰ç”¨æˆ·çš„上级用户列表 todo 邀请ç ç‰äºŽä¸€ä¸ªå›ºå®šå€¼ï¼Œåœæ¢ ç‰äºŽä¸¤ä¸ªå€¼ 七ä½XXXXXXX å’Œ 7777777 + List<User> userList = getByList(user.getUserId()); + if (CollectionUtils.isEmpty(userList)) { + //更新当å‰ç”¨æˆ·æœˆåº¦ä¸šç»© + accountManager.updateAccountPerformanceMonth(teamPerformances); + continue; + } - for (User userInfo : userList) { - //3ã€ç»Ÿè®¡å½“å‰ç”¨æˆ·ä¸Šçº§æœˆåº¦ç»©æ•ˆ - TeamPerformance team = teamPerformanceMapper.getByUserIdAndTime(userInfo.getUserId(), yearMonth); - if (null == team) { - continue; - } - //1ã€ç»Ÿè®¡å½“å‰ç”¨æˆ·æœˆåº¦ç»©æ•ˆ - BigDecimal monthCount = team.getMonthTeamPerformance().add(orderInfo.getPayment()); - team.setMonthTeamPerformance(monthCount); - teamPerformances.add(team); + for (User userInfo : userList) { + //3ã€ç»Ÿè®¡å½“å‰ç”¨æˆ·ä¸Šçº§æœˆåº¦ç»©æ•ˆ + TeamPerformance team = teamPerformanceMapper.getByUserIdAndTime(userInfo.getUserId(), yearMonth); + if (null == team) { + continue; } - - //4ã€æ›´æ–°è´¦æˆ·æœˆåº¦ç»©æ•ˆ - accountManager.updateAccountPerformanceMonth(teamPerformances); + //1ã€ç»Ÿè®¡å½“å‰ç”¨æˆ·æœˆåº¦ç»©æ•ˆ + BigDecimal monthCount = team.getMonthTeamPerformance().add(userCount); + log.info("当å‰ç”¨æˆ·æœˆåº¦ç»©æ•ˆ:" + monthCount); + team.setMonthTeamPerformance(monthCount); + teamPerformances.add(team); } + + //4ã€æ›´æ–°è´¦æˆ·æœˆåº¦ç»©æ•ˆ + accountManager.updateAccountPerformanceMonth(teamPerformances); } //5ã€èŽ·å–所有用户,如果会员ç‰çº§æ˜¯é»„金以上,计算月度收益 List<User> userList = usersMapper.getAllGoldUser(); @@ -207,9 +219,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> @Override public List<User> getByList(String userId) { List<User> list = new ArrayList<>(); - + User user = usersMapper.getByUserId(userId); getUser(list, userId); - + //去除本身 + list.remove(user); return list; } @@ -303,9 +316,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> public void getUser(List<User> list, String userId) { User user = usersMapper.getByUserId(userId); list.add(user); - if (null != user && StringUtils.isBlank(user.getBeInvitedCode())) { + if (null != user && !StringUtils.isBlank(user.getBeInvitedCode())) { User userInfo = usersMapper.getByBeInvitedCode(user.getBeInvitedCode()); - getUser(list, userInfo.getUserId()); + if (null != userInfo) { + getUser(list, userInfo.getUserId()); + } } } diff --git a/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/OrderServiceImpl.java b/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/OrderServiceImpl.java index fab30441e538ddda2afd3fbe9598c6b991a0b632..cd0a96d0a4d2e9d4777e2e01c7082ee9c84f8e0b 100644 --- a/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/OrderServiceImpl.java +++ b/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/OrderServiceImpl.java @@ -45,7 +45,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem Date endCreatedDate = null; Date startUpdateDate = null; Date endUpdateDate = null; - Date date = new Date(); +// Date date = new Date(); /** * æ ¹æ®è®¢å•çš„创建时间获å–有赞的订å•æ•°æ® æ’入本地数æ®åº“ @@ -56,6 +56,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem @XxlJob(value = "YouZanOrdersjobhandler") @Override public void getYouZanOrdersForCreateTime() throws SDKException { + Date date = new Date(); Token token = youzanToken(); YouzanTradesSoldGet youzanTradesSoldGet = new YouzanTradesSoldGet(); //创建å‚数对象,并设置å‚æ•° @@ -68,6 +69,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem startCreatedDate = sdf.parse(sdf.format(new Date(date.getTime()-(long) 5*60*1000))); log.info("订å•åˆ›å»ºå¼€å§‹æ—¶é—´"+sdf.format(startCreatedDate)); endCreatedDate = sdf.parse(sdf.format(date)); + String format = sdf.format(date); log.info("订å•åˆ›å»ºç»“æŸæ—¶é—´"+sdf.format(endCreatedDate)); } catch (ParseException e) { @@ -140,6 +142,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem @XxlJob(value = "YouZanOrdersForUpdateTimejobhandler") @Override public void getYouZanOrdersForUpdateTime() throws SDKException { + Date date = new Date(); Token token = youzanToken(); YouzanTradesSoldGet youzanTradesSoldGet = new YouzanTradesSoldGet(); //创建å‚数对象,并设置å‚æ•° @@ -148,7 +151,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem try { // startUpdateDate = sdf.parse("2021-02-28 11:04:01"); // endUpdateDate = sdf.parse("2021-03-2 16:39:59"); - startUpdateDate = sdf.parse(sdf.format(new Date(date.getTime()-(long) 60*1000))); + startUpdateDate = sdf.parse(sdf.format(new Date(date.getTime()-(long) 5*60*1000))); log.info("订å•ä¿®æ”¹å¼€å§‹æ—¶é—´"+sdf.format(startUpdateDate)); endUpdateDate = sdf.parse(sdf.format(date)); log.info("订å•ä¿®æ”¹ç»“æŸæ—¶é—´"+sdf.format(endUpdateDate)); diff --git a/wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/AccountController.java b/wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/AccountController.java index e71f2cc32f0a1a1290194a80b2f2bd4fdd653a73..fcbba0349c3f35cf4a8f4fb947bcb55399d3bb3f 100644 --- a/wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/AccountController.java +++ b/wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/AccountController.java @@ -30,20 +30,34 @@ public class AccountController extends BaseController { @ApiOperation(value = "获å–账户信æ¯", notes = "获å–账户信æ¯", httpMethod = "GET") @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String") @GetMapping("/getByUserId") - public R<AccountInfo> getByUserId(String userId){ + public R<AccountInfo> getByUserId(String userId) { return accountService.getByUserId(userId); } @ApiOperation(value = "获å–账户列表信æ¯", notes = "获å–账户列表信æ¯", httpMethod = "GET") @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String") @GetMapping("/getByList") - public List<User> getByList(String userId){ + public List<User> getByList(String userId) { return accountService.getByList(userId); } @ApiOperation(value = "订å•ä½£é‡‘", notes = "订å•ä½£é‡‘", httpMethod = "GET") @GetMapping("/orderRebate") - public R<Boolean> orderRebate(){ + public R<Boolean> orderRebate() { return accountService.orderRebate(); } + + + @ApiOperation(value = "月度肥料", notes = "月度肥料", httpMethod = "GET") + @GetMapping("/monthManure") + public R<Boolean> monthManure() { + return accountService.performanceCount(); + } + + @ApiOperation(value = "最大进æ¥å¥–", notes = "最大进æ¥å¥–", httpMethod = "GET") + @GetMapping("/growAward") + public R<Boolean> growAward() { + return accountService.progressPrizeCount(); + } + }