package com.jsh.erp.service.depotHead;

import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service(value = "depotHead_component")
@DepotHeadResource
public class DepotHeadComponent implements ICommonQuery {

    @Resource
    private DepotHeadService depotHeadService;

    @Override
    public Object selectOne(String condition) {
        return null;
    }

    @Override
    public List<?> select(Map<String, String> map) {
        return getDepotHeadList(map);
    }

    private List<?> getDepotHeadList(Map<String, String> map) {
        String search = map.get(Constants.SEARCH);
        String type = StringUtil.getInfo(search, "type");
        String subType = StringUtil.getInfo(search, "subType");
        String number = StringUtil.getInfo(search, "number");
        String beginTime = StringUtil.getInfo(search, "beginTime");
        String endTime = StringUtil.getInfo(search, "endTime");
        String dhIds = StringUtil.getInfo(search, "dhIds");
        String order = QueryUtils.order(map);
        return depotHeadService.select(type, subType, number, beginTime, endTime, dhIds, QueryUtils.offset(map), QueryUtils.rows(map));
    }

    @Override
    public int counts(Map<String, String> map) {
        String search = map.get(Constants.SEARCH);
        String type = StringUtil.getInfo(search, "type");
        String subType = StringUtil.getInfo(search, "subType");
        String number = StringUtil.getInfo(search, "number");
        String beginTime = StringUtil.getInfo(search, "beginTime");
        String endTime = StringUtil.getInfo(search, "endTime");
        String dhIds = StringUtil.getInfo(search, "dhIds");
        return depotHeadService.countDepotHead(type, subType, number, beginTime, endTime, dhIds);
    }

    @Override
    public int insert(String beanJson, HttpServletRequest request) {
        return depotHeadService.insertDepotHead(beanJson, request);
    }

    @Override
    public int update(String beanJson, Long id) {
        return depotHeadService.updateDepotHead(beanJson, id);
    }

    @Override
    public int delete(Long id) {
        return depotHeadService.deleteDepotHead(id);
    }

    @Override
    public int batchDelete(String ids) {
        return depotHeadService.batchDeleteDepotHead(ids);
    }

    @Override
    public int checkIsNameExist(Long id, String name) {
        return depotHeadService.checkIsNameExist(id, name);
    }

}
