1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package com.qmth.ops.biz.service;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.qmth.ops.biz.dao.DeployDao;
- import com.qmth.ops.biz.dao.DeployDeviceDao;
- import com.qmth.ops.biz.dao.DeployOrgDao;
- import com.qmth.ops.biz.domain.Deploy;
- import com.qmth.ops.biz.domain.DeployDevice;
- import com.qmth.ops.biz.domain.DeployOrg;
- import com.qmth.ops.biz.query.DeployQuery;
- import org.apache.commons.lang3.RandomStringUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import javax.validation.constraints.NotNull;
- import java.util.Arrays;
- import java.util.List;
- import java.util.UUID;
- @Service
- public class DeployService extends ServiceImpl<DeployDao, Deploy> {
- @Resource
- private DeployDao deployDao;
- @Resource
- private DeployDeviceDao deployDeviceDao;
- @Resource
- private DeployOrgDao deployOrgDao;
- @Transactional
- public Deploy insert(Deploy deploy) {
- deploy.setAccessKey(UUID.randomUUID().toString().replaceAll("-", ""));
- deploy.setAccessSecret(RandomStringUtils.random(32, true, true));
- deploy.setCreateTime(System.currentTimeMillis());
- deploy.setUpdateTime(deploy.getCreateTime());
- deployDao.insert(deploy);
- return deploy;
- }
- @Transactional
- public Deploy update(Deploy deploy) {
- deployDao.update(deploy,
- new LambdaUpdateWrapper<Deploy>().set(deploy.getName() != null, Deploy::getName, deploy.getName())
- .set(deploy.getMode() != null, Deploy::getMode, deploy.getMode())
- .set(deploy.getControl() != null, Deploy::getControl, deploy.getControl())
- .set(deploy.getIpAllow() != null, Deploy::getIpAllow, deploy.getIpAllow())
- .set(Deploy::getUpdateTime, System.currentTimeMillis()).eq(Deploy::getId, deploy.getId()));
- return deployDao.selectById(deploy.getId());
- }
- public DeployQuery query(DeployQuery query) {
- return deployDao.selectPage(query, query.build());
- }
- public Deploy findByAccessKey(String accessKey) {
- return deployDao.selectOne(new LambdaQueryWrapper<Deploy>().eq(Deploy::getAccessKey, accessKey));
- }
- public Deploy findById(Long id) {
- return deployDao.selectById(id);
- }
- public List<DeployDevice> listDevice(Long id) {
- return deployDeviceDao.selectList(new LambdaQueryWrapper<DeployDevice>().eq(DeployDevice::getDeployId, id));
- }
- @Transactional
- public void saveDevice(@NotNull Deploy deploy, @NotNull String deviceId, String remark) {
- deployDeviceDao.save(deploy.getId(), deviceId, remark, System.currentTimeMillis());
- }
- @Transactional
- public void deleteDevice(@NotNull Deploy deploy, @NotNull String deviceId) {
- deployDeviceDao.delete(new LambdaQueryWrapper<DeployDevice>().eq(DeployDevice::getDeployId, deploy.getId())
- .eq(DeployDevice::getDeviceId, deviceId));
- }
- @Transactional
- public void updateOrg(@NotNull Deploy deploy, Long[] orgId) {
- deployOrgDao.delete(new LambdaQueryWrapper<DeployOrg>().eq(DeployOrg::getDeployId, deploy.getId()));
- deployOrgDao.batchInsert(deploy.getId(), Arrays.asList(orgId));
- }
- }
|