package com.bohuikeji.delivery.backstage.controller.admin;

import com.bohuikeji.delivery.backstage.entity.TInviteJoin;
import com.bohuikeji.delivery.backstage.service.IGmsService;
import com.bohuikeji.delivery.backstage.service.ITInviteJoinService;
import com.bohuikeji.frame.module.admin.annotation.InitLog;
import com.bohuikeji.frame.module.admin.base.ControllerBase;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import com.bohuikeji.frame.module.admin.entity.sys.SysUser;
import com.bohuikeji.frame.module.admin.utils.YiXunGmsUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 营销骑手处理短信通知
 * @author 10552
 */
@Controller
@ResponseBody
@RequestMapping("/invitejoin")
@RequiredArgsConstructor
@Slf4j
public class InvitejoinController extends ControllerBase {

    final ITInviteJoinService inviteJoinService;
    final IGmsService gmsService;

    /**
     * inviteJoin
     * @param joinId
     * @return
     */
    @GetMapping("/send/out")
    public APIEntity getSendOut(Integer joinId){
        TInviteJoin inviteJoin=inviteJoinService.getById(joinId);
        if("营销骑手".equals(inviteJoin.getFuncRemark())){
            inviteJoin.setJoinSate("处理中");
            gmsService.sendMarketMsg(inviteJoin.getJoinPhone());
        }else {
            inviteJoin.setJoinSate("处理中");
        }
        return APIEntity.success(inviteJoinService.updateById(inviteJoin));
    }

    /**
     * inviteJoin
     * @param joinId
     * @return
     */
    @GetMapping("/del/join")
    public APIEntity getDelJoin(Integer joinId){
        TInviteJoin inviteJoin=inviteJoinService.getById(joinId);
        if(inviteJoin==null){
            return APIEntity.fail("申请数据为空，请及时暑刷新");
        }
        return APIEntity.success(inviteJoinService.removeById(inviteJoin));
    }

    @InitLog("发送短信")
    @GetMapping("/get/send/msg")
    public APIEntity sendMsg(String phone,String text) {
        if (YiXunGmsUtils.sendTxt(phone,text)){
            return APIEntity.success();
        }
        return APIEntity.fail();
    }

}