天翼云-物理机同步
							parent
							
								
									310a5fd830
								
							
						
					
					
						commit
						57edbdd781
					
				| 
						 | 
					@ -0,0 +1,43 @@
 | 
				
			||||||
 | 
					-- cmp.physical_server definition
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE `physical_server` (
 | 
				
			||||||
 | 
					                                   `id` bigint NOT NULL AUTO_INCREMENT,
 | 
				
			||||||
 | 
					                                   `region_id` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '地域',
 | 
				
			||||||
 | 
					                                   `zone_id` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '可用区',
 | 
				
			||||||
 | 
					                                   `vendor_id` bigint DEFAULT NULL COMMENT '所属平台',
 | 
				
			||||||
 | 
					                                   `resource_id` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '资源ID',
 | 
				
			||||||
 | 
					                                   `instance_uuid` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '实例id',
 | 
				
			||||||
 | 
					                                   `device_uuid` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '设备uuid',
 | 
				
			||||||
 | 
					                                   `device_type` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '设备类型',
 | 
				
			||||||
 | 
					                                   `name` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '名称',
 | 
				
			||||||
 | 
					                                   `remark` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '描述',
 | 
				
			||||||
 | 
					                                   `system_volume_raid_id` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '本地系统盘raid id',
 | 
				
			||||||
 | 
					                                   `data_volume_raid_id` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '本地数据盘raid id',
 | 
				
			||||||
 | 
					                                   `image_uuid` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '镜像id',
 | 
				
			||||||
 | 
					                                   `os_type` bigint DEFAULT NULL COMMENT '操作系统类型编号',
 | 
				
			||||||
 | 
					                                   `os_type_name` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '操作系统类型',
 | 
				
			||||||
 | 
					                                   `vpc_uuid` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'vpc uuid',
 | 
				
			||||||
 | 
					                                   `subnet_uuid` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '子网uuid',
 | 
				
			||||||
 | 
					                                   `private_ip` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '内网ipv4地址集合',
 | 
				
			||||||
 | 
					                                   `public_ip` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '公网IPv4地址集合',
 | 
				
			||||||
 | 
					                                   `ebm_state` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '物理机状态',
 | 
				
			||||||
 | 
					                                   `flavor` text COLLATE utf8mb4_general_ci COMMENT '规格信息',
 | 
				
			||||||
 | 
					                                   `interfaces` text COLLATE utf8mb4_general_ci COMMENT '网卡信息',
 | 
				
			||||||
 | 
					                                   `raid_detail` text COLLATE utf8mb4_general_ci COMMENT '磁盘阵列信息',
 | 
				
			||||||
 | 
					                                   `attached_volumes` text COLLATE utf8mb4_general_ci COMMENT '挂载的磁盘ID',
 | 
				
			||||||
 | 
					                                   `device_detail` text COLLATE utf8mb4_general_ci COMMENT '设备信息',
 | 
				
			||||||
 | 
					                                   `freezing` tinyint(1) DEFAULT NULL COMMENT '是否冻结',
 | 
				
			||||||
 | 
					                                   `expired` tinyint(1) DEFAULT NULL COMMENT '是否过期',
 | 
				
			||||||
 | 
					                                   `create_time` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建时间',
 | 
				
			||||||
 | 
					                                   `updated_time` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '更新时间',
 | 
				
			||||||
 | 
					                                   `delete_time` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '删除时间',
 | 
				
			||||||
 | 
					                                   `expired_time` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '到期时间',
 | 
				
			||||||
 | 
					                                   `on_demand` tinyint(1) DEFAULT NULL COMMENT '是否按量计费',
 | 
				
			||||||
 | 
					                                   `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
 | 
				
			||||||
 | 
					                                   `gmt_modify` datetime DEFAULT NULL COMMENT '修改时间',
 | 
				
			||||||
 | 
					                                   `creator_id` bigint DEFAULT NULL COMMENT '所属用户',
 | 
				
			||||||
 | 
					                                   `tenant_id` bigint DEFAULT NULL COMMENT '租户id',
 | 
				
			||||||
 | 
					                                   `project_id` bigint DEFAULT NULL COMMENT '项目id',
 | 
				
			||||||
 | 
					                                   `is_deleted` tinyint(1) DEFAULT NULL COMMENT '是否删除',
 | 
				
			||||||
 | 
					                                   PRIMARY KEY (`id`)
 | 
				
			||||||
 | 
					) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,140 @@
 | 
				
			||||||
 | 
					package com.bocloud.cmp.entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 | 
				
			||||||
 | 
					import com.megatron.common.utils.DateSerializer;
 | 
				
			||||||
 | 
					import com.megatron.entity.annotations.Column;
 | 
				
			||||||
 | 
					import com.megatron.entity.annotations.PK;
 | 
				
			||||||
 | 
					import com.megatron.entity.annotations.Table;
 | 
				
			||||||
 | 
					import com.megatron.entity.bean.Generic;
 | 
				
			||||||
 | 
					import com.megatron.entity.meta.PKStrategy;
 | 
				
			||||||
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					import org.springframework.format.annotation.DateTimeFormat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Date;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 物理机器类
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Table("server")
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					public class PhysicalServer extends Generic {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @PK(value = PKStrategy.AUTO)
 | 
				
			||||||
 | 
					    private Long id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("region_id")
 | 
				
			||||||
 | 
					    private String regionId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("zone_id")
 | 
				
			||||||
 | 
					    private String zoneId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("vendor_id")
 | 
				
			||||||
 | 
					    private Long vendorId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("resource_id")
 | 
				
			||||||
 | 
					    private String resourceId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("instance_uuid")
 | 
				
			||||||
 | 
					    private String instanceUuid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("device_uuid")
 | 
				
			||||||
 | 
					    private String deviceUuid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("device_type")
 | 
				
			||||||
 | 
					    private String deviceType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("name")
 | 
				
			||||||
 | 
					    private String name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("remark")
 | 
				
			||||||
 | 
					    private String remark;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("system_volume_raid_id")
 | 
				
			||||||
 | 
					    private String systemVolumeRaidId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("data_volume_raid_id")
 | 
				
			||||||
 | 
					    private String dataVolumeRaidId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("image_uuid")
 | 
				
			||||||
 | 
					    private String imageUuid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("os_type")
 | 
				
			||||||
 | 
					    private Long osType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("os_type_name")
 | 
				
			||||||
 | 
					    private String osTypeName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("vpc_uuid")
 | 
				
			||||||
 | 
					    private String vpcUuid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("subnet_uuid")
 | 
				
			||||||
 | 
					    private String subnetUuid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("private_ip")
 | 
				
			||||||
 | 
					    private String privateIp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("public_ip")
 | 
				
			||||||
 | 
					    private String publicIp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("ebm_state")
 | 
				
			||||||
 | 
					    private String ebmState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("flavor")
 | 
				
			||||||
 | 
					    private String flavor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("interfaces")
 | 
				
			||||||
 | 
					    private String interfaces;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("raid_detail")
 | 
				
			||||||
 | 
					    private String raidDetail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("attached_volumes")
 | 
				
			||||||
 | 
					    private String attachedVolumes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("device_detail")
 | 
				
			||||||
 | 
					    private String deviceDetail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("freezing")
 | 
				
			||||||
 | 
					    private Boolean freezing;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("expired")
 | 
				
			||||||
 | 
					    private Boolean expired;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("create_time")
 | 
				
			||||||
 | 
					    private String createTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("updated_time")
 | 
				
			||||||
 | 
					    private String updatedTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("delete_time")
 | 
				
			||||||
 | 
					    private String deleteTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("expired_time")
 | 
				
			||||||
 | 
					    private String expiredTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("on_demand")
 | 
				
			||||||
 | 
					    private Boolean onDemand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("gmt_create")
 | 
				
			||||||
 | 
					    @JsonSerialize(using = DateSerializer.class)
 | 
				
			||||||
 | 
					    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 | 
				
			||||||
 | 
					    private Date gmtCreate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("gmt_modify")
 | 
				
			||||||
 | 
					    @JsonSerialize(using = DateSerializer.class)
 | 
				
			||||||
 | 
					    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 | 
				
			||||||
 | 
					    private Date gmtModify;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("creator_id")
 | 
				
			||||||
 | 
					    private Long creatorId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("tenant_id")
 | 
				
			||||||
 | 
					    private Long tenantId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("project_id")
 | 
				
			||||||
 | 
					    private Long projectId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Column("is_deleted")
 | 
				
			||||||
 | 
					    private Boolean isDeleted;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,10 +1,7 @@
 | 
				
			||||||
package com.bocloud.cmp.entity;
 | 
					package com.bocloud.cmp.entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Date;
 | 
					import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 | 
				
			||||||
import java.util.List;
 | 
					import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.springframework.format.annotation.DateTimeFormat;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.megatron.common.utils.DateDeserializer;
 | 
					import com.megatron.common.utils.DateDeserializer;
 | 
				
			||||||
import com.megatron.common.utils.DateSerializer;
 | 
					import com.megatron.common.utils.DateSerializer;
 | 
				
			||||||
import com.megatron.entity.annotations.Column;
 | 
					import com.megatron.entity.annotations.Column;
 | 
				
			||||||
| 
						 | 
					@ -13,10 +10,11 @@ import com.megatron.entity.annotations.PK;
 | 
				
			||||||
import com.megatron.entity.annotations.Table;
 | 
					import com.megatron.entity.annotations.Table;
 | 
				
			||||||
import com.megatron.entity.bean.GenericEntity;
 | 
					import com.megatron.entity.bean.GenericEntity;
 | 
				
			||||||
import com.megatron.entity.meta.PKStrategy;
 | 
					import com.megatron.entity.meta.PKStrategy;
 | 
				
			||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 | 
					 | 
				
			||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import lombok.Data;
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					import org.springframework.format.annotation.DateTimeFormat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Date;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 物理机器类
 | 
					 * 物理机器类
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,56 @@
 | 
				
			||||||
 | 
					package com.bocloud.cmp.repository;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.bocloud.cmp.entity.PhysicalServer;
 | 
				
			||||||
 | 
					import com.megatron.common.utils.Common;
 | 
				
			||||||
 | 
					import com.megatron.common.utils.MapTools;
 | 
				
			||||||
 | 
					import com.megatron.database.core.intf.impl.BasicGenericDao;
 | 
				
			||||||
 | 
					import com.megatron.framework.core.CurrentService;
 | 
				
			||||||
 | 
					import org.springframework.jdbc.core.JdbcTemplate;
 | 
				
			||||||
 | 
					import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
 | 
				
			||||||
 | 
					import org.springframework.stereotype.Repository;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Date;
 | 
				
			||||||
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 物理服务器数据访问
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author wangyu
 | 
				
			||||||
 | 
					 * @version 1.0
 | 
				
			||||||
 | 
					 * @since 2020年5月15日
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Repository("serverRepository")
 | 
				
			||||||
 | 
					public class PhysicalServerRepository extends BasicGenericDao<PhysicalServer, Long> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public PhysicalServerRepository(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate, CurrentService service) {
 | 
				
			||||||
 | 
					        super(jdbcTemplate, npJdbcTemplate, service);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<PhysicalServer> listByVendor(Long vendorId) {
 | 
				
			||||||
 | 
					        String sql = "select a.* from physical_server a where a.is_deleted = 0";
 | 
				
			||||||
 | 
					        Map<String, Object> params = new HashMap<>(8);
 | 
				
			||||||
 | 
					        if (null != vendorId) {
 | 
				
			||||||
 | 
					            sql += " and a.vendor_id = :vendorId";
 | 
				
			||||||
 | 
					            params.put(Common.VENDORID, vendorId);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return this.list(PhysicalServer.class, sql, params);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean removeByVendor(Long vendorId, Long userId) {
 | 
				
			||||||
 | 
					        String sql = "update physical_server set is_deleted = true , gmt_modify = :gmtModify where is_deleted = 0 and vendor_id = :vendorId";
 | 
				
			||||||
 | 
					        Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
 | 
				
			||||||
 | 
					        params.put("gmtModify", new Date());
 | 
				
			||||||
 | 
					        return this.execute(sql, params) > 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean remove(Long id, Long userId) {
 | 
				
			||||||
 | 
					        String sql = "update physical_server set is_deleted = true,gmt_modify = :gmtModify where is_deleted = 0 and id = :id";
 | 
				
			||||||
 | 
					        Map<String, Object> params = MapTools.simpleMap("id", id);
 | 
				
			||||||
 | 
					        params.put("gmtModify", new Date());
 | 
				
			||||||
 | 
					        return this.execute(sql, params) > 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue