package com.tourism.webadmin.app.website.controller;

import com.github.pagehelper.page.PageMethod;
import com.tourism.common.additional.config.ApplicationConfig;
import com.tourism.common.additional.utils.StringUtils;
import com.tourism.common.additional.utils.UrlConvertUtils;
import com.tourism.common.core.annotation.MyRequestBody;
import com.tourism.common.core.constant.ErrorCodeEnum;
import com.tourism.common.core.object.*;
import com.tourism.common.core.util.MyCommonUtil;
import com.tourism.common.core.util.MyModelUtil;
import com.tourism.common.core.util.MyPageUtil;
import com.tourism.common.core.validator.UpdateGroup;
import com.tourism.common.huaweicloud.moderation.service.HuaweiCloudModerationService;
import com.tourism.common.log.annotation.OperationLog;
import com.tourism.common.log.model.constant.SysOperationLogType;
import com.tourism.common.sequence.wrapper.IdGeneratorWrapper;
import com.tourism.webadmin.app.website.dto.TourismProjectTravelNotesWriteDetailPageDto;
import com.tourism.webadmin.app.website.dto.TourismProjectTravelNotesWriteToWebDto;
import com.tourism.webadmin.app.website.dto.WebsiteTourUserDto;
import com.tourism.webadmin.app.website.vo.TourWriteBelongTabVo;
import com.tourism.webadmin.app.website.vo.TourismProjectTravelNotesWriteCovertVo;
import com.tourism.webadmin.back.dto.TourismTravelNotesContentWriteDto;
import com.tourism.webadmin.back.model.*;
import com.tourism.webadmin.back.model.constant.AuditState;
import com.tourism.webadmin.back.model.constant.UnmountState;
import com.tourism.webadmin.back.service.*;
import com.tourism.webadmin.back.vo.TourismProjectTravelNotesWriteVo;
import com.tourism.webadmin.back.vo.TourismTravelNotesContentWriteVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import ognl.Token;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Tag(name = "门户网站发布游记接口")
@Slf4j
@RestController
@RequestMapping("/website/tourism/publishTravelNotes")
public class WebSiteTourismTravelNotesPublishController {

    @Autowired
    private IdGeneratorWrapper idGenerator;
    @Autowired
    private TourismProjectTravelNotesWriteService tourismProjectTravelNotesWriteService;
    @Autowired
    private TourismTravelNotesContentWriteService tourismTravelNotesContentWriteService;
    @Autowired
    private TourTourismProjectTravelNotesService tourTourismProjectTravelNotesService;
    @Autowired
    private TourUserService tourUserService;
    @Autowired
    private DirectoryInfoService directoryInfoService;
    @Autowired
    private HuaweiCloudModerationService huaweiCloudModerationService;
    @Autowired
    private ApplicationConfig applicationConfig;

    /**
     * 获取草稿id
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.LIST)
    @GetMapping("/getDraftId")
    public ResponseResult<String> getDraftId() {
        return ResponseResult.success(String.valueOf(idGenerator.nextLongId()));
    }

    /**
     * 存为草稿
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.UPDATE)
    @PostMapping("/saveDraft")
    public ResponseResult<Void> saveDraft(@RequestBody TourismProjectTravelNotesWriteToWebDto tourismProjectTravelNotesWriteDto) {


        TourismProjectTravelNotesWrite tourismProjectTravelNotesWrite =
                tourismProjectTravelNotesWriteService.getById(tourismProjectTravelNotesWriteDto.getId());

        TourismProjectTravelNotesWrite tourismProjectTravelNotesWriteSave =
                MyModelUtil.copyTo(tourismProjectTravelNotesWriteDto,TourismProjectTravelNotesWrite.class);

        //将从表中的数据进行过滤，筛选出cover为1的图片为封面图，第一段落为项目简述
        List<TourismTravelNotesContentWriteDto> travelNotesContent = tourismProjectTravelNotesWriteDto.getTravelNotesContent();

        //循环遍历查询内容是否超过5000长度
        for(TourismTravelNotesContentWriteDto i:travelNotesContent){
            if(StringUtils.isNotBlank(i.getContent()) && i.getContent().length()>5000)
                return ResponseResult.error(ErrorCodeEnum.CONTENT_OUT_LIMIT);
        }
        List<TourismTravelNotesContentWriteDto> coverImageList = travelNotesContent.stream().filter(item -> item.getType().equals("image") && item.getCover() != null && item.getCover() == 1).collect(Collectors.toList());
        List<TourismTravelNotesContentWriteDto> coverImageList1 = travelNotesContent.stream().filter(item -> item.getType().equals("image")).collect(Collectors.toList());
        if(CollectionUtils.isEmpty(coverImageList)){
            if(CollectionUtils.isNotEmpty(coverImageList1)){
                tourismProjectTravelNotesWriteSave.setTourismUrl(coverImageList1.get(0).getContent());
            }
        }else{
            tourismProjectTravelNotesWriteSave.setTourismUrl(coverImageList.get(0).getContent());
        }

        //判断是新增还是更新
        if(tourismProjectTravelNotesWrite == null){
            //草稿为下架状态
            tourismProjectTravelNotesWriteSave.setUnmountState(UnmountState.DELIST);
            tourismProjectTravelNotesWriteService.saveNew(tourismProjectTravelNotesWriteSave);
        }else {
            //草稿为下架状态
            tourismProjectTravelNotesWriteSave.setUnmountState(UnmountState.DELIST);
            tourismProjectTravelNotesWriteService.updateById(tourismProjectTravelNotesWriteSave);
        }

        //判断内容是否为空
        if(tourismProjectTravelNotesWriteDto.getTravelNotesContent() != null) {
            List<TourismTravelNotesContentWriteDto> travelNotesContentWriteList = tourismProjectTravelNotesWriteDto.getTravelNotesContent();
            List<TourismTravelNotesContentWrite> tourismTravelNotesContentWriteList = MyModelUtil.copyCollectionTo(travelNotesContentWriteList, TourismTravelNotesContentWrite.class);
            for (TourismTravelNotesContentWrite item : tourismTravelNotesContentWriteList) {
                item.setAssociationId(tourismProjectTravelNotesWriteSave.getId());
                item.setId(null);
            }
            tourismTravelNotesContentWriteService.removeByAssociationId(tourismProjectTravelNotesWriteSave.getId());
            //查询关联数据的id,根据id进行更新数据表的数据
            tourismTravelNotesContentWriteService.saveNewBatch(tourismTravelNotesContentWriteList);
        }
        return ResponseResult.success();
    }

    /**
     * 获取数据列表
     * param type--->类型(0,草稿;1,待审核;2,审核未通过;3,审核通过
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.LIST)
    @GetMapping("/getDraftList")
    public ResponseResult<MyPageData<TourismProjectTravelNotesWriteCovertVo>> getDraftList(@Validated TourismProjectTravelNotesWriteDetailPageDto pageDto) {
        if (pageDto.getType() == null) {
            return ResponseResult.success(null);
        }
        Long userId = TokenData.takeFromRequest().getUserId();
        TourismProjectTravelNotesWrite tourismProjectTravelNotesWrite = new TourismProjectTravelNotesWrite();
        tourismProjectTravelNotesWrite.setCreateUserId(userId);
        tourismProjectTravelNotesWrite.setState(pageDto.getType());
        MyOrderParam myOrderParam = new MyOrderParam();
        myOrderParam.add(new MyOrderParam.OrderInfo("updateTime",false,null));
        String orderBy = MyOrderParam.buildOrderBy(myOrderParam, TourismProjectTravelNotesWrite.class);
        if(pageDto.getPageSize() != null && pageDto.getPageNum() != null){
            PageMethod.startPage(pageDto.getPageNum(), pageDto.getPageSize(), true);
        }
        //查询已发布状态的状态，则需要state为3并且上下架状态为上架
        if(pageDto.getType() == 3){
            tourismProjectTravelNotesWrite.setUnmountState(UnmountState.LISTING);
        }
        List<TourismProjectTravelNotesWrite> tourismProjectTravelNotesWriteList =
                tourismProjectTravelNotesWriteService.getTourismProjectTravelNotesWriteList(tourismProjectTravelNotesWrite, orderBy);

        MyPageData<TourismProjectTravelNotesWriteCovertVo> tourismProjectTravelNotesWriteVoMyPageData = MyPageUtil.makeResponseData(tourismProjectTravelNotesWriteList, TourismProjectTravelNotesWriteCovertVo.class);
        List<TourismProjectTravelNotesWriteCovertVo> dataList = tourismProjectTravelNotesWriteVoMyPageData.getDataList();
        if(CollectionUtils.isNotEmpty(dataList)){
            dataList.stream().forEach(item->{
                item.setTourismUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), item.getTourismUrl()));
            });
        }
        return ResponseResult.success(tourismProjectTravelNotesWriteVoMyPageData);
    }

    /**
     * 根据草稿id，获取草稿详情
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.LIST)
    @GetMapping("/getDraftDetail")
    public ResponseResult<TourismProjectTravelNotesWriteVo> getDraftDetail(@RequestParam Long writeId) {

        TourismProjectTravelNotesWrite tourismProjectTravelNotesWrite = tourismProjectTravelNotesWriteService.getByIdWithRelation(writeId,MyRelationParam.full());
        if(tourismProjectTravelNotesWrite == null){
            return ResponseResult.success(null);
        }
        TourismProjectTravelNotesWriteVo tourismProjectTravelNotesWriteVo = MyModelUtil.copyTo(tourismProjectTravelNotesWrite, TourismProjectTravelNotesWriteVo.class);

        return ResponseResult.success(tourismProjectTravelNotesWriteVo);
    }

    /**
     * 根据草稿id，删除草稿
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.UPDATE)
    @PostMapping("/removeByDraftId")
    public ResponseResult<Void> removeByDraftId(@MyRequestBody String writeId) {
        if (MyCommonUtil.existBlankArgument(writeId)) {
            return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
        }
        //验证是否为本人创建的数据
        Long userId = TokenData.takeFromRequest().getUserId();
        TourismProjectTravelNotesWrite tourismProjectTravelNotesWrite = tourismProjectTravelNotesWriteService.getById(Long.valueOf(writeId));
        if(tourismProjectTravelNotesWrite == null){
            return ResponseResult.success();
        }else {
            if(!tourismProjectTravelNotesWrite.getState().equals(AuditState.DRAFT)
                    && !tourismProjectTravelNotesWrite.getState().equals(AuditState.FAILAUDIT)){
                return ResponseResult.error(ErrorCodeEnum.UPLOAD_FILE_FAILED,"该数据状态不允许删除!");
            }
            //不是本人创建的数据
            if(!tourismProjectTravelNotesWrite.getCreateUserId().equals(userId)){
                return ResponseResult.error(ErrorCodeEnum.DATA_NOT_FOUND);
            }
        }
        tourismProjectTravelNotesWriteService.remove(Long.valueOf(writeId));
        tourismTravelNotesContentWriteService.removeByAssociationId(Long.valueOf(writeId));
        return ResponseResult.success();
    }

    /**
     * 草稿发布接口
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.PUBLISH)
    @PostMapping("/publishDraft")
    @Transactional
    public ResponseResult<Void> publishDraft(@RequestBody TourismProjectTravelNotesWriteToWebDto tourismProjectTravelNotesWriteDto) {
        String errorMessage = MyCommonUtil.getModelValidationError(tourismProjectTravelNotesWriteDto,UpdateGroup.class);
        if (errorMessage != null) {
            return ResponseResult.success(null);
        }
        TourismProjectTravelNotesWrite tourismProjectTravelNotesWrite =
                MyModelUtil.copyTo(tourismProjectTravelNotesWriteDto, TourismProjectTravelNotesWrite.class);

        //校验该游记是否为审核中和已发布状态
        TourismProjectTravelNotesWrite tourismProjectTravelNotesWriteVerify =
                tourismProjectTravelNotesWriteService.getById(tourismProjectTravelNotesWriteDto.getId());

        if(tourismProjectTravelNotesWriteVerify != null){
            if(tourismProjectTravelNotesWriteVerify.getState() .equals(AuditState.UNAUDITSTATE)) {
                return ResponseResult.error(ErrorCodeEnum.INVALID_STATUS_ARGUMENT, "该游记状态为:正在审核中,请撤销后进行操作");
            }else if(tourismProjectTravelNotesWriteVerify.getState() .equals(AuditState.SUCCEEDAUDIT)){
                return ResponseResult.error(ErrorCodeEnum.INVALID_STATUS_ARGUMENT, "该游记状态为:已发布成功,请下架后进行操作");
            }
        }
        //将从表中的数据进行过滤，筛选出cover为1的图片为封面图，第一段落为项目简述
        List<TourismTravelNotesContentWriteDto> travelNotesContent = tourismProjectTravelNotesWriteDto.getTravelNotesContent();

        //循环遍历查询内容是否超过5000长度
        for(TourismTravelNotesContentWriteDto i:travelNotesContent){
            if(StringUtils.isNotBlank(i.getContent()) && i.getContent().length()>5000)
                return ResponseResult.error(ErrorCodeEnum.CONTENT_OUT_LIMIT);
        }
        List<TourismTravelNotesContentWriteDto> coverImageList = travelNotesContent.stream().filter(item -> item.getType().equals("image") && item.getCover() != null && item.getCover() == 1).collect(Collectors.toList());
        List<TourismTravelNotesContentWriteDto> coverImageList1 = travelNotesContent.stream().filter(item -> item.getType().equals("image")).collect(Collectors.toList());
        if(CollectionUtils.isEmpty(coverImageList)){
            if(CollectionUtils.isEmpty(coverImageList1)){
                return ResponseResult.error(ErrorCodeEnum.NOT_COVER);
            }else {
                tourismProjectTravelNotesWrite.setTourismUrl(coverImageList1.get(0).getContent());
            }
        }else{
            tourismProjectTravelNotesWrite.setTourismUrl(coverImageList.get(0).getContent());
        }
        List<TourismTravelNotesContentWriteDto> sectionContent = travelNotesContent.stream().filter(item -> item.getType().equals("sectionContent")).collect(Collectors.toList());
        if(CollectionUtils.isNotEmpty(sectionContent)){
            tourismProjectTravelNotesWrite.setRemarks(sectionContent.get(0).getContent());
        }

        // 文案审核
        List<String> imageList = travelNotesContent.stream().filter(e -> e.getType().equals("image")).map(TourismTravelNotesContentWriteDto::getContent).collect(Collectors.toList());
        imageList.add(tourismProjectTravelNotesWrite.getTravelNotesBanner());
        Boolean imageResult = huaweiCloudModerationService.runImageModeration(imageList);
        // 图片审核
        List<String> titleList = travelNotesContent.stream().filter(e -> e.getType().equals("sectionTitle")).map(TourismTravelNotesContentWriteDto::getContent).collect(Collectors.toList());
        List<String> contentList = travelNotesContent.stream().filter(e -> e.getType().equals("sectionContent")).map(TourismTravelNotesContentWriteDto::getContent).collect(Collectors.toList());
        titleList.addAll(contentList);
        Boolean textResult = huaweiCloudModerationService.runTextModeration(titleList);
        String auditReson = "";
        if(imageResult && textResult){
            tourismProjectTravelNotesWrite.setAutoAuditStatus(1);
            auditReson = "图文审核通过";
        }else {
            tourismProjectTravelNotesWrite.setAutoAuditStatus(2);
            if(!imageResult){
                auditReson = "图片审核未通过：可能设计暴恐、色情、违禁、辱骂等内容;";
            }
            if(!textResult){
                auditReson += "文案审核未通过：可能设计暴恐、色情、违禁、辱骂等内容;";
            }
        }
        tourismProjectTravelNotesWrite.setAutoRejectReason(auditReson);

        tourismProjectTravelNotesWrite.setState(AuditState.UNAUDITSTATE);
        //对dto的id进行判断，如果数据表中查不到该id，则为新增;否则为修改
        TourismProjectTravelNotesWrite tourismProjectTravelNotesWrite1 =
                tourismProjectTravelNotesWriteService.getById(tourismProjectTravelNotesWriteDto.getId());
        if(tourismProjectTravelNotesWrite1 == null) {
            tourismProjectTravelNotesWriteService.saveNew(tourismProjectTravelNotesWrite);
        }else{
            if(!tourismProjectTravelNotesWrite1.getCreateUserId().equals(TokenData.takeFromRequest().getUserId())){
                return ResponseResult.error(ErrorCodeEnum.DATA_SAVE_FAILED);
            }
            tourismProjectTravelNotesWriteService.updateById(tourismProjectTravelNotesWrite);
        }
        tourismTravelNotesContentWriteService.removeByAssociationId(tourismProjectTravelNotesWriteDto.getId());
        List<TourismTravelNotesContentWrite> tourismTravelNotesContentWriteList =
                MyModelUtil.copyCollectionTo(tourismProjectTravelNotesWriteDto.getTravelNotesContent(), TourismTravelNotesContentWrite.class);
        for (TourismTravelNotesContentWrite item : tourismTravelNotesContentWriteList) {
            item.setAssociationId(tourismProjectTravelNotesWrite.getId());
            item.setId(null);
        }
        tourismTravelNotesContentWriteService.saveNewBatch(tourismTravelNotesContentWriteList);
        return ResponseResult.success();
    }

    /**
     * 审核中---->撤回接口
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.UPDATE)
    @PostMapping("/withdraw")
    public ResponseResult<Void> withdraw(@MyRequestBody String writeId) {
        if (MyCommonUtil.existBlankArgument(writeId)) {
            return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
        }
        TourismProjectTravelNotesWrite tourismProjectTravelNotesWrite = tourismProjectTravelNotesWriteService.getById(Long.valueOf(writeId));
        //判断状态是否为审核中
        if(tourismProjectTravelNotesWrite == null){
            return ResponseResult.error(ErrorCodeEnum.DATA_ACCESS_FAILED,"该游记内容不存在，请刷新重试！");
        }
        if(!tourismProjectTravelNotesWrite.getState().equals(AuditState.UNAUDITSTATE)){
            return ResponseResult.error(ErrorCodeEnum.DATA_ACCESS_FAILED,"当前状态无法撤回");
        }else if(!tourismProjectTravelNotesWrite.getCreateUserId().equals(TokenData.takeFromRequest().getUserId())){
            return ResponseResult.error(ErrorCodeEnum.DATA_ACCESS_FAILED,"当前用户无法撤回");
        }else {
            tourismProjectTravelNotesWrite.setState(AuditState.DRAFT);
            tourismProjectTravelNotesWriteService.updateById(tourismProjectTravelNotesWrite);
            return ResponseResult.success();
        }
    }

    /**
     * 已审核通过的接口进行下架操作
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.UPDATE)
    @PostMapping("/delist")
    public ResponseResult<Void> delist(@MyRequestBody String writeId) {
        if (MyCommonUtil.existBlankArgument(writeId)) {
            return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
        }
        TourismProjectTravelNotesWrite tourismProjectTravelNotesWrite = tourismProjectTravelNotesWriteService.getById(Long.valueOf(writeId));
        //校验该数据是否为用户所创建的数据
        if(!tourismProjectTravelNotesWrite.getCreateUserId().equals(TokenData.takeFromRequest().getUserId())){
            return ResponseResult.error(ErrorCodeEnum.DATA_ACCESS_FAILED,"当前用户无法进行下架操作");
        }
        //校验数据状态是否允许下架状态
        if(tourismProjectTravelNotesWrite.getUnmountState().equals(UnmountState.LISTING) && tourismProjectTravelNotesWrite.getState().equals(AuditState.SUCCEEDAUDIT)){
            tourismProjectTravelNotesWrite.setUnmountState(UnmountState.DELIST);
            tourismProjectTravelNotesWrite.setState(AuditState.DRAFT);
            tourismProjectTravelNotesWriteService.updateById(tourismProjectTravelNotesWrite);
            return ResponseResult.success();
        }else {
            return ResponseResult.error(ErrorCodeEnum.DATA_ACCESS_FAILED,"数据状态不允许下架");
        }
    }

    /**
     * 在写日志的页面，返回是否需要完善个人信息(0:需要完善个人信息;1:不需要完善)
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.LIST)
    @GetMapping("/isPerfect")
    public ResponseResult<Integer> isPerfect() {
        Long userId = TokenData.takeFromRequest().getUserId();
        TourismProjectTravelNotesWrite filter = new TourismProjectTravelNotesWrite();
        filter.setCreateUserId(userId);
        List<TourismProjectTravelNotesWrite> tourismProjectTravelNotesWriteList = tourismProjectTravelNotesWriteService.getTourismProjectTravelNotesWriteList(filter, "");
        int tourismProjectTravelNotesWriteCount = 0;
        if(CollectionUtils.isNotEmpty(tourismProjectTravelNotesWriteList)){
            tourismProjectTravelNotesWriteCount = tourismProjectTravelNotesWriteCount+(tourismProjectTravelNotesWriteList.size());
        }
        TourTourismProjectTravelNotes tourTourismProjectTravelNotes = new TourTourismProjectTravelNotes();
        tourTourismProjectTravelNotes.setCreateUserId(userId);
        List<TourTourismProjectTravelNotes> tourTourismProjectTravelNotesList = tourTourismProjectTravelNotesService.getTourTourismProjectTravelNotesList(tourTourismProjectTravelNotes, "");
        int tourTourismProjectTravelNotesCount = 0;
        if(CollectionUtils.isNotEmpty(tourTourismProjectTravelNotesList)){
            tourTourismProjectTravelNotesCount = tourTourismProjectTravelNotesCount+(tourTourismProjectTravelNotesList.size());
        }
        int totalCount = tourTourismProjectTravelNotesCount+tourismProjectTravelNotesWriteCount;

        //如果未超过3条，则不需要进行完善个人信息
        if(totalCount<3){
            return ResponseResult.success(1);
        }else {
            //查询个人信息表是否有必填信息需要用户完善
            TourUser tourUserInfo = new TourUser();
            tourUserInfo.setUserId(userId);
            TourUser tourUser = tourUserService.getOne(tourUserInfo);

            //假设用户的展示姓名和邮箱为空的话，则进行弹窗完善用户个人的信息
            if(StringUtils.isEmpty(tourUser.getShowName()) || StringUtils.isEmpty(tourUser.getEmail())){
                return ResponseResult.success(0);
            }
            return ResponseResult.success(1);
        }

    }

    /**
     * 保存个人信息
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.UPDATE)
    @PostMapping("/savePerfect")
    public ResponseResult<Void> savePerfect(@RequestBody WebsiteTourUserDto websiteTourUserDto) {
        String errorMessage = MyCommonUtil.getModelValidationError(websiteTourUserDto, UpdateGroup.class);
        if (errorMessage != null) {
            return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
        }
        Long userId = TokenData.takeFromRequest().getUserId();
//        TourUser tourUser = tourUserService.getById(userId);
        TourUser tourUserModel = MyModelUtil.copyTo(websiteTourUserDto, TourUser.class);
        tourUserModel.setUserId(userId);
//        if(websiteTourUserDto.getShowName() != null){
//            tourUserModel.setShowName(websiteTourUserDto.getShowName());
//        }
//        if(websiteTourUserDto.getEmail() != null){
//            tourUserModel.setEmail(websiteTourUserDto.getEmail());
//        }
//        if(websiteTourUserDto.getAddress() != null){
//            tourUserModel.setAddress(websiteTourUserDto.getAddress());
//        }
//        if(websiteTourUserDto.getJob() != null){
//            tourUserModel.setJob(websiteTourUserDto.getJob());
//        }


        tourUserService.updateById(tourUserModel);
        return ResponseResult.success();
    }

    /**
     * 用户发布游记选择所属分类---->目的地
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.LIST)
    @GetMapping("/getWriteBelongTab")
    public ResponseResult<List<TourWriteBelongTabVo>> getWriteBelongTab() {

        DirectoryInfo directoryInfo  = new DirectoryInfo();
        directoryInfo.setParentId(0L);
        directoryInfo.setDirectoryType(1);
        List<DirectoryInfo> directoryInfoList = directoryInfoService.getDirectoryInfoList(directoryInfo, "");

        List<TourWriteBelongTabVo> tourWriteBelongTabVoList = MyModelUtil.copyCollectionTo(directoryInfoList, TourWriteBelongTabVo.class);
        List<TourWriteBelongTabVo> newDirectoryInfoList = new ArrayList<>();
        for(TourWriteBelongTabVo i : tourWriteBelongTabVoList){
            if(!i.getId().equals("10")){
                DirectoryInfo directoryInfo2  = new DirectoryInfo();
                directoryInfo2.setParentId(Long.valueOf(i.getId()));
                directoryInfo2.setDirectoryType(1);
                List<DirectoryInfo> bodyDirectoryInfoList = directoryInfoService.getDirectoryInfoList(directoryInfo2, "");

                List<TourWriteBelongTabVo> bodyTourWriteBelongTabVoList = MyModelUtil.copyCollectionTo(bodyDirectoryInfoList, TourWriteBelongTabVo.class);
                if(CollectionUtils.isNotEmpty(bodyDirectoryInfoList)){
                    i.setTourWriteBelongTabVoList(bodyTourWriteBelongTabVoList);
                }
                newDirectoryInfoList.add(i);
            }
        }
        return ResponseResult.success(newDirectoryInfoList);
    }



}
