package com.bohuikeji.delivery.backstage.controller.api.other;

import com.bohuikeji.delivery.backstage.entity.TPartner;
import com.bohuikeji.delivery.backstage.service.TPartnerService;
import com.bohuikeji.frame.module.admin.base.ApiController;
import com.bohuikeji.frame.module.admin.component.RedisUtil;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@Api(tags = {"加盟商合作相关接口"})
@RestController
@RequestMapping("/api/partner")
public class TPartnerApi extends ApiController {
    @Autowired
    TPartnerService tPartnerService;
    @Autowired
    RedisUtil redisUtil;

    @PostMapping("save")
    @ApiOperation("快递员转单")
    @Transactional
    public APIEntity save(@RequestBody TPartner tPartner){
        if(redisUtil.get("parent_"+tPartner.getPartnerPhone())!=null){
            return APIEntity.success();
        }
        redisUtil.set("parent_"+tPartner.getPartnerPhone(),tPartner.getPartnerCity(),60);
        tPartner.setPartnerCreateTime(LocalDateTime.now());
        tPartner.setPartnerStatus("已申请");
        tPartnerService.save(tPartner);
        return APIEntity.success(tPartner);
    }
}
