package jnpf.memberLog.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import jnpf.ImRobotApi;
import jnpf.base.ActionResult;
import jnpf.base.UserInfo;
import jnpf.cultivate.utils.UserApiV2Util;
import jnpf.enums.ConstantStatusEnum;
import jnpf.enums.OptTypeEnum;
import jnpf.enums.memberLog.MemberLogContentEnum;
import jnpf.enums.memberLog.MemberLogImEnum;
import jnpf.enums.memberLog.MemberLogImJumpEnum;
import jnpf.from.*;
import jnpf.memberLog.mapper.*;
import jnpf.memberLog.service.LogService;
import jnpf.model.memberLog.dto.LogAgentAlertDto;
import jnpf.model.memberLog.dto.LogMemberAssociationDto;
import jnpf.model.memberLog.dto.LogMemberFieldDto;
import jnpf.model.memberLog.dto.LogMemberLogDto;
import jnpf.model.memberLog.po.LogMemberAssociation;
import jnpf.model.memberLog.vo.*;
import jnpf.permission.vo.v2.user.UserBoundVO;
import jnpf.util.FtbUtil;
import jnpf.util.UploaderUtil;
import jnpf.util.UserProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * describe
 * 日志实现
 *
 * @author HuangLinPan
 * @date 2023/08/07
 */
@Slf4j
@Service
public class LogServiceImpl implements LogService {

    @Resource
    private LogCommentMapper logCommentMapper;
    @Resource
    private LogMemberAssociationMapper logMemberAssociationMapper;
    @Resource
    private LogMemberFieldMapper logMemberFieldMapper;
    @Resource
    private LogMemberLogMapper logMemberLogMapper;
    @Resource
    private LogTemplateMapper logTemplateMapper;
    @Resource
    private LogTemplateFieldMapper logTemplateFieldMapper;
    @Resource
    private UserProvider userProvider;
    @Autowired
    private UserApiV2Util userApiV2Util;

    @Autowired
    private ImRobotApi imRobotApi;


    @Override
    public List<LogTemplateVo> getTemplateList() {
        List<LogTemplateVo> logTemplateVos = logTemplateMapper.getTemplateList();
        if (null != logTemplateVos && logTemplateVos.size() > 0) {
            //赋值下面字段
            logTemplateVos.forEach(v -> {
                List<LogTemplateFieldVo> fieldVos = logTemplateFieldMapper.getFieldById(v.getId());
                if (null != fieldVos) {
                    v.setLogTemplateFieldVoList(fieldVos);
                }
            });
        }
        return logTemplateVos;
    }

    @Override
    public void addLog(LogMemberLogDto logMemberLogDto) {
        //新增日志主表
        String id = FtbUtil.getId();
        logMemberLogDto.setId(id);
        String userId = userProvider.get().getUserId();
        setLogParam(logMemberLogDto, userId);
        logMemberLogMapper.addLog(logMemberLogDto, userId);
        if (null != logMemberLogDto.getLogMemberFieldList() && logMemberLogDto.getLogMemberFieldList().size() > 0) {
            logMemberLogDto.getLogMemberFieldList().forEach(v -> v.setId(FtbUtil.getId()));
            //新增字段信息
            logMemberFieldMapper.addField(logMemberLogDto.getLogMemberFieldList(), logMemberLogDto.getId());
        }
        //新增成员信息
        if (null != logMemberLogDto.getLogMemberAssociationList() && logMemberLogDto.getLogMemberAssociationList().size() > 0) {
            logMemberLogDto.getLogMemberAssociationList().forEach(v -> v.setId(FtbUtil.getId()));
            //新增字段信息
            logMemberAssociationMapper.addMemberAssociation(logMemberLogDto.getLogMemberAssociationList(), logMemberLogDto.getId());
        }

        //消息推送
        List<LogMemberAssociationDto> logMemberAssociationList = logMemberLogDto.getLogMemberAssociationList();
        if (CollectionUtil.isEmpty(logMemberAssociationList)) {
            return;
        }

        List<LogMemberFieldDto> logMemberFieldList = logMemberLogDto.getLogMemberFieldList();
        List<LogMemberFieldDto> titleDtoList = logMemberFieldList.stream().filter(log -> {
            return log.getCode().equals("TITLE") || log.getCode().equals("title");
        }).collect(Collectors.toList());

        String title = "";
        //日志/日报标题
        if (CollectionUtil.isNotEmpty(titleDtoList)) {
            //日志标题
            title = titleDtoList.get(0).getContent();
        } else {
            //日报标题需要拼接
            String userName = UserProvider.getUser().getUserName();
            title = userName + "的"+logMemberLogDto.getLogType();
        }


        //获取日报/日志内容
        String logContent = getLogContentTemplate(logMemberFieldList);

        UserInfo loginUser = UserProvider.getUser();
//        List<String> toUserIds = logMemberAssociationList.stream().map(LogMemberAssociationDto::getUserId).collect(Collectors.toList());

        List<String> toUserIds = logMemberAssociationList.stream().filter(logToUser -> {
            //推送到用户id
            return logToUser.getUserType().equals(1);
        }).map(logToUser -> {
            String toUserId = logToUser.getUserId();
            if (toUserId.contains(":")) {
                return toUserId.split(":")[1];
            }
            return toUserId;
        }).collect(Collectors.toList());

        List<String> groupIds = logMemberAssociationList.stream().filter(logToUser -> {
            return logToUser.getUserType().equals(2);
        }).map(LogMemberAssociationDto::getUserId).collect(Collectors.toList());
        //推送到个人
        if (CollectionUtil.isNotEmpty(toUserIds)) {
            msgSendToSomePeople(title, logContent, toUserIds, id, loginUser.getTenantId(), logMemberLogDto.getLogType());
        }

        if (CollectionUtil.isNotEmpty(groupIds)) {
            for (String groupId : groupIds) {
                if (StrUtil.isBlank(groupId)) {
                    continue;
                }
                //推送到群
                msgSendToGroup(title, logContent, groupId, loginUser.getTenantId(), id, logMemberLogDto.getLogType());
            }
        }
    }

    private void setLogParam(LogMemberLogDto logMemberLogDto, String userId) {
        //赋值最后一个部门/岗位
        UserBoundVO userPrimaryBoundOne = userApiV2Util.getUserPrimaryBoundOne(userId, null);
        if (null != userPrimaryBoundOne) {
            logMemberLogDto.setOrganizeId(userPrimaryBoundOne.getOrganizeId());
            logMemberLogDto.setOrganizeName(userPrimaryBoundOne.getOrganizeName());
            logMemberLogDto.setPositionId(userPrimaryBoundOne.getPositionId());
            logMemberLogDto.setPositionName(userPrimaryBoundOne.getPositionName());
        }
    }

    @Override
    public LogMemberLogVo getLogDetail(String logId) {
        String userId = userProvider.get().getUserId();
        //查询日志主表信息并统计点赞/已读数
        LogMemberLogVo logDetail = logMemberLogMapper.getLogDetail(logId);
        if (null != logDetail) {
            //查看当前用户的点赞状态
            String meLike = logMemberAssociationMapper.getMeLike(logId, userId);
            if (null != meLike) {
                logDetail.setLikeType(1);
            } else {
                logDetail.setLikeType(0);
            }
            //赋值创建用户信息
            UserBoundVO userPrimaryBoundOne = userApiV2Util.getUserPrimaryBoundOne(logDetail.getCreatorUserId(), null);

            if (null != userPrimaryBoundOne) {
                logDetail.setCreatorUserName(userPrimaryBoundOne.getUserName());
                logDetail.setCreatorUserHeadIcon(UploaderUtil.uploaderImg(userPrimaryBoundOne.getHeadIcon()));
            }
            //查询日志字段信息
            List<LogMemberFieldVo> logMemberFieldVos = logMemberFieldMapper.getFieldById(logId);
            logDetail.setLogMemberFieldVos(logMemberFieldVos);
            //判断当前登录人是否是日志的抄送人或汇报人
            List<String> ids = logMemberAssociationMapper.getMeUnRead(userId, logId);
            if (null != ids && ids.size() > 0) {
                //变为已读
                logMemberAssociationMapper.readByIds(ids);
            }
        }
        return logDetail;
    }

    @Override
    public ReceiveRangeVo getReceiveRange(String logId) {
        ReceiveRangeVo receiveRangeVo = new ReceiveRangeVo();
        List<LogMemberAssociation> logMemberAssociations = logMemberAssociationMapper.getReceiveRange(logId);
        if (null != logMemberAssociations && logMemberAssociations.size() > 0) {
            Map<Integer, List<LogMemberAssociation>> collect = logMemberAssociations.stream().collect(Collectors.groupingBy(LogMemberAssociation::getType));
            //找到汇报
            List<LogMemberAssociation> reportList = collect.get(1);
            if (null != reportList) {
                setUserParam(reportList);
                //排序
                receiveRangeVo.setReportList(reportList.stream().sorted(Comparator.comparing(LogMemberAssociation::getUserType)).collect(Collectors.toList()));
            }
            //找到抄送
            List<LogMemberAssociation> chaosongList = collect.get(2);
            if (null != chaosongList) {
                setUserParam(chaosongList);
                //排序
                receiveRangeVo.setChaosongList(chaosongList.stream().sorted(Comparator.comparing(LogMemberAssociation::getUserType)).collect(Collectors.toList()));
            }
            //找到转发
            List<LogMemberAssociation> forwardList = collect.get(3);
            if (null != forwardList) {
                List<LogMemberAssociation> list = new ArrayList<>();
                List<String> idList = new ArrayList<>();
                //去重
                for (LogMemberAssociation logMemberAssociation : forwardList) {
                    if (!idList.contains(logMemberAssociation.getUserId())) {
                        list.add(logMemberAssociation);
                        idList.add(logMemberAssociation.getUserId());
                    }
                }
                setUserParam(list);
                //排序
                receiveRangeVo.setForwardList(list.stream().sorted(Comparator.comparing(LogMemberAssociation::getUserType)).collect(Collectors.toList()));
            }
        }
        return receiveRangeVo;
    }

    @Override
    public List<LogMemberAssociation> getReadList(String logId) {
        List<LogMemberAssociation> readDependence = logMemberAssociationMapper.getReadDependence(logId, 1);
        setUserParam(readDependence);
        return readDependence;
    }

    @Override
    public List<LogMemberAssociation> getUnReadList(String logId) {
        List<LogMemberAssociation> readDependence = logMemberAssociationMapper.getReadDependence(logId, 0);
        setUserParam(readDependence);
        return readDependence;
    }

    @Override
    public List<LogMemberAssociation> getLikeList(String logId) {
        List<LogMemberAssociation> readDependence = logMemberAssociationMapper.getLikeList(logId);
        setUserParam(readDependence);
        return readDependence;
    }

    @Override
    public void updateLog(LogMemberLogDto logMemberLogDto) {
        //修改日志主表
        String userId = userProvider.get().getUserId();
        setLogParam(logMemberLogDto, userId);
        logMemberLogMapper.updateLog(logMemberLogDto, userId);
        if (null != logMemberLogDto.getLogMemberFieldList() && logMemberLogDto.getLogMemberFieldList().size() > 0) {
            //先删除原来的字段
            logMemberFieldMapper.deleteByLogId(logMemberLogDto.getId());
            logMemberLogDto.getLogMemberFieldList().forEach(v -> v.setId(FtbUtil.getId()));
            //新增字段信息
            logMemberFieldMapper.addField(logMemberLogDto.getLogMemberFieldList(), logMemberLogDto.getId());
        }
        if (1 == logMemberLogDto.getUpdateType()) {
            //修改并通知 清除阅读状态
            logMemberAssociationMapper.updateUnRead(logMemberLogDto.getId());

            //日志/日报标题
            String title = "";

            //消息推送
            List<LogMemberFieldDto> titleDtoList = logMemberLogDto.getLogMemberFieldList().stream().filter(log -> {
                return log.getCode().equals("TITLE");
            }).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(titleDtoList)) {
                title = titleDtoList.get(0).getContent();
            } else {
                String userName = UserProvider.getUser().getUserName();
                title = userName + "的日报";
            }

            if (CollectionUtil.isEmpty(logMemberLogDto.getLogMemberAssociationList())) {
                return;
            }

            if (CollectionUtil.isEmpty(logMemberLogDto.getLogMemberFieldList())) {
                return;
            }

            List<LogMemberFieldDto> logMemberFieldList = logMemberLogDto.getLogMemberFieldList();
            String logMsg = title;

            String content = getLogContentTemplate(logMemberFieldList);
            UserInfo loginUser = UserProvider.getUser();
//            List<String> toUserIds = logMemberLogDto.getLogMemberAssociationList().stream().map(LogMemberAssociationDto::getUserId).collect(Collectors.toList());
            List<LogMemberAssociationDto> logMemberAssociationList = logMemberLogDto.getLogMemberAssociationList();
            List<String> toUserIds = logMemberAssociationList.stream().filter(logToUser -> {
                //推送到用户id
                return logToUser.getUserType().equals(1);
            }).map(logToUser -> {
                String toUserId = logToUser.getUserId();
                if (toUserId.contains(":")) {
                    return toUserId.split(":")[1];
                }
                return toUserId;
            }).collect(Collectors.toList());

            List<String> groupIds = logMemberAssociationList.stream().filter(logToUser -> {
                return logToUser.getUserType().equals(2);
            }).map(LogMemberAssociationDto::getUserId).collect(Collectors.toList());

            if (CollectionUtil.isNotEmpty(toUserIds)) {
                //推送到个人
                msgSendToSomePeople(logMsg, content, toUserIds, logMemberLogDto.getId(), loginUser.getTenantId(), logMemberLogDto.getLogType());
            }
            if (CollectionUtil.isNotEmpty(groupIds)) {
                //推送到群
                for (String groupId : groupIds) {
                    if (StrUtil.isBlank(groupId)) {
                        continue;
                    }
                    msgSendToGroup(logMsg, content, groupId, loginUser.getTenantId(), logMemberLogDto.getId(), logMemberLogDto.getLogType());
                }
            }

        }
    }

    @Override
    public List<LogTemplateVo> getTemplateNameList() {
        return logTemplateMapper.getTemplateList();
    }

    @Override
    public Integer deleteLog(String logId) {
        String userId = userProvider.get().getUserId();
        LogMemberLogVo logDetail = logMemberLogMapper.getLogDetail(logId);
        if (null == logDetail) {
            return -1;
        }
        if (!userId.equals(logDetail.getCreatorUserId())) {
            return -2;
        }
        logMemberLogMapper.deleteLog(logId, userId);
        return 1;
    }

    /**
     * 给工作日志相关人员发im消息
     *
     * @param dto 请求对象
     */
    @Override
    public void agentAlert(LogAgentAlertDto dto) {
        if (CollectionUtil.isEmpty(dto.getUserIds())) {
            throw new RuntimeException("提醒人员不能为空");
        }
        if (StrUtil.isEmpty(dto.getLogId())) {
            throw new RuntimeException("日志id不能为空");
        }
        String logId = dto.getLogId();

//        //未读列表
//        List<LogMemberAssociation> readDependence = logMemberAssociationMapper.getReadDependence(logId,0);
//
        LogMemberLogVo logMemberLogDto = logMemberLogMapper.selectById(logId);
        //查询字段
        List<LogMemberFieldVo> field = logMemberFieldMapper.getFieldById(logId);
        if (CollectionUtil.isEmpty(field)) {
            return;
        }

        String title = "";
        //日志/日报标题
        //获取日报/日志内容
        StringBuilder logContentBuilder = new StringBuilder();
        UserBoundVO userPrimaryBoundOne = userApiV2Util.getUserPrimaryBoundOne(logMemberLogDto.getCreatorUserId(), null);
        if (userPrimaryBoundOne != null) {
            title = userPrimaryBoundOne.getName() + "的" + logMemberLogDto.getLogType();
        } else {
            title = logMemberLogDto.getLogType();
        }

        if (logMemberLogDto.getLogType().equals("日志")) {
            for (LogMemberFieldVo logMemberFieldVo : field) {
                if (logMemberFieldVo.getCode().equals("TITLE")) {
                    title = logMemberFieldVo.getContent();
                } else if (logMemberFieldVo.getCode().equals("CONTENT")) {
                    logContentBuilder.append(logMemberFieldVo.getContent());
                }
            }
        } else {
            for (LogMemberFieldVo logMemberFieldVo : field) {
                if (StrUtil.isNotEmpty(logMemberFieldVo.getContent())) {
                    logContentBuilder.append(logMemberFieldVo.getField())
                            .append(":<br>")
                            .append(logMemberFieldVo.getContent())
                            .append("<br>");
                }
            }
        }

        String logContent = logContentBuilder.toString();
        if (StrUtil.isEmpty(title) || StrUtil.isEmpty(logContent)) {
            return;
        }

        // 去掉 logContent 最后一个br
        if (logContent.endsWith("<br>")) {
            logContent = logContent.substring(0, logContent.lastIndexOf("<br>"));
        }

        UserInfo loginUser = UserProvider.getUser();
        //推送到个人
        msgSendToSomePeople(title, logContent, dto.getUserIds(), logMemberLogDto.getId(), loginUser.getTenantId(), logMemberLogDto.getLogType());
    }


    private void setUserParam(List<LogMemberAssociation> reportList) {
        if (null != reportList && reportList.size() > 0) {
            for (LogMemberAssociation logMemberAssociation : reportList) {
                String userId = logMemberAssociation.getUserId();
                if (StrUtil.isNotBlank(userId) && userId.contains(":")) {
                    // 查询数据库发现有类似于yawen:1234之类的用户id，这些数据作为用户id是查询不到数据的
                    String uid = userId.split(":")[1];
                    logMemberAssociation.setUserId(uid);
                }
            }

            Map<Integer, List<LogMemberAssociation>> userTypeMap = reportList.stream().collect(Collectors.groupingBy(LogMemberAssociation::getUserType));
            //人 赋值人员信息
            List<LogMemberAssociation> logMemberMap = userTypeMap.get(1);
            if (null != logMemberMap && logMemberMap.size() > 0) {
                List<String> userIds = logMemberMap.stream().distinct().map(LogMemberAssociation::getUserId).collect(Collectors.toList());
                // 查询成员信息
                Map<String, UserBoundVO> map = userApiV2Util.getUserPrimaryBoundBatch(userIds, null);
                logMemberMap.forEach(v -> {
                    UserBoundVO userInfoVo = map.get(v.getUserId());
                    if (null != userInfoVo) {
                        v.setHeadIcon(UploaderUtil.uploaderImg(userInfoVo.getHeadIcon()));
                        v.setUserName(userInfoVo.getUserName());
                        v.setOrganizeId(userInfoVo.getOrganizeId());
                        v.setOrganizeName(userInfoVo.getOrganizeName());
                        v.setPositionId(userInfoVo.getPositionId());
                        v.setPositionName(userInfoVo.getPositionName());
                    }
                });
            }
        }
    }

    /**
     * 消息推送到一些人
     *
     * @param content   内容
     * @param toUserIds 推送到用户id
     * @param logId     日志id
     * @param tenantId  租户id
     */
    private void msgSendToSomePeople(String title, String content, List<String> toUserIds, String logId, String tenantId, String logType) {
        //通知
        SingleSendRobotNoticeForm sendRobotNoticeForm = new SingleSendRobotNoticeForm();
//        List<String> toUserIds = logMemberLogDto.getLogMemberAssociationList().stream().map(LogMemberAssociationDto::getUserId).collect(Collectors.toList());
        sendRobotNoticeForm.setToUserIds(toUserIds);
        sendRobotNoticeForm.setTenantId(tenantId);
//            ImRobotTypeEnum imRobotTypeEnum = ImRobotTypeEnum.getByUserId(loginUser.getUserId());
//            sendRobotNoticeForm.setRobotTypeEnum(imRobotTypeEnum);
        sendRobotNoticeForm.setRobotTypeEnum(ImRobotTypeEnum.FTB_XZS);

        //消息体
        SendRobotNoticeDataForm msgBody = new SendRobotNoticeDataForm();


        msgBody.setTitle(title);
        msgBody.setContent(content);
        msgBody.setScene(MemberLogImEnum.UPDATE_LOG.getScene());
        msgBody.setContentSummary(content);
        msgBody.setAppName(MemberLogImEnum.UPDATE_LOG.getTitle());
        msgBody.setLogo(MemberLogImEnum.UPDATE_LOG.getLogoUrl());


        //按钮
        LinkedList<JumpUrlListModel> jumpList = new LinkedList<>();
        JumpUrlListModel jump = new JumpUrlListModel();
        jump.setButtonName(MemberLogImJumpEnum.MEMBER_LOG.getButtonName());
        jump.setType(1);
        jump.setReqMethod(JumpUrlListModel.ReqMethodEnum.GET);
        jump.setDisplayMethodEnum(JumpUrlListModel.DisplayMethodEnum.TRUE);
        jump.setMpId(MemberLogImJumpEnum.MEMBER_LOG.getMpId());
        String jumpUrl = String.format(MemberLogImJumpEnum.MEMBER_LOG.getUrl(), logId, UserProvider.getLoginUserId(), logType);
        jump.setUrl(jumpUrl);
        jumpList.add(jump);
        msgBody.setJumpUrlList(jumpList);

        sendRobotNoticeForm.setRobotNoticeDataForm(msgBody);
        ActionResult actionResult = imRobotApi.sendSingleRobotNotice(sendRobotNoticeForm);
        if (!ActionResult.success().getCode().equals(actionResult.getCode())) {
            log.error(actionResult.getMsg());
        }
    }

    /**
     * 消息推送到群
     *
     * @param content  内容
     * @param groupId  群id
     * @param tenantId 租户id
     */
    private void msgSendToGroup(String title, String content, String groupId, String tenantId, String logId, String logType) {
        AddOrDeleteRobotInGroupForm addForm = new AddOrDeleteRobotInGroupForm();
        addForm.setGroupId(groupId);
        addForm.setOptTypeEnum(OptTypeEnum.ADD);
        addForm.setIsNotice(ConstantStatusEnum.NUM_FALSE);
        addForm.setTenantId(tenantId);
        addForm.setRobotTypeEnum(ImRobotTypeEnum.FTB_XZS);
        addForm.setSource("日志");
        ActionResult addImResult = imRobotApi.addOrDeleteRobotInGroup(addForm);
        if (!ActionResult.success().getCode().equals(addImResult.getCode())) {
            log.error("添加im机器人异常:{}", addImResult.getMsg());
        }
        //通知
        GroupSendRobotNoticeForm sendRobotNoticeForm = new GroupSendRobotNoticeForm();
        sendRobotNoticeForm.setGroupId(groupId);
        sendRobotNoticeForm.setTenantId(tenantId);

        sendRobotNoticeForm.setRobotTypeEnum(ImRobotTypeEnum.FTB_XZS);

        //消息体
        SendRobotNoticeDataForm msgBody = new SendRobotNoticeDataForm();


        msgBody.setTitle(title);
        msgBody.setContent(content);
        msgBody.setScene(MemberLogImEnum.UPDATE_LOG.getScene());
        msgBody.setContentSummary(content);
        msgBody.setAppName(MemberLogImEnum.UPDATE_LOG.getTitle());
        msgBody.setLogo(MemberLogImEnum.UPDATE_LOG.getLogoUrl());

        //按钮
        LinkedList<JumpUrlListModel> jumpList = new LinkedList<>();
        JumpUrlListModel jump = new JumpUrlListModel();
        jump.setButtonName(MemberLogImJumpEnum.MEMBER_LOG.getButtonName());
        jump.setType(1);
        jump.setReqMethod(JumpUrlListModel.ReqMethodEnum.GET);
        jump.setDisplayMethodEnum(JumpUrlListModel.DisplayMethodEnum.TRUE);
        jump.setMpId(MemberLogImJumpEnum.MEMBER_LOG.getMpId());
        String jumpUrl = String.format(MemberLogImJumpEnum.MEMBER_LOG.getUrl(), logId, UserProvider.getLoginUserId(), logType);
        jump.setUrl(jumpUrl);
        jumpList.add(jump);
        msgBody.setJumpUrlList(jumpList);

        sendRobotNoticeForm.setRobotNoticeDataForm(msgBody);

        ActionResult actionResult = imRobotApi.sendGroupRobotNotice(sendRobotNoticeForm);
        if (!ActionResult.success().getCode().equals(actionResult.getCode())) {
            log.error(actionResult.getMsg());
        }
    }

    private String getLogContentTemplate(List<LogMemberFieldDto> logMemberFieldList) {
        String content = "";
        for (int i = 0; i < logMemberFieldList.size(); i++) {
            LogMemberFieldDto logMemberFieldDto = logMemberFieldList.get(i);
            if (logMemberFieldDto.getCode().equals("TITLE")) {
                continue;
            }
            String contentFormat = MemberLogContentEnum.getContentFormat(logMemberFieldDto.getCode());
            if (StrUtil.isBlank(contentFormat)) {
                continue;
            }
            if(StrUtil.isEmpty(logMemberFieldDto.getContent())){
                continue;
            }
            if (i == (logMemberFieldList.size() - 1)) {
                content += String.format(contentFormat, logMemberFieldDto.getContent());
            } else {
                content += String.format(contentFormat, logMemberFieldDto.getContent()) + "<br>";
            }

        }
        return content;
    }
}
