123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747 |
- package com.fdkanfang.web.backend;
- import cn.hutool.core.io.FileUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkanfang.common.constant.ConstantFilePath;
- import com.fdkanfang.common.constant.MsgCode;
- import com.fdkanfang.common.constant.TypeCode;
- import com.fdkanfang.common.enums.ImageResolutionRate;
- import com.fdkanfang.common.enums.ResultCodeEnum;
- import com.fdkanfang.common.exception.BaseRuntimeException;
- import com.fdkanfang.common.exception.CommonBaseException;
- import com.fdkanfang.common.model.PageDto;
- import com.fdkanfang.common.util.*;
- import com.fdkanfang.domain.backend.*;
- import com.fdkanfang.domain.dto.*;
- import com.fdkanfang.domain.response.HouseResponse;
- import com.fdkanfang.domain.response.UserResponse;
- import com.fdkanfang.service.backend.*;
- import com.fdkanfang.web.backend.utils.UserUtils;
- import com.fdkanfang.web.mq.config.RabbitConfig;
- import com.fdkanfang.web.shiro.JWTUtil;
- import com.github.pagehelper.PageInfo;
- import io.swagger.annotations.*;
- import lombok.extern.log4j.Log4j2;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.shiro.authz.annotation.Logical;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.apache.shiro.authz.annotation.RequiresRoles;
- import org.springframework.amqp.rabbit.core.RabbitTemplate;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.CollectionUtils;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import tk.mybatis.mapper.entity.Condition;
- import javax.validation.Valid;
- import java.io.File;
- import java.io.IOException;
- import java.time.LocalDateTime;
- import java.util.*;
- /**
- * Created by owen on 2020/2/18 0018 12:17
- */
- @Api(tags = "房源管理")
- @RestController
- @RequestMapping("manage/house")
- @Transactional
- @Log4j2
- public class HouseController extends BaseController {
- // 服务器文件保存位置
- @Value("${output.file.path}")
- private String OUTPATH;
- @Value("${server.domain}")
- private String domain;
- @Autowired
- private HouseService2 houseService2;
- @Autowired
- private ImageService2 imageService2;
- @Autowired
- private RabbitTemplate rabbitTemplate;
- @Autowired
- private ISceneProService sceneProService;
- @Autowired
- private ISceneProEditService sceneProEditService;
- @Autowired
- private RoleService2 roleService;
- @Autowired
- private UserUtils userUtils;
- @ApiOperation("房源列表")
- @PostMapping("list")
- public R list(@RequestBody PageDto param){
- String token = getToken();
- // 获取用户角色
- List<String> userRoles = userUtils.getRolesByToken(token);
- UserEntity user = userUtils.getUserByToken(token);
- Long userId = user.getId();
- PageInfo<HouseResponse> page = null;
- if (userRoles.contains("admin")) {
- page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, null, null));
- } else if (userRoles.contains("edit")){
- if (userRoles.size() == 2) {
- log.info("有edit、upload权限");
- // 有edit、upload
- // page = new PageInfo<>(houseService2.findAllBySearchKey(param, userId, userId));
- page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, null ,userId));
- } else {
- // 只有edit
- log.info("只有edit权限");
- page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, userId , null));
- }
- } else {
- page = new PageInfo<>(houseService2.findAllBySearchKey(param, userId, null));
- }
- return new R(2000, page);
- }
- /**
- * 服务器版本+垂直校验
- *
- * 使用mq队列
- *
- * 上传文件,不能使用json传参,只能用表单
- *
- * 如果图片审核不通过,就直接把这条记录禁用or删除,从新添加一条。
- * 修改只能修改房源信息,不能修改图片
- *
- * 上传的图片必须是以xxx_xxx.jpg 格式命名,xxx_:图片所属的户型
- *
- *
- * 这里要用手写的表单验证验证方式
- *
- * 提前把垂直校验,模型图片地址写入数据库,需要配合状态来判断算法计算是否完成;
- */
- @RequiresRoles(value = {"admin", "edit", "upload"}, logical = Logical.OR)
- @ApiOperation("新增或修改房源信息 + 垂直校验")
- @PostMapping(value = "save", consumes = {"multipart/form-data"})
- @Transactional(rollbackFor = Exception.class)
- public R save(HouseDto param){
- if(StringUtils.isBlank(param.getDistrictName())){
- log.error("小区名称不能为空");
- return new R(MsgCode.e_COMMON_3001, "小区名称不能为空");
- }
- if(null == param.getFloor() || !StringUtils.isNoneBlank(param.getUnitType() , param.getArea() , param.getOrientation())){
- return new R(MsgCode.e_COMMON_3001, "楼层/户型/面积/朝向不能为空");
- }
- boolean isNewAdd = false;
- HouseEntity house = null;
- if (param.getId() == null) {
- house = new HouseEntity();
- UserEntity user = userUtils.getUserByToken(getToken());
- house.setUserId(user.getId());
- param.setId(null);
- BeanUtils.copyProperties(param, house);
- Integer byMaxNum = houseService2.findByMaxNum();
- // 用于第一条数据
- byMaxNum = (byMaxNum == null)? 10000:byMaxNum;
- String sceneCode = getSceneCode();
- house.setNum(byMaxNum + 1);
- house.setSceneCode(sceneCode);
- house.setWebSite(domain+"?m="+sceneCode);
- house.setFilePath(OUTPATH + sceneCode);
- houseService2.save(house);
- SceneProEntity sceneProEntity = new SceneProEntity();
- sceneProEntity.setNum(house.getSceneCode());
- sceneProService.save(sceneProEntity);
- SceneProEditEntity sceneProEditEntity = new SceneProEditEntity();
- sceneProEditEntity.setProId(sceneProEntity.getId());
- // 默认是1
- sceneProEditEntity.setPanoVisi(1);
- sceneProEditEntity.setM2dVisi(1);
- sceneProEditEntity.setM3dVisi(1);
- sceneProEditEntity.setMeasureVisi(1);
- sceneProEditService.save(sceneProEditEntity);
- isNewAdd = true;
- } else {
- house = houseService2.findById(param.getId());
- if (house == null) {
- log.error("房源不存在: {}", param.getId());
- return new R(MsgCode.e_COMMON_3002, MsgCode.msg_COMMON_3002);
- }
- BeanUtils.copyProperties(param, house);
- house.setUpdateTime(new Date());
- houseService2.update(house);
- }
- // 处理上传图片
- MultipartFile[] files = param.getFiles();
- if (files == null || files.length <= 0) {
- log.info("文件为空");
- return new R(MsgCode.e_COMMON_3100, MsgCode.msg_COMMON_3100);
- }
- // 只有新增是才保存图片,修改时另外处理
- if (isNewAdd) {
- //场景码
- String sceneCode = house.getSceneCode();
- boolean needSendMqMsg = false;
- String directoryName = OUTPATH + sceneCode + File.separator + "input_img"+ File.separator;
- FileUtil.mkdir(directoryName);
- HashMap<String, String> ossVerticalImageHighMap = new HashMap<>();
- HashMap<String, String> ossVerticalImageLowMap = new HashMap<>();
- String imageHighPath = null;
- String imageLowPath = null;
- //照片分辨率,以最高的为准
- ImageResolutionRate maxResolutionRate = null;
- int imageResolutionRateSort = 0;
- for (MultipartFile file : files) {
- ImageEntity image = new ImageEntity();
- String filename = file.getOriginalFilename();
- if(StringUtils.isBlank(filename)){
- throw new CommonBaseException(ResultCodeEnum.D100 , "文件名不能为空");
- }
- if(filename.contains(".JPG")){
- int index = filename.lastIndexOf(".");
- String fileNameWithoutPostfix = filename.substring(0 , index);
- filename = fileNameWithoutPostfix + ".jpg";
- log.info("照片的格式写成了大写,需要转成小写:{}" , filename);
- }
- // 检查一下,测试时,可能会没有"_"
- if (!filename.contains("_")) {
- log.error("filename: {}", filename);
- throw new BaseRuntimeException(MsgCode.e_COMMON_3003, "图片命名不符合要求,需要类型+下划线");
- }
- if (RegexpUtils.isContainChinese(filename)) {
- log.error("图片名称不允许中文字符: {}", filename);
- throw new BaseRuntimeException(MsgCode.e_COMMON_3003, "图片名称不允许中文字符");
- }
- // 获取图片房间类型
- String imageType = StringUtils.substringBefore(filename, "_");
- // 本地图片保存位置: /root/data/kanfang/场景码/input_img/xxxx.jpg
- String fileFullPath = directoryName + filename;
- imageHighPath = OUTPATH + sceneCode + "/output_img/" + filename;
- imageLowPath = OUTPATH + sceneCode + "/output_img_low/" + filename;
- // 提前把算法的图片路径存到数据库,但不代表算法运行成功,最后好是要看house的状态;
- String ossVerticalHighPath = ConstantFilePath.OSS_IMAGE_PATH+ sceneCode+"/pan/high/"+ filename;
- String ossVerticalLowPath = ConstantFilePath.OSS_IMAGE_PATH+ sceneCode+"/pan/low/"+ filename;
- image.setVerticalPath(ossVerticalHighPath);
- image.setFileName(filename);
- // 这个参数给前端用,只要有文件名就可以了
- image.setPath(fileFullPath);
- image.setLocalPath(fileFullPath);
- image.setHouseId(house.getId());
- // 默认所有图片都是一楼
- image.setFloor(1);
- image.setType(imageType);
- try {
- //将图片保存到本地指定目录filePath eg: /root/data/kanfang/d_9iRDUgn3l/input_img/xxx.jpg
- int resolutionRate = FileUtils.downloanAndGetResolutionRate(file.getInputStream(), fileFullPath , false);
- maxResolutionRate = ImageResolutionRate.getResolutionRateByRate(resolutionRate);
- image.setResolutionRate(null != maxResolutionRate ? maxResolutionRate.name() : "TWO_K");
- imageService2.save(image);
- // 封装垂直校验后的图片到信息到oss
- ossVerticalImageHighMap.put(imageHighPath, ossVerticalHighPath);
- ossVerticalImageLowMap.put(imageLowPath, ossVerticalLowPath);
- needSendMqMsg = true;
- } catch (IOException e) {
- needSendMqMsg = false;
- log.error("保存照片到本地和持久化image对象出现异常:{}" , e);
- }
- }
- if (needSendMqMsg) {
- HashMap<Object, Object> mqMap = new HashMap<>();
- mqMap.put("ossImageHigh", ossVerticalImageHighMap);
- mqMap.put("ossImageLow", ossVerticalImageLowMap);
- mqMap.put("id", house.getId());
- mqMap.put("basePath", OUTPATH);
- mqMap.put("dataDescribe", "");
- log.info("houseId: {}", house.getId());
- //发消息到mq
- rabbitTemplate.convertAndSend(RabbitConfig.VERTICAL_EXCHANGE, RabbitConfig.VERTICAL_QUEUE_ROUTING, mqMap);
- }
- }
- return new R(MsgCode.SUCCESS_CODE, house);
- }
- @ApiOperation("预审")
- @ResponseBody
- @PostMapping(value = "/auditHouse")
- @Transactional(rollbackFor = Exception.class)
- public Result auditHouse(@RequestBody @ApiParam(name = "用户登录注册实体", value = "传入json格式", required = true) HouseAuditDto houseAuditDto) {
- if(StringUtils.isBlank(houseAuditDto.getDesc()) || null == houseAuditDto.getHouseId() || null == houseAuditDto.getResult()){
- throw new CommonBaseException(ResultCodeEnum.D3001);
- }
- HouseEntity houseEntity = houseService2.findById(houseAuditDto.getHouseId());
- if(null == houseEntity){
- throw new CommonBaseException(ResultCodeEnum.D101 , "房源不存在");
- }
- if(houseAuditDto.getResult().compareTo(1) != 0 && houseAuditDto.getResult().compareTo(0) != 0){
- throw new CommonBaseException(ResultCodeEnum.D101 , "审批结果格式不正确");
- }
- houseEntity.setAuditResult(houseAuditDto.getResult());
- houseEntity.setAuditDesc(houseAuditDto.getDesc());
- houseEntity.setUpdateTime(new Date());
- int update = houseService2.update(houseEntity);
- if(update != 1){
- throw new CommonBaseException(ResultCodeEnum.D101 , "更新房源预审信息失败");
- }
- return Result.success();
- }
- @ApiOperation("标记不能编辑")
- @ResponseBody
- @PostMapping(value = "/markFail")
- public Result markCannotEditHouse(@RequestBody @ApiParam(name = "用户登录注册实体", value = "传入json格式", required = true) HouseAuditDto houseAuditDto) {
- if(StringUtils.isBlank(houseAuditDto.getDesc()) || null == houseAuditDto.getHouseId()){
- throw new CommonBaseException(ResultCodeEnum.D3001);
- }
- HouseEntity houseEntity = houseService2.findById(houseAuditDto.getHouseId());
- if(null == houseEntity){
- throw new CommonBaseException(ResultCodeEnum.D101 , "房源不存在");
- }
- houseEntity.setCanNotEdit(0);
- houseEntity.setCanNotEditDesc(houseAuditDto.getDesc());
- houseEntity.setUpdateTime(new Date());
- int update = houseService2.update(houseEntity);
- if(update != 1){
- throw new CommonBaseException(ResultCodeEnum.D101 , "更新房源无法制作信息失败");
- }
- return Result.success();
- }
- /**
- *
- * @param houseId
- * @param floor 可选参数
- */
- @ApiOperation("查询房源信息")
- @GetMapping("detail")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "houseId", value = "房源id", required = true),
- @ApiImplicitParam(name = "floor", value = "楼层", required = false)
- })
- public R detail(Long houseId, Integer floor){
- HouseEntity house = houseService2.findById(houseId);
- List<ImageEntity> images = imageService2.findByHouseIdAndFloor(houseId, floor);
- if(null != house){
- house.setImages(images);
- return new R(MsgCode.SUCCESS_CODE, house);
- }else{
- return new R(MsgCode.ERROR_CODE, "房源不存在");
- }
- }
- @RequiresRoles(value = {"admin", "edit", "upload"}, logical = Logical.OR)
- @ApiOperation("删除房源(软删除)")
- @GetMapping("removes/{ids}")
- public R removes(@PathVariable String ids){
- List<String> userRoles = userUtils.getRolesByToken(getToken());
- UserEntity user = userUtils.getUserByToken(getToken());
- Long loginUserId = user.getId();
- String roleKey = null;
- // 只有一个权限时
- if (userRoles.size() == 1) {
- roleKey = (String)userRoles.get(0);
- }
- String[] split = ids.split(",");
- for (String s : split) {
- HouseEntity houseEntity = houseService2.findById(Long.valueOf(s));
- if (houseEntity == null) {
- log.error("房源id有误,没有存在的房源");
- return new R(MsgCode.e_COMMON_3002,"没有存在的房源");
- }
- if ("upload".equals(roleKey)) {
- if(null != houseEntity.getAuditResult() && houseEntity.getAuditResult().compareTo(1) == 0){
- log.error("只有upload, 房源id!=0,审批通过的房源不能删除");
- return new R(MsgCode.e_COMMON_3002,"审批通过的房源不能删除");
- }
- }
- if ("edit".equals(roleKey)) {
- log.error("只有edit,没有权限删除房源");
- return new R(MsgCode.e_COMMON_3002,"没有权限删除房源");
- }
- if (!loginUserId.equals(houseEntity.getUserId()) && !userRoles.contains("admin")) {
- log.error("userId: {}, loginUserId: {}", houseEntity.getUserId(), loginUserId);
- log.error("用户不相等时, edit,upload不能删除他人房源");
- return new R(MsgCode.e_COMMON_3002,"没有权限删除房源");
- }
- houseEntity.setRecStatus("I");
- houseEntity.setUpdateTime(new Date());
- houseService2.update(houseEntity);
- }
- return new R(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
- }
- /**
- * 更新sceneJson(写到另一个字段), 保留原始sceneJson数据
- *
- */
- @RequiresRoles(value = {"admin", "edit"}, logical = Logical.OR)
- @ApiOperation("更新sceneJson")
- @PostMapping("update/sceneJson")
- public R updateSceneJson(@Valid @RequestBody SceneJsonDto param){
- HouseEntity house = houseService2.findById(param.getId());
- if (house == null) {
- log.error("房源id不存在");
- return new R(MsgCode.e_COMMON_3001, "房源id不存在");
- }
- house.setNewSceneJson(param.getSceneJson());
- house.setUpdateTime(new Date());
- houseService2.update(house);
- return new R(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
- }
- @ApiOperation("获取楼层户型图")
- @GetMapping("image/find/floor/{houseId}/{floor}")
- public R findImageByFloor(@PathVariable Long houseId, @PathVariable Integer floor){
- List<ImageEntity> images = imageService2.findByHouseIdAndFloor(houseId, floor);
- return new R(MsgCode.SUCCESS_CODE, images);
- }
- /**
- * 只有管理员才能分配制作人
- * 制作人是edit角色
- */
- @RequiresRoles(value = {"admin"}, logical = Logical.OR)
- @ApiOperation("获取制作人")
- @GetMapping("getHandler")
- public R getHandler(){
- // 根据edit权限查询用户
- List<UserResponse> usre = roleService.findUserByRoleKey("edit");
- return new R(MsgCode.SUCCESS_CODE, usre);
- }
- @RequiresRoles(value = {"admin"}, logical = Logical.OR)
- @ApiOperation("分配制作人")
- @GetMapping("setHandler/{houseId}/{userId}")
- public R setHandler(@PathVariable Long houseId, @PathVariable Long userId){
- // 根据edit权限查询用户
- HouseEntity houseEntity = houseService2.findById(houseId);
- if (houseEntity == null) {
- log.error("房源不存在: {}", houseId);
- return new R(MsgCode.e_COMMON_3001, "房源不存在");
- }
- houseEntity.setHandler(userId);
- houseEntity.setUpdateTime(new Date());
- houseService2.update(houseEntity);
- return new R(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
- }
- @ApiOperation("查询房源图片")
- @GetMapping("image/detail/{id}")
- public R imageDetail(@PathVariable Long id){
- return new R(MsgCode.SUCCESS_CODE, imageService2.findById(id));
- }
- @RequiresRoles(value = {"admin", "edit"}, logical = Logical.OR)
- @ApiOperation("编辑图片信息")
- @PostMapping("image/edit")
- public R imageEdit(@RequestBody ImageDto param){
- ImageEntity image = imageService2.findById(param.getId());
- if (image == null){
- log.error("图片id不存在: {}" , param.getId());
- throw new BaseRuntimeException(MsgCode.e_COMMON_3002, MsgCode.msg_COMMON_3002);
- }
- BeanUtils.copyProperties(param, image);
- image.setUpdateTime(new Date());
- imageService2.update(image);
- return new R(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
- }
- @RequiresRoles(value = {"admin", "edit"}, logical = Logical.OR)
- @ApiOperation("批量编辑图片信息")
- @PostMapping("image/edit/all")
- public R imageEdit(@RequestBody Map<Long, String> param){
- for (Map.Entry<Long, String> a : param.entrySet()) {
- ImageEntity image = imageService2.findById(a.getKey());
- image.setUpdateTime(new Date());
- image.setIssue(a.getValue());
- imageService2.update(image);
- }
- return new R(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
- }
- /**
- * 陈世超的算法
- * 调用算法计算场景,生产全景图
- *
- * 图片是用垂直校验后的图片
- *
- * Content传到后台会生成两个文件:floorplan.json、vision.txt
- */
- @RequiresRoles(value = {"admin", "edit"}, logical = Logical.OR)
- @ApiOperation("生成模型")
- @PostMapping("rsa/pano")
- @Transactional(rollbackFor = Exception.class)
- public R rsaPano(@Valid @RequestBody PanoDto param) throws Exception {
- log.info("run rsaPano");
- if (param == null) {
- log.error("参数为空");
- return new R(50001, "error");
- }
- HouseEntity house = houseService2.findById(param.getHouseId());
- if (house == null) {
- log.error("房源不存在: {}", param.getHouseId());
- return new R(MsgCode.e_COMMON_3002, MsgCode.msg_COMMON_3002);
- }
- String sceneCode = house.getSceneCode();
- boolean flagQ = false;
- // data/kanfang/10001/pano
- String savePath = OUTPATH + sceneCode + "/" + TypeCode.SCENE_PANO;
- // 检查场景码对应的pano文件夹是否存在,存在则删除里面的内容(用户从新编辑场景)
- if (FileUtil.isDirectory(savePath)) {
- FileUtil.del(savePath);
- log.info("删除旧目录重新计算: {}", sceneCode);
- }
- log.warn("savePath: {}", savePath);
- String sourcePath = savePath + "/extras/";
- try {
- FileUtils.createDir(sourcePath);
- /*
- /***
- * 以下字段为给算法部传递的参数(data.json),用于生成模型和
- * 照片,提供前端使用,完整的参数如下:
- * {
- * "split_type": "SPLIT_V5",
- * "skybox_type": "SKYBOX_V5",
- * "extras": {
- * "has_vision_txt": true,
- * "has_floorplan_json": true,
- * "has_source_images": true
- * }
- * }
- * */
- String content = "";
- //生成data.json供算法部使用
- JSONObject dataJson = new JSONObject();
- dataJson.put("split_type", "SPLIT_V5");
- String imageResolution = checkImageResolutionRate(house);
- if(ImageResolutionRate.TWO_K.name().equals(imageResolution)){
- //2 K 照片
- dataJson.put("skybox_type", "SKYBOX_V7");
- }else{
- //4 k照片
- dataJson.put("skybox_type", "SKYBOX_V6");
- }
- dataJson.put("extras", null);
- JSONObject extrasJson = new JSONObject();
- extrasJson.put("has_vision_txt" , true);
- extrasJson.put("has_floorplan_json" , true);
- extrasJson.put("has_source_images" , true);
- dataJson.put("extras" , extrasJson);
- FileUtils.fileWriter(dataJson.toJSONString(), savePath + "/data.json");
- log.warn("dataJson的生成路径: {}", savePath + "/data.json");
- // 解析json
- JSONObject original = JSON.parseObject(param.getContent());
- // 获取modelData, cameraData
- String floorPlan = original.getString("floorplan");
- String vision = original.getString("vision");
- if (floorPlan == null) {
- log.error("floorPlan不能为空");
- return new R(50002, "floorPlan不能为空");
- }
- if (vision == null) {
- log.error("vision不能为空");
- return new R(50002, "vision不能为空");
- }
- // json写入服务器
- FileUtils.fileWriter(floorPlan, sourcePath + "floorplan.json");
- FileUtils.fileWriter(vision, sourcePath + "vision.txt");
- log.info("floorplan.json生成完成");
- log.info("vision.txt生成完成");
- // 复制垂直校验图片到指定目录
- String verticalImagePath = OUTPATH + sceneCode+"/output_img";
- String panoImagePath = sourcePath + "images/";
- // srcPath: /data/kanfang/10002/output_img
- log.info("srcPath: {}", verticalImagePath);
- // target: /data/kanfang/10002/pano/extras/images/
- log.info("target: {}", panoImagePath);
- FileUtil.copyFilesFromDir(new File(verticalImagePath), new File(panoImagePath), true);
- flagQ = true;
- } catch (Exception e) {
- e.printStackTrace();
- log.error("出错了……");
- return new R(50002, e.getMessage());
- }
- if (flagQ) {
- HashMap<Object, Object> mqMap = new HashMap<>();
- mqMap.put("id", house.getId());
- mqMap.put("basePath", savePath);
- // 上传floorplan.json到oss, 并命名为floor.json
- HashMap<String, String> uploadJson = new HashMap<>();
- // osspath : images/images+sceneCode/floor.json
- uploadJson.put(sourcePath + "floorplan.json", ConstantFilePath.OSS_FLOOR_PATH+sceneCode+"/floor.json");
- AliyunOssUtil.uploadMulFiles(uploadJson);
- // savePath:/data/kanfang/房源编号/
- // basePath: /data/kanfang/10002/pano
- log.info("basePath: {}", savePath);
- log.info("houseId: {}", house.getId());
- //发消息到mq
- rabbitTemplate.convertAndSend(RabbitConfig.PANO_EXCHANGE, RabbitConfig.PANO_QUEUE_ROUTING, mqMap);
- // 修改房源状态, 3:模型计算中
- house.setStatus(3);
- house.setUpdateTime(new Date());
- houseService2.update(house);
- // 每点击生成模型一次,就修改SceneProEditEntity的部分值
- SceneProEntity sceneProEntity = sceneProService.findBySceneNum(house.getSceneCode());
- if (sceneProEntity == null) {
- log.error("sceneProEntity对象不存在:{}", house.getSceneCode());
- return new R(MsgCode.ERROR_CODE, "sceneProEntity对象不存在");
- }
- SceneProEditEntity proEditEntity = sceneProEditService.findByProId(sceneProEntity.getId());
- proEditEntity.setVersion(proEditEntity.getVersion() + 1);
- proEditEntity.setFloorEditVer(proEditEntity.getFloorEditVer() + 1);
- proEditEntity.setFloorPublishVer(proEditEntity.getFloorPublishVer() + 1);
- proEditEntity.setUpdateTime(new Date());
- sceneProEditService.update(proEditEntity);
- log.info("更新SceneProEditEntity数据完成");
- log.info("入队成功");
- }
- return new R(MsgCode.SUCCESS_CODE, house);
- }
- private String checkImageResolutionRate(HouseEntity houseEntity){
- if(null == houseEntity || null == houseEntity.getId()){
- return null;
- }
- List<ImageEntity> imageEntities = imageService2.findByHouseId(houseEntity.getId());
- if(CollectionUtils.isEmpty(imageEntities)){
- log.error("房源[{}]下面无照片,默认返回2k的分辨率");
- return ImageResolutionRate.TWO_K.name();
- }
- int sort = 0;
- ImageResolutionRate maxResolution = null;
- for (ImageEntity imageEntity : imageEntities){
- if(StringUtils.isBlank(imageEntity.getResolutionRate())){
- log.warn("房源[{}]的照片[{}]没有设置照片分辨率,跳过" , houseEntity.getId() , imageEntity.getId());
- break;
- }
- ImageResolutionRate curResolution = ImageResolutionRate.getResolutionByName(imageEntity.getResolutionRate());
- if(null != curResolution){
- if(curResolution.getOrder() > sort){
- sort = curResolution.getOrder();
- maxResolution = curResolution;
- }
- }
- }
- log.info("房源[{}]的照片最大的分辨率为:{}" , houseEntity.getId() , null != maxResolution ? maxResolution.name() :"空值");
- return null != maxResolution ? maxResolution.name() : ImageResolutionRate.TWO_K.name();
- }
- /***
- * 获取唯一场景码
- */
- private String getSceneCode(){
- String randowString = null;
- Condition condition = new Condition(HouseEntity.class);
- List<HouseEntity> all = null;
- boolean flag = true;
- while (flag) {
- randowString = RandomUtils.randowString(9);
- condition.and().andEqualTo("sceneCode", randowString);
- all = houseService2.findAll(condition);
- log.info(all.size());
- flag = all.size() > 0;
- }
- log.info("code: {}", randowString);
- return "d_" + randowString;
- }
- }
|