package org.jeecg.modules.apiService.impl;

import org.jeecg.common.api.vo.Result;
import org.jeecg.config.shiro.ShiroRealm;
import org.jeecg.modules.apiService.AfterService;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService;
import org.jeecg.modules.teambuyBuycar.entity.TeambuyBuycar;
import org.jeecg.modules.teambuyBuycar.service.ITeambuyBuycarService;
import org.jeecg.modules.teambuyGoods.service.ITeambuyGoodsService;
import org.jeecg.modules.teambuyService.entity.TeambuyService;
import org.jeecg.modules.teambuyService.service.ITeambuyServiceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AfterServiceImpl implements AfterService {
    /******************************************************************************************************************/
    //权限验证
    @Resource
    private ShiroRealm shiroRealm;
    //用户信息
    @Resource
    private IHanHaiMemberService hanHaiMemberService;
    //购物车信息
    @Resource
    private ITeambuyServiceService teambuyServiceService;
    /******************************************************************************************************************/
    //添加购物车
    @Override
    public Result<?> addAfterService(String token, TeambuyService teambuyService) {
        //权限验证
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token);
        //HanHaiMember hanHaiMember = hanHaiMemberService.getById("1919589727643111426");
        //返回信息
        String massege = "";

        try{
            //执行新增操作(不传id进行新增，传了id则进行修改)
            teambuyService.setUserId(hanHaiMember.getId());
            boolean result = teambuyServiceService.saveOrUpdate(teambuyService);

            //判断是否新增成功
            if(result){
                return Result.OK("操作成功");
            }else {
                return Result.OK("操作失败");
            }

        }catch (Exception e){
            e.printStackTrace();
            return Result.error("操作失败");
        }
    }
}
