| | |
| | | package com.by4cloud.platformx.device.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | import com.by4cloud.platformx.device.entity.Contract; |
| | | import com.by4cloud.platformx.device.entity.ContractItem; |
| | | import com.by4cloud.platformx.device.mapper.ContractItemMapper; |
| | | import com.by4cloud.platformx.device.mapper.ContractMapper; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | | import com.by4cloud.platformx.device.constant.CommonStatusContant; |
| | | import com.by4cloud.platformx.device.entity.*; |
| | | import com.by4cloud.platformx.device.mapper.*; |
| | | import com.by4cloud.platformx.device.service.ContractService; |
| | | import org.springframework.stereotype.Service; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import lombok.RequiredArgsConstructor; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | /** |
| | | * 合同表 |
| | |
| | | @RequiredArgsConstructor |
| | | public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> implements ContractService { |
| | | private final ContractItemMapper contractItemMapper; |
| | | private final DeviceLeasingLedgerMapper leasingLedgerMapper; |
| | | private final DeviceLeasingLedgerItemMapper ledgerItemMapper; |
| | | private final DeviceInventoryMapper inventoryMapper; |
| | | private final InventoryFlowWaterMapper flowWaterMapper; |
| | | private final DeviceMapper deviceMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean saveDeep(Contract contract) { |
| | | contract.setStatus(CommonStatusContant.CONTRACT_STATUS_PENDING_APPROVAL); |
| | | baseMapper.insert(contract); |
| | | for (ContractItem contractItem : contract.getContractItemList()) { |
| | | contractItem.setContractId(contract.getId()); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean updateDeep(Contract contract) { |
| | | baseMapper.updateById(contract); |
| | | for (ContractItem contractItem : contract.getContractItemList()) { |
| | | if (Objects.isNull(contractItem.getId())) { |
| | | contractItem.setContractId(contract.getId()); |
| | | contractItemMapper.insert(contractItem); |
| | | } else { |
| | | contractItemMapper.updateById(contractItem); |
| | | } |
| | | } |
| | | if (contract.getContractItemList() != null&&contract.getContractItemList().size()>0) { |
| | | QueryWrapper<ContractItem> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("contract_id",contract.getId()); |
| | | contractItemMapper.delete(queryWrapper); |
| | | for (ContractItem contractItem : contract.getContractItemList()) { |
| | | contractItem.setId(null); |
| | | contractItem.setContractId(contract.getId()); |
| | | contractItemMapper.insert( contractItem); |
| | | } |
| | | } |
| | | |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | |
| | | contractItemMapper.deleteBatchIds(CollUtil.toList(ids)); |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | | @Override |
| | | public Contract getDetailById(Long id) { |
| | | Contract contract = baseMapper.selectById(id); |
| | | QueryWrapper<ContractItem> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("contract_id",id); |
| | | List<ContractItem> itemList = contractItemMapper.selectList(queryWrapper); |
| | | contract.setContractItemList(itemList); |
| | | return contract; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean approved(Long id) { |
| | | Contract contract = baseMapper.selectById(id); |
| | | contract.setStatus(CommonStatusContant.CONTRACT_STATUS_APPROVED); |
| | | baseMapper.updateById(contract); |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | | @Override |
| | | public List<Contract> getApprovedContractList() { |
| | | QueryWrapper<Contract> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("status",CommonStatusContant.CONTRACT_STATUS_APPROVED); |
| | | List<Contract> list = baseMapper.selectList(queryWrapper); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public R approvelInvalid(Long id) { |
| | | Contract contract = baseMapper.selectById(id); |
| | | contract.setStatus(CommonStatusContant.CONTRACT_STATUS_INVALID_PENDING_APPROVAL); |
| | | baseMapper.updateById(contract); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public R invalidById(Long id) { |
| | | Contract contract = baseMapper.selectById(id); |
| | | contract.setStatus(CommonStatusContant.CONTRACT_STATUS_INVALID); |
| | | baseMapper.updateById(contract); |
| | | //根据合同查找相关租赁台账 |
| | | QueryWrapper<DeviceLeasingLedger> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("contract_id",id); |
| | | DeviceLeasingLedger ledger = leasingLedgerMapper.selectOne(queryWrapper); |
| | | if (ledger!=null){ |
| | | //查找相关台账明细 |
| | | QueryWrapper<DeviceLeasingLedgerItem> ledgerItemQueryWrapper = new QueryWrapper<>(); |
| | | ledgerItemQueryWrapper.eq("ledger_id",ledger.getId()); |
| | | List<DeviceLeasingLedgerItem> ledgerItemList = ledgerItemMapper.selectList(ledgerItemQueryWrapper); |
| | | if(ledgerItemList.size()>0){ |
| | | //根据台账明细查询设备库存 |
| | | ledgerItemList.stream().forEach(deviceLeasingLedgerItem -> { |
| | | QueryWrapper<DeviceInventory> inventoryQueryWrapper = new QueryWrapper<>(); |
| | | inventoryQueryWrapper.eq("ledger_item_id",deviceLeasingLedgerItem.getId()); |
| | | List<DeviceInventory> inventoryList = inventoryMapper.selectList(inventoryQueryWrapper); |
| | | //将设备库存状态更为可用 |
| | | if (inventoryList.size()>0){ |
| | | inventoryList.stream().forEach(deviceInventory -> { |
| | | deviceInventory.setInventoryStatus(CommonStatusContant.DEVICE_INVENTORY_USABLE); |
| | | inventoryMapper.updateById(deviceInventory); |
| | | //库存流水 |
| | | InventoryFlowWater flowWater = new InventoryFlowWater(); |
| | | flowWater.setDeviceId(deviceInventory.getDeviceId()); |
| | | Device device = deviceMapper.selectById(deviceInventory.getDeviceId()); |
| | | if (device!=null){ |
| | | flowWater.setClassId(device.getClassId()); |
| | | } |
| | | flowWater.setInventoryId(deviceInventory.getId()); |
| | | flowWater.setSerialNo(deviceInventory.getSerialNo()); |
| | | flowWater.setOperateType(CommonStatusContant.DEVICE_INVENTORY_FLOW_WATER_IN); |
| | | flowWaterMapper.insert(flowWater); |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |