| | |
| | | package com.example.erp.service.mm; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.example.erp.entity.mm.*; |
| | | import com.example.erp.entity.pp.FlowCard; |
| | | import com.example.erp.entity.pp.OptimizeUse; |
| | | import com.example.erp.entity.sd.Delivery; |
| | | import com.example.erp.entity.sd.DeliveryDetail; |
| | | import com.example.erp.entity.sd.OrderDetail; |
| | | import com.example.erp.entity.userInfo.Log; |
| | | import com.example.erp.entity.userInfo.SysError; |
| | | import com.example.erp.mapper.mm.BasicWarehouseTypeMapper; |
| | | import com.example.erp.mapper.mm.MaterialInventoryMapper; |
| | | import com.example.erp.mapper.mm.MaterialStoreMapper; |
| | | import com.example.erp.service.userInfo.LogService; |
| | | import com.example.erp.service.userInfo.SysErrorService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | import java.util.List; |
| | | import java.util.ArrayList; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @DS("mm") |
| | |
| | | BasicWarehouseTypeMapper basicWarehouseTypeMapper; |
| | | @Autowired |
| | | SysErrorService sysErrorService; |
| | | @Autowired |
| | | LogService logService; |
| | | |
| | | public Boolean saveMaterialOutbound(Map<String,Object> object) { |
| | | boolean saveState = true; |
| | |
| | | if (object.get("materialOutboundId") != null) { |
| | | materialOutboundId = object.get("materialOutboundId").toString(); |
| | | } |
| | | Log log = new Log(); |
| | | log.setContent(object.toString()); |
| | | try { |
| | | MaterialOutbound materialOutbound = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), MaterialOutbound.class); |
| | | List<MaterialOutboundDetail> materialOutboundDetailList = JSONArray.parseArray(JSONObject.toJSONString(object.get("materialOutboundDetail")), MaterialOutboundDetail.class); |
| | |
| | | } |
| | | //删除材料出库明细的数据 |
| | | materialInventoryMapper.deleteMaterialOutboundDetail(materialOutboundId); |
| | | materialInventoryMapper.updateMaterialOutbound(materialOutbound, materialOutboundId); |
| | | oddNumber = materialOutboundId; |
| | | log.setFunction("saveMaterialOutbound修改:"+oddNumber); |
| | | } else { |
| | | //获取单号 |
| | | oddNumber = orderNumberSetting("出库"); |
| | | //新增材料出库表数据 |
| | | materialInventoryMapper.insertMaterialOutbound(materialOutbound, oddNumber); |
| | | log.setFunction("saveMaterialOutbound新增:"+oddNumber); |
| | | } |
| | | |
| | | //获取对象集合循环进行新增修改 |
| | |
| | | } |
| | | |
| | | } |
| | | logService.saveLog(log); |
| | | |
| | | } catch (Exception e) { |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e.toString()); |
| | | sysError.setFunc("saveOrder"); |
| | | sysError.setError(e+Arrays.toString(e.getStackTrace())); |
| | | sysError.setFunc("saveMaterialOutbound"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = false; |
| | | |
| | |
| | | |
| | | public Boolean saveMaterialInventory(Map<String,Object> object) { |
| | | boolean saveState = true; |
| | | Double singlePieceArea = 0.0; |
| | | Double totalArea = 0.0; |
| | | Long materialCode = 0L; |
| | | if (object.get("singlePieceArea") != null) { |
| | | singlePieceArea = Double.valueOf(object.get("singlePieceArea").toString()); |
| | | } |
| | | if (object.get("totalArea") != null) { |
| | | totalArea = Double.valueOf(object.get("totalArea").toString()); |
| | | } |
| | | if (object.get("materialCode") != null) { |
| | | materialCode = Long.valueOf(object.get("materialCode").toString()); |
| | | } |
| | | //设置回滚点 |
| | | Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | try { |
| | | Double singlePieceArea = 0.0; |
| | | Double totalArea = 0.0; |
| | | Long materialCode = 0L; |
| | | if (object.get("singlePieceArea") != null) { |
| | | singlePieceArea = Double.valueOf(object.get("singlePieceArea").toString()); |
| | | } |
| | | if (object.get("totalArea") != null) { |
| | | totalArea = Double.valueOf(object.get("totalArea").toString()); |
| | | } |
| | | if (object.get("materialCode") != null) { |
| | | materialCode = Long.valueOf(object.get("materialCode").toString()); |
| | | } |
| | | Log log = new Log(); |
| | | log.setContent(object.toString()); |
| | | |
| | | MaterialInventory materialInventory = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), MaterialInventory.class); |
| | | MaterialInventory materialInventory = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), MaterialInventory.class); |
| | | |
| | | //查询物料是否存在 |
| | | Integer MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(materialCode,materialInventory.getDateOfManufacture()); |
| | | //查询物料是否存在 |
| | | Integer MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(materialCode,materialInventory.getDateOfManufacture()); |
| | | |
| | | if(MaterialInventoryCount>0){ |
| | | materialInventoryMapper.updateMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory); |
| | | }else { |
| | | materialInventoryMapper.insertMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory); |
| | | if(MaterialInventoryCount>0){ |
| | | materialInventoryMapper.updateMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory); |
| | | log.setFunction("saveMaterialInventory修改"); |
| | | }else { |
| | | materialInventoryMapper.insertMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory); |
| | | log.setFunction("saveMaterialInventory新增"); |
| | | } |
| | | logService.saveLog(log); |
| | | } catch (Exception e) { |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e+Arrays.toString(e.getStackTrace())); |
| | | sysError.setFunc("saveMaterialInventory"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = false; |
| | | |
| | | } |
| | | return saveState; |
| | | |
| | |
| | | Integer offset = (pageNum - 1) * pageSize; |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("data", materialInventoryMapper.getSelectMaterialInventory(offset, pageSize, materialInventory)); |
| | | map.put("total", materialInventoryMapper.getSelectMaterialInventoryPageTotal(offset, pageSize, materialInventory)); |
| | | List<Long> ids=new ArrayList<>();; |
| | | if(materialInventory.getStockId()!=null && !materialInventory.getStockId().isEmpty()){ |
| | | List<String> result = StrUtil.split(materialInventory.getStockId(), '|'); |
| | | ids=result.stream().map(Long::valueOf).collect(Collectors.toList()); |
| | | } |
| | | map.put("data", materialInventoryMapper.getSelectMaterialInventory(offset, pageSize, materialInventory,ids)); |
| | | map.put("total", materialInventoryMapper.getSelectMaterialInventoryPageTotal(offset, pageSize, materialInventory,ids)); |
| | | return map; |
| | | } |
| | | |
| | | public Map<String, Object> getSelectMaterialInventoryEngineering(Integer pageNum, Integer pageSize, OptimizeUse optimizeUse) { |
| | | Integer offset = (pageNum - 1) * pageSize; |
| | | System.out.println(optimizeUse); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("data", materialInventoryMapper.getSelectMaterialInventoryEngineering(offset, pageSize, optimizeUse)); |
| | | map.put("total", materialInventoryMapper.getSelectMaterialInventoryEngineeringPageTotal(offset, pageSize, optimizeUse)); |
| | | List<Long> ids=new ArrayList<>();; |
| | | if(optimizeUse.getRawStockCode()!=null && !optimizeUse.getRawStockCode().isEmpty()){ |
| | | List<String> result = StrUtil.split(optimizeUse.getRawStockCode(), '|'); |
| | | ids=result.stream().map(Long::valueOf).collect(Collectors.toList()); |
| | | } |
| | | map.put("data", materialInventoryMapper.getSelectMaterialInventoryEngineering(offset, pageSize, optimizeUse,ids)); |
| | | map.put("total", materialInventoryMapper.getSelectMaterialInventoryEngineeringPageTotal(offset, pageSize, optimizeUse,ids)); |
| | | return map; |
| | | } |
| | | |
| | |
| | | materialInventoryMapper.deleteMaterialOutboundDetail(materialOutboundId); |
| | | materialInventoryMapper.deleteMaterialOutbound(materialOutboundId); |
| | | } |
| | | |
| | | Log log = new Log(); |
| | | log.setContent(object.toString()); |
| | | log.setFunction("deleteMaterialOutbound删除:"+materialOutboundId); |
| | | logService.saveLog(log); |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e.toString()); |
| | | sysError.setFunc("saveOrder"); |
| | | sysError.setError(e+Arrays.toString(e.getStackTrace())); |
| | | sysError.setFunc("deleteMaterialOutbound"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = false; |
| | | |
| | |
| | | if (object.get("reviewed") != null) { |
| | | reviewed = object.get("reviewed").toString(); |
| | | } |
| | | Log log = new Log(); |
| | | log.setOperator(reviewed); |
| | | log.setContent(object.toString()); |
| | | log.setFunction("updateMaterialOutboundToExamine:"+type); |
| | | logService.saveLog(log); |
| | | |
| | | if (type==1){ |
| | | List<MaterialOutboundDetail> materialOutboundDetailList = materialInventoryMapper.getIsNotMaterialOutboundDetail(materialOutboundId); |
| | |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e.toString()); |
| | | sysError.setFunc("saveOrder"); |
| | | sysError.setError(e+Arrays.toString(e.getStackTrace())); |
| | | sysError.setFunc("updateMaterialOutboundToExamine"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = false; |
| | | |
| | |
| | | boolean saveState = true; |
| | | //设置回滚点 |
| | | Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | String returningId = ""; |
| | | String oddNumber; |
| | | if (object.get("returningId") != null) { |
| | | returningId = object.get("returningId").toString(); |
| | | } |
| | | try { |
| | | String returningId = ""; |
| | | String oddNumber; |
| | | if (object.get("returningId") != null) { |
| | | returningId = object.get("returningId").toString(); |
| | | } |
| | | Log log = new Log(); |
| | | log.setContent(object.toString()); |
| | | |
| | | ReturningWarehouse returningWarehouse = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), ReturningWarehouse.class); |
| | | List<ReturningWarehouseDetail> returningWarehouseDetailList = JSONArray.parseArray(JSONObject.toJSONString(object.get("returningWarehouseDetail")), ReturningWarehouseDetail.class); |
| | | //查询出库单是否存在 |
| | |
| | | //删除材料出库明细的数据 |
| | | materialInventoryMapper.deleteReturningWarehouseDetail(returningId); |
| | | oddNumber = returningId; |
| | | log.setFunction("saveReturningWarehouse修改:"+oddNumber); |
| | | } else { |
| | | //获取单号 |
| | | oddNumber = orderNumberSetting("返库"); |
| | | //新增材料出库表数据 |
| | | materialInventoryMapper.insertReturningWarehouse(returningWarehouse, oddNumber); |
| | | log.setFunction("saveReturningWarehouse新增:"+oddNumber); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | } |
| | | logService.saveLog(log); |
| | | |
| | | } catch (Exception e) { |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e+Arrays.toString(e.getStackTrace())); |
| | | sysError.setFunc("saveReturningWarehouse"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = false; |
| | | |
| | | } |
| | | return saveState; |
| | | |
| | | } |
| | |
| | | if (object.get("reviewed") != null) { |
| | | reviewed = object.get("reviewed").toString(); |
| | | } |
| | | Log log = new Log(); |
| | | log.setOperator(reviewed); |
| | | log.setContent(object.toString()); |
| | | log.setFunction("updateReturningWarehouseToExamine:"+type); |
| | | logService.saveLog(log); |
| | | |
| | | if (type==1){ |
| | | List<ReturningWarehouseDetail> returningWarehouseDetailList = materialInventoryMapper.getIsNotReturningWarehouseDetail(returningId); |
| | |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e.toString()); |
| | | sysError.setFunc("saveOrder"); |
| | | sysError.setError(e+Arrays.toString(e.getStackTrace())); |
| | | sysError.setFunc("updateReturningWarehouseToExamine"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = false; |
| | | |
| | |
| | | return map; |
| | | } |
| | | |
| | | public Map<String, Object> getSelectSurplusMaterialsDate(Integer pageNum, Integer pageSize, List<String> selectDate, SurplusMaterials surplusMaterials) { |
| | | Integer offset = (pageNum - 1) * pageSize; |
| | | String endDate = LocalDate.now().toString(); |
| | | String startDate = LocalDate.now().minusDays(15).toString(); |
| | | if(selectDate !=null && selectDate.size()==2){ |
| | | if(!selectDate.get(0).isEmpty()){ |
| | | startDate = selectDate.get(0); |
| | | } |
| | | if(!selectDate.get(1).isEmpty()){ |
| | | endDate = selectDate.get(1); |
| | | } |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("data", materialInventoryMapper.getSelectSurplusMaterialsDate(offset, pageSize,startDate, endDate, surplusMaterials)); |
| | | map.put("total", materialInventoryMapper.getSelectSurplusMaterialsDatePageTotal(offset, pageSize,startDate, endDate, surplusMaterials)); |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(startDate); |
| | | list.add(endDate); |
| | | map.put("selectDate",list); |
| | | return map; |
| | | } |
| | | |
| | | public Boolean addSelectSurplusMaterialsDate(Map<String,Object> object) { |
| | | boolean saveState = true; |
| | | //设置回滚点 |
| | | Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | |
| | | String creator = ""; |
| | | if (object.get("creator") != null) { |
| | | creator = object.get("creator").toString(); |
| | | } |
| | | String type = ""; |
| | | if (object.get("type") != null) { |
| | | type = object.get("type").toString(); |
| | | } |
| | | int state = 0; |
| | | if (object.get("state") != null) { |
| | | state = Integer.parseInt(object.get("state").toString()); |
| | | } |
| | | Log log = new Log(); |
| | | log.setOperator(creator); |
| | | log.setContent(object.toString()); |
| | | log.setFunction("addSelectSurplusMaterialsDate:"+state); |
| | | logService.saveLog(log); |
| | | |
| | | if(state==1){ |
| | | SurplusMaterials surplusMaterials = JSONObject.parseObject(JSONObject.toJSONString(object.get("surplusMaterials")), SurplusMaterials.class); |
| | | if(surplusMaterials!=null){ |
| | | SurplusMaterials surplusMaterials1=materialInventoryMapper.selectSurplusMaterialsCount(surplusMaterials); |
| | | if(surplusMaterials1!=null){ |
| | | System.out.println(surplusMaterials1); |
| | | materialInventoryMapper.updateSurplusMaterialsIntQuantity(surplusMaterials1); |
| | | materialInventoryMapper.insertSurplusMaterialsLog(surplusMaterials1,creator,type); |
| | | }else{ |
| | | materialInventoryMapper.insertSurplusMaterials(surplusMaterials); |
| | | materialInventoryMapper.insertSurplusMaterialsLog(surplusMaterials,creator,type); |
| | | } |
| | | } |
| | | } else if (state==2) { |
| | | List<SurplusMaterials> surplusMaterialsList = JSONArray.parseArray(JSONObject.toJSONString(object.get("surplusMaterials")), SurplusMaterials.class); |
| | | if(!surplusMaterialsList.isEmpty()){ |
| | | for(SurplusMaterials surplusMaterials:surplusMaterialsList){ |
| | | materialInventoryMapper.updateSurplusMaterialsOutQuantity(surplusMaterials); |
| | | materialInventoryMapper.insertSurplusMaterialsLog(surplusMaterials,creator,type); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | return saveState; |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | public Map<String, Object> printCreateOutbound(String materialOutboundId) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("createOutbound", materialInventoryMapper.getPrintCreateOutbound(materialOutboundId)); |
| | | map.put("createOutboundDetail", materialInventoryMapper.getPrintCreateOutboundDetail(materialOutboundId)); |
| | | return map; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public String orderNumberSetting(String type) { |