ConfigValueService.java 2.27 KB
package com.huaheng.pc.config.configValue.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.configValue.domain.ConfigValue;
import com.huaheng.pc.config.configValue.mapper.ConfigValueMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class ConfigValueService extends ServiceImpl<ConfigValueMapper, ConfigValue> {

    /**
     * 复制系统参数配置表
     * @param warehouseCode 原仓库编码
     * @param newWarehouseCode 新仓库编码
     * @return 是否复制成功
     */
    @Transactional
    public boolean configValueCopy(String warehouseCode, String newWarehouseCode){
        log.trace("开始复制系统参数配置表");
        LambdaQueryWrapper<ConfigValue> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ConfigValue::getWarehouseCode, newWarehouseCode);
        if (!this.list(lambdaQueryWrapper).isEmpty()){
            log.error(newWarehouseCode+"仓库已存在");
            return false;
        }

        lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ConfigValue::getWarehouseCode, warehouseCode);
        List<ConfigValue> configValueList = this.list(lambdaQueryWrapper);

        for ( ConfigValue configValue : configValueList) {
            configValue.setId(null);
            configValue.setWarehouseCode(newWarehouseCode);
        }

        if ( this.saveBatch(configValueList) ){
            log.trace("复制系统参数配置表成功,新仓库编码是:"+newWarehouseCode);
            return true;
        } else {
            return false;
        }
    }

    public ConfigValue getConfigValueByIdentifer(String identifier , String warehouseCode) {
        LambdaQueryWrapper<ConfigValue> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ConfigValue::getWarehouseCode, warehouseCode)
                          .eq(ConfigValue::getIdentifier, identifier);
        ConfigValue configValue = getOne(lambdaQueryWrapper);
        return configValue;
    }
}