package com.tuoheng.admin.service.goods;

import cn.hutool.core.util.ObjectUtil;
import com.tuoheng.admin.entity.domain.Goods;
import com.tuoheng.admin.entity.request.goods.QueryGoodsListByWarehouseIdRequest;
import com.tuoheng.admin.mapper.GoodsMapper;
import com.tuoheng.admin.service.goods.query.QueryGoodsListByWarehouseIdService;
import com.tuoheng.admin.utils.GaodeUtil;
import com.tuoheng.common.common.BaseServiceImpl;
import com.tuoheng.common.exception.ServiceException;
import com.tuoheng.common.utils.JsonResult;
import com.tuoheng.common.utils.StringUtils;
import com.tuoheng.system.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 物资Service业务层处理
 *
 * @author wanjing
 * @team tuoheng
 * @date 2023-02-06
 */
@Service
public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Autowired
    private QueryGoodsListByWarehouseIdService queryGoodsListService;

    /**
     * 根据仓库Id查询物资列表
     *
     * @param request 查询物资列表实体
     * @return 摄像头集合
     */
    @Override
    public JsonResult getListByWarehouseId(QueryGoodsListByWarehouseIdRequest request) {
        return queryGoodsListService.getListByWarehouseId(request);
    }

    /**
     * 查询物资
     *
     * @param id 物资主键
     * @return 物资
     */
    @Override
    public JsonResult getOnesById(String id) {
        return null;
    }

    @Override
    public JsonResult editInfo(Goods entity) {
        //新增
        if (StringUtils.isNull(entity.getId())) {
            if (StringUtils.isEmpty(entity.getGoodsName())) {
                throw new ServiceException("物资名称不能为空");
            }
            if (ObjectUtil.isEmpty(entity.getGoodsType())) {
                throw new ServiceException("物资类型不能为空");
            }
            Integer tenantId = ShiroUtils.getTenantId();
            entity.setTenantId(tenantId);
            entity.setCreateUser(ShiroUtils.getUserId());
        }
        entity.setUpdateUser(ShiroUtils.getUserId());
        super.edit(entity);
        return JsonResult.success();
    }

}
