DeployService.java 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.qmth.ops.biz.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.qmth.ops.biz.dao.DeployDao;
  6. import com.qmth.ops.biz.dao.DeployDeviceDao;
  7. import com.qmth.ops.biz.dao.DeployOrgDao;
  8. import com.qmth.ops.biz.domain.AppDeploy;
  9. import com.qmth.ops.biz.domain.Deploy;
  10. import com.qmth.ops.biz.domain.DeployDevice;
  11. import com.qmth.ops.biz.domain.DeployOrg;
  12. import com.qmth.ops.biz.query.DeployQuery;
  13. import org.apache.commons.lang3.RandomStringUtils;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import javax.annotation.Resource;
  17. import javax.validation.constraints.NotNull;
  18. import java.util.Arrays;
  19. import java.util.List;
  20. import java.util.UUID;
  21. @Service
  22. public class DeployService extends ServiceImpl<DeployDao, Deploy> {
  23. @Resource
  24. private DeployDao deployDao;
  25. @Resource
  26. private DeployDeviceDao deployDeviceDao;
  27. @Resource
  28. private DeployOrgDao deployOrgDao;
  29. public List<AppDeploy> listAppDeploy() {
  30. return deployDao.listAppDeploy();
  31. }
  32. @Transactional
  33. public Deploy insert(Deploy deploy) {
  34. deploy.setAccessKey(UUID.randomUUID().toString().replaceAll("-", ""));
  35. deploy.setAccessSecret(RandomStringUtils.random(32, true, true));
  36. deploy.setCreateTime(System.currentTimeMillis());
  37. deploy.setUpdateTime(deploy.getCreateTime());
  38. deployDao.insert(deploy);
  39. return deploy;
  40. }
  41. @Transactional
  42. public Deploy update(Deploy deploy) {
  43. deployDao.update(deploy,
  44. new LambdaUpdateWrapper<Deploy>().set(deploy.getName() != null, Deploy::getName, deploy.getName())
  45. .set(deploy.getMode() != null, Deploy::getMode, deploy.getMode())
  46. .set(deploy.getControl() != null, Deploy::getControl, deploy.getControl())
  47. .set(deploy.getIpAllow() != null, Deploy::getIpAllow, deploy.getIpAllow())
  48. .set(Deploy::getUpdateTime, System.currentTimeMillis()).eq(Deploy::getId, deploy.getId()));
  49. return deployDao.selectById(deploy.getId());
  50. }
  51. public DeployQuery query(DeployQuery query) {
  52. return deployDao.selectPage(query, query.build());
  53. }
  54. public Deploy findByAccessKey(String accessKey) {
  55. return deployDao.selectOne(new LambdaQueryWrapper<Deploy>().eq(Deploy::getAccessKey, accessKey));
  56. }
  57. public Deploy findById(Long id) {
  58. return deployDao.selectById(id);
  59. }
  60. public List<DeployDevice> listDevice(Long id) {
  61. return deployDeviceDao.selectList(new LambdaQueryWrapper<DeployDevice>().eq(DeployDevice::getDeployId, id));
  62. }
  63. @Transactional
  64. public void saveDevice(@NotNull Deploy deploy, @NotNull String deviceId, String remark) {
  65. deployDeviceDao.save(deploy.getId(), deviceId, remark, System.currentTimeMillis());
  66. }
  67. @Transactional
  68. public void deleteDevice(@NotNull Deploy deploy, @NotNull String deviceId) {
  69. deployDeviceDao.delete(new LambdaQueryWrapper<DeployDevice>().eq(DeployDevice::getDeployId, deploy.getId())
  70. .eq(DeployDevice::getDeviceId, deviceId));
  71. }
  72. @Transactional
  73. public void updateOrg(@NotNull Deploy deploy, Long[] orgId) {
  74. deployOrgDao.delete(new LambdaQueryWrapper<DeployOrg>().eq(DeployOrg::getDeployId, deploy.getId()));
  75. deployOrgDao.batchInsert(deploy.getId(), Arrays.asList(orgId));
  76. }
  77. }