package com.sqx.modules.consortia.controller;

import com.sqx.common.utils.DateUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.app.annotation.LoginUser;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.artificer.entity.Artificer;
import com.sqx.modules.artificer.service.ArtificerService;
import com.sqx.modules.consortia.entity.Consortia;
import com.sqx.modules.consortia.service.ConsortiaService;
import com.sqx.modules.coupon.entity.CouponCardType;
import com.sqx.modules.coupon.service.CouponCardService;
import com.sqx.modules.coupon.service.CouponCardTypeService;
import com.sqx.modules.sys.controller.AbstractController;
import com.sqx.modules.sys.entity.SysUserEntity;
import com.sqx.modules.utils.excel.ExcelData;
import com.sqx.modules.utils.excel.ExportExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@RestController
@Api(value = "商家", tags = {"商家"})
@RequestMapping(value = "/consortia")
public class ConsortiaController extends AbstractController {

    @Autowired
    private ConsortiaService consortiaService;

    @Autowired
    private ArtificerService artificerService;

    @PostMapping("/insertConsortia")
    @ApiOperation("添加商家")
    public Result insertConsortia(@RequestBody Consortia consortia){
        return consortiaService.insertConsortia(consortia);
    }

    @PostMapping("/updateConsortia")
    @ApiOperation("修改商家")
    public Result updateConsortia(@RequestBody Consortia consortia){
        return consortiaService.updateConsortia(consortia);
    }

    @PostMapping("/deleteConsortia")
    @ApiOperation("删除商家")
    public Result deleteConsortia(Long consortiaId){
        return consortiaService.deleteConsortiaById(consortiaId);
    }

    @GetMapping("/selectConsortiaList")
    @ApiOperation("查询商家列表")
    public Result selectConsortiaList(Integer page,Integer limit,String consortiaName,String userName,String phone){
        return consortiaService.selectConsortiaList(page, limit, consortiaName, userName, phone);
    }

    @GetMapping("/selectConsortiaByUserId")
    @ApiOperation("查询商家详情")
    public Result selectConsortiaByUserId(Long consortiaId){
        return consortiaService.selectConsortiaByUserId(consortiaId);
    }

    @PostMapping("/insertConsortiaUser")
    @ApiOperation("关联师傅")
    public Result insertConsortiaUser(Long userId,Long consortiaId){
        return consortiaService.insertConsortiaUser(userId, consortiaId);
    }

    @PostMapping("/deleteConsortiaUser")
    @ApiOperation("移除师傅")
    public Result deleteConsortiaUser(Long userId){
        return consortiaService.deleteConsortiaUser(userId);
    }

    @GetMapping("/selectUserListByConsortiaId")
    @ApiOperation("查询师傅列表")
    public Result selectUserListByConsortiaId(Integer page,Integer limit,String userName,String phone,Long consortiaId,Long shopId,Integer flag,String time){
        return consortiaService.selectUserListByConsortiaId(page, limit, userName, phone, consortiaId,shopId,flag,time);
    }

    @GetMapping("/selectConsortiaMoney")
    @ApiOperation("查询师傅带来的总收益")
    public Result selectConsortiaMoney(Long shopId,Integer flag,String time){
        return consortiaService.selectConsortiaMoney(shopId, flag, time);
    }


    @Login
    @GetMapping("/selectConsortiaListNew")
    @ApiOperation("pc查询下自己的商家信息")
    public Result selectConsortiaListNew(){
        SysUserEntity user = getUser();
        System.out.println("user-->"+user);
        Artificer artificer = artificerService.selectByPhone(user.getMobile());
        Long userId =  0L;
        if(artificer!=null){
            userId =  artificer.getUserId();
        }
        return consortiaService.selectConsortiaUserId(userId);
    }


    @GetMapping("/genOrGetQrCodePath")
    @ApiOperation("生成或获取二维码地址")
    public Result genOrGetQrCodePath(String id){
        return consortiaService.genOrGetQrCodePath(id);
    }




}