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.common.core.util.R;
|
import com.by4cloud.platformx.device.entity.*;
|
import com.by4cloud.platformx.device.mapper.*;
|
import com.by4cloud.platformx.device.service.DeviceLeasingLedgerService;
|
import lombok.AllArgsConstructor;
|
import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
/**
|
* 设备租赁台账
|
*
|
* @author syt
|
* @date 2025-03-27 09:30:29
|
*/
|
@Service
|
@AllArgsConstructor
|
public class DeviceLeasingLedgerServiceImpl extends ServiceImpl<DeviceLeasingLedgerMapper, DeviceLeasingLedger> implements DeviceLeasingLedgerService {
|
|
private final DeviceMapper deviceMapper;
|
private final DeviceLeasingLedgerItemMapper itemMapper;
|
private final ContractItemMapper contractItemMapper;
|
private final ContractMapper contractMapper;
|
private final DeviceInventoryMapper inventoryMapper;
|
private final InventoryFlowWaterMapper inventoryFlowWaterMapper;
|
|
@Override
|
public List<DeviceLeasingLedger> getSelectList() {
|
QueryWrapper<DeviceLeasingLedger> queryWrapper = new QueryWrapper<>();
|
List<DeviceLeasingLedger> list = baseMapper.selectList(queryWrapper);
|
return list;
|
}
|
|
@Override
|
public List<Device> getDeviceSelectList(Long ledgerId) {
|
List<Device> list = deviceMapper.getDeviceSelectListByLedgerId(ledgerId);
|
return list;
|
}
|
|
@Override
|
public R saveDeep(DeviceLeasingLedger deviceLeasingLedger) {
|
//明细设备数量与合同中签订数据比对
|
QueryWrapper<Contract> contractQueryWrapper = new QueryWrapper<>();
|
contractQueryWrapper.eq("number",deviceLeasingLedger.getContractCode());
|
Contract contract = contractMapper.selectOne(contractQueryWrapper);
|
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()!=deviceLeasingLedger.getLedgerItemList().size()){
|
return R.failed("合同中设备种类与台账明细中不一致");
|
}
|
|
//比较单个设备台账数量是否与合同中一致
|
for (ContractItem contractItem:list
|
) {
|
for (DeviceLeasingLedgerItem item:deviceLeasingLedger.getLedgerItemList()
|
) {
|
if (contractItem.getDeviceId()==item.getDeviceId()){
|
if (contractItem.getNum()!=item.getNum()) {
|
return R.failed("合同中"+contract.getName()+"设备数量与台账明细中不一致");
|
}
|
}
|
}
|
}
|
|
//入库
|
baseMapper.insert(deviceLeasingLedger);
|
for (DeviceLeasingLedgerItem item:deviceLeasingLedger.getLedgerItemList()
|
) {
|
item.setLedgerId(deviceLeasingLedger.getId());
|
itemMapper.insert(item);
|
for (String serialNo:item.getSerialNos()
|
) {
|
Device device = deviceMapper.selectById(item.getDeviceId());
|
if (device!=null) {
|
DeviceInventory inventory = new DeviceInventory();
|
inventory.setDeviceId(item.getDeviceId());
|
inventory.setDeviceNumber(item.getDeviceCode());
|
inventory.setName(device.getName());
|
inventory.setSerialNo(serialNo);
|
//根据合同类型 购买 承租 合同类型为入库操作
|
if (contract!=null&&(contract.getType()==1||contract.getType()==2)){
|
inventory.setSource(1);
|
//入库操作 库存状态为 可用
|
inventory.setInventoryStatus(1);
|
}
|
//根据合同类型 租赁 合同类型为出库操作
|
if (contract!=null&&contract.getType()==0){
|
inventory.setSource(0);
|
//出库操作 库存状态为 租赁中
|
inventory.setInventoryStatus(2);
|
}
|
//库存调整
|
inventoryMapper.insert(inventory);
|
|
//设备库存流水同步新增
|
InventoryFlowWater flowWater = new InventoryFlowWater();
|
flowWater.setDeviceId(item.getDeviceId());
|
flowWater.setSerialNo(serialNo);
|
flowWater.setInventoryId(inventory.getId());
|
flowWater.setClassId(device.getClassId());
|
//根据合同类型 购买 承租 流水操作类型为入库操作
|
if (contract!=null&&(contract.getType()==1||contract.getType()==2)){
|
flowWater.setOperateType(2);
|
}
|
//根据合同类型 租赁 流水操作类型为出库操作
|
if (contract!=null&&contract.getType()==0){
|
flowWater.setOperateType(1);
|
}
|
//记录库存流水
|
inventoryFlowWaterMapper.insert(flowWater);
|
}
|
}
|
}
|
|
//更新合同状态为完成
|
contract.setStatus(2);
|
contractMapper.updateById(contract);
|
|
return R.ok();
|
}
|
|
@Override
|
public List<DeviceInventory> getLedgerDeviceList(Long deviceId) {
|
QueryWrapper<DeviceInventory> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("device_id",deviceId);
|
queryWrapper.eq("inventory_status",1);
|
List<DeviceInventory> list = inventoryMapper.selectList(queryWrapper);
|
return list;
|
}
|
|
@Override
|
public DeviceLeasingLedger getByIdDeep(Long id) {
|
DeviceLeasingLedger deviceLeasingLedger = baseMapper.selectById(id);
|
QueryWrapper<DeviceLeasingLedgerItem> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("ledger_id",id);
|
List<DeviceLeasingLedgerItem> itemList = itemMapper.selectList(queryWrapper);
|
deviceLeasingLedger.setLedgerItemList(itemList);
|
return deviceLeasingLedger;
|
}
|
}
|