| | |
| | | package com.gkhy.hazmat.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.hazmat.common.api.CommonPage; |
| | | import com.gkhy.hazmat.common.config.IdTableNameHandler; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = RuntimeException.class) |
| | | public void hazmatUse(Long hazmatId) { |
| | | public void hazmatUse(Long hazmatId, Integer used) { |
| | | SysUser currentUser=SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(null,currentUser); |
| | | //设置分表id |
| | |
| | | checkUserAllowed(hazmat,currentUser); |
| | | //获取变动前仓库库存 |
| | | int count = baseMapper.selectHazmatCountOfWarehouse(hazmat.getWarehouseId(), hazmat.getBasicId(), currentUser.getCompanyId()); |
| | | hazmat.setState(HazmatStatusEnum.USING.getCode()); |
| | | hazmat.setUpdateBy(currentUser.getUsername()); |
| | | updateById(hazmat); |
| | | |
| | | //生成流向 |
| | | BigDecimal remaining=hazmat.getRemaining(); |
| | | HzHazmatFlow hazmatFlow=new HzHazmatFlow(); |
| | | hazmatFlow.setHazmatId(hazmatId); |
| | | hazmatFlow.setBasicId(hazmat.getBasicId()); |
| | | hazmatFlow.setState(OperateStatusEnum.USING.getCode()); |
| | | hazmatFlow.setCompanyId(currentUser.getCompanyId()); |
| | | hazmatFlow.setNum(hazmat.getRemaining().multiply(BigDecimal.valueOf(-1))); |
| | | hazmatFlow.setNum(remaining.multiply(BigDecimal.valueOf(-1))); |
| | | hazmatFlow.setCreateId(currentUser.getId()); |
| | | hazmatFlowMapper.insert(hazmatFlow); |
| | | hazmat.setState(HazmatStatusEnum.USING.getCode()); |
| | | if(used==1){//用尽流向 |
| | | hazmatFlow=new HzHazmatFlow(); |
| | | hazmatFlow.setHazmatId(hazmatId); |
| | | hazmatFlow.setBasicId(hazmat.getBasicId()); |
| | | hazmatFlow.setState(OperateStatusEnum.USE_UP.getCode()); |
| | | hazmatFlow.setCompanyId(currentUser.getCompanyId()); |
| | | hazmatFlow.setNum(remaining.multiply(BigDecimal.valueOf(-1))); |
| | | hazmatFlow.setCreateId(currentUser.getId()); |
| | | hazmatFlowMapper.insert(hazmatFlow); |
| | | hazmat.setState(HazmatStatusEnum.USED.getCode()); |
| | | hazmat.setRemaining(BigDecimal.valueOf(0)); |
| | | } |
| | | hazmat.setUpdateBy(currentUser.getUsername()); |
| | | updateById(hazmat);//更新试剂状态 |
| | | //生成库存变动记录 |
| | | //新增危化品变动记录 |
| | | HzWarehouseRecord warehouseRecord = new HzWarehouseRecord() |
| | |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | HzHazmat dbhazmat=getById(hazmat.getId()); |
| | | if(!dbhazmat.getState().equals(HazmatStatusEnum.USING.getCode())){ |
| | | throw new ApiException("危化品非使用中状态,不能进行归还操作"); |
| | | BigDecimal remaining=dbhazmat.getRemaining(); |
| | | if(!dbhazmat.getState().equals(HazmatStatusEnum.USING.getCode())&&!dbhazmat.getState().equals(HazmatStatusEnum.USED.getCode())){ |
| | | throw new ApiException("危化品非使用中或者用尽状态,不能进行归还操作"); |
| | | } |
| | | if(dbhazmat.getRemaining().compareTo(hazmat.getRemaining())<0){ |
| | | if(dbhazmat.getState().equals(HazmatStatusEnum.USING.getCode())&&remaining.compareTo(hazmat.getRemaining())<0){ |
| | | throw new ApiException("退还的容量不能高于库存容量"); |
| | | } |
| | | if(dbhazmat.getState().equals(HazmatStatusEnum.USED.getCode())){ |
| | | HzHazmatBasic hazmatBasic=hazmatBasicMapper.selectById(dbhazmat.getBasicId()); |
| | | if(hazmatBasic.getMetering().compareTo(hazmat.getRemaining())<0) { |
| | | throw new ApiException("退还的容量不能高于最小包装数量"); |
| | | } |
| | | } |
| | | checkUserAllowed(dbhazmat,currentUser); |
| | | //获取变动前仓库库存 |
| | |
| | | if(!hazmat.getState().equals(HazmatStatusEnum.USING.getCode())){ |
| | | throw new ApiException("危化品非使用中状态,不能进行用完登记操作"); |
| | | } |
| | | |
| | | BigDecimal remaining=hazmat.getRemaining(); |
| | | hazmat.setState(HazmatStatusEnum.USED.getCode()); |
| | | hazmat.setRemaining(BigDecimal.valueOf(0)); |
| | | hazmat.setUpdateBy(currentUser.getUsername()); |
| | | updateById(hazmat); |
| | | //生成流向 |
| | |
| | | hazmatFlow.setBasicId(hazmat.getBasicId()); |
| | | hazmatFlow.setState(OperateStatusEnum.USE_UP.getCode()); |
| | | hazmatFlow.setCompanyId(currentUser.getCompanyId()); |
| | | hazmatFlow.setNum(hazmat.getRemaining().multiply(BigDecimal.valueOf(-1))); |
| | | hazmatFlow.setNum(remaining.multiply(BigDecimal.valueOf(-1))); |
| | | hazmatFlow.setCreateId(currentUser.getId()); |
| | | hazmatFlowMapper.insert(hazmatFlow); |
| | | IdTableNameHandler.removeCurrentId(); |
| | |
| | | IdTableNameHandler.removeCurrentId(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = RuntimeException.class) |
| | | public void changeRemaining(HzHazmat hazmat) { |
| | | if(hazmat.getId()==null||hazmat.getRemaining()==null){ |
| | | throw new ApiException("参数不正确"); |
| | | } |
| | | SysUser currentUser=SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(null,currentUser); |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | HzHazmat dbHazmat=getById(hazmat.getId()); |
| | | checkUserAllowed(dbHazmat,currentUser); |
| | | if(hazmat.getRemaining().compareTo(dbHazmat.getRemaining())>=0){ |
| | | throw new ApiException("修改值不能大于等于在库容量"); |
| | | } |
| | | //校验是否产生流向 |
| | | Long flowCount=hazmatFlowMapper.selectCount(Wrappers.<HzHazmatFlow>lambdaQuery().eq(HzHazmatFlow::getHazmatId,hazmat.getId()) |
| | | .ne(HzHazmatFlow::getState,OperateStatusEnum.ENTRY.getCode())); |
| | | if(flowCount>0){ |
| | | throw new ApiException("该危化品已流转,不能修改!"); |
| | | } |
| | | HzHazmat newHazmat=new HzHazmat().setId(hazmat.getId()).setRemaining(hazmat.getRemaining()); |
| | | newHazmat.setUpdateBy(currentUser.getUsername()); |
| | | updateById(newHazmat); |
| | | //生成流向 |
| | | HzHazmatFlow hazmatFlow=new HzHazmatFlow(); |
| | | hazmatFlow.setHazmatId(hazmat.getId()); |
| | | hazmatFlow.setBasicId(dbHazmat.getBasicId()); |
| | | hazmatFlow.setState(OperateStatusEnum.REMNANT.getCode()); |
| | | hazmatFlow.setCompanyId(currentUser.getCompanyId()); |
| | | hazmatFlow.setNum(hazmat.getRemaining()); |
| | | hazmatFlow.setCreateId(currentUser.getId()); |
| | | hazmatFlowMapper.insert(hazmatFlow); |
| | | IdTableNameHandler.removeCurrentId(); |
| | | } |
| | | |
| | | public void checkUserAllowed(HzHazmat hazmat,SysUser user) { |
| | | if (user.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())) { |
| | | throw new ApiException("管理员不能操作"); |