/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.modules.architecture.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.google.zxing.WriterException;
|
import io.minio.*;
|
import io.minio.errors.*;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import liquibase.pro.packaged.L;
|
import lombok.AllArgsConstructor;
|
|
import javax.validation.Valid;
|
|
import org.springblade.common.utils.Base64Util;
|
import org.springblade.common.utils.QRCodeUtil;
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.mp.support.Query;
|
import org.springblade.core.oss.model.BladeFile;
|
import org.springblade.core.oss.model.OssFile;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.modules.life.entity.Life;
|
import org.springblade.modules.life.service.ILifeService;
|
import org.springblade.modules.mechanism.entity.Mechanism;
|
import org.springblade.modules.mechanism.service.IMechanismService;
|
import org.springblade.modules.resource.builder.oss.OssBuilder;
|
import org.springblade.modules.resource.entity.Oss;
|
import org.springblade.modules.resource.service.IOssService;
|
import org.springframework.core.io.support.ResourceRegion;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.web.bind.annotation.*;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import org.springblade.modules.architecture.entity.Architecture;
|
import org.springblade.modules.architecture.vo.ArchitectureVO;
|
import org.springblade.modules.architecture.service.IArchitectureService;
|
import org.springblade.core.boot.ctrl.BladeController;
|
import springfox.documentation.annotations.ApiIgnore;
|
import sun.misc.BASE64Encoder;
|
|
import java.io.*;
|
import java.net.URLEncoder;
|
import java.security.InvalidKeyException;
|
import java.security.NoSuchAlgorithmException;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 控制器
|
* 校园建筑
|
*
|
* @author BladeX
|
* @since 2021-11-23
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("blade-architecture/architecture")
|
@Api(value = "", tags = "接口")
|
public class ArchitectureController extends BladeController {
|
|
|
private final IOssService ossService;
|
|
private final IArchitectureService architectureService;
|
private final IMechanismService mechanismService;
|
private final ILifeService lifeService;
|
/**
|
* 对象存储构建类
|
*/
|
private final OssBuilder ossBuilder;
|
|
/**
|
* 详情
|
*/
|
@GetMapping("/detail")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入architecture")
|
public R<Architecture> detail(Architecture architecture) {
|
Architecture detail = architectureService.getOne(Condition.getQueryWrapper(architecture));
|
return R.data(detail);
|
}
|
|
/**
|
* 分页
|
*/
|
@GetMapping("/list")
|
@ApiOperationSupport(order = 2)
|
@ApiOperation(value = "分页", notes = "传入architecture")
|
public R<IPage<Architecture>> list(@ApiIgnore @RequestParam Map<String, Object> architecture, Query query) {
|
IPage<Architecture> pages = architectureService.page(Condition.getPage(query), Condition.getQueryWrapper(architecture, Architecture.class));
|
return R.data(pages);
|
}
|
|
|
/**
|
* 自定义分页
|
*/
|
@GetMapping("/page")
|
@ApiOperationSupport(order = 3)
|
@ApiOperation(value = "分页", notes = "传入architecture")
|
public R<IPage<ArchitectureVO>> page(ArchitectureVO architecture, Query query) {
|
IPage<ArchitectureVO> pages = architectureService.selectArchitecturePage(Condition.getPage(query), architecture);
|
return R.data(pages);
|
}
|
|
/**
|
* 新增
|
*/
|
@PostMapping("/save")
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "新增", notes = "传入architecture")
|
public R save(@Valid @RequestBody Architecture architecture) throws IOException, WriterException, ServerException, InsufficientDataException, NoSuchAlgorithmException, InternalException, InvalidResponseException, XmlParserException, InvalidKeyException, ErrorResponseException {
|
architecture.setPitch("-90");
|
architecture.setHeading("0");
|
architecture.setRoll("0");
|
architecture.setGd("0");
|
//String url = "http://192.168.0.115:8080/#/mobileLayout/default";
|
String url = "https://dev.jxpskj.com:8023/zhjg/#/mobileLayout/default";
|
String gotos = URLEncoder.encode("arc", "UTF-8");
|
String addressName = URLEncoder.encode(architecture.getAddressName(), "UTF-8");
|
String mechanismname = URLEncoder.encode(architecture.getMechanismname(), "UTF-8");
|
String address = null;
|
if (architecture.getAddress() != null) {
|
address = URLEncoder.encode(architecture.getAddress(), "UTF-8");
|
}
|
String telephone = null;
|
if (architecture.getTelephone() != null) {
|
telephone = URLEncoder.encode(architecture.getTelephone(), "UTF-8");
|
}
|
String introduce = URLEncoder.encode(architecture.getIntroduce(), "UTF-8");
|
String jd = URLEncoder.encode(architecture.getJd(), "UTF-8");
|
String wd = URLEncoder.encode(architecture.getWd(), "UTF-8");
|
String gd = URLEncoder.encode(architecture.getGd(), "UTF-8");
|
String tpurl = null;
|
if (architecture.getTpurl() != null) {
|
tpurl = URLEncoder.encode(architecture.getTpurl(), "UTF-8");
|
}
|
String websiteurl = null;
|
if (architecture.getWebsiteurl() != null) {
|
websiteurl = URLEncoder.encode(architecture.getWebsiteurl(), "UTF-8");
|
}
|
String type = URLEncoder.encode(architecture.getType(), "UTF-8");
|
String x = URLEncoder.encode(architecture.getX(), "UTF-8");
|
String xtype = URLEncoder.encode(architecture.getCampus(), "UTF-8");
|
String heading = URLEncoder.encode(architecture.getHeading(), "UTF-8");
|
String pitch = URLEncoder.encode(architecture.getPitch(), "UTF-8");
|
String roll = URLEncoder.encode(architecture.getRoll(), "UTF-8");
|
String videourl = null;
|
if (architecture.getVideourl() != null) {
|
videourl = URLEncoder.encode(architecture.getVideourl(), "UTF-8");
|
}
|
String panoramaurl = null;
|
if (architecture.getPanoramaurl() != null) {
|
panoramaurl = URLEncoder.encode(architecture.getPanoramaurl(), "UTF-8");
|
}
|
String content = url + "?methods=" + gotos + "&mechanismname=" + mechanismname + "&address=" + address +
|
"&telephone=" + telephone +
|
"&introduce=" + introduce +
|
"&jd=" + jd +
|
"&x=" + x +
|
"&wd=" + wd +
|
"&gd=" + gd +
|
"&tpurl=" + tpurl +
|
"&websiteurl=" + websiteurl +
|
"&type=" + type +
|
"&xtype=" + xtype +
|
"&heading=" + heading +
|
"&pitch=" + pitch +
|
"&roll=" + roll +
|
"&panoramaurl=" + panoramaurl + "&addressName=" + addressName +
|
"&videourl=" + videourl;
|
//生成标注二维码
|
byte[] qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350);
|
// String encode = new BASE64Encoder().encode(qrCodeImage);
|
// //设置二维码
|
// String a = "data:image/png;base64," + encode;
|
ByteArrayInputStream stream = new ByteArrayInputStream(qrCodeImage);
|
String upload = upload(stream);
|
stream.close();
|
//设置二维码地址
|
architecture.setCodeurl(upload);
|
return R.status(architectureService.save(architecture));
|
}
|
|
/**
|
* 修改
|
*/
|
@PostMapping("/update")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "修改", notes = "传入architecture")
|
public R update(@Valid @RequestBody Architecture architecture) {
|
return R.status(architectureService.updateById(architecture));
|
}
|
|
/**
|
* 新增或修改
|
*/
|
@PostMapping("/submit")
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "新增或修改", notes = "传入architecture")
|
public R submit(@Valid @RequestBody Architecture architecture) {
|
return R.status(architectureService.saveOrUpdate(architecture));
|
}
|
|
|
/**
|
* 删除
|
*/
|
@PostMapping("/remove")
|
@ApiOperationSupport(order = 8)
|
@ApiOperation(value = "删除", notes = "传入ids")
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
return R.status(architectureService.removeByIds(Func.toLongList(ids)));
|
}
|
|
|
/**
|
* 联动
|
*
|
* @return
|
*/
|
@GetMapping("/selectType")
|
public R selectType(String campus, String type) {
|
return R.data(architectureService.selectType(campus, type));
|
}
|
|
/**
|
* 查询校内建筑列表
|
*
|
* @return
|
*/
|
@GetMapping("/selectList")
|
public R selectList(String campus, String type) {
|
List<Map<Object, Object>> map = architectureService.selectList(campus, type);
|
return R.data(map);
|
}
|
|
/**
|
* 查询校内建筑基本信息及其楼内所属
|
*
|
* @return
|
*/
|
@GetMapping("/selectInArchite")
|
public R selectInArchite(String id) {
|
Map map1 = new HashMap();
|
List list = new ArrayList();
|
String sub = "";
|
Map<Object, Object> map = architectureService.selectInArchite(id);
|
//教学科研行政
|
String jx = mechanismService.selectIn(id);
|
//生活设施
|
String sh = architectureService.selectIns(id);
|
//排除为null的数据
|
//List<Map<Object, Object>> list2 = list1.parallelStream().filter(Objects::nonNull).collect(Collectors.toList());
|
map1.put("list", map);
|
map1.put("jx", jx);
|
map1.put("sh", sh);
|
list.add(map1);
|
return R.data(list);
|
}
|
|
/**
|
* 查询所有全景信息
|
*
|
* @return
|
*/
|
@GetMapping("/selectArch")
|
public R selectArch() {
|
return R.data(architectureService.selectArch());
|
}
|
|
/**
|
* 标签
|
*
|
* @return
|
*/
|
@GetMapping("/selectArchALL")
|
public R selectArchALL() {
|
return R.data(architectureService.selectArchALL());
|
}
|
|
/**
|
* @param num 0:教学科研行政 1:生活设施详情
|
* @param mechanismName 名称
|
* @return
|
*/
|
@GetMapping("/selectInfo")
|
public R selectInfo(int num, String mechanismName) {
|
//0:教学科研行政
|
if (num == 0) {
|
Mechanism mechanism = new Mechanism();
|
mechanism.setMechanismname(mechanismName);
|
Mechanism detail = mechanismService.getOne(Condition.getQueryWrapper(mechanism));
|
return R.data(detail);
|
}
|
//1:生活设施详情
|
else {
|
Life life = new Life();
|
life.setMechanismname(mechanismName);
|
Life one = lifeService.getOne(Condition.getQueryWrapper(life));
|
return R.data(one);
|
}
|
}
|
|
|
/**
|
* 监控视频
|
*
|
* @return
|
*/
|
@GetMapping("/selectVideo")
|
public R selectVideo() {
|
List<Map<Object, Object>> maps = architectureService.selectVideo();
|
//排除为null的数据
|
List<Map<Object, Object>> list2 = maps.parallelStream().filter(Objects::nonNull).collect(Collectors.toList());
|
return R.data(list2);
|
}
|
|
// /**
|
// * 校园搜索
|
// *
|
// * @param mechanismName 名称模糊查询
|
// * @return
|
// */
|
// @GetMapping("/selectLook")
|
// public R selectLook(String mechanismName) {
|
// List list = new ArrayList();
|
// String sub = "";
|
// List<Map<Object, Object>> maps = architectureService.selectLook(mechanismName);
|
// //排除为null的数据
|
// List<Map<Object, Object>> list2 = maps.parallelStream().filter(Objects::nonNull).collect(Collectors.toList());
|
// if (list2.size() != 0) {
|
// for (int i = 0; i < list2.size(); i++) {
|
// String mechanismname = list2.get(i).get("mechanismname").toString();
|
// if (i == list2.size() - 1) {
|
// sub += mechanismname;
|
// } else {
|
// sub += mechanismname + ",";
|
// }
|
// }
|
// String[] split = sub.split(",");
|
// long startTime = System.currentTimeMillis(); //获取开始时间
|
// for (int j = 0; j < split.length; j++) {
|
// //机构设施
|
// Mechanism mechanism = new Mechanism();
|
// mechanism.setMechanismname(split[j]);
|
// Mechanism one = mechanismService.getOne(Condition.getQueryWrapper(mechanism));
|
// //建筑
|
// Architecture architecture = new Architecture();
|
// architecture.setMechanismname(split[j]);
|
// Architecture one1 = architectureService.getOne(Condition.getQueryWrapper(architecture));
|
// //生活
|
// Life life = new Life();
|
// life.setMechanismname(split[j]);
|
// Life one2 = lifeService.getOne(Condition.getQueryWrapper(life));
|
// //机构设施
|
// if (one != null) {
|
// Map map = new HashMap();
|
// map.put("name", split[j]);
|
// map.put("list", one);
|
// list.add(map);
|
// }
|
// //建筑
|
// else if (one1 != null) {
|
// Map map = new HashMap();
|
//// //教学科研行政
|
//// String jx = mechanismService.selectIn(one1.getId().toString());
|
//// //生活设施
|
//// String sh = architectureService.selectIns(one1.getId().toString());
|
//// map.put("jx", jx);
|
//// map.put("sh", sh);
|
// map.put("name", split[j]);
|
// map.put("list", one1);
|
// list.add(map);
|
// }
|
// //生活
|
// else {
|
// Map map = new HashMap();
|
// map.put("name", split[j]);
|
// map.put("list", one2);
|
// list.add(map);
|
// }
|
//
|
// }
|
// long endTime = System.currentTimeMillis(); //获取结束时间
|
// System.out.println("程序运行时间: " + (endTime - startTime) + "ms");
|
// }
|
// return R.data(list);
|
// }
|
|
/**
|
* 校园搜索
|
*
|
* @param mechanismName 名称模糊查询
|
* @return
|
*/
|
@GetMapping("/selectLook")
|
public R selectLook(String mechanismName) {
|
List list = new ArrayList();
|
List<Map<Object, Object>> maps = architectureService.selectLook(mechanismName);
|
//排除为null的数据
|
List<Map<Object, Object>> list2 = maps.parallelStream().filter(Objects::nonNull).collect(Collectors.toList());
|
// for (int i = 0; i < list2.size(); i++) {
|
// Map map = new HashMap();
|
// map.put("name", list2.get(i).get("mechanismname"));
|
// map.put("list", list2);
|
// list.add(map);
|
// }
|
return R.data(list2);
|
}
|
|
|
/**
|
* code url 转换
|
*/
|
@GetMapping("/url")
|
public void url() throws IOException, ServerException, InsufficientDataException, NoSuchAlgorithmException, InternalException, InvalidResponseException, XmlParserException, InvalidKeyException, ErrorResponseException {
|
List<Architecture> list = architectureService.selectArchALL();
|
for (Architecture architecture : list) {
|
int index = architecture.getCodeurl().lastIndexOf(",") +1;
|
String substring = architecture.getCodeurl().substring(index);
|
byte[] qrCodeImage = Base64Util.decode(substring);
|
ByteArrayInputStream inputStream = new ByteArrayInputStream(qrCodeImage);
|
String url = upload(inputStream);
|
architecture.setCodeurl(url);
|
architectureService.updateById(architecture);
|
//关闭流
|
inputStream.close();
|
}
|
}
|
|
private String upload(ByteArrayInputStream in) throws IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, ErrorResponseException {
|
QueryWrapper<Oss> wrapper = new QueryWrapper<>();
|
wrapper.eq("is_deleted",0);
|
Oss one = ossService.getOne(wrapper);
|
//填写你文件上传的地址以及相应信息
|
// String url = "http://106.225.193.35:2081";
|
// String access = "zhbaadmin";
|
// String secret = "zhbapassword";
|
// String bucket = "zhxy";
|
String url = one.getEndpoint();
|
String access = one.getAccessKey();
|
String secret = one.getSecretKey();
|
String bucket = one.getBucketName();
|
|
MinioClient minioClient =
|
MinioClient.builder()
|
.endpoint(url)
|
.credentials(access, secret)
|
.build();
|
// 检查存储桶是否已经存在
|
boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
|
if (!isExist) {
|
// 创建一个名为zip的存储桶,用于zip文件。
|
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
|
minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
|
}
|
String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "") + ".png";
|
//创建头部信息
|
Map<String, String> headers = new HashMap<>(1 << 2);
|
//添加自定义内容类型
|
headers.put("Content-Type", "application/octet-stream");
|
//上传
|
minioClient.putObject(
|
PutObjectArgs.builder().bucket(bucket).object(newName).stream(
|
in, in.available(), -1)
|
.headers(headers)
|
.build());
|
|
//文件推送
|
String urls = url + "/"+ bucket +"/" + newName;
|
//返回
|
return urls;
|
}
|
|
|
/**
|
* 二维码重新生成 code url 转换
|
*/
|
@GetMapping("/refreshCode")
|
public void refreshCode() throws IOException, ServerException, InsufficientDataException, NoSuchAlgorithmException, InternalException, InvalidResponseException, XmlParserException, InvalidKeyException, ErrorResponseException {
|
List<Architecture> list = architectureService.selectArchALL();
|
for (Architecture architecture : list) {
|
int index = architecture.getCodeurl().lastIndexOf(",") +1;
|
String substring = architecture.getCodeurl().substring(index);
|
byte[] qrCodeImage = Base64Util.decode(substring);
|
ByteArrayInputStream inputStream = new ByteArrayInputStream(qrCodeImage);
|
String url = upload(inputStream);
|
architecture.setCodeurl(url);
|
architectureService.updateById(architecture);
|
//关闭流
|
inputStream.close();
|
}
|
}
|
}
|