Index: ssts-web/src/main/java/com/forgon/disinfectsystem/stocktakerecordmanager/service/StockTakeRecordManagerImpl.java =================================================================== diff -u -r13224 -r13226 --- ssts-web/src/main/java/com/forgon/disinfectsystem/stocktakerecordmanager/service/StockTakeRecordManagerImpl.java (.../StockTakeRecordManagerImpl.java) (revision 13224) +++ ssts-web/src/main/java/com/forgon/disinfectsystem/stocktakerecordmanager/service/StockTakeRecordManagerImpl.java (.../StockTakeRecordManagerImpl.java) (revision 13226) @@ -1,44 +1,24 @@ package com.forgon.disinfectsystem.stocktakerecordmanager.service; -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.commons.lang.StringUtils; -import com.forgon.databaseadapter.service.DateQueryAdapter; import com.forgon.directory.acegi.tools.AcegiHelper; -import com.forgon.directory.model.OrgUnit; -import com.forgon.directory.service.OrgUnitManager; import com.forgon.directory.vo.LoginUserData; -import com.forgon.disinfectsystem.basedatamanager.supplyroomconfig.service.SupplyRoomConfigManager; -import com.forgon.disinfectsystem.diposablegoods.service.DiposableGoodsManager; -import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsBatchStock; import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsStock; import com.forgon.disinfectsystem.entity.assestmanagement.IdentificationOfDisposableGoods; -import com.forgon.disinfectsystem.entity.basedatamanager.supplyroomconfig.SupplyRoomConfig; -import com.forgon.disinfectsystem.entity.receiverecord.ReceiveRecord; -import com.forgon.disinfectsystem.entity.receiverecord.ReceiveRecordItem; -import com.forgon.disinfectsystem.entity.stocktakerecordmanager.St_material_detail; -import com.forgon.disinfectsystem.entity.stocktakerecordmanager.St_tousse_detail; import com.forgon.disinfectsystem.entity.stocktakerecordmanager.StockDiposableGoodBatch; import com.forgon.disinfectsystem.entity.stocktakerecordmanager.StockDiposableGoods; import com.forgon.disinfectsystem.entity.stocktakerecordmanager.StockIdentificationOfGoods; import com.forgon.disinfectsystem.entity.stocktakerecordmanager.StockTakeRecord; -import com.forgon.disinfectsystem.settlement.service.SettlementWriteBackManager; -import com.forgon.log.model.Log; -import com.forgon.log.service.LogManager; import com.forgon.systemsetting.model.HttpOption; import com.forgon.systemsetting.service.HttpOptionManager; -import com.forgon.tools.MathTools; -import com.forgon.tools.db.DatabaseUtil; import com.forgon.tools.hibernate.ObjectDao; -import com.forgon.treenode.model.THTreeNode; /** * @author wangyi @@ -49,50 +29,12 @@ private ObjectDao objectDao; - private DateQueryAdapter dateQueryAdapter; - - private OrgUnitManager orgUnitManager; - - private DiposableGoodsManager diposableGoodsManager; - private HttpOptionManager httpOptionManager; - private SupplyRoomConfigManager supplyRoomConfigManager; - - private SettlementWriteBackManager settlementWriteBackManager; - - private LogManager appLogManager; - - public void setAppLogManager(LogManager appLogManager) { - this.appLogManager = appLogManager; - } - - public void setSettlementWriteBackManager( - SettlementWriteBackManager settlementWriteBackManager) { - this.settlementWriteBackManager = settlementWriteBackManager; - } - - public void setSupplyRoomConfigManager( - SupplyRoomConfigManager supplyRoomConfigManager) { - this.supplyRoomConfigManager = supplyRoomConfigManager; - } - public void setHttpOptionManager(HttpOptionManager httpOptionManager) { this.httpOptionManager = httpOptionManager; } - public void setDiposableGoodsManager(DiposableGoodsManager diposableGoodsManager) { - this.diposableGoodsManager = diposableGoodsManager; - } - - public void setOrgUnitManager(OrgUnitManager orgUnitManager) { - this.orgUnitManager = orgUnitManager; - } - - public void setDateQueryAdapter(DateQueryAdapter dateQueryAdapter) { - this.dateQueryAdapter = dateQueryAdapter; - } - public void setObjectDao(ObjectDao objectDao) { this.objectDao = objectDao; } @@ -108,18 +50,9 @@ StockTakeRecord.class.getSimpleName(), "id", Long.valueOf(id)); } - private StockTakeRecord getLastRecord(StockTakeRecord record) { - StockTakeRecord lastRecord = null; - if(record != null){ - String sql = "where po.warehouseId = " + record.getWarehouseId() + " and id < " + record.getId() + " order by id desc"; - lastRecord = (StockTakeRecord)objectDao.getBySql(StockTakeRecord.class.getSimpleName(), sql); - } - return lastRecord; - } - @Override public void createStockTakeRecord(Long warehouseId,Long inventoryRecordId) { - StockTakeRecord record =null; + StockTakeRecord record = null; List types = httpOptionManager.getHttpOptionTextById(HttpOption.SYSTEMSETTING_DIPOSABLEGOODS_TYPE); Map typeMap = new HashMap(); for (int i = 0; i < types.size(); i++) { @@ -130,9 +63,9 @@ .findBySql(DisposableGoodsStock.class.getSimpleName(), " where po.warehouseID = " + warehouseId + " order by po.externalCode asc"); - int totalAmount = 0; - double totalPrice = 0.00; - if(diposableGoodsStockList != null && diposableGoodsStockList.size() > 0){ + int recordTotalAmount = 0; + double recordTotalPrice = 0.00; + if(diposableGoodsStockList != null){ record = new StockTakeRecord(); record.setStockTakeDate(new Date()); LoginUserData loginUser = AcegiHelper.getLoginUser(); @@ -141,46 +74,41 @@ record.setInventoryRecordId(inventoryRecordId); List list = new ArrayList(); for (DisposableGoodsStock disposableGoodsStock : diposableGoodsStockList) { - //入库记 List batcheList = new ArrayList(); Double goodsPrice = 0.00; - for (DisposableGoodsBatchStock batchStock : disposableGoodsStock.getGoodsBatchs()) { - StockDiposableGoodBatch stockDiposableGoodBatch = new StockDiposableGoodBatch(); - stockDiposableGoodBatch.setBarcode(batchStock.getBarcode()); - stockDiposableGoodBatch.setBatchNumber(batchStock.getBatchNumber()); - stockDiposableGoodBatch.setCost(batchStock.getCost()); - stockDiposableGoodBatch.setStorage(batchStock.getStorage()); - stockDiposableGoodBatch.setSupplierName(batchStock.getSupplierName()); - stockDiposableGoodBatch.setManufacturer(batchStock.getManufacturer()); - - if(batchStock.getStorage() != 0 ){ - goodsPrice = batchStock.getCost(); - } - //设置标识号 - List identificationList = new ArrayList(); - if(batchStock.getIdentifications() != null && batchStock.getIdentifications().size() > 0){ - for (IdentificationOfDisposableGoods identification : batchStock.getIdentifications()) { - StockIdentificationOfGoods stockIdentification = new StockIdentificationOfGoods(); - stockIdentification.setAmount(identification.getAmount()); - stockIdentification.setIdentification(identification.getIdentification()); - stockIdentification.setPrice(identification.getPrice()); - stockIdentification.setStockDiposableGoodBatch(stockDiposableGoodBatch); - identificationList.add(stockIdentification); - if(identification.getAmount()!= null && identification.getAmount() != 0){ - Long amount = identification.getAmount();//数量 - totalAmount += amount; - Double price = identification.getPrice();//单价 - Double goodsTotalPrice = 0.0; - if(price != null && amount != null){ - goodsTotalPrice = price*amount;//总价 - } - totalPrice = new BigDecimal(totalPrice).add(new BigDecimal(goodsTotalPrice)).doubleValue(); - } - } - } - stockDiposableGoodBatch.setStockIdentifications(identificationList); - batcheList.add(stockDiposableGoodBatch); - } + Set goodsBatchs = disposableGoodsStock.getGoodsBatchs(); + if(goodsBatchs != null){ + for (DisposableGoodsBatchStock batchStock : goodsBatchs) { + StockDiposableGoodBatch stockDiposableGoodBatch = new StockDiposableGoodBatch(); + stockDiposableGoodBatch.setBarcode(batchStock.getBarcode()); + stockDiposableGoodBatch.setBatchNumber(batchStock.getBatchNumber()); + stockDiposableGoodBatch.setCost(batchStock.getCost()); + stockDiposableGoodBatch.setStorage(batchStock.getStorage()); + stockDiposableGoodBatch.setSupplierName(batchStock.getSupplierName()); + stockDiposableGoodBatch.setManufacturer(batchStock.getManufacturer()); + //设置标识号 + List identificationList = new ArrayList(); + List identifications = batchStock.getIdentifications(); + if(identifications != null){ + for (IdentificationOfDisposableGoods identification : identifications) { + StockIdentificationOfGoods stockIdentification = new StockIdentificationOfGoods(); + stockIdentification.setAmount(identification.getAmount()); + stockIdentification.setIdentification(identification.getIdentification()); + stockIdentification.setPrice(identification.getPrice()); + stockIdentification.setStockDiposableGoodBatch(stockDiposableGoodBatch); + identificationList.add(stockIdentification); + if(identification.getAmount() != null && identification.getPrice() != null){ + recordTotalAmount += identification.getAmount(); + Double goodsTotalPrice = identification.getPrice() * identification.getAmount(); + recordTotalPrice += goodsTotalPrice; + goodsPrice += goodsTotalPrice; + } + } + } + stockDiposableGoodBatch.setStockIdentifications(identificationList); + batcheList.add(stockDiposableGoodBatch); + } + } //物品 StockDiposableGoods stockDiposableGoods = new StockDiposableGoods(); stockDiposableGoods.setAmount(disposableGoodsStock.getAmount()); @@ -195,252 +123,17 @@ stockDiposableGoods.setDisposableGoodsId(disposableGoodsStock.getDisposableGoodsID()); stockDiposableGoods.setGoodsBatchs(batcheList); - Double totalPrice2 = MathTools - .mul(MathTools.object2Double(disposableGoodsStock - .getAmount()), - MathTools.object2Double(goodsPrice)) - .doubleValue(); - - stockDiposableGoods.setTotalPrice(totalPrice2);//总价 + stockDiposableGoods.setTotalPrice(goodsPrice);//总价 list.add(stockDiposableGoods); } - record.setAmount(Long.valueOf(totalAmount)); - record.setTotalPrice(totalPrice); + record.setAmount(Long.valueOf(recordTotalAmount)); + record.setTotalPrice(recordTotalPrice); record.setDiposableGoods(list); record.setWarehouseId(warehouseId); objectDao.saveOrUpdate(record); - } - /*//物资领用(一次性物品)出库明细 - try{ - StockTakeRecord lastRecord = getLastRecord(record); - if(record != null && lastRecord != null){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - SimpleDateFormat ym_sdf = new SimpleDateFormat("yyyy-MM"); - String startDate = sdf.format(lastRecord.getStockTakeDate()); - String endDate = sdf.format(record.getStockTakeDate()); - String month = ym_sdf.format(record.getStockTakeDate()); - godownOutOfdiposableGoods(startDate,endDate, month); - monthDepartTousseTotal(startDate, endDate, month); - if (settlementWriteBackManager != null) { - settlementWriteBackManager.settlementWriteBack(month); - } - } - }catch(Exception e){ - LoginUserData loginUser = AcegiHelper.getLoginUser(); - appLogManager.saveLog(loginUser, Log.MODEL_DISPOSABLEGOODS_WRITEBACK, "A", "回写报错信息:"+e.getMessage()); - }*/ } - public void deleteMaterialDetail(String year_month){ - String sql = "where po.year_month = '" + year_month + "'"; - List materialList = objectDao.findBySql(St_material_detail.class.getSimpleName(), sql); - for (St_material_detail st_material_detail : materialList) { - objectDao.delete(st_material_detail); - } - } - - public void deleteTousseDetail(String year_month){ - String sql = "where po.year_month = '" + year_month + "'"; - List tousseList = objectDao.findBySql(St_tousse_detail.class.getSimpleName(), sql); - for (St_tousse_detail st_tousse_detail : tousseList) { - objectDao.delete(st_tousse_detail); - } - } - - /** - * 月部门各类包统计 - * @param startDate - * @param endDate - * @param year_month - */ - public void monthDepartTousseTotal(String startDate,String endDate,String year_month){ - //删除月份相同的记录 - deleteTousseDetail(year_month); - - startDate = dateQueryAdapter.dateAdapter(startDate); - endDate = dateQueryAdapter.dateAdapter(endDate); - String sql = "select temptable.coding,sum(temptable.amount),sum(temptable.totalPrice) from (" + - " select p.departcoding as coding,sum(i.tousseAmount) as amount,sum(i.totalPrice)as totalPrice from invoice i,invoiceplan p " + - "where i.invoiceplan_id = p.id and p.type != '一次性物品申请单' and (i.status = '收货签收' " + - "or i.status = '已发货') and i.sendtime between " + startDate + " and " + endDate + " group by p.departcoding union " + - "select r.departcoding as coding,sum(-i.amount) as amount,sum(-i.amount*i.price) as totalPrice from ReturnGoodsRecord r,ReturnGoodsItem i" + - " where r.id = i.returngoodsrecord_id " + - "and r.type = '器械包' and r.returntime between " + startDate + " and " + endDate + - " group by r.departcoding )temptable group by temptable.coding"; - @SuppressWarnings("unchecked") - ResultSet rs = objectDao.executeSql(sql); - try { - while (rs.next()) { - String departCoding = rs.getString(1); - Long amount = rs.getLong(2); - Double totalPrice = rs.getDouble(3); - - St_tousse_detail tousseDetail = new St_tousse_detail(); - tousseDetail.setAmount(totalPrice); - tousseDetail.setNum(amount); - tousseDetail.setYear_month(year_month); - //获取部门ID - THTreeNode tHTreeNode = orgUnitManager.getOrgUnitByCode(departCoding); - if(tHTreeNode != null){ - Long orgunitId = tHTreeNode.getId(); - tousseDetail.setDept_id(orgunitId); - } - tousseDetail.setRecord_time(new Date()); - objectDao.save(tousseDetail); - } - //供应室领用物品 - String receiveRecordSql = " where po.time between "+startDate+" and "+endDate+" "; - List receiveList = objectDao.findBySql(ReceiveRecord.class.getSimpleName(), receiveRecordSql); - String orgunitSql = " where po.name = '供应室'"; - OrgUnit org = (OrgUnit)objectDao.getBySql(OrgUnit.class.getSimpleName(), orgunitSql); - for (ReceiveRecord receiveRecord : receiveList) { - for (ReceiveRecordItem receiveItem : receiveRecord.getItems()) { - if("一次性物品".equals(receiveItem.getType()) == false){ - Double price = receiveItem.getPrice(); - double totalPrice = new BigDecimal(price).multiply(new BigDecimal(receiveItem.getAmount())).doubleValue(); - String tousseSql = " where po.year_month = '"+year_month+"' and po.dept_id = " + org.getId(); - List tousseList = getTousseBySql(tousseSql); - St_tousse_detail toussedetail = null; - if(tousseList != null && tousseList.size() > 0){ - toussedetail = tousseList.get(0); - double tp = new BigDecimal(totalPrice).add(new BigDecimal(toussedetail.getAmount())).doubleValue(); - toussedetail.setAmount(tp);//总价 - toussedetail.setNum(receiveItem.getAmount()+toussedetail.getNum());//数量 - }else{ - toussedetail = new St_tousse_detail(); - toussedetail.setAmount(totalPrice);//总价 - toussedetail.setDept_id(org.getId()); - toussedetail.setNum(Long.valueOf(receiveItem.getAmount())); - toussedetail.setRecord_time(new Date()); - toussedetail.setYear_month(year_month); - } - objectDao.saveOrUpdate(toussedetail); - } - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - } - - @SuppressWarnings("unchecked") - public List getTousseBySql(String sql){ - if(StringUtils.isNotBlank(sql)){ - return objectDao.findBySql(St_tousse_detail.class.getSimpleName(), sql); - } - return null; - } - - //物资领用(一次性物品)出库明细 - public void godownOutOfdiposableGoods(String startDate,String endDate,String year_month){ - //删除月份相同的记录 - deleteMaterialDetail(year_month); - - startDate = dateQueryAdapter.dateAdapter(startDate); - endDate = dateQueryAdapter.dateAdapter(endDate); - String sql = "select temptable.gname,temptable.depart,sum(temptable.amount),temptable.price from " + - "(select d.name as gname,p.departcoding as depart,sum(d.amount) as amount,sum(d.price) as price from invoice i,invoiceplan p,DiposableGoodsItem d " + - "where i.invoiceplan_id = p.id and i.id = d.invoice_id and i.sendTime between " + startDate + " and " + endDate + - " group by p.departcoding,d.name union all " + - "select i.toussename as gname,r.departcoding as depart,sum(-i.amount) as amount,sum(-i.price) as price from ReturnGoodsRecord r,ReturnGoodsItem i" + - " where r.id = i.returngoodsrecord_id and r.type = '一次性物品' and r.returntime between " + startDate + " and " + endDate + "" + - " group by r.departcoding,i.toussename)temptable group by temptable.gname,temptable.depart,temptable.price"; - @SuppressWarnings("unchecked") - ResultSet rs = objectDao.executeSql(sql); - try { - while (rs.next()) { - String name = rs.getString(1); - String departCoding = rs.getString(2); - Long amount = rs.getLong(3); - double price = rs.getDouble(4); - //获取物品ID - St_material_detail materialDetail = new St_material_detail(); - double totalPrice = new BigDecimal(amount).multiply(new BigDecimal(price)).doubleValue(); - materialDetail.setNum(amount);//数量 - materialDetail.setPrice(price);//单价 - materialDetail.setAmount(totalPrice);//总价 - int length = name.lastIndexOf("["); - if(length != -1){ - String tempName = name.substring(0,length); - String specification = name.substring(length+1,name.length()-1); - DisposableGoods disposableGoods = diposableGoodsManager.getDisposableGoodsByName(tempName, specification); - if(disposableGoods != null){ - materialDetail.setMaterial_id(disposableGoods.getId()); - } - }else{ - DisposableGoods disposableGoods = diposableGoodsManager.getDisposableGoodsByName(name, null); - if(disposableGoods != null){ - materialDetail.setMaterial_id(disposableGoods.getId()); - } - } - //获取部门ID - THTreeNode tHTreeNode = orgUnitManager.getOrgUnitByCode(departCoding); - if(tHTreeNode != null){ - Long orgunitId = tHTreeNode.getId(); - materialDetail.setDept_id(orgunitId); - } - materialDetail.setYear_month(year_month); - materialDetail.setRecord_time(new Date()); - objectDao.save(materialDetail); - } - //供应室领用物品 - String receiveRecordSql = " where po.time between "+startDate+" and "+endDate+" "; - List receiveList = objectDao.findBySql(ReceiveRecord.class.getSimpleName(), receiveRecordSql); - - - SupplyRoomConfig supplyRoom = supplyRoomConfigManager.getFirstSupplyRoomConfig(); - - String orgUnitCoding = supplyRoom.getOrgUnitCoding(); - - String orgunitSql = " where po.orgUnitCoding = '" + orgUnitCoding + "'"; - OrgUnit org = (OrgUnit)objectDao.getBySql(OrgUnit.class.getSimpleName(), orgunitSql); - - for (ReceiveRecord receiveRecord : receiveList) { - for (ReceiveRecordItem receiveItem : receiveRecord.getItems()) { - if("一次性物品".equals(receiveItem.getType())){ - Long goodsId = receiveItem.getDiposableGoodBatchStock().getDiposableGoods().getId(); - Double price = receiveItem.getPrice(); - double totalPrice = new BigDecimal(price).multiply(new BigDecimal(receiveItem.getAmount())).doubleValue(); - String materialSql = " where po.year_month = '"+year_month+"' and po.material_id = "+goodsId+" and po.dept_id = " + org.getId()+" and po.price = " + price; - List materialList = getMaterialBySql(materialSql); - St_material_detail materialdetail = null; - if(materialList != null && materialList.size() > 0){ - materialdetail = materialList.get(0); - double tp = new BigDecimal(totalPrice).add(new BigDecimal(materialdetail.getAmount())).doubleValue(); - materialdetail.setAmount(tp);//总价 - materialdetail.setNum(receiveItem.getAmount()+materialdetail.getNum());//数量 - }else{ - materialdetail = new St_material_detail(); - materialdetail.setAmount(totalPrice);//总价 - materialdetail.setDept_id(org.getId()); - materialdetail.setMaterial_id(goodsId); - materialdetail.setNum(Long.valueOf(receiveItem.getAmount())); - materialdetail.setPrice(price); - materialdetail.setRecord_time(new Date()); - materialdetail.setYear_month(year_month); - } - objectDao.saveOrUpdate(materialdetail); - } - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - } - - @SuppressWarnings("unchecked") - public List getMaterialBySql(String sql){ - if(StringUtils.isNotBlank(sql)){ - return objectDao.findBySql(St_material_detail.class.getSimpleName(), sql); - } - return null; - } - @Override public void deleteStockRecord(String ids) { if(StringUtils.isNotBlank(ids)){