| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | | import com.by4cloud.platformx.device.constant.CommonStatusContant; |
| | | import com.by4cloud.platformx.device.constant.MaxSizeContant; |
| | | import com.by4cloud.platformx.device.dto.ReceivingNoteQueryDTO; |
| | | import com.by4cloud.platformx.device.entity.*; |
| | | import com.by4cloud.platformx.device.mapper.*; |
| | | import com.by4cloud.platformx.device.service.JcMaxSizeService; |
| | | import com.by4cloud.platformx.device.service.ReceivingNoteService; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 验收表 |
| | |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | @Slf4j |
| | | public class ReceivingNoteServiceImpl extends ServiceImpl<ReceivingNoteMapper, ReceivingNote> implements ReceivingNoteService { |
| | | |
| | | private final JcMaxSizeService maxSizeService; |
| | | private final ReceivingNoteItemMapper itemMapper; |
| | | private final DeviceInventoryMapper inventoryMapper; |
| | | private final InventoryFlowWaterMapper inventoryFlowWaterMapper; |
| | | private final DeviceMapper deviceMapper; |
| | | private final ContractMapper contractMapper; |
| | | private final ContractItemMapper contractItemMapper; |
| | | |
| | | @Override |
| | | public IPage pageNew(Page page, ReceivingNoteQueryDTO queryDTO) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean saveDeep(ReceivingNote entity) { |
| | | public R saveDeep(ReceivingNote entity) { |
| | | //明细设备数量与合同中签订数据比对 |
| | | Contract contract = contractMapper.selectById(entity.getContractId()); |
| | | if (contract == null) { |
| | | return R.failed("合同不存在"); |
| | | } |
| | | |
| | | //查询合同明细中设备情况 |
| | | QueryWrapper<ContractItem> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("contract_id",contract.getId()); |
| | | List<ContractItem> list = contractItemMapper.selectList(queryWrapper); |
| | | // |
| | | // //比较设备种类是否一致 |
| | | // if (list.size()!=entity.getNoteItemList().size()){ |
| | | // return R.failed("合同中设备种类与验收明细中不一致"); |
| | | // } |
| | | // |
| | | //比较单个设备台账数量是否与合同中一致 |
| | | for (ContractItem contractItem:list |
| | | ) { |
| | | for (ReceivingNoteItem item:entity.getNoteItemList() |
| | | ) { |
| | | if (contractItem.getDeviceId().equals(item.getDeviceId())){ |
| | | if (contractItem.getNum() < item.getNum()) { |
| | | return R.failed("验收明细中"+item.getDeviceName()+"设备数量不能超过合同明细中签订的设备数量"); |
| | | } |
| | | Integer deviceNum = itemMapper.selectDeviceNumByContractId(contractItem.getContractId(),item.getDeviceId()); |
| | | if (contractItem.getNum()<(deviceNum+item.getNum())){ |
| | | return R.failed("实际验收明细中"+item.getDeviceName()+"设备数量不能超过合同明细中签订的设备数量"); |
| | | } |
| | | } |
| | | //设备序列号检查是否有相同的存在 |
| | | List<String> serialArr = Arrays.stream(item.getSerialNos().split(",")).collect(Collectors.toList()); |
| | | for (String serialNo:serialArr |
| | | ) { |
| | | QueryWrapper<DeviceInventory> inventoryQueryWrapper = new QueryWrapper<>(); |
| | | inventoryQueryWrapper.eq("device_id",item.getDeviceId()); |
| | | inventoryQueryWrapper.eq("serial_no",serialNo); |
| | | List<DeviceInventory> inventoryList = inventoryMapper.selectList(inventoryQueryWrapper); |
| | | if (inventoryList!=null&&inventoryList.size()>0){ |
| | | return R.failed("合同明细中设备序列号"+serialNo+"已存在,请检查序列号"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //生成验收单编号 |
| | | entity.setReleaseCode(maxSizeService.nextNo(MaxSizeContant.RELEASE_CODE)); |
| | | //入库 |
| | | baseMapper.insert(entity); |
| | | if (entity.getNoteItemList()!=null&&entity.getNoteItemList().size()>0){ |
| | | for (ReceivingNoteItem item:entity.getNoteItemList() |
| | | ) { |
| | | List<String> serialArr = new ArrayList<>(); |
| | | if (item.getSerialNos()!=null&&!"".equals(item.getSerialNos())) { |
| | | item.setSerialNos(item.getSerialNos()); |
| | | serialArr = Arrays.stream(item.getSerialNos().split(",")).collect(Collectors.toList()); |
| | | } |
| | | item.setNoteId(entity.getId()); |
| | | itemMapper.insert(item); |
| | | //设备库存同步新增 |
| | | if (item.getSerialNos()!=null&&item.getSerialNos().size()>0){ |
| | | for (String serialNo:item.getSerialNos() |
| | | if (serialArr.size()>0){ |
| | | for (String serialNo:serialArr |
| | | ) { |
| | | Device device = deviceMapper.selectById(item.getDeviceId()); |
| | | Contract contract = contractMapper.selectById(entity.getContractId()); |
| | | if (device!=null) { |
| | | DeviceInventory inventory = new DeviceInventory(); |
| | | inventory.setDeviceId(item.getDeviceId()); |
| | |
| | | inventory.setName(device.getName()); |
| | | inventory.setSerialNo(serialNo); |
| | | if (contract!=null&&(contract.getType()==1||contract.getType()==2)){ |
| | | inventory.setSource(1); |
| | | inventory.setInventoryStatus(1); |
| | | inventory.setSource(CommonStatusContant.DEVICE_INVENTORY_RESOURCE_WAREHOUSE); |
| | | inventory.setInventoryStatus(CommonStatusContant.DEVICE_INVENTORY_USABLE); |
| | | } |
| | | if (contract!=null&&contract.getType()==0){ |
| | | inventory.setSource(1); |
| | | inventory.setInventoryStatus(2); |
| | | inventory.setSource(CommonStatusContant.DEVICE_INVENTORY_RESOURCE_WAREHOUSE); |
| | | inventory.setInventoryStatus(CommonStatusContant.DEVICE_INVENTORY_RENTING); |
| | | } |
| | | inventoryMapper.insert(inventory); |
| | | //设备库存流水同步新增 |
| | |
| | | flowWater.setOperateType(2); |
| | | } |
| | | if (contract!=null&&contract.getType()==0){ |
| | | flowWater.setOperateType(1); |
| | | flowWater.setOperateType(CommonStatusContant.DEVICE_INVENTORY_FLOW_WATER_OUT); |
| | | } |
| | | inventoryFlowWaterMapper.insert(flowWater); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | return Boolean.TRUE; |
| | | |
| | | //合同明细中与实际验收对比 |
| | | for (ContractItem contractItem:list |
| | | ) { |
| | | Integer deviceNum = itemMapper.selectDeviceNumByContractId(contractItem.getContractId(),contractItem.getDeviceId()); |
| | | if (contractItem.getNum()!=deviceNum){ |
| | | return R.ok(); |
| | | } |
| | | } |
| | | //更新合同状态为完成 |
| | | contract.setStatus(2); |
| | | contractMapper.updateById(contract); |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | note.setNoteItemList(itemList); |
| | | return note; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | int l1= 2; |
| | | int l2 = 3; |
| | | System.out.println(l1>=l2); |
| | | } |
| | | } |