package com.hssx.pcbms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hssx.pcbms.entity.Goods;
import com.hssx.pcbms.entity.GoodsNo;
import com.hssx.pcbms.entity.RacksEquipment;
import com.hssx.pcbms.mapper.GoodsMapper;
import com.hssx.pcbms.mapper.GoodsNoMapper;
import com.hssx.pcbms.mapper.RacksEquipmentMapper;
import com.hssx.pcbms.service.GoodsNoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hssx.pcbms.util.HttpRespMsg;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 吴涛涛
 * @since 2019-10-28
 */
@Service
public class GoodsNoServiceImpl extends ServiceImpl<GoodsNoMapper, GoodsNo> implements GoodsNoService {

    @Resource
    private GoodsMapper goodsMapper;
    @Resource
    private GoodsNoMapper goodsNoMapper;
    @Resource
    private RacksEquipmentMapper racksEquipmentMapper;

    @Override
    public HttpRespMsg updateInfo(Goods goods,Integer frameId) {
        HttpRespMsg msg = new HttpRespMsg();
        if(null != frameId){
            //上架
            RacksEquipment rackId = new RacksEquipment();
            rackId.setRackGoodsId(frameId);
            rackId.setEquipmentGoodsId(goods.getId());
            racksEquipmentMapper.insert(rackId);
            GoodsNo goodsNo = goodsNoMapper.selectOne(new QueryWrapper<GoodsNo>().eq("goods_id", goods.getId()));
            goodsNo.setGroundingTime(LocalDateTime.now());
            goodsNo.setIsRack(1);
            goodsNoMapper.updateById(goodsNo);
        }else{
            //下架
            racksEquipmentMapper.delete(new QueryWrapper<RacksEquipment>().eq("equipment_goods_id",goods.getId()));
            GoodsNo goodsNo = goodsNoMapper.selectOne(new QueryWrapper<GoodsNo>().eq("goods_id", goods.getId()));
            goodsNo.setGroundingTime(LocalDateTime.now());
            goodsNo.setIsRack(1);
            goodsNoMapper.updateById(goodsNo);
        }
        return msg;
    }

}
