DeployService.java 3.4 KB

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