资源目录配置

项目需求 资源目录配置
文章图片

资源目录配置
文章图片

资源目录配置包含两个页面:(1)区域信息配置(2)点位类型图标配置
需求分析 1.区域信息配置页面
该页面需要提供的接口有:
(1)展示数据库中所有的区域信息接口
(2)查询接口:可以根据区域名称、区域编码、是否配置点位类型以及点位类型进行数据库搜索操作
(2)批量/单个区域信息修改接口:只能修改是否配置点位类型以及点位类型,本质上是更新数据库数据
2.点位类型图标配置
该页面需要提供的接口有:
(1)图片上传接口:将图片上传至云存储,返回url和图片名称
(2)新增点位类型接口:点击新增时,输入点位类型名称,并通过上传接口将点位类型对应的点位图标、聚合图标上传至云存储,并返回对应的url和图片名称,点击确定后,将点位类型名称和两个url存入数据库
(3)修改接口:修改点位类型的对应图标
(4)删除接口
实现 1.数据库的创建 数据库表字段
一条完整的区域信息需要包含的字段有:区域编码(主键,唯一)、区域名称、区域路径、是否配置点位类型(0-未配置 1-已配置)、点位类型(0-未配置/无类型 1-蓝天卫士 2-重点监控)、点位图标url、点位图标名称、聚合图标url、聚合图标名称、创建时间、创建人、更新时间、更新人
数据库表脚本
数据库脚本表创建脚本如下所示:

/*==============================================================*/ /* DBMS name:PostgreSQL 9.x*/ /* Created on:2021/10/27 08:54:08*/ /*==============================================================*/ SET client_encoding = 'utf8'; CREATE extension IF NOT EXISTS "uuid-ossp"; /*==============================================================*/ /* Table: tb_resource_config*/ /*==============================================================*/ CREATE TABLE public.tb_resource_config ( index_codevarchar(128) NOT NULL, region_namevarchar(64) NOT NULL, region_pathvarchar NOT NULL, point_configinteger NOT NULL, point_typeinteger NOT NULL, point_icon_urlvarchar, point_icon_namevarchar, aggre_icon_urlvarchar, aggre_icon_namevarchar, create_timetimestamp NOT NULL, create_uservarchar NOT NULL, update_timetimestamp NOT NULL, update_uservarchar NOT NULL, CONSTRAINT pk_tb_resource_config PRIMARY KEY (index_code) ); COMMENT ON TABLE public.tb_resource_config IS '资源配置表'; -- Column commentsCOMMENT ON COLUMN public.tb_resource_config.index_code IS '区域编码'; COMMENT ON COLUMN public.tb_resource_config.region_name IS '区域名称'; COMMENT ON COLUMN public.tb_resource_config.region_path IS '区域路径'; COMMENT ON COLUMN public.tb_resource_config.point_config IS '是否配置点位类型:0-未配置1-已配置'; COMMENT ON COLUMN public.tb_resource_config.point_type IS '点位类型:0-未配置/无类型 1-蓝天卫士;2-重点监控'; COMMENT ON COLUMN public.tb_resource_config.point_icon_url IS '点位图标url'; COMMENT ON COLUMN public.tb_resource_config.point_icon_name IS '点位图标名称'; COMMENT ON COLUMN public.tb_resource_config.aggre_icon_url IS '聚合图标url'; COMMENT ON COLUMN public.tb_resource_config.aggre_icon_name IS '聚合图标名称'; COMMENT ON COLUMN public.tb_resource_config.create_time IS '创建时间'; COMMENT ON COLUMN public.tb_resource_config.create_user IS '创建人名称'; COMMENT ON COLUMN public.tb_resource_config.update_time IS '更新时间'; COMMENT ON COLUMN public.tb_resource_config.update_user IS '更新人名称';

实体类 创建数据库表对应的实体类
在business->entity->local下创建实体类TbResource.java
@Data @TableName("tb_resource_config") @ApiModel("区域信息配置") @Builder public class TbResource {@TableId("index_code") @ApiModelProperty("区域编码") private String indexCode; @TableField("region_name") @ApiModelProperty("区域名称") private String regionName; @TableField("region_path") @ApiModelProperty("区域路径") private String regionPath; @TableField("point_config") @ApiModelProperty("是否配置点位类型:0-未配置1-已配置") private Integer pointConfig; @TableField("point_type") @ApiModelProperty("点位类型:0-未配置/无类型 1-蓝天卫士;2-重点监控") private Integer pointType; @TableField("point_icon_url") @ApiModelProperty("点位图标url") private String pointIconUrl; @TableField("point_icon_name") @ApiModelProperty("点位图标名称") private String pointIconName; @TableField("aggre_icon_url") @ApiModelProperty("聚合图标url") private String aggreIconUrl; @TableField("aggre_icon_name") @ApiModelProperty("聚合图标name") private String aggreIconName; @TableField("delete") @ApiModelProperty("是否删除:-1-删除 0-未删除") private Integer delete; @TableField("create_time") @ApiModelProperty("创建时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Timestamp createTime; @TableField("create_user") @ApiModelProperty("创建人名称") private String createUser; @TableField("update_time") @ApiModelProperty("更新时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Timestamp updateTime; @TableField("update_user") @ApiModelProperty("更新人名称") private String updateUser; }

Mapper层 在business->mapper->local下创建实体类TbResourceMapper.java
/** * @Description: * @Author: wangzhenguo7 * @Date: 2021/11/03 11:12 */ @Mapper public interface TbResourceMapper extends BaseMapper {}

2.从irds组件获取原始区域信息数据 原始的区域信息(区域编码、区域名称、区域路径)需要从irds组件获取,从irds组件获取全部的区域信息后,将其转换为TbResource对象存入数据库,同时开启定时任务,监控irds组件的区域信息是否发生新增、更新、删除等,具体操作可在海星框架下通过starfish-starter-sync-resource(资源同步)来完成
irds组件的区域数据同步实例
示例代码如下:
@Service public class RegionIrdsSyncService implements IResourceIrdsSync { private static Logger logger = LoggerFactory.getLogger(RegionIrdsSyncService.class) ; /** * 获取资源类型: * 1.用于接收变更通知和获取irds数据,例如region * @return */ @Override public String getResourceType() { //设置获取的资源类型为REGION return ResourceTypeEnum.REGION.getResourceType(); }/** * 全量同步 * 1.向数据来源获取指定资源类型的所有数据 * @param list全量数据,即从irds组件获取到的原始区域信息 */ @Override public void syncAll(List resList) { logger.info(); //TODO 自定义操作,转换数据类型存入自己的数据库 } /** * 实时添加 * 1.接收变更通知,向数据来源获取指定资源类型的变更数据 * @param list变更数据,即irds组件新增的原始区域信息 */ @Override public void add(List resList) { logger.info(); //TODO 变更数据添加 } /** * 实时更新 * 1.接收变更通知,向数据来源获取指定资源类型的变更数据 * @param list变更数据 ,即irds组件修改的原始区域信息 */ @Override public void update(List resList) { logger.info(); //TODO 变更数据修改 } /** * 实时删除 * 1.接收变更通知 * @param list变更数据标识,删除原始区域信息的标识 */ @Override public void delete(List resIdList) { logger.info(); //TODO 变更数据删除 } }

定时任务出发操作:
starfish.resource.sync.cron-time=0 0 1 * * ?

自定义irds组件区域数据同步
  1. 获取原始区域信息中的区域编码、区域名称、区域路径
    irds组件中的原始区域信息在实际项目中并非全部都是必须的,在本项目中只需要区域编码、区域名称、区域路径这三个属性值即可,因此需要定义一个实体类,从原始区域信息对象中获取所需的属性即可
    在business->dto下创建RegionIrdsInfo.java
/** * @Description:对irds组件区域信息进行转换 * @Author: wangzhenguo7 * @Date: 2021/11/03 11:10 */ @Data public class RegionIrdsInfo {@ApiModelProperty("区域路径") private String regionPath; @ApiModelProperty("区域名称") private String name; @ApiModelProperty("区域编码") private String indexCode; }

  1. 引入starfish-starter-sync-resource(资源同步)
    (1)引入pom依赖
    在business下的pom文件中引入pom依赖
com.hikvision.starfish starfish-starter-sync-resource 1.8.1.RELEASE

(2)在service->impl下创建RegionSyncService.java,实现IResourceIrdsSync接口,进行区域信息的全量同步
@Service public class RegionSyncService implements IResourceIrdsSync {private static Logger LOGGER = LoggerFactory.getLogger(RegionSyncService.class); @Autowired private TbResourceMapper tbResourceMapper; /** * 获取资源类型: * 1.用于接收变更通知和获取irds数据,例如region * @return */ @Override public String getResourceType() { //设置获取的资源类型为REGION return ResourceTypeEnum.REGION.getResourceType(); }/** * 全量同步 * 1.向数据来源获取指定资源类型的所有数据 * @param list全量数据 */ @Override public void syncAll(List list) { LOGGER.info("全量同步irds组件的区域信息:{}", list); List regionIrdsInfoList = this.map2Object(list); try { if (!CollectionUtils.isEmpty(regionIrdsInfoList)){ saveTbResource(regionIrdsInfoList); //存入数据库 } }catch (Exception e){ LOGGER.error("{},{},{}", DefaultErrorCode.PG_SQL_INSERT_ERROR.getCode(), DefaultErrorCode.PG_SQL_INSERT_ERROR.getMessage(), DefaultErrorCode.PG_SQL_INSERT_ERROR.getContent(), e); } }/** * 实时添加 * 1.接收变更通知,向数据来源获取指定资源类型的变更数据 * @param list变更数据 */ @Override public void add(List list) { LOGGER.info("irds组件新增的区域信息:{}", list); List regionIrdsInfoList = this.map2Object(list); try { if (!CollectionUtils.isEmpty(regionIrdsInfoList)){ saveTbResource(regionIrdsInfoList); //存入数据库 } }catch (Exception e){ LOGGER.error("{},{},{}", DefaultErrorCode.PG_SQL_INSERT_ERROR.getCode(), DefaultErrorCode.PG_SQL_INSERT_ERROR.getMessage(), DefaultErrorCode.PG_SQL_INSERT_ERROR.getContent(), e); } }/** * 实时更新 * 1.接收变更通知,向数据来源获取指定资源类型的变更数据 * @param list变更数据 */ @Override public void update(List list) { LOGGER.info("irds组件更新的区域信息:{}", list); List regionIrdsInfoList = this.map2Object(list); try { if (!CollectionUtils.isEmpty(regionIrdsInfoList)){ updateTbResource(regionIrdsInfoList); //更新数据库 } }catch (Exception e){ LOGGER.error("{},{},{}", DefaultErrorCode.PG_SQL_UPDATE_ERROR.getCode(), DefaultErrorCode.PG_SQL_UPDATE_ERROR.getMessage(), DefaultErrorCode.PG_SQL_UPDATE_ERROR.getContent(), e); } }/** * 实时删除 * 1.接收变更通知 * @param list变更数据标识 */ @Override public void delete(List list) { LOGGER.info("irds组件删除的区域信息:{}", list); try { if (!CollectionUtils.isEmpty(list)){ list.forEach(l->{ tbResourceMapper.deleteById(l); //删除数据 }); } }catch (Exception e){ LOGGER.error("{},{},{}", DefaultErrorCode.PG_SQL_DELETE_ERROR.getCode(), DefaultErrorCode.PG_SQL_DELETE_ERROR.getMessage(), DefaultErrorCode.PG_SQL_DELETE_ERROR.getContent(), e); } }/** * 类型转换 * 将从irds获取到的区域信息转换为RegionIrdsInfo类对象 * @param resList * @return */ public List map2Object(List resList){ List regionIrdsInfos = new ArrayList<>(); if (!CollectionUtils.isEmpty(resList)){ resList.forEach(res->{ RegionIrdsInfo regionIrdsInfo = JSONObject.parseObject(JSONObject.toJSONString(res), RegionIrdsInfo.class); regionIrdsInfos.add(regionIrdsInfo); }); } return regionIrdsInfos; }/** * 存入数据库 * @param list */ private void saveTbResource(List list){ list.forEach(l->{ TbResource tbResource = TbResource.builder() .indexCode(l.getIndexCode()) .regionName(l.getName()) .regionPath(l.getRegionPath()) .pointConfig(0) .pointType(0) .pointIconUrl(null) .aggreIconUrl(null) .createTime(getNowTime()) .createUser("ss") .updateTime(getNowTime()) .updateUser("ss") .build(); tbResourceMapper.insert(tbResource); }); }/** * 更新数据 * 1.需要获取irds组件更新数据中的name和regionPath,将两者通过indexCode关联更新数据库中的数据,同时更新数据库中的updateTime * @param list */ private void updateTbResource(List list){ list.forEach(l->{ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("index_code", l.getIndexCode()); TbResource tbResource = TbResource.builder() .regionName(l.getName()) .regionPath(l.getRegionPath()) .updateTime(getNowTime()) .build(); tbResourceMapper.update(tbResource,wrapper); }); }/** * 获得当前时间 "yyyy-MM-dd HH:mm:ss"的形式 */ public static Timestamp getNowTime(){ String type = "yyyy-MM-dd HH:mm:ss"; Date date1=new Date(); SimpleDateFormat format1=new SimpleDateFormat(type); Timestamp time = Timestamp.valueOf(format1.format(date1)); return time; } }

(3)配置定时任务触发
在配置文件中添加
starfish.resource.sync.cron-time=0 0 1 * * ?

(4)运行
项目启动时,该部分代码会自动运行,从irds拉取数据存入数据库
资源目录配置
文章图片

3.接口实现 3.1 获取数据库所有区域信息接口
前端需要的区域信息具体属性去下所示:
资源目录配置
文章图片

而数据库中的区域信息如下所示(TbResource对象):
资源目录配置
文章图片

因此,在获取数据库数据后,需要进行转换,将TbResource对象转换为前端需要的对象进行返回
(1)在vo->response下创建TbRegionInfoVo对象:
/** * @Description: 返回前端的区域信息对象 * @Author: wangzhenguo7 * @Date: 2021/11/04 10:02 */ @Data @Builder public class TbRegionInfoVo { @ApiModelProperty("是否配置点位类型") private Integer pointConfig; @ApiModelProperty("点位类型") private Integer pointType; @ApiModelProperty("区域名称") private String regionName; @ApiModelProperty("区域编码") private String indexCode; @ApiModelProperty("区域路径") private String regionPath; }

(2)创建service层接口
在service下创建ITbResourceService.java,创建接口getAllRegionInfo():
/** * @Description: * @Author: wangzhenguo7 * @Date: 2021/11/03 11:27 */ public interface ITbResourceService {/**获取数据库中所有区域信息,进行展示*/ BaseResponse> getAllRegionInfo(); }

(3)创建接口实现类
在service->impl下创建TbResourceServiceImpl.java,作为ITbResourceService.java的接口实现类,重写getAllRegionInfo()方法
由于前端需要的区域路径是:河南省/郑州市/二七区 形式的,而数据库中是以区域编码形式的,因此还需要定义方法进行转换
/** * @Description: * @Author: wangzhenguo7 * @Date: 2021/11/03 11:33 */ @Service public class TbResourceServiceImpl implements ITbResourceService { private static Logger LOGGER = LoggerFactory.getLogger(TbResourceServiceImpl.class); @Autowired private TbResourceMapper tbResourceMapper; /**获取所有的区域信息*/ @Override public BaseResponse> getAllRegionInfo() { BaseResponse baseResponse = new BaseResponse(); QueryWrapper wrapper = new QueryWrapper(); List tbResourceList = new ArrayList<>(); List tbRegionInfoVos = new ArrayList<>(); try{ tbResourceList = tbResourceMapper.selectList(wrapper); tbResourceList.forEach(l->{ TbRegionInfoVo tbRegionInfoVo = TbRegionInfoVo.builder() .regionName(l.getRegionName()) .indexCode(l.getIndexCode()) .regionPath(changeRegionPath(l.getRegionPath())) .pointConfig(l.getPointConfig()) .pointType(l.getPointType()) .build(); tbRegionInfoVos.add(tbRegionInfoVo); }); baseResponse.setData(tbRegionInfoVos); baseResponse.setMsg("区域信息获取成功"); baseResponse.setCode("0"); return baseResponse; }catch (Exception e){ LOGGER.error("{},{},{}", DefaultErrorCode.PG_SQL_ERROR.getCode(),DefaultErrorCode.PG_SQL_ERROR.getMessage(), DefaultErrorCode.PG_SQL_ERROR.getContent(), e); } baseResponse.setMsg("区域信息获取失败"); baseResponse.setCode("-1"); return baseResponse; }/** * 区域路径由原始的编码转换为名称 * @root000000@4d65faee-8abb-41b2-8e9e-645a867c8ad6@e7db1f53-220e-4056-a475-e0857f69f0d8@ * 转换为:河南省/郑州市/二七区 * @param regionPath * @return */ public String changeRegionPath(String regionPath){ String s = regionPath.replaceFirst("@", ""); String[] strings = s.split("@"); List list = new ArrayList<>(); for (int i =0 ; i < strings.length; i++){ list.add(getNameByCode(strings[i])); } String result = Joiner.on("/").join(list); return result; }/** * 根据区域编码获取区域名称 * @param code * @return */ public String getNameByCode(String code){ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("index_code", code); TbResource tbResource = tbResourceMapper.selectOne(wrapper); return tbResource.getRegionName(); } }

(4)创建controller层
在controller下创建TbResourceController.java
/** * @Description: 区域信息资源接口 * @Author: wangzhenguo7 * @Date: 2021/11/03 11:33 */ @RestController @RequestMapping(value = "https://www.it610.com/region/resource") @Api(tags = "区域信息资源接口") public class TbResourceController {@Autowired private ITbResourceService tbResourceService; @ApiOperation("获取所有区域资源信息") @GetMapping(value = "https://www.it610.com/getAllRegionInfo") @ResponseBody public BaseResponse> getAllRegionInfo(){ return tbResourceService.getAllRegionInfo(); } }

(5)测试接口
打开swagger,运行接口
资源目录配置
文章图片

3.2 单个/批量区域的点位信息的修改
单个区域的点位信息的修改可以和批量区域的点位信息的修改共有一个接口
(1)定义请求对象,用来接收前端传来的修改后的区域信息
在vo->request下创建TbRegionUpdateVo.java
/** * @Description: 前端修改区域信息进行保存的请求对象 * @Author: wangzhenguo7 * @Date: 2021/11/04 10:02 */ @Data public class TbRegionUpdateVo { @ApiModelProperty("是否配置点位类型") private Integer pointConfig; @ApiModelProperty("点位类型") private Integer pointType; @ApiModelProperty("区域信息") private List regionInfos; @Data public static class RegionInfo{ @ApiModelProperty("区域名称") private String regionName; @ApiModelProperty("区域编码") private String indexCode; @ApiModelProperty("区域路径") private String regionPath; } }

(2)定义接口类方法updateBatchRegion
在接口类ITbResourceService.java中添加方法updateBatchRegion
/** * @Description: * @Author: wangzhenguo7 * @Date: 2021/11/03 11:27 */ public interface ITbResourceService {/**获取数据库中所有区域信息,进行展示*/ BaseResponse> getAllRegionInfo(); /**修改/更新单个或批量区域信息的点位类型信息*/ BaseResponse updateBatchRegion(TbRegionUpdateVo tbRegionInfoVo); }

(3)重写方法updateBatchRegion
在接口实现类TbResourceServiceImpl.java中重写updateBatchRegion方法
/** * @Description: * @Author: wangzhenguo7 * @Date: 2021/11/03 11:33 */ @Service public class TbResourceServiceImpl implements ITbResourceService { private static Logger LOGGER = LoggerFactory.getLogger(TbResourceServiceImpl.class); @Autowired private TbResourceMapper tbResourceMapper; /**获取所有的区域信息*/ @Override public BaseResponse> getAllRegionInfo() { BaseResponse baseResponse = new BaseResponse(); QueryWrapper wrapper = new QueryWrapper(); List tbResourceList = new ArrayList<>(); List tbRegionInfoVos = new ArrayList<>(); try{ tbResourceList = tbResourceMapper.selectList(wrapper); tbResourceList.forEach(l->{ TbRegionInfoVo tbRegionInfoVo = TbRegionInfoVo.builder() .regionName(l.getRegionName()) .indexCode(l.getIndexCode()) .regionPath(changeRegionPath(l.getRegionPath())) .pointConfig(l.getPointConfig()) .pointType(l.getPointType()) .build(); tbRegionInfoVos.add(tbRegionInfoVo); }); baseResponse.setData(tbRegionInfoVos); baseResponse.setMsg("区域信息获取成功"); baseResponse.setCode("0"); return baseResponse; }catch (Exception e){ LOGGER.error("{},{},{}", DefaultErrorCode.PG_SQL_ERROR.getCode(),DefaultErrorCode.PG_SQL_ERROR.getMessage(), DefaultErrorCode.PG_SQL_ERROR.getContent(), e); } baseResponse.setMsg("区域信息获取失败"); baseResponse.setCode("-1"); return baseResponse; }/**批量修改或单个修改区域的点位信息*/ @Override public BaseResponse updateBatchRegion(TbRegionUpdateVo tbRegionUpdateVo) { BaseResponse baseResponse = new BaseResponse(); try{ tbRegionUpdateVo.getRegionInfos().forEach(l->{ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("index_code", l.getIndexCode()); TbResource tbResource = tbResourceMapper.selectOne(wrapper); tbResource.setPointConfig(tbRegionUpdateVo.getPointConfig()); //修改是否配置点位类型 tbResource.setPointType(tbRegionUpdateVo.getPointType()); //修改点位类型 tbResource.setUpdateTime(getNowTime()); //修改更新时间为现在 tbResource.setUpdateUser("s1"); //修改更新人名称 tbResourceMapper.update(tbResource, wrapper); //更新 }); baseResponse.setMsg("批量区域点位信息修改/更新成功"); baseResponse.setCode("0"); return baseResponse; }catch (Exception e){ LOGGER.error("{},{},{}", DefaultErrorCode.PG_SQL_UPDATE_ERROR.getCode(), DefaultErrorCode.PG_SQL_UPDATE_ERROR.getMessage(), DefaultErrorCode.PG_SQL_UPDATE_ERROR.getContent(), e); } baseResponse.setMsg("批量区域点位信息修改/更新失败"); baseResponse.setCode("-1"); return baseResponse; }/** * 获得当前时间 "yyyy-MM-dd HH:mm:ss"的形式 */ public static Timestamp getNowTime(){ String type = "yyyy-MM-dd HH:mm:ss"; Date date1=new Date(); SimpleDateFormat format1=new SimpleDateFormat(type); Timestamp time = Timestamp.valueOf(format1.format(date1)); return time; }/** * 区域路径由原始的编码转换为名称 * @root000000@4d65faee-8abb-41b2-8e9e-645a867c8ad6@e7db1f53-220e-4056-a475-e0857f69f0d8@ * 转换为:河南省/郑州市/二七区 * @param regionPath * @return */ public String changeRegionPath(String regionPath){ String s = regionPath.replaceFirst("@", ""); String[] strings = s.split("@"); List list = new ArrayList<>(); for (int i =0 ; i < strings.length; i++){ list.add(getNameByCode(strings[i])); } String result = Joiner.on("/").join(list); return result; }/** * 根据区域编码获取区域名称 * @param code * @return */ public String getNameByCode(String code){ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("index_code", code); TbResource tbResource = tbResourceMapper.selectOne(wrapper); return tbResource.getRegionName(); } }

(4)定义controller层
在TbResourceController.java中创建接口
/** * @Description: 区域信息资源接口 * @Author: wangzhenguo7 * @Date: 2021/11/03 11:33 */ @RestController @RequestMapping(value = "https://www.it610.com/region/resource") @Api(tags = "区域信息资源接口") public class TbResourceController {@Autowired private ITbResourceService tbResourceService; @ApiOperation("获取所有区域资源信息") @GetMapping(value = "https://www.it610.com/getAllRegionInfo") @ResponseBody public BaseResponse> getAllRegionInfo(){ return tbResourceService.getAllRegionInfo(); }@ApiOperation("修改单个/批量区域的点位信息") @PostMapping(value = "https://www.it610.com/updateBatchRegion") @ResponseBody public BaseResponse updateBatchRegion(@ApiParam("前端修改点位信息后的单个/批量区域信息列表") @RequestBody TbRegionUpdateVo tbRegionInfoVo){ return tbResourceService.updateBatchRegion(tbRegionInfoVo); } }

(5)测试
在swagger中进行测试:
修改前的数据:
资源目录配置
文章图片

资源目录配置
文章图片

请求对象:
资源目录配置
文章图片

修改后的数据:
资源目录配置
文章图片

资源目录配置
文章图片

3.3 根据条件查询数据 可以根据四个属性中的任意几个或全部进行查询:区域名称、区域列表、是否配置点位类型、点位类型
资源目录配置
文章图片

(1)定义请求对象
在vo->request下创建TbRegionQuestVo.java
/** * @Description: 前端进行查询的请求对象 * @Author: wangzhenguo7 * @Date: 2021/11/04 10:02 */ @Data public class TbRegionQuestVo {@ApiModelProperty("非必填,区域名称") private String regionName; @ApiModelProperty("非必填,区域编码") private String indexCode; @ApiModelProperty("必填,是否配置点位类型-1-未选择0-未配置1-配置") private Integer pointConfig; @ApiModelProperty("必填,点位类型-1-未选择 1-蓝天卫士 2-重点监控") private Integer pointType; }

【资源目录配置】(2)创建接口方法
在ITbResourceService.java接口类中创建查询接口方法getRegion
/** * @Description: * @Author: wangzhenguo7 * @Date: 2021/11/03 11:27 */ public interface ITbResourceService {/**获取数据库中所有区域信息,进行展示*/ BaseResponse> getAllRegionInfo(); /**修改/更新单个或批量区域信息的点位类型*/ BaseResponse updateBatchRegion(TbRegionUpdateVo tbRegionInfoVo); /**查询区域信息:四个查询条件:区域名称、区域编码、是否配置点位类型、点位类型*/ BaseResponse> getRegion(TbRegionQuestVo tbRegionQuest); }

(3)重写查询接口方法getRegion
在TbResourceServiceImpl.java接口实现类中重写查询接口方法getRegion
/** * @Description: * @Author: wangzhenguo7 * @Date: 2021/11/03 11:33 */ @Service public class TbResourceServiceImpl implements ITbResourceService { private static Logger LOGGER = LoggerFactory.getLogger(TbResourceServiceImpl.class); @Autowired private TbResourceMapper tbResourceMapper; /**获取所有的区域信息*/ @Override public BaseResponse> getAllRegionInfo() { BaseResponse baseResponse = new BaseResponse(); QueryWrapper wrapper = new QueryWrapper(); List tbResourceList = new ArrayList<>(); List tbRegionInfoVos = new ArrayList<>(); try{ tbResourceList = tbResourceMapper.selectList(wrapper); tbResourceList.forEach(l->{ TbRegionInfoVo tbRegionInfoVo = TbRegionInfoVo.builder() .regionName(l.getRegionName()) .indexCode(l.getIndexCode()) .regionPath(changeRegionPath(l.getRegionPath())) .pointConfig(l.getPointConfig()) .pointType(l.getPointType()) .build(); tbRegionInfoVos.add(tbRegionInfoVo); }); baseResponse.setData(tbRegionInfoVos); baseResponse.setMsg("区域信息获取成功"); baseResponse.setCode("0"); return baseResponse; }catch (Exception e){ LOGGER.error("{},{},{}", DefaultErrorCode.PG_SQL_ERROR.getCode(),DefaultErrorCode.PG_SQL_ERROR.getMessage(), DefaultErrorCode.PG_SQL_ERROR.getContent(), e); } baseResponse.setMsg("区域信息获取失败"); baseResponse.setCode("-1"); return baseResponse; }/**批量修改或单个修改区域的点位信息*/ @Override public BaseResponse updateBatchRegion(TbRegionUpdateVo tbRegionUpdateVo) { BaseResponse baseResponse = new BaseResponse(); try{ tbRegionUpdateVo.getRegionInfos().forEach(l->{ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("index_code", l.getIndexCode()); TbResource tbResource = tbResourceMapper.selectOne(wrapper); tbResource.setPointConfig(tbRegionUpdateVo.getPointConfig()); //修改是否配置点位类型 tbResource.setPointType(tbRegionUpdateVo.getPointType()); //修改点位类型 tbResource.setUpdateTime(getNowTime()); //修改更新时间为现在 tbResource.setUpdateUser("s1"); //修改更新人名称 tbResourceMapper.update(tbResource, wrapper); //更新 }); baseResponse.setMsg("批量区域点位信息修改/更新成功"); baseResponse.setCode("0"); return baseResponse; }catch (Exception e){ LOGGER.error("{},{},{}", DefaultErrorCode.PG_SQL_UPDATE_ERROR.getCode(), DefaultErrorCode.PG_SQL_UPDATE_ERROR.getMessage(), DefaultErrorCode.PG_SQL_UPDATE_ERROR.getContent(), e); } baseResponse.setMsg("批量区域点位信息修改/更新失败"); baseResponse.setCode("-1"); return baseResponse; }/**查询数据库信息*/ @Override public BaseResponse> getRegion(TbRegionQuestVo tbRegionQuest) { BaseResponse baseResponse = new BaseResponse(); List tbResourceList = new ArrayList<>(); List regionInfoVoList = new ArrayList<>(); QueryWrapper wrapper = new QueryWrapper(); if (!StringUtils.isEmpty(tbRegionQuest.getRegionName())){ wrapper.like("region_name", tbRegionQuest.getRegionName()); } if (!StringUtils.isEmpty(tbRegionQuest.getIndexCode())){ wrapper.like("index_code", tbRegionQuest.getIndexCode()); } if (tbRegionQuest.getPointConfig() != -1){ wrapper.eq("point_config", tbRegionQuest.getPointConfig()); } if (tbRegionQuest.getPointType() != -1){ wrapper.eq("point_type", tbRegionQuest.getPointType()); } try { tbResourceList = tbResourceMapper.selectList(wrapper); tbResourceList.forEach(l->{ TbRegionInfoVo tbRegionInfoVo = TbRegionInfoVo.builder() .regionName(l.getRegionName()) .indexCode(l.getIndexCode()) .regionPath(changeRegionPath(l.getRegionPath())) .pointConfig(l.getPointConfig()) .pointType(l.getPointType()) .build(); regionInfoVoList.add(tbRegionInfoVo); }); baseResponse.setData(regionInfoVoList); baseResponse.setMsg("查询区域信息成功"); baseResponse.setCode("0"); return baseResponse; }catch (Exception e){ LOGGER.error("{},{},{}", DefaultErrorCode.PG_SQL_ERROR.getCode(),DefaultErrorCode.PG_SQL_ERROR.getMessage(), DefaultErrorCode.PG_SQL_ERROR.getContent(), e); } baseResponse.setMsg("查询区域信息失败"); baseResponse.setCode("-1"); return baseResponse; }/** * 获得当前时间 "yyyy-MM-dd HH:mm:ss"的形式 */ public static Timestamp getNowTime(){ String type = "yyyy-MM-dd HH:mm:ss"; Date date1=new Date(); SimpleDateFormat format1=new SimpleDateFormat(type); Timestamp time = Timestamp.valueOf(format1.format(date1)); return time; }/** * 区域路径由原始的编码转换为名称 * @root000000@4d65faee-8abb-41b2-8e9e-645a867c8ad6@e7db1f53-220e-4056-a475-e0857f69f0d8@ * 转换为:河南省/郑州市/二七区 * @param regionPath * @return */ public String changeRegionPath(String regionPath){ String s = regionPath.replaceFirst("@", ""); String[] strings = s.split("@"); List list = new ArrayList<>(); for (int i =0 ; i < strings.length; i++){ list.add(getNameByCode(strings[i])); } String result = Joiner.on("/").join(list); return result; }/** * 根据区域编码获取区域名称 * @param code * @return */ public String getNameByCode(String code){ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("index_code", code); TbResource tbResource = tbResourceMapper.selectOne(wrapper); return tbResource.getRegionName(); } }

(4)定义controller层接口
在TbResourceController.java中添加接口
/** * @Description: 区域信息资源接口 * @Author: wangzhenguo7 * @Date: 2021/11/03 11:33 */ @RestController @RequestMapping(value = "https://www.it610.com/region/resource") @Api(tags = "区域信息资源接口") public class TbResourceController {@Autowired private ITbResourceService tbResourceService; @ApiOperation("获取所有区域资源信息") @GetMapping(value = "https://www.it610.com/getAllRegionInfo") @ResponseBody public BaseResponse> getAllRegionInfo(){ return tbResourceService.getAllRegionInfo(); }@ApiOperation("修改批量区域的点位信息") @PostMapping(value = "https://www.it610.com/updateBatchRegion") @ResponseBody public BaseResponse updateBatchRegion(@ApiParam("前端修改点位信息后的批量区域信息列表") @RequestBody TbRegionUpdateVo tbRegionInfoVo){ return tbResourceService.updateBatchRegion(tbRegionInfoVo); }@ApiOperation("根据区域名称、区域编码、是否配置点位类型和点位类型查询区域资源信息") @PostMapping(value = "https://www.it610.com/getRegion") @ResponseBody public BaseResponse> getRegion(@RequestBody TbRegionQuestVo tbRegionQuest){ return tbResourceService.getRegion(tbRegionQuest); } }

(5)测试
在swagger中进行测试
测试1:区域名称的模糊搜索
资源目录配置
文章图片

资源目录配置
文章图片

测试2:
资源目录配置
文章图片

资源目录配置
文章图片

测试3:区域编码的模糊搜索
资源目录配置
文章图片

资源目录配置
文章图片

3.4 上传图片到云存储,返回url和图片名称
(1)创建mapper层
在mapper->local下创建TbPointMapper.java
@Mapper public interface TbPointMapper extends BaseMapper { }

(2)创建service层接口upload
在service下创建ITbPointService.java,定义上传图片到云存储,并返回url和图片名称的方法upload
/** * @Description: * @Author: wangzhenguo7 * @Date: 2021/11/03 15:17 */ public interface ITbPointService {/**上传图片到云存储,并返回url和图片名称*/ BaseResponse upload(MultipartFile multipartFile); }

(3)创建接口实现类,重写upload方法
在service->impl下创建UploadPicImpl.java,实现ITbPointService,重写upload方法
/** * @author :zhangfuxuan * @date :Created in 2021/10/27 16:11 * @description: * @modified By: * @version: 1.0 */ @Service public class UploadPicImpl implements ITbPointService { private static final Logger logger = LoggerFactory.getLogger(UploadPicImpl.class); @Autowired private TbPointMapper tbPointMapper; @Autowired private ServiceDirectoryClient serviceDirectoryClient; @Autowired @Qualifier("myRestTemplates") private RestTemplate myRestTemplates; private static PoolInfo poolInfo = null; @Autowired private HikCStorUtil hikCStorUtil; /** * 上传图片到云存储,返回url和图片名称 * @param multipartFile * @return */ @Override public BaseResponse upload(MultipartFile multipartFile) { BaseResponse baseResponse = new BaseResponse(); try { byte[] picBbytes= multipartFile.getBytes(); String base64Str=new String(org.apache.commons.codec.binary.Base64.encodeBase64(picBbytes),"utf-8"); String picUrl=getUploadPicUrl(base64Str); Map map = new HashMap<>(); if (picUrl != null){ map.put("picUrl", picUrl); map.put("picName", multipartFile.getOriginalFilename()); baseResponse.setData(map); baseResponse.setMsg("图片上传成功"); baseResponse.setCode("0"); return baseResponse; } }catch (IOException e) { logger.error("错误码:{},错误信息:{},record:{}", DefaultErrorCode.PIC_UPLOAD_ERROR.getCode(), DefaultErrorCode.PIC_UPLOAD_ERROR.getMessage(), e); } baseResponse.setMsg(DefaultErrorCode.PIC_UPLOAD_ERROR.getMessage()); baseResponse.setCode("-1"); return baseResponse; }/** * 图片存储到云存储 * @param picBase64 * @return */ public String getUploadPicUrl(String picBase64) { try{ picBase64 = picBase64.replaceFirst("data:image/jpg; base64,", ""); byte[] picBuff = Base64.decode(picBase64); HikCStorConstant cStorConstant = getStorageDeviceList(); //logger.debug("获取存储设备信息列表: " + cStorConstant.getDeviceIP()); if(cStorConstant != null){ if (poolInfo == null){ poolInfo = getPoolInfoList(cStorConstant.getDeviceID()); } //logger.debug("获取资源池: " + poolInfo); if(poolInfo != null){ //logger.debug("图片准备上传云存储"); cStorConstant.setPoolId(poolInfo.getPoolId()); cStorConstant.setSerialID(cStorConstant.getDeviceID()); String secretKey = new String( AESSO.decrypt(java.util.Base64.getDecoder().decode(cStorConstant.getSecretKey()), Authentication.exportSK(),false),"UTF-8"); //logger.debug("图片上传云存储secretKey: " + secretKey); cStorConstant.setSecretKey(secretKey.trim()); String picUrl = hikCStorUtil.writePic(cStorConstant,picBuff); logger.debug("图片上传云存储URL: "+picUrl); return "http://" + cStorConstant.getDeviceIP() + ":" + String.valueOf(cStorConstant.getPicDownloadPort()) + picUrl; } } }catch (Exception e){ logger.error("getUploadPicUrl error: ",e); } return null; } public ServiceAddressInfoDto findServiceInfo() { ServiceAddressInfoDto serviceAddressInfoDto = null; try { ApiResponse serviceInfo = serviceDirectoryClient.getServiceInfo("sac","sac"); if (serviceInfo.getCode().equals("0")){ if (!org.apache.commons.lang3.ObjectUtils.isEmpty(serviceInfo.getData()) && serviceInfo.getData().getAddress().size() > 0){ for (ServiceAddressInfoDto dto:serviceInfo.getData().getAddress()) { if (dto.getNetprotocol().toLowerCase().equals("http")){ serviceAddressInfoDto = dto; break; } } serviceAddressInfoDto=serviceInfo.getData().getAddress().get(0); if (serviceAddressInfoDto == null){ serviceAddressInfoDto = serviceInfo.getData().getAddress().get(0); } } } } catch (Exception e) { logger.error("findServiceInfo error: ",e); } return serviceAddressInfoDto; } /** * 获取存储设备信息列表 * @return * @throws Exception */ public HikCStorConstant getStorageDeviceList() throws Exception { String uri = "/ISAPI/Storage/storageDeviceList?marker=&maxKeys=3000"; ServiceAddressInfoDto dto=findServiceInfo(); String url = null; if (dto!=null) { String sacUrl = "http://" + dto.getIp() + ":" + dto.getPort(); url = sacUrl + uri; } String secretKey = new String(Authentication.exportSK(),"UTF-8"); String accessKey = new String(Authentication.exportAK(),"UTF-8"); String date = DateGMCUtil.getGmtTime(); String auth = AuthProcess.getAuthorization(accessKey, secretKey, "GET", "","", date, uri, 1,"storage"); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("Date", date); httpHeaders.set("Authorization", auth); httpHeaders.set("Connection", "close"); httpHeaders.setAccept(Lists.newArrayList(MediaType.APPLICATION_JSON)); HttpEntity httpEntity = new HttpEntity(httpHeaders); ResponseEntity entity = myRestTemplates.exchange(URI.create(url), HttpMethod.GET, httpEntity, String.class); if(entity != null && entity.getStatusCode() == HttpStatus.OK){ ResourceDeviceInfo deviceInfo = JSONObject.parseObject(entity.getBody(),ResourceDeviceInfo.class); for(HikCStorConstant cStorConstant : deviceInfo.getList()){ /**deviceType:1-云存储,2-CVR,3-PCNVR2.0,4-NVR*/ if(cStorConstant.getPicDownloadPort()!= 0 && cStorConstant.getPicUploadPort() != 0 /*&& cStorConstant.getDeviceType() == 1 */){ return cStorConstant; } } } return null; }/** * 获取资源池 * @return * @throws Exception */ public PoolInfo getPoolInfoList(String deviceId) throws Exception { String uri = "/ISAPI/Storage/poolInfoList?marker=&maxKeys=3000"; ServiceAddressInfoDto dto=findServiceInfo(); String url = null; if (dto!=null) { String sacUrl = "http://" + dto.getIp() + ":" + dto.getPort(); url = sacUrl + uri; }String secretKey = new String(Authentication.exportSK(),"UTF-8"); String accessKey = new String(Authentication.exportAK(),"UTF-8"); String date = DateGMCUtil.getGmtTime(); String auth = AuthProcess.getAuthorization(accessKey, secretKey, "GET", "", "", date, uri, 1,"storage"); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("Date", date); httpHeaders.set("Authorization", auth); httpHeaders.set("X-Stor-DeviceID", deviceId); httpHeaders.set("Connection", "close"); httpHeaders.setAccept(Lists.newArrayList(MediaType.APPLICATION_JSON)); HttpEntity httpEntity = new HttpEntity(httpHeaders); RestTemplate myRestTemplate=new RestTemplate(); ResponseEntity entity = myRestTemplate.exchange(URI.create(url), HttpMethod.GET, httpEntity, String.class); if(entity.getStatusCode() == HttpStatus.OK){ ResourcePoolInfo poolInfo = JSONObject.parseObject(entity.getBody(),ResourcePoolInfo.class); Boolean isExist = false; for(PoolInfo pool : poolInfo.getList()){ //0-通用池 1-视频池 3-图片池 if(pool.getPoolType() == 0&& pool.getPoolStatus() == 1){ //是否存在图片资源池 isExist = true; return pool; } } if (!isExist){ for(PoolInfo pool : poolInfo.getList()){ //0-通用池 1-视频池 3-图片池 if(pool.getCoverType()==0 && pool.getPoolType() == 0 && "1".equals(pool.getDeviceType()) && pool.getPoolStatus() == 1){ //不可覆盖通用资源池 return pool; } } } } return null; } }

(4)创建controller层
在controller下创建TbPointController.java
/** * @Description: 点位类型接口 * @Author: wangzhenguo7 * @Date: 2021/11/03 16:24 */ @RestController @RequestMapping(value = "https://www.it610.com/point") @Api(tags = "点位类型接口") public class TbPointController {@Autowired private ITbPointService iTbPointService; @ApiOperation("上传图片到云存储,并返回url") @PostMapping(value = "https://www.it610.com/upload") @ResponseBody public BaseResponse upload(@ApiParam("图片文件") @RequestParam MultipartFile multipartFile){ return iTbPointService.upload(multipartFile); } }

(5)测试
在swagger进行测试
资源目录配置
文章图片

3.5 新增点位类型
新增点位类型时,后端接收到前端请求的对象有三个属性:点位类型的名称、点位图标url、点位图标名称、聚合图标url、聚合图标名称
(1)创建请求对象
在vo->request下创建TbPointQuestVo.java
/** * @Description: 区域信息 * @Author: wangzhenguo7 * @Date: 2021/11/03 15:11 */ @Data public class TbPointQuestVo {@ApiModelProperty("点位类型") private Integer pointType; @ApiModelProperty("点位图标url") private String pointIconUrl; @ApiModelProperty("点位图标名称") private String pointIconName; @ApiModelProperty("聚合图标url") private String aggreIconUrl; @ApiModelProperty("聚合图标名称") private String aggreIconName; }

(2)定义接口类方法addPoint
在ITbPointService.java内定义添加点位类型配置(点位类型、以及对应的点位图标和聚合图标)的接口方法addPoint
/** * @Description: * @Author: wangzhenguo7 * @Date: 2021/11/03 15:17 */ public interface ITbPointService {/**添加点位类型配置(点位类型、以及对应的点位图标和聚合图标)*/ BaseResponse addPoint(TbPointQuestVo pointInfoVo); /**上传图片到云存储,并返回url*/ BaseResponse upload(MultipartFile multipartFile); }

(3)定义接口实现类,重写addPoint
新增点位类型时,在上传完图片至云存储,并点击确定后,后端接收到是TbPointQuestVo对象
所以在addPoint方法内,首先要找到数据库中相同点位类型的数据,将该条数据的点位图标url,聚合图标url、点位图标名称、聚合图标名称进行更新
在UploadPicImpl.java接口实现类中重写addPoint方法
/** * 新增点位类型; * 更新数据库中该点位类型的每条数据的点位图标url和聚合图标url * @param pointInfoVo * @return */ @Override public BaseResponse addPoint(TbPointQuestVo pointInfoVo) { BaseResponse baseResponse = new BaseResponse(); QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("point_type", pointInfoVo.getPointType()); try { //获得相同点位类型的所有数据 List tbResourceList = tbResourceMapper.selectList(wrapper); //遍历数据,更新每条数据的点位图标url和名称、聚合图标url和名称以及更新时间和更新人名称 tbResourceList.forEach(l->{ l.setPointIconUrl(pointInfoVo.getPointIconUrl()); l.setPointIconName(pointInfoVo.getPointIconName()); l.setAggreIconUrl(pointInfoVo.getAggreIconUrl()); l.setAggreIconName(pointInfoVo.getAggreIconName()); l.setUpdateTime(getNowTime()); l.setUpdateUser("s1"); tbResourceMapper.update(l, wrapper); }); baseResponse.setMsg("添加点位类型成功"); baseResponse.setCode("0"); return baseResponse; }catch (Exception e){ logger.error("{},{},{}", DefaultErrorCode.PG_SQL_UPDATE_ERROR.getCode(), DefaultErrorCode.PG_SQL_UPDATE_ERROR.getMessage(), DefaultErrorCode.PG_SQL_UPDATE_ERROR.getContent(), e); } baseResponse.setMsg(DefaultErrorCode.PG_SQL_UPDATE_ERROR.getMessage()); baseResponse.setCode("-1"); return baseResponse; }

(4)定义controller层接口
在TbPointController.java中添加接口
/** * @Description: 点位类型接口 * @Author: wangzhenguo7 * @Date: 2021/11/03 16:24 */ @RestController @RequestMapping(value = "https://www.it610.com/point") @Api(tags = "点位类型接口") public class TbPointController {@Autowired private ITbPointService iTbPointService; @ApiOperation("新增点位类型") @PostMapping(value = "https://www.it610.com/addPoint") @ResponseBody public BaseResponse addPoint(@ApiParam("从前端接收的包含url和名称的新增的点位类型对象") @RequestParam TbPointQuestVo pointInfoVo){ return iTbPointService.addPoint(pointInfoVo); }@ApiOperation("上传图片到云存储,并返回url和图片名称") @PostMapping(value = "https://www.it610.com/upload") @ResponseBody public BaseResponse upload(@ApiParam("图片文件") @RequestParam MultipartFile multipartFile){ return iTbPointService.upload(multipartFile); } }

(5)测试
将数据库中部分数据的点位类型配置为1
资源目录配置
文章图片

调用上面实现的的接口:
资源目录配置
文章图片

数据库数据:
资源目录配置
文章图片

3.6 删除点位类型 删除点位类型后,要将数据库中该点位类型的数据的point_config设置为0、point_type设置为0、点位图标url和名称、聚合图标url和名称设置为null
(1)定义接口方法deletePoint
在接口类ITbPointService.java中添加方法deletePoint
/** * @Description: * @Author: wangzhenguo7 * @Date: 2021/11/03 15:17 */ public interface ITbPointService {/**添加点位类型配置(点位类型、以及对应的点位图标和聚合图标)*/ BaseResponse addPoint(TbPointQuestVo pointInfoVo); /**根据点位类型删除点位*/ BaseResponse deletePoint(Integer point); /**上传图片到云存储,并返回url和图片名称*/ BaseResponse upload(MultipartFile multipartFile); }

(2)重写方法deletePoint
在接口实现类UploadPicImpl.java内重写deletePoint方法
/** * 根据点位类型名称删除点位类型 * @param point * @return */ @Override public BaseResponse deletePoint(Integer point) { BaseResponse baseResponse = new BaseResponse(); QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("point_type", point); try { //获得相同点位类型的所有数据 List tbResourceList = tbResourceMapper.selectList(wrapper); tbResourceList.forEach(l->{ l.setPointConfig(0); l.setPointType(0); l.setPointIconUrl(""); l.setPointIconName(""); l.setAggreIconUrl(""); l.setAggreIconName(""); l.setUpdateTime(getNowTime()); l.setUpdateUser("s1"); tbResourceMapper.update(l, wrapper); }); baseResponse.setMsg("删除点位类型成功"); baseResponse.setCode("0"); return baseResponse; }catch (Exception e){ logger.error("{},{},{}", DefaultErrorCode.PG_SQL_UPDATE_ERROR.getCode(), DefaultErrorCode.PG_SQL_UPDATE_ERROR.getMessage(), DefaultErrorCode.PG_SQL_UPDATE_ERROR.getContent(), e); } baseResponse.setMsg(DefaultErrorCode.PG_SQL_UPDATE_ERROR.getMessage()); baseResponse.setCode("-1"); return baseResponse; }

(3)定义controller层接口
在TbPointController.java中添加接口
/** * @Description: 点位类型接口 * @Author: wangzhenguo7 * @Date: 2021/11/03 16:24 */ @RestController @RequestMapping(value = "https://www.it610.com/point") @Api(tags = "点位类型接口") public class TbPointController {@Autowired private ITbPointService iTbPointService; @ApiOperation("新增点位类型") @PostMapping(value = "https://www.it610.com/addPoint") @ResponseBody public BaseResponse addPoint(@ApiParam("从前端接收的包含url的新增的点位类型对象") @RequestBody TbPointQuestVo pointInfoVo){ return iTbPointService.addPoint(pointInfoVo); }@ApiOperation("删除已有的点位类型") @GetMapping(value = "https://www.it610.com/deletePoint") public BaseResponse deletePoint(@ApiParam("删除的点位类型的名称") @RequestParam Integer point){ return iTbPointService.deletePoint(point); }@ApiOperation("上传图片到云存储,并返回url和图片名称") @PostMapping(value = "https://www.it610.com/upload") @ResponseBody public BaseResponse upload(@ApiParam("图片文件") @RequestParam MultipartFile multipartFile){ return iTbPointService.upload(multipartFile); } }

(4)测试
数据库原数据:
资源目录配置
文章图片

将点位类型为1的点位类型删除:
资源目录配置
文章图片

数据库数据:
资源目录配置
文章图片

    推荐阅读