AppServiceImpl.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package com.om.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.om.entity.po.*;
  6. import com.om.entity.vo.AppVO;
  7. import com.om.entity.vo.DignosisPageVO;
  8. import com.om.entity.vo.PcbInfoVO;
  9. import com.om.mapper.AppMapper;
  10. import com.om.service.*;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.om.utils.CommonUtil;
  13. import com.om.utils.Result;
  14. import com.om.utils.UserContext;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.apache.commons.lang.StringUtils;
  17. import org.springframework.stereotype.Service;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import javax.annotation.Resource;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. /**
  23. * <p>
  24. * 服务实现类
  25. * </p>
  26. *
  27. * @author bmmx
  28. * @since 2024-03-11
  29. */
  30. @Service
  31. @Slf4j
  32. public class AppServiceImpl extends ServiceImpl<AppMapper, App> implements IAppService {
  33. @Resource
  34. private IUserService userService;
  35. @Resource
  36. private IAppVersionDescribeService describeService;
  37. @Resource
  38. private IAppsClientsService clientsService;
  39. @Override
  40. public Result add(AppVO appVO) {
  41. App app = new App();
  42. BeanUtil.copyProperties(appVO,app);
  43. this.save(app);
  44. Integer appId = app.getId();
  45. //appClient
  46. for (int i = 0; i < appVO.getClientNums().length; i++) {
  47. AppsClients appsClients = new AppsClients();
  48. appsClients.setAppId(appId);
  49. appsClients.setClientNum(appVO.getClientNums()[i]);
  50. clientsService.save(appsClients);
  51. }
  52. for (int i = 0; i < appVO.getLanguage().length; i++) {
  53. AppVersionDescribe describe = new AppVersionDescribe();
  54. describe.setAppId(appId);
  55. describe.setLanguage(appVO.getLanguage()[i]);
  56. describe.setDescription(appVO.getDescription()[i]);
  57. describeService.save(describe);
  58. }
  59. return Result.ok();
  60. }
  61. @Override
  62. public Result delete(Integer id) {
  63. removeById(id);
  64. LambdaQueryWrapper<AppVersionDescribe> queryWrapper = new LambdaQueryWrapper<>();
  65. queryWrapper.eq(AppVersionDescribe::getAppId,id);
  66. boolean info = describeService.remove(queryWrapper);
  67. //还有关联表删除
  68. LambdaQueryWrapper<AppsClients> clientsLambdaQueryWrapper = new LambdaQueryWrapper<>();
  69. clientsLambdaQueryWrapper.eq(AppsClients::getAppId,id);
  70. clientsService.remove(clientsLambdaQueryWrapper);
  71. return Result.ok();
  72. }
  73. @Override
  74. public Result downloadFile(AppVO app) {
  75. return null;
  76. }
  77. @Override
  78. public Result getPageList(Integer pageIndex, Integer pageSize, String username) {
  79. Page<App> page = this.lambdaQuery()
  80. .like(StringUtils.isNotBlank(username), App::getAdmin, username)
  81. .page(new Page<>(pageIndex, pageSize));
  82. List<App> infoList = page.getRecords();
  83. //返回的List集合
  84. List<AppVO> appInfoVOS = new ArrayList<>();
  85. for (int i = 0; i < infoList.size(); i++) {
  86. //传输的类型
  87. AppVO appVO = new AppVO();
  88. App appInfo = infoList.get(i);
  89. //先copy基本数据
  90. BeanUtil.copyProperties(appInfo,appVO);
  91. Integer id = appInfo.getId();
  92. //先取语言和描述信息
  93. LambdaQueryWrapper<AppVersionDescribe> describeQueryWrapper = new LambdaQueryWrapper<>();
  94. describeQueryWrapper.eq(AppVersionDescribe::getAppId,id);
  95. List<AppVersionDescribe> describeList = describeService.list(describeQueryWrapper);
  96. //把取出来的数据存入俩个字符串中
  97. String [] l = new String[describeList.size()];
  98. String [] d = new String[describeList.size()];
  99. for (int i1 = 0; i1 < describeList.size(); i1++) {
  100. l[i1] = describeList.get(i1).getLanguage();
  101. d[i1] = describeList.get(i1).getDescription();
  102. }
  103. appVO.setDescription(d);
  104. appVO.setLanguage(l);
  105. //在取出来客户端编号
  106. LambdaQueryWrapper<AppsClients> queryWrapper = new LambdaQueryWrapper<>();
  107. queryWrapper.eq(AppsClients::getAppId,id);
  108. List<AppsClients> list = clientsService.list(queryWrapper);
  109. String [] n = new String[list.size()];
  110. for (int j = 0; j < n.length; j++) {
  111. n[j] = list.get(j).getClientNum();
  112. }
  113. appVO.setClientNums(n);
  114. appInfoVOS.add(appVO);
  115. }
  116. Page<AppVO> appVOPage = new Page<>();
  117. BeanUtil.copyProperties(page,appVOPage);
  118. appVOPage.setRecords(appInfoVOS);
  119. return Result.ok(appVOPage);
  120. }
  121. @Override
  122. @Transactional
  123. public Result edit(AppVO appVO) {
  124. App app = getById(appVO.getId());
  125. LambdaQueryWrapper<App> infoQueryWapper = new LambdaQueryWrapper<>();
  126. infoQueryWapper.eq(App::getId,app.getId());
  127. BeanUtil.copyProperties(appVO,app);
  128. this.update(app,infoQueryWapper);
  129. //修改客户端id
  130. String[] clientNum = appVO.getClientNums();
  131. LambdaQueryWrapper<AppsClients> clientQueryWrapper = new LambdaQueryWrapper<>();
  132. clientQueryWrapper.eq(AppsClients::getAppId,appVO.getId());
  133. clientsService.remove(clientQueryWrapper);
  134. for (int i = 0; i < clientNum.length; i++) {
  135. AppsClients clients = new AppsClients();
  136. clients.setAppId(appVO.getId());
  137. clients.setClientNum(clientNum[i]);
  138. log.info("修改之后添加的");
  139. clientsService.save(clients);
  140. }
  141. //没有进行描述和语言进行修改
  142. String[] language = appVO.getLanguage();
  143. String[] description = appVO.getDescription();
  144. LambdaQueryWrapper<AppVersionDescribe> queryWrapper = new LambdaQueryWrapper<>();
  145. queryWrapper.eq(AppVersionDescribe::getAppId,appVO.getId());
  146. describeService.remove(queryWrapper);
  147. for (int i = 0; i < language.length; i++) {
  148. AppVersionDescribe describe = new AppVersionDescribe();
  149. describe.setAppId(appVO.getId());
  150. describe.setDescription(description[i]);
  151. describe.setLanguage(language[i]);
  152. describeService.save(describe);
  153. }
  154. return Result.ok();
  155. }
  156. }