cy
2023-11-22 8fc8b4788ed8be27ff6aae1cdd3fe9a584972ae3
consum-base/src/main/java/com/consum/base/service/BaseWarehouseServiceImpl.java
@@ -2,19 +2,21 @@
import com.consum.base.Constants;
import com.consum.base.core.CodeGeneratorService;
import com.consum.base.core.utils.IdUtil;
import com.consum.base.pojo.BaseWarehouseParam;
import com.consum.base.util.IdUtil;
import com.consum.model.po.*;
import com.consum.model.po.BaseWarehouse;
import com.consum.model.po.FinSysTenant;
import com.consum.model.po.FinSysTenantDepartment;
import com.consum.model.po.SDictData;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.jdbc.service.BaseServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -47,16 +49,16 @@
        baseWarehouse.setId(IdUtil.generateId());
        baseWarehouse.setWarehouseType(Constants.WAREHOUSE_TYPE_TENANT);
        baseWarehouse.setWarehouseCode(codeGeneratorService.createWarehouseCode());
//        //根据机构id查询机构
//        FinSysTenant finSysTenant = finSysTenantService.get(new FinSysTenant(baseWarehouse.getAgencyId()));
//        if (finSysTenant != null) {
//            baseWarehouse.setParentAgencyId(finSysTenant.getParentId());
//            baseWarehouse.setAgencyName(finSysTenant.getName());
//        }
        //根据机构id查询机构
        FinSysTenant finSysTenant = finSysTenantService.get(new FinSysTenant(baseWarehouse.getAgencyId()));
        if (finSysTenant != null) {
            baseWarehouse.setParentAgencyId(finSysTenant.getParentId());
            baseWarehouse.setAgencyName(finSysTenant.getName());
        }
        //根据CLASSIFICATION_CODE查询CLASSIFICATION_NAME
        S_dict_data s_dict_data = this.sDictDataService.get(new S_dict_data(Long.valueOf(param.getClassificationCode())));
        if (s_dict_data != null) {
            baseWarehouse.setClassificationName(s_dict_data.getDict_label());
        SDictData dictData = this.sDictDataService.get(new SDictData(Long.valueOf(param.getClassificationCode())));
        if (dictData != null) {
            baseWarehouse.setClassificationName(dictData.getDict_label());
        }
        baseWarehouse.setIsDefault(Constants.IS_DEFAULT_YES);
@@ -68,7 +70,6 @@
     * @Author 卢庆阳
     * @Date 2023/10/26
     */
//    public GenericPager<BaseWarehouse> queryList(BaseWarehouseParam param, FinSysTenantUser sysInfo) {
    public GenericPager<BaseWarehouse> queryList(BaseWarehouseParam param) {
        StringBuilder sql = new StringBuilder("SELECT * FROM base_warehouse WHERE 1 = 1 ");
        HashMap<String, Object> paramts = new HashMap<>();
@@ -84,12 +85,10 @@
            paramts.put("CLASSIFICATION_CODE", param.getClassificationCode());
        }
        //机构id
//        sql.append(" and AGENCY_ID =:AGENCY_ID ");
//        if (param.getAgencyId() != null) {
//            paramts.put("AGENCY_ID", param.getAgencyId());
//        } else {
//            paramts.put("AGENCY_ID", Long.valueOf(sysInfo.getTenantId()));
//        }
        if (param.getAgencyId() != null) {
            sql.append(" and AGENCY_ID =:AGENCY_ID ");
            paramts.put("AGENCY_ID", param.getAgencyId());
        }
        //状态
        if (param.getStates() != null) {
            sql.append(" and states =:states ");
@@ -108,15 +107,22 @@
     * @Date 2023/10/26
     */
    public int updateBaseWarehouse(BaseWarehouse baseWarehouse) {
        S_dict_data s_dict_data = this.sDictDataService.get(new S_dict_data(Long.valueOf(baseWarehouse.getClassificationCode())));
        if (s_dict_data != null) {
            baseWarehouse.setClassificationName(s_dict_data.getDict_label());
        SDictData SDictData = this.sDictDataService.get(new SDictData(Long.valueOf(baseWarehouse.getClassificationCode())));
        if (SDictData != null) {
            baseWarehouse.setClassificationName(SDictData.getDict_label());
        }
        //根据机构id查询机构
        FinSysTenant finSysTenant = finSysTenantService.get(new FinSysTenant(baseWarehouse.getAgencyId()));
        if (finSysTenant != null) {
            baseWarehouse.setParentAgencyId(finSysTenant.getParentId());
            baseWarehouse.setAgencyName(finSysTenant.getName());
        }
        return this.update(baseWarehouse);
    }
    /**
     * 根据id查询仓库详情
     *
     * @author 卢庆阳
     * @Date 2023/10/26
     */
@@ -158,12 +164,12 @@
    }
    /**
     * @Description  根据机构id查询机构仓库
     * @return
     * @Description 根据机构id查询机构仓库
     * @Author 卢庆阳
     * @Date 2023/10/27
     * @return
     */
    public List<BaseWarehouse> getByAgencyId(Long agencyId) {
    public List<BaseWarehouse> getByAgencyId(Long agencyId, Short isDefault, Short states) {
        StringBuilder sql = new StringBuilder("SELECT * FROM base_warehouse WHERE 1 = 1 ");
        HashMap<String, Object> paramts = new HashMap<>();
@@ -172,6 +178,54 @@
            sql.append(" and AGENCY_ID =:AGENCY_ID ");
            paramts.put("AGENCY_ID", agencyId);
        }
        // 是否为默认仓库
        if (isDefault != null) {
            sql.append(" and IS_DEFAULT =:isDefault ");
            paramts.put("isDefault", isDefault);
        }
        // 状态
        if (states != null) {
            sql.append(" and states =:states ");
            paramts.put("states", states);
        }
        return select(sql.toString(), paramts, new BaseWarehouse());
    }
    /**
     * 根据机构id查询默认仓库
     *
     * @param agencyId
     * @return
     */
    public BaseWarehouse getDefaultWarehouseByAgencyId(Long agencyId) {
        StringBuilder sql = new StringBuilder("SELECT * FROM base_warehouse WHERE IS_DEFAULT = 1 and AGENCY_ID =:agencyId ");
        Map<String, Object> param = new HashMap<>();
        param.put("agencyId", agencyId);
        List<BaseWarehouse> select = select(sql.toString(), param, new BaseWarehouse());
        Optional<BaseWarehouse> optional = select.stream().findFirst();
        if (optional.isPresent()) {
            return optional.get();
        }
        return null;
    }
    public BaseWarehouse getWarehouseByAgencyId(Long agencyId, String warehouseName) {
        StringBuilder sql = new StringBuilder("SELECT * FROM base_warehouse WHERE STATES= 1");
        Map<String, Object> param = new HashMap<>();
        if (agencyId != null) {
            sql.append(" and AGENCY_ID =:agencyId ");
            param.put("agencyId", agencyId);
        }
        if (StringUtils.isNotEmpty(warehouseName)) {
            sql.append(" and WAREHOUSE_NAME =:warehouseName ");
            param.put("warehouseName", warehouseName);
        }
        sql.append(" limit 1");
        List<BaseWarehouse> select = select(sql.toString(), param, new BaseWarehouse());
        if (CollectionUtils.isEmpty(select)) {
            return null;
        }
        return select.get(0);
    }
}