package org.jeecg.modules.userCode.service.impl;


import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.config.shiro.ShiroRealm;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService;
import org.jeecg.modules.tbOrder.entity.TbOrder;
import org.jeecg.modules.tbOrder.service.ITbOrderService;
import org.jeecg.modules.tbTask.entity.TbTask;
import org.jeecg.modules.tbTask.service.ITbTaskService;
import org.jeecg.modules.userCode.model.req.TaskReq;
import org.jeecg.modules.userCode.model.req.TaskReq2;
import org.jeecg.modules.userCode.service.OrderService;
import org.jeecg.modules.userCode.service.UserService;
import org.jeecg.modules.userRole.entity.TbUserRole;
import org.jeecg.modules.userRole.service.ITbUserRoleService;
import org.jeecg.modules.utils.ValidateTool;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.swing.text.TabableView;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Map;


@Service
public class OrderServiceImpl implements OrderService {


    @Resource
    private ITbTaskService tbTaskService;

    @Autowired
    private IHanHaiMemberService iHanHaiMemberService;
    @Autowired
    private ITbOrderService tbOrderService;
    @Resource
    private ITbUserRoleService tbUserRoleService;
    @Resource
    private ShiroRealm shiroRealm;



    @Transactional
    @Override
    public String addOrder(String taskId, String token) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        TbTask byId = tbTaskService.getById(taskId);
        if (ValidateTool.isNull(byId)) {
            throw new JeecgBootException("参数错误，请选择师傅");
        }
        TbOrder tbOrder = new TbOrder();
        BeanUtils.copyProperties(byId, tbOrder);
        tbOrder.setId(IdWorker.getIdStr());
        tbOrder.setPayMoney(new BigDecimal("0.01"));
        tbOrder.setWorkId(byId.getUserId());
        tbOrder.setBossId(hanHaiMember.getId());
        tbOrderService.save(tbOrder);
        return tbOrder.getId();
    }
}
