|
|
@@ -1,21 +1,19 @@
|
|
|
package com.cyksj.web.controller.manage;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
-import com.cyksj.mapper.AccountMapper;
|
|
|
-import com.cyksj.mapper.GoodsDonMapper;
|
|
|
-import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
-import com.cyksj.mapper.UserMapper;
|
|
|
+import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.netflix.NetflixUserMapper;
|
|
|
+import com.cyksj.mapper.netflix.OrdersMapper;
|
|
|
import com.cyksj.mapper.netflix.TicketMapper;
|
|
|
-import com.cyksj.model.dto.GzhUnionidUserinfo;
|
|
|
-import com.cyksj.model.entity.Account;
|
|
|
-import com.cyksj.model.entity.GoodsDon;
|
|
|
-import com.cyksj.model.entity.GroupsRelation;
|
|
|
-import com.cyksj.model.entity.User;
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.entity.netflix.NetfilxTicket;
|
|
|
+import com.cyksj.model.entity.netflix.NetflixOrders;
|
|
|
import com.cyksj.model.entity.netflix.NetflixUser;
|
|
|
-import com.cyksj.model.entity.netflix.Ticket;
|
|
|
import com.cyksj.model.manage.views.UserView;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
@@ -23,12 +21,14 @@ import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -59,6 +59,14 @@ public class CmsUserController{
|
|
|
|
|
|
private final GoodsDonMapper goodsDonMapper;
|
|
|
|
|
|
+ private final OrdersMapper ordersMapper;
|
|
|
+
|
|
|
+ private final GoodsDonSkuMapper skuMapper;
|
|
|
+
|
|
|
+ private final GroupsMapper groupsMapper;
|
|
|
+
|
|
|
+ private final HomeGroupMapper homeGroupMapper;
|
|
|
+
|
|
|
|
|
|
|
|
|
@GetMapping("/get")
|
|
|
@@ -101,20 +109,239 @@ public class CmsUserController{
|
|
|
|
|
|
@GetMapping("/account/init")
|
|
|
public Result<String> accountInit(){
|
|
|
- List<Account> accounts = accountMapper.selectList(Wrappers.lambdaQuery());
|
|
|
- accounts.forEach((account)->{
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectOne(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getTitle, account.getTitle()));
|
|
|
- account.setGoodsId(goodsDon.getId());
|
|
|
- accountMapper.updateById(account);
|
|
|
+ List<GoodsDon> goodsDons = goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class).notIn(GoodsDon::getTitle, List.of("路由器", "奈飞客厅解决")));
|
|
|
+ List<String> collect = goodsDons.stream().map(GoodsDon::getTitle).collect(Collectors.toList());
|
|
|
+ List<NetfilxTicket> tickets = ticketMapper.selectList(Wrappers.lambdaQuery(NetfilxTicket.class).notIn(NetfilxTicket::getPlatName,List.of("Apple One","Spotify","Youtube")).in(NetfilxTicket::getPlatName,collect));
|
|
|
+
|
|
|
+ List<NetflixOrders> orders = ordersMapper.selectList(Wrappers.lambdaQuery(NetflixOrders.class).ne(NetflixOrders::getMqId, "").like(NetflixOrders::getMqId,"@").ne(NetflixOrders::getGqId, ""));
|
|
|
+
|
|
|
+ orders.forEach((o)->{
|
|
|
+ Account account = new Account();
|
|
|
+ account.setTitle("Apple One");
|
|
|
+ account.setAccount(o.getMqId());
|
|
|
+ account.setPassword(o.getGqId());
|
|
|
+ account.setGoodsId(2L);
|
|
|
+ if(accountMapper.selectOne(Wrappers.lambdaQuery(Account.class).eq(Account::getAccount,account.getAccount()).eq(Account::getPassword,account.getPassword())) == null){
|
|
|
+ try {
|
|
|
+ accountMapper.insert(account);
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ tickets.forEach((ticket)->{
|
|
|
+ List<NetfilxTicket.Buyer> buyers = JSONUtil.parseArray(ticket.getBuyers()).toList(NetfilxTicket.Buyer.class);
|
|
|
+
|
|
|
+ List<NetfilxTicket.Buyer> filter = buyers.stream().filter((buyer) -> (StringUtils.isNotBlank(buyer.getId()))).collect(Collectors.toList());
|
|
|
+ if (filter.size() > 0) {
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectOne(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getTitle, ticket.getPlatName()));
|
|
|
+
|
|
|
+ if (goodsDon != null) {
|
|
|
+ Account account = new Account();
|
|
|
+ account.setTitle(goodsDon.getTitle());
|
|
|
+ account.setGoodsId(goodsDon.getId());
|
|
|
+ account.setAccount(ticket.getAccount());
|
|
|
+ account.setPassword(ticket.getPassword());
|
|
|
+ accountMapper.insert(account);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|
|
|
@GetMapping("/group/init")
|
|
|
public Result<String> groupInt(){
|
|
|
- List<String> list = accountMapper.selectList(Wrappers.lambdaQuery()).stream().map(Account::getAccount).collect(Collectors.toList());
|
|
|
- List<Ticket> tickets = ticketMapper.selectList(Wrappers.lambdaQuery(Ticket.class).in(Ticket::getAccount, list));
|
|
|
+ List<String> list = accountMapper.selectList(Wrappers.lambdaQuery(Account.class).ne(Account::getTitle,"Apple One")).stream().map(Account::getAccount).collect(Collectors.toList());
|
|
|
+ List<NetfilxTicket> tickets = ticketMapper.selectList(Wrappers.lambdaQuery(NetfilxTicket.class).in(NetfilxTicket::getAccount, list));
|
|
|
+
|
|
|
+ tickets.forEach((ticket)->{
|
|
|
+ try {
|
|
|
+ List<NetfilxTicket.Buyer> buyers = JSONUtil.parseArray(ticket.getBuyers()).toList(NetfilxTicket.Buyer.class);
|
|
|
+ List<NetfilxTicket.Buyer> filter = buyers.stream().filter((buyer) -> (StringUtils.isNotBlank(buyer.getId())))
|
|
|
+ .filter((buyer)-> Optional.ofNullable(buyer.getPayflag()).orElse(false))
|
|
|
+ .filter((buyer)->{
|
|
|
+ return ordersMapper.selectOne(Wrappers.lambdaQuery(NetflixOrders.class).eq(NetflixOrders::getTicketId, ticket.getId()).eq(NetflixOrders::getUserId,buyer.getId()).eq(NetflixOrders::getState, "已支付").orderByDesc(NetflixOrders::getId).last(" limit 1")) != null;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (filter.size() > 0) {
|
|
|
+ Account account;
|
|
|
+ NetflixOrders orders = ordersMapper.selectOne(Wrappers.lambdaQuery(NetflixOrders.class).eq(NetflixOrders::getTicketId, ticket.getId()).eq(NetflixOrders::getState, "已支付").orderByDesc(NetflixOrders::getId).last(" limit 1"));
|
|
|
+ if (orders == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectOne(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getTitle, orders.getPlatName()));
|
|
|
+ if(goodsDon == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ account = accountMapper.selectOne(Wrappers.lambdaQuery(Account.class).eq(Account::getAccount, ticket.getAccount()).eq(Account::getTitle,ticket.getPlatName()));
|
|
|
+ Integer months = orders.getMonths();
|
|
|
+ if(months >= 12){
|
|
|
+ months = 13;
|
|
|
+ }
|
|
|
+ if(goodsDon != null){
|
|
|
+ GoodsDonSku sku = skuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, goodsDon.getId()).eq(GoodsDonSku::getMonths, months));
|
|
|
+ GroupsTrips groupsTrips = new GroupsTrips();
|
|
|
+ groupsTrips.setAccountId(account.getId());
|
|
|
+ groupsTrips.setSkuId(sku.getId());
|
|
|
+ groupsTrips.setNum(sku.getNum());
|
|
|
+ groupsTrips.setAvailableNum(sku.getNum() - filter.size());
|
|
|
+ groupsTrips.setStatus(GroupsTrips.Status.validity);
|
|
|
+ groupsMapper.insert(groupsTrips);
|
|
|
|
|
|
+ for (int i = 1; i <= filter.size(); i++) {
|
|
|
+ NetfilxTicket.Buyer buyer = filter.get(i-1);
|
|
|
+ try {
|
|
|
+ NetflixOrders order = ordersMapper.selectOne(Wrappers.lambdaQuery(NetflixOrders.class).eq(NetflixOrders::getTicketId, ticket.getId()).eq(NetflixOrders::getUserId,buyer.getId()).eq(NetflixOrders::getState, "已支付").orderByDesc(NetflixOrders::getId).last(" limit 1"));
|
|
|
+
|
|
|
+ User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getOpenId, buyer.getId()));
|
|
|
+ GroupsRelation relation = new GroupsRelation();
|
|
|
+ relation.setUserId(user.getId());
|
|
|
+
|
|
|
+ relation.setStartTime(new DateTime(Long.parseLong(buyer.getCreat_time())).toJdkDate());
|
|
|
+ relation.setExpiryTime(new DateTime(Long.parseLong(buyer.getEnd_time())).toJdkDate());
|
|
|
+ relation.setStatus(GroupsRelation.Status.validity);
|
|
|
+ relation.setGroupsId(groupsTrips.getId());
|
|
|
+ relation.setAccount(order.getAddAccount());
|
|
|
+ relation.setNum(i);
|
|
|
+ relationMapper.insert(relation);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("error:{}",buyer);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Integer i = filter.size() + 1; i <= groupsTrips.getNum(); i++) {
|
|
|
+ GroupsRelation relation = new GroupsRelation();
|
|
|
+ relation.setUserId(0L);
|
|
|
+ relation.setStatus(GroupsRelation.Status.none);
|
|
|
+ relation.setGroupsId(groupsTrips.getId());
|
|
|
+ relation.setNum(i);
|
|
|
+ relationMapper.insert(relation);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("error:{}",ticket);
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //邀请制度
|
|
|
+ AtomicReference<Integer> count = new AtomicReference<>(1);
|
|
|
+ AtomicReference<Integer> youcount = new AtomicReference<>(1);
|
|
|
+ AtomicReference<Integer> appleCount = new AtomicReference<>(1);
|
|
|
+ Map<String,AtomicReference<Integer>> map = new HashMap<>();
|
|
|
+
|
|
|
+ map.put("Spotify",count);
|
|
|
+ map.put("Youtube",youcount);
|
|
|
+ map.put("Apple One",appleCount);
|
|
|
+ List<NetfilxTicket> ticketList = ticketMapper.selectList(Wrappers.lambdaQuery(NetfilxTicket.class).in(NetfilxTicket::getPlatName,List.of("Apple One", "Spotify", "Youtube")));
|
|
|
+
|
|
|
+ for (NetfilxTicket ticket : ticketList) {
|
|
|
+
|
|
|
+ List<NetfilxTicket.Buyer> buyers = JSONUtil.parseArray(ticket.getBuyers()).toList(NetfilxTicket.Buyer.class);
|
|
|
+
|
|
|
+ log.info("buyers:{}",buyers);
|
|
|
+ List<NetfilxTicket.Buyer> filter = buyers.stream().filter((buyer) -> (StringUtils.isNotBlank(buyer.getId())))
|
|
|
+ .filter((buyer)-> Optional.ofNullable(buyer.getPayflag()).orElse(false))
|
|
|
+ .filter((buyer)-> ordersMapper.selectOne(Wrappers.lambdaQuery(NetflixOrders.class).eq(NetflixOrders::getTicketId, ticket.getId()).eq(NetflixOrders::getUserId,buyer.getId()).eq(NetflixOrders::getState, "已支付").orderByDesc(NetflixOrders::getId).last(" limit 1")) != null)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(filter.size() > 0){
|
|
|
+ NetflixOrders order = ordersMapper.selectOne(Wrappers.lambdaQuery(NetflixOrders.class).eq(NetflixOrders::getTicketId, ticket.getId())
|
|
|
+ .eq(NetflixOrders::getState, "已支付")
|
|
|
+ .orderByDesc(NetflixOrders::getId)
|
|
|
+ .last(" limit 1"));
|
|
|
+ Integer months = order.getMonths();
|
|
|
+ if(order.getMonths() >= 12){
|
|
|
+ months = 13;
|
|
|
+ }
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectOne(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getTitle, order.getPlatName()));
|
|
|
+ if(goodsDon == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ GoodsDonSku sku;
|
|
|
+ if(order.getPlatName().equals("Apple One")){
|
|
|
+ String ticketType = order.getTicketType();
|
|
|
+ if (!StringUtils.equalsAny(ticketType,"美区","台区","马来西亚区")) {
|
|
|
+ ticketType = "美区";
|
|
|
+ }
|
|
|
+ sku = skuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class)
|
|
|
+ .eq(GoodsDonSku::getGoodsId, goodsDon.getId()).like(GoodsDonSku::getSpecVal,ticketType)
|
|
|
+ .eq(GoodsDonSku::getMonths, months));
|
|
|
+ }else {
|
|
|
+ sku = skuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class)
|
|
|
+ .eq(GoodsDonSku::getGoodsId, goodsDon.getId())
|
|
|
+ .eq(GoodsDonSku::getMonths, months));
|
|
|
+
|
|
|
+ }
|
|
|
+ Account account = new Account();
|
|
|
+ account.setAccount(ticket.getPlatName() + map.get(ticket.getPlatName()).get() + "@yhlxj.vip" );
|
|
|
+ account.setPassword(ticket.getPlatName());
|
|
|
+ account.setTitle(goodsDon.getTitle());
|
|
|
+ account.setGoodsId(goodsDon.getId());
|
|
|
+ map.get(ticket.getPlatName()).getAndSet(map.get(ticket.getPlatName()).get() + 1);
|
|
|
+ accountMapper.insert(account);
|
|
|
+
|
|
|
+ GroupsTrips groupsTrips = new GroupsTrips();
|
|
|
+ groupsTrips.setAccountId(account.getId());
|
|
|
+ groupsTrips.setSkuId(sku.getId());
|
|
|
+ groupsTrips.setNum(sku.getNum());
|
|
|
+ groupsTrips.setAvailableNum(sku.getNum() - filter.size());
|
|
|
+ groupsTrips.setStatus(GroupsTrips.Status.validity);
|
|
|
+ groupsMapper.insert(groupsTrips);
|
|
|
+
|
|
|
+ for (int i = 1; i <= filter.size(); i++) {
|
|
|
+ NetfilxTicket.Buyer buyer = filter.get(i-1);
|
|
|
+
|
|
|
+ User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getOpenId, buyer.getId()));
|
|
|
+ if(user == null){
|
|
|
+ log.error("用户不存在 {} ticket:{}", buyer.getId(),ticket);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ NetflixOrders orderByUserId = ordersMapper.selectOne(Wrappers.lambdaQuery(NetflixOrders.class).eq(NetflixOrders::getTicketId, ticket.getId())
|
|
|
+ .eq(NetflixOrders::getState, "已支付")
|
|
|
+ .eq(NetflixOrders::getUserId,user.getOpenId())
|
|
|
+ .orderByDesc(NetflixOrders::getId)
|
|
|
+ .last(" limit 1"));
|
|
|
+ if (orderByUserId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ GroupsRelation relation = new GroupsRelation();
|
|
|
+ relation.setUserId(user.getId());
|
|
|
+ relation.setStartTime(new DateTime(Long.parseLong(buyer.getCreat_time())).toJdkDate());
|
|
|
+ relation.setExpiryTime(new DateTime(Long.parseLong(buyer.getEnd_time())).toJdkDate());
|
|
|
+ relation.setStatus(GroupsRelation.Status.validity);
|
|
|
+ relation.setGroupsId(groupsTrips.getId());
|
|
|
+ relation.setAccount(orderByUserId.getAddAccount());
|
|
|
+ relation.setNum(i);
|
|
|
+ relationMapper.insert(relation);
|
|
|
+ HomeGroup homeGroup = new HomeGroup();
|
|
|
+ homeGroup.setRelationId(relation.getId());
|
|
|
+ homeGroup.setAccountId(account.getId());
|
|
|
+ homeGroup.setStatus(orderByUserId.getIsVisit().equals("已邀请") ? "invited" : "uninvited");
|
|
|
+ homeGroupMapper.insert(homeGroup);
|
|
|
+ }
|
|
|
+ for (Integer i = filter.size() + 1; i <= groupsTrips.getNum(); i++) {
|
|
|
+ GroupsRelation relation = new GroupsRelation();
|
|
|
+ relation.setUserId(0L);
|
|
|
+ relation.setStatus(GroupsRelation.Status.none);
|
|
|
+ relation.setGroupsId(groupsTrips.getId());
|
|
|
+ relation.setNum(i);
|
|
|
+ relationMapper.insert(relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|