package com.liquidnet.service.sweet.service.impl;

import com.alibaba.fastjson.JSON;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.sweet.dto.param.SweetFormSubmissionParam;
import com.liquidnet.service.sweet.service.ISweetFormSubmissionService;
import com.liquidnet.service.sweet.utils.QueueUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;

/**
 * 动态表单报名
 */
@Service
public class SweetFormSubmissionServiceImpl implements ISweetFormSubmissionService {

    @Autowired
    private QueueUtils queueUtils;

    @Override
    public ResponseDto<Boolean> submit(SweetFormSubmissionParam param) {
        String submissionId = IDGenerator.nextSnowId();
        String activityName = param.getActivityName().trim();
        String dataJson = JSON.toJSONString(param.getData());

        LinkedList<String> sqls = CollectionUtil.linkedListString();
        LinkedList<Object[]> sqlsDataA = CollectionUtil.linkedListObjectArr();
        sqls.add(SqlMapping.get("sweet_form_submission.insert"));
        sqlsDataA.add(new Object[]{submissionId, activityName, dataJson});
        queueUtils.sendMsgByRedis(MQConst.SweetQueue.SWEET_ANSWER_INSERT.getKey(),
                SqlMapping.gets(sqls, sqlsDataA));

        return ResponseDto.success(true);
    }
}
