summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshizhendong <[email protected]>2021-03-17 13:57:13 +0800
committershizhendong <[email protected]>2021-03-17 13:57:13 +0800
commit227a3b11cb2a2ad05c1ce194056b44ca55ec8d66 (patch)
tree8c6b287c0e0c7a7063ceca1c078e60e31dc4db63
parent4d72cd078d4ded9b0ac4935a75ab87b1edb05d13 (diff)
NEZ-510 feat: 新增 asset brand / model 接口
-rw-r--r--nz-admin/src/main/java/com/nis/modules/alert/controller/AlertMessageReceiveController.java2
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/controller/AssetBrandModelController.java117
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/dao/AssetBrandDao.java18
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/dao/AssetModelDao.java24
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/entity/Asset.java2
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/entity/AssetBrand.java42
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/entity/AssetModel.java51
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/AssetBrandService.java26
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/AssetModelService.java26
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetBrandServiceImpl.java113
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetModelServiceImpl.java117
-rw-r--r--nz-admin/src/main/resources/db/V2021.03.17__1.Insert asset_brand and asset_model table.sql29
-rw-r--r--nz-admin/src/main/resources/mapper/asset/AssetModelDao.xml33
-rw-r--r--nz-common/src/main/java/com/nis/common/utils/RCode.java8
-rw-r--r--nz-common/src/main/java/com/nis/common/utils/TypeEnum.java3
15 files changed, 609 insertions, 2 deletions
diff --git a/nz-admin/src/main/java/com/nis/modules/alert/controller/AlertMessageReceiveController.java b/nz-admin/src/main/java/com/nis/modules/alert/controller/AlertMessageReceiveController.java
index c7338e21..a79ef17f 100644
--- a/nz-admin/src/main/java/com/nis/modules/alert/controller/AlertMessageReceiveController.java
+++ b/nz-admin/src/main/java/com/nis/modules/alert/controller/AlertMessageReceiveController.java
@@ -41,7 +41,7 @@ public class AlertMessageReceiveController {
try {
alertMessageService.saveBatchToCache(receiveStr, request);
} catch (Exception e) {
- logger.error(request.getRemoteAddr() + " 推送过来的 promethues 告警消息处理异常,消息是:" + receiveStr + " 异常信息是:" + e);
+ logger.error(request.getRemoteAddr() + " 推送过来的 promethues 告警消息处理异常,消息是:" + receiveStr + " 异常信息是:" + e.getMessage(), e);
throw new NZException(RCode.ALERTMSG_PARSE_ERROR);
}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetBrandModelController.java b/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetBrandModelController.java
new file mode 100644
index 00000000..c28152dc
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetBrandModelController.java
@@ -0,0 +1,117 @@
+package com.nis.modules.asset.controller;
+
+import com.nis.common.annotation.SysLog;
+import com.nis.common.smartvalidate.ValidateUtils;
+import com.nis.common.utils.*;
+import com.nis.modules.asset.entity.AssetBrand;
+import com.nis.modules.asset.entity.AssetModel;
+import com.nis.modules.asset.service.AssetBrandService;
+import com.nis.modules.asset.service.AssetModelService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+/**
+ * 资产品牌、型号 controller
+ *
+ * @author shizhendong
+ * @date 2021-03-16
+ */
+@RestController
+@RequestMapping
+public class AssetBrandModelController {
+
+ @Autowired
+ private AssetBrandService brandService;
+
+ @Autowired
+ private AssetModelService modelService;
+
+ @GetMapping("/asset/brand/{id}")
+ @SysLog(operation = OperationEnum.QUERY, type = TypeEnum.ASSETBRAND)
+ public R queryBrandInfo(@PathVariable("id") Integer id) {
+ AssetBrand brand = brandService.queryBrandInfo(id);
+ return R.ok(brand);
+ }
+
+ @GetMapping("/asset/brand")
+ @SysLog(operation = OperationEnum.QUERY, type = TypeEnum.ASSETBRAND)
+ public R queryBrandList(@RequestParam Map<String, Object> params) {
+ PageUtils page = brandService.queryPage(params);
+ return R.ok(page);
+ }
+
+ @PostMapping("/asset/brand")
+ @SysLog(operation = OperationEnum.ADD, type = TypeEnum.ASSETBRAND)
+ public R saveAssetBrand(@RequestBody AssetBrand brand) {
+ ValidateUtils.is(brand.getName()).notNull(RCode.ASSET_BRAND_NAME_ISNULL);
+
+ brandService.saveBrand(brand);
+ return R.ok();
+ }
+
+ @PutMapping("/asset/brand")
+ @SysLog(operation = OperationEnum.UPDATE, type = TypeEnum.ASSETBRAND)
+ public R editAssetBrand(@RequestBody AssetBrand brand) {
+ ValidateUtils.is(brand.getId()).notNull(RCode.ASSET_BRAND_ID_ISNULL)
+ .and(brand.getName()).notNull(RCode.ASSET_BRAND_NAME_ISNULL);
+
+ brandService.updateBrand(brand);
+ return R.ok();
+ }
+
+ @DeleteMapping("/asset/brand")
+ @SysLog(operation = OperationEnum.DELETE, type = TypeEnum.ASSETBRAND)
+ public R deleteAssetBrands(@RequestParam Integer... ids) {
+ ValidateUtils.is(ids).notNull(RCode.ASSET_BRAND_ID_ISNULL);
+
+ brandService.delete(ids);
+ return R.ok();
+ }
+
+ @GetMapping("/asset/model/{id}")
+ @SysLog(operation = OperationEnum.QUERY, type = TypeEnum.MODEL)
+ public R queryModelInfo(@PathVariable("id") Integer id) {
+ AssetModel model = modelService.queryModelInfo(id);
+ return R.ok(model);
+ }
+
+ @GetMapping("/asset/model")
+ @SysLog(operation = OperationEnum.QUERY, type = TypeEnum.MODEL)
+ public R queryModelList(@RequestParam Map<String, Object> params) {
+ PageUtils page = modelService.queryPage(params);
+ return R.ok(page);
+ }
+
+ @PostMapping("/asset/model")
+ @SysLog(operation = OperationEnum.ADD, type = TypeEnum.MODEL)
+ public R saveAssetModel(@RequestBody AssetModel model) {
+ ValidateUtils.is(model.getName()).notNull(RCode.ASSET_MODELNAME_ISNULL)
+ .and(model.getBrandId()).notNull(RCode.ASSET_MODEL_BRANDID_ISNULL);
+
+ modelService.saveModel(model);
+ return R.ok();
+ }
+
+ @PutMapping("/asset/model")
+ @SysLog(operation = OperationEnum.ADD, type = TypeEnum.MODEL)
+ public R editAssetModel(@RequestBody AssetModel model) {
+ ValidateUtils.is(model.getId()).notNull(RCode.ASSET_MODELID_ISNULL)
+ .and(model.getName()).notNull(RCode.ASSET_MODELNAME_ISNULL)
+ .and(model.getBrandId()).notNull(RCode.ASSET_MODEL_BRANDID_ISNULL);
+
+ modelService.updateModel(model);
+ return R.ok();
+ }
+
+ @DeleteMapping("/asset/model")
+ @SysLog(operation = OperationEnum.DELETE, type = TypeEnum.MODEL)
+ public R deleteAssetModels(@RequestParam Integer... ids) {
+ ValidateUtils.is(ids).notNull(RCode.ASSET_MODELID_ISNULL);
+
+ modelService.delete(ids);
+ return R.ok();
+ }
+
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/dao/AssetBrandDao.java b/nz-admin/src/main/java/com/nis/modules/asset/dao/AssetBrandDao.java
new file mode 100644
index 00000000..0261cf79
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/dao/AssetBrandDao.java
@@ -0,0 +1,18 @@
+package com.nis.modules.asset.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.nis.modules.asset.entity.AssetBrand;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * 资产品牌 dao
+ *
+ * @author shizhendong
+ * @date 2021-03-16
+ */
+@Mapper
+@Repository
+public interface AssetBrandDao extends BaseMapper<AssetBrand> {
+
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/dao/AssetModelDao.java b/nz-admin/src/main/java/com/nis/modules/asset/dao/AssetModelDao.java
new file mode 100644
index 00000000..61abb454
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/dao/AssetModelDao.java
@@ -0,0 +1,24 @@
+package com.nis.modules.asset.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.nis.modules.asset.entity.AssetModel;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 资产型号 dao
+ *
+ * @author shizhendong
+ * @date 2021-03-16
+ */
+@Mapper
+@Repository
+public interface AssetModelDao extends BaseMapper<AssetModel> {
+
+ List<AssetModel> queryList(IPage<AssetModel> page, @Param("params") Map<String, Object> params);
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/entity/Asset.java b/nz-admin/src/main/java/com/nis/modules/asset/entity/Asset.java
index c7bbbe4a..9cc86128 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/entity/Asset.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/entity/Asset.java
@@ -209,4 +209,6 @@ public class Asset implements Serializable {
private Integer stateId;
private Integer typeId;
+
+ private Integer brandId;
}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/entity/AssetBrand.java b/nz-admin/src/main/java/com/nis/modules/asset/entity/AssetBrand.java
new file mode 100644
index 00000000..bef31691
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/entity/AssetBrand.java
@@ -0,0 +1,42 @@
+package com.nis.modules.asset.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+
+
+/**
+ * 资产品牌实体
+ *
+ * @author shizhendong
+ * @date 2021-03-16
+ */
+@Data
+@TableName("asset_brand")
+public class AssetBrand implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 主键
+ */
+ @TableId(type = IdType.AUTO)
+ private Integer id;
+
+ /**
+ * 名称
+ */
+ private String name;
+
+ /**
+ * 备注
+ */
+ private String remark;
+
+ /**
+ * 导入seq
+ */
+ private String seq;
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/entity/AssetModel.java b/nz-admin/src/main/java/com/nis/modules/asset/entity/AssetModel.java
new file mode 100644
index 00000000..63a82c1d
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/entity/AssetModel.java
@@ -0,0 +1,51 @@
+package com.nis.modules.asset.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+
+
+/**
+ * 资产型号实体
+ *
+ * @author shizhendong
+ * @date 2021-03-16
+ */
+@Data
+@TableName("asset_model")
+public class AssetModel implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 主键
+ */
+ @TableId(type = IdType.AUTO)
+ private Integer id;
+
+ /**
+ * 品牌id
+ */
+ private Integer brandId;
+
+ /**
+ * 名称
+ */
+ private String name;
+
+ /**
+ * 备注
+ */
+ private String remark;
+
+ /**
+ * 导入seq
+ */
+ private String seq;
+
+ @TableField(exist = false)
+ private AssetBrand brand;
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/AssetBrandService.java b/nz-admin/src/main/java/com/nis/modules/asset/service/AssetBrandService.java
new file mode 100644
index 00000000..8333dd63
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/AssetBrandService.java
@@ -0,0 +1,26 @@
+package com.nis.modules.asset.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.nis.common.utils.PageUtils;
+import com.nis.modules.asset.entity.AssetBrand;
+
+import java.util.Map;
+
+/**
+ * 资产品牌 service
+ *
+ * @author shizhendong
+ * @date 2021-03-16
+ */
+public interface AssetBrandService extends IService<AssetBrand> {
+
+ AssetBrand queryBrandInfo(Integer id);
+
+ PageUtils queryPage(Map<String, Object> params);
+
+ void saveBrand(AssetBrand brand);
+
+ void updateBrand(AssetBrand brand);
+
+ void delete(Integer... ids);
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/AssetModelService.java b/nz-admin/src/main/java/com/nis/modules/asset/service/AssetModelService.java
new file mode 100644
index 00000000..8852b856
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/AssetModelService.java
@@ -0,0 +1,26 @@
+package com.nis.modules.asset.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.nis.common.utils.PageUtils;
+import com.nis.modules.asset.entity.AssetModel;
+
+import java.util.Map;
+
+/**
+ * 资产型号 service
+ *
+ * @author shizhendong
+ * @date 2021-03-16
+ */
+public interface AssetModelService extends IService<AssetModel> {
+
+ AssetModel queryModelInfo(Integer id);
+
+ PageUtils queryPage(Map<String, Object> params);
+
+ void saveModel(AssetModel model);
+
+ void updateModel(AssetModel model);
+
+ void delete(Integer... ids);
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetBrandServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetBrandServiceImpl.java
new file mode 100644
index 00000000..59e65237
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetBrandServiceImpl.java
@@ -0,0 +1,113 @@
+package com.nis.modules.asset.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.nis.common.exception.NZException;
+import com.nis.common.utils.PageUtils;
+import com.nis.common.utils.Query;
+import com.nis.common.utils.RCode;
+import com.nis.common.utils.ToolUtil;
+import com.nis.modules.asset.dao.AssetBrandDao;
+import com.nis.modules.asset.entity.Asset;
+import com.nis.modules.asset.entity.AssetBrand;
+import com.nis.modules.asset.entity.AssetModel;
+import com.nis.modules.asset.service.AssetBrandService;
+import com.nis.modules.asset.service.AssetModelService;
+import com.nis.modules.asset.service.AssetService;
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 资产品牌 service 实现类
+ *
+ * @author shizhendong
+ * @date 2021-03-16
+ */
+@Service
+public class AssetBrandServiceImpl extends ServiceImpl<AssetBrandDao, AssetBrand> implements AssetBrandService {
+
+ @Autowired
+ private AssetService assetService;
+
+ @Autowired
+ private AssetModelService modelService;
+
+ @Override
+ public AssetBrand queryBrandInfo(Integer id) {
+ AssetBrand brand = this.getById(id);
+ if (ToolUtil.isEmpty(brand)) {
+ throw new NZException(RCode.ASSET_BRAND_NOT_FOUND);
+ }
+ return brand;
+ }
+
+ @Override
+ public PageUtils queryPage(Map<String, Object> params) {
+ LambdaQueryWrapper<AssetBrand> queryWrapper = new LambdaQueryWrapper<AssetBrand>()
+ .like(ToolUtil.isNotEmpty(params.get("name")), AssetBrand::getName, params.get("name"));
+ IPage<AssetBrand> page = this.page(new Query<AssetBrand>().getPage(params), queryWrapper);
+ return new PageUtils(page);
+ }
+
+ private void validateAssetBrandInfo(AssetBrand brand) {
+ // 1. 名称重复
+ List<AssetBrand> list = this.list(new LambdaQueryWrapper<AssetBrand>().eq(AssetBrand::getName, brand.getName()));
+ boolean flag = false;
+ // 当只有一个结果并且这个结果是自身时,或没有结果时,说明名称不重复
+ if ((list == null || list.size() == 0) || (list != null && list.size() == 1 && list.get(0).getId().equals(brand.getId()))) {
+ flag = true;
+ }
+
+ if (!flag) {
+ throw new NZException(RCode.ASSET_BRAND_NAME_DUPLICATE);
+ }
+ }
+
+ @Override
+ public void saveBrand(AssetBrand brand) {
+ // 1. 校验
+ this.validateAssetBrandInfo(brand);
+
+ // 保存
+ this.save(brand);
+ }
+
+ @Override
+ public void updateBrand(AssetBrand brand) {
+ // 1. 校验
+ this.validateAssetBrandInfo(brand);
+
+ // 保存
+ this.updateById(brand);
+ }
+
+ @Override
+ public void delete(Integer... ids) {
+ // 1. 已被 asset_model 引用的品牌信息不允许删除
+ List<AssetModel> modelList = modelService.list();
+ List<Integer> modelUseBrandIdList = modelList.stream().map(AssetModel::getBrandId).distinct().collect(Collectors.toList());
+
+ modelUseBrandIdList.retainAll(Arrays.asList(ids));
+ if (CollectionUtils.isNotEmpty(modelUseBrandIdList)) {
+ throw new NZException("These brands have been used by models and cannot be deleted. Details: " + modelUseBrandIdList.toString(), RCode.ASSET_BRAND_BEUSED_CAN_NOT_REMOVE.getCode());
+ }
+
+ // 2. 已被 asset 引用的品牌信息不允许删除
+ List<Asset> assetList = assetService.list();
+ List<Integer> assetUseBrandIdList = assetList.stream().map(Asset::getBrandId).distinct().collect(Collectors.toList());
+ assetUseBrandIdList.retainAll(Arrays.asList(ids));
+ if (CollectionUtils.isNotEmpty(assetUseBrandIdList)) {
+ throw new NZException("These brands have been used by assets and cannot be deleted. Details: " + assetUseBrandIdList.toString(), RCode.ASSET_BRAND_BEUSED_CAN_NOT_REMOVE.getCode());
+ }
+
+ // 删除
+ this.removeByIds(Arrays.asList(ids));
+ }
+}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetModelServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetModelServiceImpl.java
new file mode 100644
index 00000000..dd9f2789
--- /dev/null
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetModelServiceImpl.java
@@ -0,0 +1,117 @@
+package com.nis.modules.asset.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.nis.common.exception.NZException;
+import com.nis.common.utils.PageUtils;
+import com.nis.common.utils.Query;
+import com.nis.common.utils.RCode;
+import com.nis.common.utils.ToolUtil;
+import com.nis.modules.asset.dao.AssetModelDao;
+import com.nis.modules.asset.entity.Asset;
+import com.nis.modules.asset.entity.AssetBrand;
+import com.nis.modules.asset.entity.AssetModel;
+import com.nis.modules.asset.service.AssetBrandService;
+import com.nis.modules.asset.service.AssetModelService;
+import com.nis.modules.asset.service.AssetService;
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 资产型号 service 实现类
+ *
+ * @author shizhendong
+ * @date 2021-03-16
+ */
+@Service
+public class AssetModelServiceImpl extends ServiceImpl<AssetModelDao, AssetModel> implements AssetModelService {
+
+ @Autowired
+ private AssetService assetService;
+
+ @Autowired
+ private AssetBrandService brandService;
+
+ @Autowired
+ private AssetModelDao assetModelDao;
+
+ @Override
+ public AssetModel queryModelInfo(Integer id) {
+ AssetModel model = this.getById(id);
+ if (ToolUtil.isEmpty(model)) {
+ throw new NZException(RCode.ASSET_MODEL_NOTFOUND);
+ }
+ AssetBrand brand = brandService.getById(model.getBrandId());
+ model.setBrand(brand);
+ return model;
+ }
+
+ @Override
+ public PageUtils queryPage(Map<String, Object> params) {
+ IPage<AssetModel> page = new Query<AssetModel>().getPage(params);
+ List<AssetModel> modelList = assetModelDao.queryList(page, params);
+ page.setRecords(modelList);
+ return new PageUtils(page);
+ }
+
+ private void validateAssetModelInfo(AssetModel model) {
+ // 1. brand 是否存在
+ AssetBrand brand = brandService.getById(model.getBrandId());
+ if (ToolUtil.isEmpty(brand)) {
+ throw new NZException(RCode.ASSET_BRAND_NOT_FOUND);
+ }
+
+ // 2. 名称重复
+ List<AssetModel> list = this.list(new LambdaQueryWrapper<AssetModel>().eq(AssetModel::getBrandId, model.getBrandId()).eq(AssetModel::getName, model.getName()));
+ boolean flag = false;
+ // 当只有一个结果并且这个结果是自身时,或没有结果时,说明名称不重复
+ if ((list == null || list.size() == 0) || (list != null && list.size() == 1 && list.get(0).getId().equals(model.getId()))) {
+ flag = true;
+ }
+
+ if (!flag) {
+ throw new NZException(RCode.ASSET_MODELNAME_DUPLICATE);
+ }
+ }
+
+ @Override
+ public void saveModel(AssetModel model) {
+ // 1. 校验
+ this.validateAssetModelInfo(model);
+
+ // 保存
+ this.save(model);
+ }
+
+
+ @Override
+ public void updateModel(AssetModel model) {
+ // 1. 校验
+ this.validateAssetModelInfo(model);
+
+ // 保存
+ this.updateById(model);
+ }
+
+ @Override
+ public void delete(Integer... ids) {
+ // 1. 已被 asset 引用的型号信息不允许删除
+ List<Asset> assetList = assetService.list();
+ List<Integer> assetUseModelIdList = assetList.stream().map(Asset::getModelId).distinct().collect(Collectors.toList());
+
+ assetUseModelIdList.retainAll(Arrays.asList(ids));
+ if (CollectionUtils.isNotEmpty(assetUseModelIdList)) {
+ throw new NZException("These models have been used by assets and cannot be deleted. Details: " + assetUseModelIdList.toString(), RCode.ASSET_MODELRELATED_ASSET.getCode());
+ }
+
+ // 删除
+ this.removeByIds(Arrays.asList(ids));
+ }
+}
diff --git a/nz-admin/src/main/resources/db/V2021.03.17__1.Insert asset_brand and asset_model table.sql b/nz-admin/src/main/resources/db/V2021.03.17__1.Insert asset_brand and asset_model table.sql
new file mode 100644
index 00000000..261b633c
--- /dev/null
+++ b/nz-admin/src/main/resources/db/V2021.03.17__1.Insert asset_brand and asset_model table.sql
@@ -0,0 +1,29 @@
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ----------------------------
+-- Table structure for asset_brand
+-- ----------------------------
+DROP TABLE IF EXISTS `asset_brand`;
+CREATE TABLE `asset_brand` (
+ `id` int(10) NOT NULL AUTO_INCREMENT,
+ `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '名称',
+ `remark` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '备注',
+ `seq` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
+ PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
+
+-- ----------------------------
+-- Table structure for asset_model
+-- ----------------------------
+DROP TABLE IF EXISTS `asset_model`;
+CREATE TABLE `asset_model` (
+ `id` int(10) NOT NULL AUTO_INCREMENT,
+ `brand_id` int(10) NOT NULL,
+ `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '型号名称',
+ `remark` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
+ `seq` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
+ PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
+
+SET FOREIGN_KEY_CHECKS = 1;
diff --git a/nz-admin/src/main/resources/mapper/asset/AssetModelDao.xml b/nz-admin/src/main/resources/mapper/asset/AssetModelDao.xml
new file mode 100644
index 00000000..14fc125e
--- /dev/null
+++ b/nz-admin/src/main/resources/mapper/asset/AssetModelDao.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.nis.modules.asset.dao.AssetModelDao">
+
+ <resultMap type="com.nis.modules.asset.entity.AssetModel" id="modelWithBrandMap">
+ <result property="id" column="id"/>
+ <result property="name" column="name"/>
+ <result property="brandId" column="brand_id"/>
+ <result property="remark" column="remark"/>
+ <result property="seq" column="seq"/>
+
+ <association property="brand" columnPrefix="b_" javaType="com.nis.modules.asset.entity.AssetBrand">
+ <id property="id" column="id"/>
+ <result property="name" column="name"/>
+ </association>
+ </resultMap>
+
+ <select id="queryList" resultMap="modelWithBrandMap">
+ SELECT
+ model.*,
+ brand.id as b_id,
+ brand.name as b_name
+ FROM
+ asset_model model
+ LEFT JOIN asset_brand brand ON model.brand_id = brand.id
+ <where>
+ <if test="params.name != null and params.name != ''">
+ model.name LIKE CONCAT('%', #{params.name}, '%')
+ </if>
+ </where>
+ </select>
+</mapper>
diff --git a/nz-common/src/main/java/com/nis/common/utils/RCode.java b/nz-common/src/main/java/com/nis/common/utils/RCode.java
index db36e1dd..950dc2f8 100644
--- a/nz-common/src/main/java/com/nis/common/utils/RCode.java
+++ b/nz-common/src/main/java/com/nis/common/utils/RCode.java
@@ -250,6 +250,8 @@ public enum RCode {
ASSET_MODELID_INCONSISTENT(323010,"Asset model is inconsistent with model Id"),
ASSET_IPMITYPE_ERROR(323011,"Asset type must be a server can save ipmi information"),
ASSET_MODELRELATED_MIBS(323012, "These models contain mibs and cannot be deleted"),
+ ASSET_MODEL_BRANDID_ISNULL(321013, "Asset model brand id can not be null"),
+
ACCOUNT_AUTHTYPE_ISNULL(331000, "Authentication type cannot be empty"),
ACCOUNT_AUTHTYPE_INVALIDE(333001, "Invalid authentication type"),
@@ -317,6 +319,12 @@ public enum RCode {
TYPECONF_PARENT_NOT_FOUND(356015, "Asset type parent config not found"),
TYPECONF_CONTAIN_BABY_CAN_NOT_REMOVE(357016, "This configurations contain sub-configuration and cannot be deleted"),
+ ASSET_BRAND_NOT_FOUND(366000, "Asset brand not found"),
+ ASSET_BRAND_NAME_ISNULL(361001, "Asset brand name is null"),
+ ASSET_BRAND_ID_ISNULL(361002, "Asset brand id is null"),
+ ASSET_BRAND_NAME_DUPLICATE(362003, "Asset brand name is duplicate"),
+ ASSET_BRAND_BEUSED_CAN_NOT_REMOVE(367004, "This brand is already used and cannot be deleted"),
+
/**
* alerts菜单栏相关
*/
diff --git a/nz-common/src/main/java/com/nis/common/utils/TypeEnum.java b/nz-common/src/main/java/com/nis/common/utils/TypeEnum.java
index 916c56be..5ee2c044 100644
--- a/nz-common/src/main/java/com/nis/common/utils/TypeEnum.java
+++ b/nz-common/src/main/java/com/nis/common/utils/TypeEnum.java
@@ -28,7 +28,8 @@ public enum TypeEnum {
ALERTSILENCE("alert silence"),
ASSETSTATECONF("asset state conf"),
ASSETTYPECONF("asset type conf"),
- EXPRESSIONTMPL("expression tmpl");
+ EXPRESSIONTMPL("expression tmpl"),
+ ASSETBRAND("asset brand");
private String value;
public String getValue(){