SceneCooperationCountServiceImpl.java 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.fdkankan.ucenter.service.impl;
  2. import com.alibaba.druid.sql.visitor.functions.Concat;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  5. import com.fdkankan.ucenter.entity.ProductCooperation;
  6. import com.fdkankan.ucenter.entity.SceneCooperation;
  7. import com.fdkankan.ucenter.entity.SceneCooperationCount;
  8. import com.fdkankan.ucenter.entity.User;
  9. import com.fdkankan.ucenter.mapper.ISceneCooperationCountMapper;
  10. import com.fdkankan.ucenter.service.ISceneCooperationCountService;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.fdkankan.ucenter.service.ISceneCooperationService;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import java.util.*;
  17. import java.util.stream.Collectors;
  18. /**
  19. * <p>
  20. * 服务实现类
  21. * </p>
  22. *
  23. * @author
  24. * @since 2025-03-20
  25. */
  26. @Service
  27. public class SceneCooperationCountServiceImpl extends ServiceImpl<ISceneCooperationCountMapper, SceneCooperationCount> implements ISceneCooperationCountService {
  28. @Autowired
  29. ISceneCooperationService sceneCooperationService;
  30. @Override
  31. public void saveCount(List<ProductCooperation> needPay, Integer size) {
  32. if(needPay == null || needPay.isEmpty() || size <=0){
  33. return;
  34. }
  35. HashSet<String> hashSet = new HashSet<>();
  36. for (ProductCooperation productCooperation : needPay) {
  37. if(hashSet.contains(productCooperation.getNum()+productCooperation.getSceneType())){
  38. continue;
  39. }
  40. hashSet.add(productCooperation.getNum()+productCooperation.getSceneType());
  41. String num = productCooperation.getNum();
  42. SceneCooperationCount byNum = this.getByNum(num, productCooperation.getSceneType());
  43. if(byNum == null){
  44. SceneCooperationCount count = new SceneCooperationCount();
  45. count.setSceneType(productCooperation.getSceneType());
  46. count.setNum(num);
  47. count.setCount( needPay.size() + 1);
  48. this.save(count);
  49. }else {
  50. LambdaUpdateWrapper<SceneCooperationCount> wrapper = new LambdaUpdateWrapper<>();
  51. wrapper.eq(SceneCooperationCount::getId,byNum.getId());
  52. wrapper.set(SceneCooperationCount::getCount, byNum.getCount() + needPay.size());
  53. this.update(wrapper);
  54. }
  55. }
  56. }
  57. @Override
  58. public List<SceneCooperationCount> getByNumList(List<String> numList,String sceneType) {
  59. if(numList == null || numList.isEmpty()){
  60. return new ArrayList<>();
  61. }
  62. LambdaQueryWrapper<SceneCooperationCount> wrapper = new LambdaQueryWrapper<>();
  63. wrapper.in(SceneCooperationCount::getNum,numList);
  64. wrapper.eq(SceneCooperationCount::getSceneType,sceneType);
  65. return this.list(wrapper);
  66. }
  67. @Override
  68. public SceneCooperationCount getByNum(String num,String sceneType) {
  69. LambdaQueryWrapper<SceneCooperationCount> wrapper = new LambdaQueryWrapper<>();
  70. wrapper.eq(SceneCooperationCount::getNum,num);
  71. wrapper.eq(SceneCooperationCount::getSceneType,sceneType);
  72. List<SceneCooperationCount> list = this.list(wrapper);
  73. if(list == null || list.isEmpty()){
  74. return null;
  75. }
  76. return list.get(0);
  77. }
  78. }