ReceiptPreferenceService.java 2.05 KB
package com.huaheng.pc.config.receiptPreference.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.pc.config.cycleCountPreference.domain.CycleCountPreference;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.config.receiptPreference.mapper.ReceiptPreferenceMapper;
import com.huaheng.pc.config.receiptPreference.domain.ReceiptPreference;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ReceiptPreferenceService extends ServiceImpl<ReceiptPreferenceMapper, ReceiptPreference> {

    /**
     * 复制盘点首选项表
     *
     * @param warehouseCode    原仓库编码
     * @param newWarehouseCode 新仓库编码
     * @return 是否复制成功
     */
    @Transactional
    public boolean receiptPreferenceCopy(String warehouseCode, String newWarehouseCode) {
        log.trace("开始入库首选项表");
        LambdaQueryWrapper<ReceiptPreference> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ReceiptPreference::getWarehouseCode, newWarehouseCode);
        if (!this.list(lambdaQueryWrapper).isEmpty()){
            log.error(newWarehouseCode+"仓库已存在");
            return false;
        }

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

        for ( ReceiptPreference receiptPreference : receiptPreferenceList) {
            receiptPreference.setId(null);
            receiptPreference.setWarehouseCode(newWarehouseCode);
        }

        if ( this.saveBatch(receiptPreferenceList) ){
            log.trace("复制入库首选项表成功,新仓库编码是:"+newWarehouseCode);
            return true;
        } else {
            return false;
        }
    }
}