kangwei :药剂入库审核,出库、与入库完善
正在显示
7 个修改的文件
包含
126 行增加
和
85 行删除
... | @@ -339,10 +339,12 @@ public class MaterialINController { | ... | @@ -339,10 +339,12 @@ public class MaterialINController { |
339 | Result<MaterialINVO> result = new Result<MaterialINVO>(); | 339 | Result<MaterialINVO> result = new Result<MaterialINVO>(); |
340 | try { | 340 | try { |
341 | materialINService.auditMaterialINVO(materialINVO); | 341 | materialINService.auditMaterialINVO(materialINVO); |
342 | } catch (Exception e) { | ||
343 | log.error("审批失败",e.getMessage()); | ||
344 | result.setResult(materialINVO); | 342 | result.setResult(materialINVO); |
345 | result.setSuccess(true); | 343 | result.setSuccess(true); |
344 | } catch (Exception e) { | ||
345 | log.error("审批失败",e.getMessage()); | ||
346 | |||
347 | result.error500("审批失败:"+e.getMessage()); | ||
346 | } | 348 | } |
347 | return result; | 349 | return result; |
348 | } | 350 | } | ... | ... |
... | @@ -17,7 +17,7 @@ public interface IMaterialINService extends IService<MaterialIN> { | ... | @@ -17,7 +17,7 @@ public interface IMaterialINService extends IService<MaterialIN> { |
17 | * 审核药剂入库单 | 17 | * 审核药剂入库单 |
18 | * @param materialINVO | 18 | * @param materialINVO |
19 | */ | 19 | */ |
20 | String auditMaterialINVO(MaterialINVO materialINVO); | 20 | String auditMaterialINVO(MaterialINVO materialINVO) throws Exception; |
21 | 21 | ||
22 | /*** | 22 | /*** |
23 | * 列表查询到货记录列表 | 23 | * 列表查询到货记录列表 | ... | ... |
... | @@ -6,20 +6,27 @@ import com.skua.core.context.BaseContextHandler; | ... | @@ -6,20 +6,27 @@ import com.skua.core.context.BaseContextHandler; |
6 | import com.skua.core.context.SpringContextUtils; | 6 | import com.skua.core.context.SpringContextUtils; |
7 | import com.skua.modules.equipment.dto.EquipmentInDTO; | 7 | import com.skua.modules.equipment.dto.EquipmentInDTO; |
8 | import com.skua.modules.equipment.dto.EquipmentOutDTO; | 8 | import com.skua.modules.equipment.dto.EquipmentOutDTO; |
9 | import com.skua.modules.equipment.entity.EquipmentIn; | ||
9 | import com.skua.modules.equipment.entity.EquipmentInChild; | 10 | import com.skua.modules.equipment.entity.EquipmentInChild; |
11 | import com.skua.modules.equipment.entity.EquipmentOutChild; | ||
10 | import com.skua.modules.equipment.service.IEquipmentInService; | 12 | import com.skua.modules.equipment.service.IEquipmentInService; |
11 | import com.skua.modules.equipment.service.IEquipmentOutService; | 13 | import com.skua.modules.equipment.service.IEquipmentOutService; |
12 | import com.skua.modules.erp.entity.ApproveRecord; | 14 | import com.skua.modules.erp.entity.ApproveRecord; |
15 | import com.skua.modules.erp.entity.ERPPurchaseContract; | ||
13 | import com.skua.modules.erp.entity.MaterialIN; | 16 | import com.skua.modules.erp.entity.MaterialIN; |
14 | import com.skua.modules.erp.mapper.ApproveRecordMapper; | 17 | import com.skua.modules.erp.mapper.ApproveRecordMapper; |
18 | import com.skua.modules.erp.mapper.ERPPurchaseContractMapper; | ||
15 | import com.skua.modules.erp.mapper.MaterialINMapper; | 19 | import com.skua.modules.erp.mapper.MaterialINMapper; |
20 | import com.skua.modules.erp.service.IERPPurchaseContractService; | ||
16 | import com.skua.modules.erp.service.IMaterialINService; | 21 | import com.skua.modules.erp.service.IMaterialINService; |
17 | import com.skua.modules.erp.vo.ArrivalRecordExcelExportVO; | 22 | import com.skua.modules.erp.vo.ArrivalRecordExcelExportVO; |
18 | import com.skua.modules.erp.vo.MaterialINVO; | 23 | import com.skua.modules.erp.vo.MaterialINVO; |
19 | import com.skua.modules.guest.util.DateUtil; | 24 | import com.skua.modules.guest.util.DateUtil; |
25 | import com.skua.modules.quartz.util.BaseUtil; | ||
20 | import com.skua.modules.supplies.entity.SuppliesWarehouse; | 26 | import com.skua.modules.supplies.entity.SuppliesWarehouse; |
21 | import com.skua.modules.supplies.service.ISuppliesWarehouseService; | 27 | import com.skua.modules.supplies.service.ISuppliesWarehouseService; |
22 | import org.apache.commons.lang3.StringUtils; | 28 | import org.apache.commons.lang3.StringUtils; |
29 | import org.hibernate.service.spi.ServiceException; | ||
23 | import org.springframework.beans.factory.annotation.Autowired; | 30 | import org.springframework.beans.factory.annotation.Autowired; |
24 | import org.springframework.jdbc.core.JdbcTemplate; | 31 | import org.springframework.jdbc.core.JdbcTemplate; |
25 | import org.springframework.stereotype.Service; | 32 | import org.springframework.stereotype.Service; |
... | @@ -41,6 +48,8 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia | ... | @@ -41,6 +48,8 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia |
41 | @Resource | 48 | @Resource |
42 | private ApproveRecordMapper recordMapper; | 49 | private ApproveRecordMapper recordMapper; |
43 | @Autowired | 50 | @Autowired |
51 | private IERPPurchaseContractService purchaseContractService; | ||
52 | @Autowired | ||
44 | private IEquipmentInService equipmentInService; | 53 | private IEquipmentInService equipmentInService; |
45 | @Autowired | 54 | @Autowired |
46 | private IEquipmentOutService equipmentOutService; | 55 | private IEquipmentOutService equipmentOutService; |
... | @@ -52,7 +61,7 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia | ... | @@ -52,7 +61,7 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia |
52 | * @param materialINVO | 61 | * @param materialINVO |
53 | */ | 62 | */ |
54 | @Transactional | 63 | @Transactional |
55 | public String auditMaterialINVO(MaterialINVO materialINVO){ | 64 | public String auditMaterialINVO(MaterialINVO materialINVO)throws Exception { |
56 | boolean inAndOutStock = false; | 65 | boolean inAndOutStock = false; |
57 | String errMsg = null; | 66 | String errMsg = null; |
58 | QueryWrapper<SuppliesWarehouse> queryWrapper = new QueryWrapper<SuppliesWarehouse>(); | 67 | QueryWrapper<SuppliesWarehouse> queryWrapper = new QueryWrapper<SuppliesWarehouse>(); |
... | @@ -68,32 +77,29 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia | ... | @@ -68,32 +77,29 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia |
68 | return "所属厂站["+departName+"]下没有找到仓库信息!"; | 77 | return "所属厂站["+departName+"]下没有找到仓库信息!"; |
69 | } | 78 | } |
70 | //保存 | 79 | //保存 |
80 | MaterialIN materialINTemp = this.baseMapper.selectById(materialINVO.getId()); | ||
71 | //purchasePlan.getApproveState() 审批状态 1通过2不通过 | 81 | //purchasePlan.getApproveState() 审批状态 1通过2不通过 |
72 | if("1".equals( materialINVO.getApproveState() )){ | 82 | if("1".equals( materialINVO.getApproveState() )){ |
73 | materialINVO.setAuditStatus( "3" ); | 83 | materialINTemp.setAuditStatus( "3" ); |
74 | inAndOutStock = true; | 84 | inAndOutStock = true; |
75 | } | 85 | } |
76 | if("2".equals( materialINVO.getApproveState() )){ | 86 | if("2".equals( materialINVO.getApproveState() )){ |
77 | materialINVO.setAuditStatus( "2" ); | 87 | materialINTemp.setAuditStatus( "2" ); |
78 | } | 88 | } |
79 | this.baseMapper.updateById( materialINVO ) ; | ||
80 | 89 | ||
81 | //审批记录 | ||
82 | ApproveRecord record = new ApproveRecord( "YJIN", materialINVO.getApplyUser(), materialINVO.getId(), BaseContextHandler.getUserId(), materialINVO.getApproveMessage(), materialINVO.getApproveState()); | ||
83 | recordMapper.insert( record ) ; | ||
84 | 90 | ||
85 | // 审核通过,生成入库单据、物料单 | 91 | // 审核通过,生成入库单据、物料单 |
86 | if(inAndOutStock ){ | 92 | if(inAndOutStock ){ |
87 | try { | 93 | //出库 |
88 | //出库 | 94 | errMsg = syncEquipmentOut(materialINTemp); |
89 | syncEquipmentOut(materialINVO); | 95 | //入库 |
90 | //入库 | 96 | errMsg = syncEquipmentIn(materialINTemp,inWarehouseId); |
91 | syncEquipmentIn(materialINVO,inWarehouseId); | ||
92 | } catch (Exception e) { | ||
93 | e.printStackTrace(); | ||
94 | |||
95 | } | ||
96 | } | 97 | } |
98 | this.baseMapper.updateById( materialINTemp ) ; | ||
99 | |||
100 | //审批记录 | ||
101 | ApproveRecord record = new ApproveRecord( "YJIN", materialINVO.getApplyUser(), materialINVO.getId(), BaseContextHandler.getUserId(), materialINVO.getApproveMessage(), materialINVO.getApproveState()); | ||
102 | recordMapper.insert( record ) ; | ||
97 | 103 | ||
98 | return errMsg; | 104 | return errMsg; |
99 | } | 105 | } |
... | @@ -130,12 +136,53 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia | ... | @@ -130,12 +136,53 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia |
130 | * 出库 | 136 | * 出库 |
131 | * @return | 137 | * @return |
132 | */ | 138 | */ |
133 | public int syncEquipmentOut(MaterialINVO materialINVO){ | 139 | public String syncEquipmentOut(MaterialIN materialINTemp)throws Exception{ |
140 | String errMsg = null; | ||
134 | EquipmentOutDTO equipmentOutDTO = new EquipmentOutDTO(); | 141 | EquipmentOutDTO equipmentOutDTO = new EquipmentOutDTO(); |
135 | 142 | try{ | |
136 | 143 | ||
144 | ERPPurchaseContract erpPurchaseContract = purchaseContractService.getById(materialINTemp.getPurchaseContractId()); | ||
145 | if(erpPurchaseContract != null ){ | ||
146 | if(StringUtils.isNotEmpty(erpPurchaseContract.getEquipmentInId())){ | ||
147 | EquipmentIn equipmentIn = equipmentInService.getById( erpPurchaseContract.getEquipmentInId() ); | ||
148 | equipmentOutDTO.setDepartId( equipmentIn.getDepartId() ) ; | ||
149 | equipmentOutDTO.setOutType("9");// | ||
150 | equipmentOutDTO.setRemark( materialINTemp.getRemark() ); | ||
151 | equipmentOutDTO.setChooseTime(BaseUtil.getCurrentDate());//经办时间 | ||
152 | equipmentOutDTO.setUseBy( BaseContextHandler.getUserId() );//使用人 | ||
153 | equipmentOutDTO.setOutDate( BaseUtil.getCurrentDate() ); | ||
154 | equipmentOutDTO.setInventoryUpdateTimeEnd( BaseUtil.getCurrentDate()); | ||
155 | equipmentOutDTO.setSuppliesWarehouseId( equipmentIn.getSuppliesWarehouseId() );// this.suppliesWarehouseId = suppliesWarehouseId;//所属仓库 | ||
156 | //this.outOrder = outOrder; | ||
157 | // this.recipient = recipient;//领用人 | ||
158 | equipmentOutDTO.setRecipient( materialINTemp.getReceiver());//收货人,领用人 | ||
159 | |||
160 | EquipmentOutChild equipmentOutChild = new EquipmentOutChild(); | ||
161 | equipmentOutChild.setSparepartId(materialINTemp.getSparepartId() );// | ||
162 | equipmentOutChild.setOutNum( new BigDecimal( materialINTemp.getMaterialNum() ) ) ;//出库数量 | ||
163 | equipmentOutChild.setTotalPrice( new BigDecimal( materialINTemp.getDistributTotalPrice() ) );//总价格 | ||
164 | equipmentOutChild.setBatchNum( materialINTemp.getGoodCode() );//批次号 | ||
165 | |||
166 | List<EquipmentOutChild> outChildList = new ArrayList<EquipmentOutChild>(); | ||
167 | outChildList.add( equipmentOutChild ); | ||
168 | equipmentOutDTO.setEquipmentOutChildList( outChildList ); | ||
169 | |||
170 | |||
171 | // 创建出库单 | ||
172 | equipmentOutService.saveEquipmentOut(equipmentOutDTO); | ||
173 | |||
174 | materialINTemp.setEquipmentOutId( equipmentOutDTO.getId()); | ||
175 | }else{ | ||
176 | throw new ServiceException("未找到统购合同的入库信息"); | ||
177 | } | ||
178 | }else{ | ||
179 | throw new ServiceException("统购合同不存在"); | ||
180 | } | ||
181 | }catch(ServiceException e){ | ||
182 | e.printStackTrace(); | ||
183 | } | ||
137 | //equipmentOutService.saveEquipmentOut(equipmentOutDTO); | 184 | //equipmentOutService.saveEquipmentOut(equipmentOutDTO); |
138 | return 1; | 185 | return errMsg; |
139 | } | 186 | } |
140 | 187 | ||
141 | /*** | 188 | /*** |
... | @@ -143,7 +190,8 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia | ... | @@ -143,7 +190,8 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia |
143 | * @param materialINVO | 190 | * @param materialINVO |
144 | * @return | 191 | * @return |
145 | */ | 192 | */ |
146 | public int syncEquipmentIn(MaterialINVO materialINVO,String inWarehouseId) throws Exception{ | 193 | public String syncEquipmentIn(MaterialIN materialINVO,String inWarehouseId) throws Exception{ |
194 | String errMsg = null; | ||
147 | EquipmentInDTO equipmentInDTO = new EquipmentInDTO(); | 195 | EquipmentInDTO equipmentInDTO = new EquipmentInDTO(); |
148 | // EquipmentIn equipmentIn = new EquipmentIn(); | 196 | // EquipmentIn equipmentIn = new EquipmentIn(); |
149 | //入库类型 | 197 | //入库类型 |
... | @@ -160,12 +208,12 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia | ... | @@ -160,12 +208,12 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia |
160 | EquipmentInChild equipmentInChild = new EquipmentInChild();// | 208 | EquipmentInChild equipmentInChild = new EquipmentInChild();// |
161 | 209 | ||
162 | equipmentInChild.setSparepartId( materialINVO.getSparepartId());//物料编号 | 210 | equipmentInChild.setSparepartId( materialINVO.getSparepartId());//物料编号 |
211 | |||
163 | equipmentInChild.setInNum( new BigDecimal(materialINVO.getMaterialNum())); //物料数量 | 212 | equipmentInChild.setInNum( new BigDecimal(materialINVO.getMaterialNum())); //物料数量 |
164 | equipmentInChild.setBatchNum(materialINVO.getGoodCode() ) ;//批次号 | 213 | equipmentInChild.setBatchNum(materialINVO.getGoodCode() ) ;//批次号 |
165 | 214 | ||
166 | equipmentInChildrenList.add( equipmentInChild ) ; | 215 | equipmentInChildrenList.add( equipmentInChild ) ; |
167 | 216 | ||
168 | |||
169 | equipmentInDTO.setEquipmentInChildList( equipmentInChildrenList ); | 217 | equipmentInDTO.setEquipmentInChildList( equipmentInChildrenList ); |
170 | //调用接口入库 | 218 | //调用接口入库 |
171 | equipmentInService.saveEquipmentIn(equipmentInDTO ) ; | 219 | equipmentInService.saveEquipmentIn(equipmentInDTO ) ; |
... | @@ -175,9 +223,10 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia | ... | @@ -175,9 +223,10 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia |
175 | if(erpPurchaseContract == null ){ | 223 | if(erpPurchaseContract == null ){ |
176 | throw new Exception("采购合同记录不存在"); | 224 | throw new Exception("采购合同记录不存在"); |
177 | }*/ | 225 | }*/ |
178 | materialINVO.setEquipmentInId( equipmentInDTO.getId() ) ;//记录入库单号 | 226 | materialINVO.setEquipmentInId( equipmentInDTO.getId() ) ;//记录入库编号 |
227 | materialINVO.setInOrder( equipmentInDTO.getInOrder() ) ;// 入库单号 | ||
179 | log.debug("记录入库单号{"+equipmentInDTO.getId()+"},入库单号:"+equipmentInDTO.getInOrder()); | 228 | log.debug("记录入库单号{"+equipmentInDTO.getId()+"},入库单号:"+equipmentInDTO.getInOrder()); |
180 | this.baseMapper.updateById(materialINVO ) ; | 229 | |
181 | return 1; | 230 | return errMsg; |
182 | } | 231 | } |
183 | } | 232 | } | ... | ... |
... | @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; | ... | @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; |
4 | import com.baomidou.mybatisplus.annotation.TableId; | 4 | import com.baomidou.mybatisplus.annotation.TableId; |
5 | import com.baomidou.mybatisplus.annotation.TableName; | 5 | import com.baomidou.mybatisplus.annotation.TableName; |
6 | import com.fasterxml.jackson.annotation.JsonFormat; | 6 | import com.fasterxml.jackson.annotation.JsonFormat; |
7 | import com.skua.core.aspect.annotation.Dict; | ||
7 | import io.swagger.annotations.ApiModel; | 8 | import io.swagger.annotations.ApiModel; |
8 | import io.swagger.annotations.ApiModelProperty; | 9 | import io.swagger.annotations.ApiModelProperty; |
9 | import lombok.Data; | 10 | import lombok.Data; |
... | @@ -42,6 +43,7 @@ public class EquipmentInChild { | ... | @@ -42,6 +43,7 @@ public class EquipmentInChild { |
42 | */ | 43 | */ |
43 | @Excel(name = "备品备件id", width = 15) | 44 | @Excel(name = "备品备件id", width = 15) |
44 | @ApiModelProperty(value = "备品备件id") | 45 | @ApiModelProperty(value = "备品备件id") |
46 | @Dict(dictTable = "equipment_sparepart_supplies", dicCode="id", dicText = "sparepart_name") | ||
45 | private String sparepartId; | 47 | private String sparepartId; |
46 | /** | 48 | /** |
47 | * 入库数量 | 49 | * 入库数量 |
... | @@ -117,4 +119,4 @@ public class EquipmentInChild { | ... | @@ -117,4 +119,4 @@ public class EquipmentInChild { |
117 | /**税率*/ | 119 | /**税率*/ |
118 | private BigDecimal taxRate; | 120 | private BigDecimal taxRate; |
119 | 121 | ||
120 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
122 | } | ... | ... |
... | @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; | ... | @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; |
4 | import com.baomidou.mybatisplus.annotation.TableId; | 4 | import com.baomidou.mybatisplus.annotation.TableId; |
5 | import com.baomidou.mybatisplus.annotation.TableName; | 5 | import com.baomidou.mybatisplus.annotation.TableName; |
6 | import com.fasterxml.jackson.annotation.JsonFormat; | 6 | import com.fasterxml.jackson.annotation.JsonFormat; |
7 | import com.skua.core.aspect.annotation.Dict; | ||
7 | import io.swagger.annotations.ApiModel; | 8 | import io.swagger.annotations.ApiModel; |
8 | import io.swagger.annotations.ApiModelProperty; | 9 | import io.swagger.annotations.ApiModelProperty; |
9 | import lombok.Data; | 10 | import lombok.Data; |
... | @@ -42,6 +43,7 @@ public class EquipmentOutChild { | ... | @@ -42,6 +43,7 @@ public class EquipmentOutChild { |
42 | */ | 43 | */ |
43 | @Excel(name = "备品备件id", width = 15) | 44 | @Excel(name = "备品备件id", width = 15) |
44 | @ApiModelProperty(value = "备品备件id") | 45 | @ApiModelProperty(value = "备品备件id") |
46 | @Dict(dictTable = "equipment_sparepart_supplies", dicCode="id", dicText = "sparepart_name") | ||
45 | private String sparepartId; | 47 | private String sparepartId; |
46 | /** | 48 | /** |
47 | * 出库数量 | 49 | * 出库数量 | ... | ... |
... | @@ -115,7 +115,7 @@ public class EquipmentInServiceImpl extends ServiceImpl<EquipmentInMapper, Equip | ... | @@ -115,7 +115,7 @@ public class EquipmentInServiceImpl extends ServiceImpl<EquipmentInMapper, Equip |
115 | }*/ | 115 | }*/ |
116 | for (EquipmentInChild equipmentInChild : equipmentInDTO.getEquipmentInChildList()) { | 116 | for (EquipmentInChild equipmentInChild : equipmentInDTO.getEquipmentInChildList()) { |
117 | equipmentInChild.setInId(inId); | 117 | equipmentInChild.setInId(inId); |
118 | taskExecutor.execute(() -> { | 118 | // taskExecutor.execute(() -> { |
119 | try { | 119 | try { |
120 | String sparepartId = equipmentInChild.getSparepartId(); | 120 | String sparepartId = equipmentInChild.getSparepartId(); |
121 | String suppliesWarehouseId = equipmentInDTO.getSuppliesWarehouseId(); | 121 | String suppliesWarehouseId = equipmentInDTO.getSuppliesWarehouseId(); |
... | @@ -173,7 +173,7 @@ public class EquipmentInServiceImpl extends ServiceImpl<EquipmentInMapper, Equip | ... | @@ -173,7 +173,7 @@ public class EquipmentInServiceImpl extends ServiceImpl<EquipmentInMapper, Equip |
173 | } finally { | 173 | } finally { |
174 | countDownLatch.countDown(); | 174 | countDownLatch.countDown(); |
175 | } | 175 | } |
176 | }); | 176 | // }); |
177 | } | 177 | } |
178 | countDownLatch.await(); | 178 | countDownLatch.await(); |
179 | return 1; | 179 | return 1; | ... | ... |
... | @@ -20,9 +20,8 @@ import com.skua.tool.util.UniqIdUtils; | ... | @@ -20,9 +20,8 @@ import com.skua.tool.util.UniqIdUtils; |
20 | import org.apache.commons.lang.StringUtils; | 20 | import org.apache.commons.lang.StringUtils; |
21 | import org.springframework.beans.BeanUtils; | 21 | import org.springframework.beans.BeanUtils; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.beans.factory.annotation.Qualifier; | ||
24 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
25 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
24 | import org.springframework.transaction.annotation.Transactional; | ||
26 | import org.springframework.transaction.support.TransactionTemplate; | 25 | import org.springframework.transaction.support.TransactionTemplate; |
27 | 26 | ||
28 | import javax.annotation.Resource; | 27 | import javax.annotation.Resource; |
... | @@ -37,10 +36,6 @@ import java.util.concurrent.CountDownLatch; | ... | @@ -37,10 +36,6 @@ import java.util.concurrent.CountDownLatch; |
37 | */ | 36 | */ |
38 | @Service | 37 | @Service |
39 | public class EquipmentOutServiceImpl extends ServiceImpl<EquipmentOutMapper, EquipmentOut> implements IEquipmentOutService { | 38 | public class EquipmentOutServiceImpl extends ServiceImpl<EquipmentOutMapper, EquipmentOut> implements IEquipmentOutService { |
40 | |||
41 | @Autowired | ||
42 | @Qualifier("taskExecutor") | ||
43 | private ThreadPoolTaskExecutor taskExecutor; | ||
44 | @Resource | 39 | @Resource |
45 | private EquipmentOutMapper equipmentOutMapper; | 40 | private EquipmentOutMapper equipmentOutMapper; |
46 | 41 | ||
... | @@ -63,6 +58,7 @@ public class EquipmentOutServiceImpl extends ServiceImpl<EquipmentOutMapper, Equ | ... | @@ -63,6 +58,7 @@ public class EquipmentOutServiceImpl extends ServiceImpl<EquipmentOutMapper, Equ |
63 | * @param equipmentOutDTO | 58 | * @param equipmentOutDTO |
64 | * @return | 59 | * @return |
65 | */ | 60 | */ |
61 | @Transactional | ||
66 | public String saveEquipmentOut(EquipmentOutDTO equipmentOutDTO) throws Exception { | 62 | public String saveEquipmentOut(EquipmentOutDTO equipmentOutDTO) throws Exception { |
67 | String errMsg = null; | 63 | String errMsg = null; |
68 | if (equipmentOutDTO.getEquipmentOutChildList() == null || equipmentOutDTO.getEquipmentOutChildList().isEmpty()) { | 64 | if (equipmentOutDTO.getEquipmentOutChildList() == null || equipmentOutDTO.getEquipmentOutChildList().isEmpty()) { |
... | @@ -80,61 +76,51 @@ public class EquipmentOutServiceImpl extends ServiceImpl<EquipmentOutMapper, Equ | ... | @@ -80,61 +76,51 @@ public class EquipmentOutServiceImpl extends ServiceImpl<EquipmentOutMapper, Equ |
80 | EquipmentOut equipmentOut = BeanExtUtils.bean2Bean(equipmentOutDTO, EquipmentOut.class); | 76 | EquipmentOut equipmentOut = BeanExtUtils.bean2Bean(equipmentOutDTO, EquipmentOut.class); |
81 | equipmentOut.setInventoryUpdateTime(new Date()); | 77 | equipmentOut.setInventoryUpdateTime(new Date()); |
82 | this.baseMapper.insert(equipmentOut); | 78 | this.baseMapper.insert(equipmentOut); |
83 | CountDownLatch countDownLatch = new CountDownLatch(equipmentOutDTO.getEquipmentOutChildList().size()); | 79 | // CountDownLatch countDownLatch = new CountDownLatch(equipmentOutDTO.getEquipmentOutChildList().size()); |
84 | for (EquipmentOutChild equipmentOutChild : equipmentOutDTO.getEquipmentOutChildList()) { | 80 | for (EquipmentOutChild equipmentOutChild : equipmentOutDTO.getEquipmentOutChildList()) { |
85 | equipmentOutChild.setId(UniqIdUtils.getInstance().getUniqID()); | 81 | equipmentOutChild.setId(UniqIdUtils.getInstance().getUniqID()); |
86 | equipmentOutChild.setOutId(outId); | 82 | equipmentOutChild.setOutId(outId); |
87 | taskExecutor.execute(() -> { | 83 | // taskExecutor.execute(() -> { |
88 | try { | 84 | String sparepartId = equipmentOutChild.getSparepartId(); |
89 | String sparepartId = equipmentOutChild.getSparepartId(); | 85 | String suppliesWarehouseId = equipmentOutDTO.getSuppliesWarehouseId(); |
90 | String suppliesWarehouseId = equipmentOutDTO.getSuppliesWarehouseId(); | ||
91 | 86 | ||
92 | //根据物资id和仓库id获取库存 | 87 | //根据物资id和仓库id获取库存 |
93 | QueryWrapper<EquipmentSparepart> sparepartQueryWrapper = new QueryWrapper<>(); | 88 | QueryWrapper<EquipmentSparepart> sparepartQueryWrapper = new QueryWrapper<>(); |
94 | sparepartQueryWrapper.eq("supplies_id", sparepartId).eq("supplies_warehouse_id", suppliesWarehouseId); | 89 | sparepartQueryWrapper.eq("supplies_id", sparepartId).eq("supplies_warehouse_id", suppliesWarehouseId); |
95 | EquipmentSparepart equipmentSparepart = iEquipmentSparepartService.getOne(sparepartQueryWrapper); | 90 | EquipmentSparepart equipmentSparepart = iEquipmentSparepartService.getOne(sparepartQueryWrapper); |
96 | if (ObjectUtil.isEmpty(equipmentSparepart)) { | 91 | if (ObjectUtil.isEmpty(equipmentSparepart)) { |
97 | //物料信息 | 92 | //物料信息 |
98 | EquipmentSparepartSupplies supplies = sparepartSuppliesService.getById(sparepartId); | 93 | EquipmentSparepartSupplies supplies = sparepartSuppliesService.getById(sparepartId); |
99 | equipmentSparepart = new EquipmentSparepart(); | 94 | equipmentSparepart = new EquipmentSparepart(); |
100 | BeanUtils.copyProperties(supplies, equipmentSparepart); | 95 | BeanUtils.copyProperties(supplies, equipmentSparepart); |
101 | equipmentSparepart.setId(null); | 96 | equipmentSparepart.setId(null); |
102 | equipmentSparepart.setStorageNum(BigDecimal.ZERO); | 97 | equipmentSparepart.setStorageNum(BigDecimal.ZERO); |
103 | equipmentSparepart.setSuppliesId(sparepartId); | 98 | equipmentSparepart.setSuppliesId(sparepartId); |
104 | equipmentSparepart.setSuppliesWarehouseId(suppliesWarehouseId); | 99 | equipmentSparepart.setSuppliesWarehouseId(suppliesWarehouseId); |
105 | //如果没有物料库存信息,新增库存信息为0 | 100 | //如果没有物料库存信息,新增库存信息为0 |
106 | iEquipmentSparepartService.saveOrUpdate(equipmentSparepart); | 101 | iEquipmentSparepartService.saveOrUpdate(equipmentSparepart); |
107 | equipmentSparepart = iEquipmentSparepartService.getOne(sparepartQueryWrapper); | 102 | equipmentSparepart = iEquipmentSparepartService.getOne(sparepartQueryWrapper); |
108 | 103 | ||
109 | } | ||
110 | BigDecimal resetStorageNum = equipmentSparepart.getStorageNum().subtract(equipmentOutChild.getOutNum()); | ||
111 | if (resetStorageNum.doubleValue() < 0) { | ||
112 | return; | ||
113 | } | ||
114 | Integer version = equipmentSparepart.getVersion(); | ||
115 | String id = equipmentSparepart.getId(); | ||
116 | Integer executeRes = transactionTemplate.execute(transactionStatus -> { | ||
117 | int val0 = iEquipmentSparepartService.updateStorageNumById(id, resetStorageNum.doubleValue(), version); | ||
118 | if (val0 == 1 && iEquipmentOutChildService.saveOrUpdate(equipmentOutChild)) { | ||
119 | return 1; | ||
120 | } else { | ||
121 | transactionStatus.setRollbackOnly(); | ||
122 | return 0; | ||
123 | } | ||
124 | }); | ||
125 | // if (executeRes != null && executeRes == 1) { | ||
126 | // | ||
127 | // } | ||
128 | |||
129 | } catch (Exception e) { | ||
130 | e.printStackTrace(); | ||
131 | //log.error("异常error: {}", e.getMessage()); | ||
132 | } finally { | ||
133 | countDownLatch.countDown(); | ||
134 | } | 104 | } |
135 | }); | 105 | BigDecimal resetStorageNum = equipmentSparepart.getStorageNum().subtract(equipmentOutChild.getOutNum()); |
106 | if (resetStorageNum.doubleValue() < 0) { | ||
107 | continue; | ||
108 | //return; | ||
109 | } | ||
110 | Integer version = equipmentSparepart.getVersion(); | ||
111 | String id = equipmentSparepart.getId(); | ||
112 | Integer executeRes = transactionTemplate.execute(transactionStatus -> { | ||
113 | int val0 = iEquipmentSparepartService.updateStorageNumById(id, resetStorageNum.doubleValue(), version); | ||
114 | if (val0 == 1 && iEquipmentOutChildService.saveOrUpdate(equipmentOutChild)) { | ||
115 | return 1; | ||
116 | } else { | ||
117 | transactionStatus.setRollbackOnly(); | ||
118 | return 0; | ||
119 | } | ||
120 | }); | ||
121 | // }); | ||
136 | } | 122 | } |
137 | countDownLatch.await(); | 123 | // countDownLatch.await(); |
138 | return errMsg ; | 124 | return errMsg ; |
139 | } | 125 | } |
140 | } | 126 | } | ... | ... |
-
请 注册 或 登录 后发表评论