239 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			Java
		
	
	
			
		
		
	
	
			239 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			Java
		
	
	
package hhwms;
 | 
						|
 | 
						|
import java.io.File;
 | 
						|
import java.io.IOException;
 | 
						|
import java.math.BigDecimal;
 | 
						|
import java.text.ParseException;
 | 
						|
import java.text.SimpleDateFormat;
 | 
						|
import java.util.Date;
 | 
						|
import java.util.List;
 | 
						|
 | 
						|
import jxl.Sheet;
 | 
						|
import jxl.Workbook;
 | 
						|
import jxl.read.biff.BiffException;
 | 
						|
 | 
						|
import com.dev.energy.server.dao.CommonDao;
 | 
						|
import com.dev.energy.server.exception.BusinessException;
 | 
						|
import com.dev.energy.server.model.EntityFactory;
 | 
						|
import com.dev.energy.server.web.security.UserHolder;
 | 
						|
import com.dev.swms.server.model.base.BillType;
 | 
						|
import com.dev.swms.server.model.base.Item;
 | 
						|
import com.dev.swms.server.model.base.ItemKey;
 | 
						|
import com.dev.swms.server.model.base.Location;
 | 
						|
import com.dev.swms.server.model.base.LocationTypes;
 | 
						|
import com.dev.swms.server.model.base.Locations;
 | 
						|
import com.dev.swms.server.model.base.LotInfo;
 | 
						|
import com.dev.swms.server.model.base.PackageUnit;
 | 
						|
import com.dev.swms.server.model.base.WarehouseArea;
 | 
						|
import com.dev.swms.server.model.base.WarehouseAreaStatus;
 | 
						|
import com.dev.swms.server.model.inventory.Inventory;
 | 
						|
import com.dev.swms.server.model.inventory.InventoryLog;
 | 
						|
import com.dev.swms.server.model.inventory.InventoryLogType;
 | 
						|
import com.dev.swms.server.model.inventory.Stock;
 | 
						|
import com.dev.swms.server.service.base.ItemManager;
 | 
						|
import com.dev.swms.server.service.interfaceLog.WmsOperationHisManager;
 | 
						|
import com.dev.swms.server.utils.DoubleUtils;
 | 
						|
import com.dev.swms.server.web.filter.WarehouseHolder;
 | 
						|
 | 
						|
public class MyThread extends Thread{
 | 
						|
	public File file;
 | 
						|
	public CommonDao commonDao ;
 | 
						|
	public WmsOperationHisManager wmsOperationHisManager;
 | 
						|
	public MyThread(File file,CommonDao commonDao,WmsOperationHisManager wmsOperationHisManager){
 | 
						|
		this.file=file;
 | 
						|
		this.commonDao=commonDao;
 | 
						|
		this.wmsOperationHisManager=wmsOperationHisManager;
 | 
						|
	}
 | 
						|
	
 | 
						|
	@Override
 | 
						|
	public void run() {
 | 
						|
		try {
 | 
						|
		Workbook workbook = Workbook.getWorkbook(file);
 | 
						|
		Sheet sheet = workbook.getSheet(0);
 | 
						|
		for (int i = 1; i <sheet.getRows(); i++) {
 | 
						|
			String Code=sheet.getCell(0,i).getContents().trim();//库位编号(库位号)
 | 
						|
			String kuwei=sheet.getCell(1,i).getContents().trim();//库位属性
 | 
						|
			String cunfang=sheet.getCell(2,i).getContents().trim();//库位类型
 | 
						|
			String zone=sheet.getCell(3,i).getContents().trim();//库区(所属库区)
 | 
						|
			String rackType=sheet.getCell(4,i).getContents().trim();//(是否货品混放)
 | 
						|
			String aaa=sheet.getCell(5,i).getContents().trim();//是否批次混放
 | 
						|
			boolean mixItem=false;
 | 
						|
			if(rackType.equals("是")){
 | 
						|
				mixItem=true;
 | 
						|
			}
 | 
						|
			boolean mixLot=false;
 | 
						|
			if(aaa.equals("是")){
 | 
						|
				mixLot=true;
 | 
						|
			}
 | 
						|
			if(Code==null || Code.length()<=0){
 | 
						|
				break;
 | 
						|
			}
 | 
						|
			String reason="";
 | 
						|
			WarehouseArea warehouseArea=null;
 | 
						|
			List<WarehouseArea> warehouseAreas = commonDao.findByQuery("from WarehouseArea where code='"+zone+"'");
 | 
						|
			if(warehouseAreas.size()>0){
 | 
						|
				warehouseArea=warehouseAreas.get(0);
 | 
						|
			}else{
 | 
						|
				reason=zone+"不存在!";
 | 
						|
			}
 | 
						|
			Locations locations=null;
 | 
						|
			List<Locations> locationss = commonDao.findByQuery("from Locations where name='"+kuwei+"'");
 | 
						|
			if(locationss.size()>0){
 | 
						|
				locations=locationss.get(0);
 | 
						|
			}else{
 | 
						|
				reason+=kuwei+"不存在!";
 | 
						|
			}
 | 
						|
			LocationTypes locationType=null;
 | 
						|
			List<LocationTypes> LocationTypes = commonDao.findByQuery("from LocationTypes where name='"+cunfang+"'");
 | 
						|
			if(LocationTypes.size()>0){
 | 
						|
				locationType=LocationTypes.get(0);
 | 
						|
			}else{
 | 
						|
				reason+=cunfang+"不存在!";
 | 
						|
			}
 | 
						|
			
 | 
						|
			if(reason==null||reason.length()<=0){
 | 
						|
				Location locationa=null;
 | 
						|
				List<Location> Locations = commonDao.findByQuery("from Location where code='"+Code+"'");
 | 
						|
				if(Locations.size()>0){
 | 
						|
					locationa=Locations.get(0);
 | 
						|
					locationa.setCode(Code);//库位号
 | 
						|
					locationa.setName(Code);//库位号
 | 
						|
					locationa.setLocations(locations);//库位类型
 | 
						|
					locationa.setLocationTypes(locationType);//存放类型
 | 
						|
					locationa.setType(kuwei);
 | 
						|
					locationa.setZone(warehouseArea);//所属库区
 | 
						|
					locationa.setMixItem(mixItem);//是否货品混放
 | 
						|
					locationa.setMixLot(mixLot);//是否批次混放
 | 
						|
					locationa.setDisabled(false);
 | 
						|
					if(locationa.getZone().getName().indexOf("地堆库")!=-1){
 | 
						|
						//地堆库
 | 
						|
						double b=locationa.getLocationTypes().getLength()*locationa.getLocationTypes().getWidth();
 | 
						|
						BigDecimal bg2 = new BigDecimal(b);
 | 
						|
						double dimension = bg2.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();//小数保留三位
 | 
						|
						locationa.setDimension(dimension);
 | 
						|
					}else{
 | 
						|
						double a=locationa.getLocationTypes().getLength()*locationa.getLocationTypes().
 | 
						|
								getWidth()*locationa.getLocationTypes().getHeight()/locationa.getLocationTypes().getQuantity();
 | 
						|
						BigDecimal bg1 = new BigDecimal(a);
 | 
						|
						double volume = bg1.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();//小数保留三位
 | 
						|
						locationa.setVolume(volume);
 | 
						|
					}
 | 
						|
					commonDao.store(locationa);
 | 
						|
					wmsOperationHisManager.storeOperationHis(locationa.getId(),locationa.getCode(), null,"", "库位信息", "数据导入",null,
 | 
						|
							null,0, 0,0, 0, "", "WMS");
 | 
						|
				}else{
 | 
						|
					Location location=EntityFactory.getEntity(Location.class);
 | 
						|
					location.setCode(Code);//库位号
 | 
						|
					location.setName(Code);//库位号
 | 
						|
					location.setType(kuwei);
 | 
						|
					location.setLocations(locations);//库位类型
 | 
						|
					location.setLocationTypes(locationType);//存放类型
 | 
						|
					location.setZone(warehouseArea);//所属库区
 | 
						|
					location.setMixItem(mixItem);//是否货品混放
 | 
						|
					location.setMixLot(mixLot);//是否批次混放
 | 
						|
					location.setStatus(WarehouseAreaStatus.FREE);
 | 
						|
					location.setWarehouse(WarehouseHolder.getWarehouse());
 | 
						|
					if(location.getZone().getName().indexOf("地堆库")!=-1){
 | 
						|
						//地堆库
 | 
						|
						double b=location.getLocationTypes().getLength()*location.getLocationTypes().getWidth();
 | 
						|
						BigDecimal bg2 = new BigDecimal(b);
 | 
						|
						double dimension = bg2.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();//小数保留三位
 | 
						|
						location.setDimension(dimension);
 | 
						|
					}else{
 | 
						|
						double a=location.getLocationTypes().getLength()*location.getLocationTypes().
 | 
						|
								getWidth()*location.getLocationTypes().getHeight()/location.getLocationTypes().getQuantity();
 | 
						|
						BigDecimal bg1 = new BigDecimal(a);
 | 
						|
						double volume = bg1.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();//小数保留三位
 | 
						|
						location.setVolume(volume);
 | 
						|
					}
 | 
						|
					
 | 
						|
					commonDao.store(location);
 | 
						|
				}
 | 
						|
			}else{
 | 
						|
				wmsOperationHisManager.storeOperationHiss(Code, kuwei, cunfang, zone, rackType, aaa, reason);
 | 
						|
			}
 | 
						|
			
 | 
						|
			
 | 
						|
		}
 | 
						|
	} catch (BiffException e) {
 | 
						|
		// TODO 自动生成的 catch 块
 | 
						|
		e.printStackTrace();
 | 
						|
	} catch (IOException e) {
 | 
						|
		// TODO 自动生成的 catch 块
 | 
						|
		e.printStackTrace();
 | 
						|
	}
 | 
						|
	
 | 
						|
	}
 | 
						|
	
 | 
						|
	public Inventory receiving(Location loc, ItemKey itemKey, double quantity,Stock lp,String status,
 | 
						|
			Date storageDate, String soi,String logType, String operator,WarehouseArea warehouseArea,String barCode,BillType billType){
 | 
						|
		if (quantity == 0) {
 | 
						|
			return null;
 | 
						|
		}
 | 
						|
		Inventory inventory = getInventory(itemKey,loc,itemKey.getItem(), null, lp, status, storageDate, soi,warehouseArea,barCode);
 | 
						|
		if (inventory == null) {
 | 
						|
			inventory = new Inventory();//EntityFactory.getEntity(Inventory.class);
 | 
						|
			inventory.setLocation(loc);
 | 
						|
			inventory.setItemKey(itemKey);
 | 
						|
			loc.setCurrentItem(itemKey.getId());
 | 
						|
			loc.setCurrentLot(itemKey.getId());
 | 
						|
			inventory.setCaCoefficient(itemKey.getItem().getCAcoefficient()==null?0:itemKey.getItem().getCAcoefficient());
 | 
						|
			inventory.setLP(lp);
 | 
						|
			inventory.setStatus(status);
 | 
						|
			inventory.setStorageDate(storageDate);
 | 
						|
			inventory.setSOI(soi == null ? "" : soi);
 | 
						|
			inventory.setWarehouse(WarehouseHolder.getWarehouse());
 | 
						|
			inventory.setWarehouseArea(warehouseArea);
 | 
						|
			inventory.setBarCode(barCode);
 | 
						|
			itemKey.getInventories().add(inventory);
 | 
						|
			commonDao.store(inventory);
 | 
						|
		}
 | 
						|
		inventory.setQuantity(inventory.getQuantity()+quantity);
 | 
						|
		inventory.setQtyOfMasterPack(inventory.getQuantity());
 | 
						|
		if (inventory.isNew()) {
 | 
						|
			itemKey.getInventories().add(inventory);
 | 
						|
		} else {
 | 
						|
			if (DoubleUtils.format4F(inventory.getQtyOfMasterPack()) == 0 && DoubleUtils.format4F(inventory.getQueuedQuantity()) == 0) {
 | 
						|
				itemKey.getInventories().remove(inventory);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		loc.setStatus(WarehouseAreaStatus.OCCUPY);
 | 
						|
		commonDao.store(loc);
 | 
						|
		commonDao.store(itemKey);
 | 
						|
		//写库存日志
 | 
						|
		InventoryLog log = new InventoryLog(logType,inventory.getSOI(), 1, operator, loc, itemKey, new Date(), quantity, null, status, null, null);
 | 
						|
		log.setOperator(operator);
 | 
						|
		log.setRelatedBill(soi);
 | 
						|
		log.setBillType(billType);
 | 
						|
		if(WarehouseHolder.getWarehouse()!=null) {
 | 
						|
		log.setWarehouse(WarehouseHolder.getWarehouse());
 | 
						|
		}else {
 | 
						|
			log.setWarehouse(loc.getWarehouse());
 | 
						|
		}
 | 
						|
		commonDao.store(log);
 | 
						|
		return inventory;
 | 
						|
	}
 | 
						|
	
 | 
						|
	public Inventory getInventory(ItemKey ik,Location location,Item item, PackageUnit packageUnit, Stock LP,String status, 
 | 
						|
			Date storageDate, String soi,WarehouseArea warehouseArea,String barCode){
 | 
						|
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 | 
						|
		if(barCode==null) {
 | 
						|
			barCode="";
 | 
						|
		}
 | 
						|
		for (Inventory inventory : ik.getInventories()) {
 | 
						|
			if (inventory.getLocation().getId().equals(location.getId())
 | 
						|
				&&inventory.getItemKey().getItem().getId().equals(ik.getItem().getId())&&
 | 
						|
				((inventory.getWarehouseArea()==null&&warehouseArea==null) ||((inventory.getWarehouseArea()!=null&&warehouseArea!=null)
 | 
						|
				&&inventory.getWarehouseArea().getId().equals(warehouseArea.getId())))
 | 
						|
				&&(
 | 
						|
				((inventory.getBarCode()==null||inventory.getBarCode().equals(""))&&(barCode==null||barCode.equals(""))) 
 | 
						|
				|| (barCode.length()>0&&inventory.getBarCode().equals(barCode)))
 | 
						|
				) {
 | 
						|
				return inventory;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		return null;
 | 
						|
	}
 | 
						|
 | 
						|
}
 |