package com.pqs9900.serviceImpl.message;

import cn.hutool.core.collection.CollectionUtil;
import com.njcn.shiro.token.TokenManager;
import com.pqs9900.mapper.message.MsgCofMapper;
import com.pqs9900.pojo.message.MsgBaseConfDTO;
import com.pqs9900.service.message.SendMessageService;
import com.pqs9900.task.SendMessage;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.UUID;

/**
 * @author hongawen
 * @date: 2020/9/24 11:33
 */
@Service
public class SendMessageServiceImpl implements SendMessageService {
    @Autowired
    private SendMessage sendMessage;

    @Autowired
    private MsgCofMapper msgCofMapper;

    /**
     * @Author chendaofei
     * @Description 修改短信配置
     * @Date 10:17 2020/5/14
     **/
    @Override
    @Transactional
    public String updateMsgCofig(MsgBaseConfDTO msgBaseConfDTO) {
        MsgBaseConfDTO resultMap = msgCofMapper.getMsgConfig();
        String strUserGuid = TokenManager.getToken().getUserIndex();
        msgBaseConfDTO.setUpdateUser(strUserGuid);
        msgBaseConfDTO.setUpdateTime(new Date());
        if (resultMap != null) {
            Integer res = msgCofMapper.updateMsgCofig(msgBaseConfDTO);
        } else {
            //新增操作
            msgBaseConfDTO.setMsgCofIndex(UUID.randomUUID().toString());
            msgCofMapper.addMsgConfig(msgBaseConfDTO);
        }
        msgCofMapper.updateMsgDicState2();
        if (!CollectionUtil.isEmpty(msgBaseConfDTO.getList())) {
            msgCofMapper.updateMsgDicState(msgBaseConfDTO.getList());
        }
        sendMessage.stop();
        sendMessage.start(sendMessage.getTaskRegistrar());
        return "配置成功";
    }


}
