|
@ -8,10 +8,12 @@ import com.win.framework.common.exception.util.ServiceExceptionUtil; |
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
import com.win.module.eam.controller.itemaccounts.vo.*; |
|
|
import com.win.module.eam.controller.itemaccounts.vo.*; |
|
|
|
|
|
import com.win.module.eam.controller.transaction.vo.TransactionCreateReqVO; |
|
|
import com.win.module.eam.convert.itemaccounts.ItemAccountsConvert; |
|
|
import com.win.module.eam.convert.itemaccounts.ItemAccountsConvert; |
|
|
import com.win.module.eam.dal.dataobject.devicemaintenancejob.DeviceMaintenanceJobMainDO; |
|
|
import com.win.module.eam.dal.dataobject.devicemaintenancejob.DeviceMaintenanceJobMainDO; |
|
|
import com.win.module.eam.dal.dataobject.item.ItemDO; |
|
|
import com.win.module.eam.dal.dataobject.item.ItemDO; |
|
|
import com.win.module.eam.dal.dataobject.itemaccounts.ItemAccountsDO; |
|
|
import com.win.module.eam.dal.dataobject.itemaccounts.ItemAccountsDO; |
|
|
|
|
|
import com.win.module.eam.dal.dataobject.iteminlocation.ItemInLocationDO; |
|
|
import com.win.module.eam.dal.dataobject.itemlocationreplace.ItemLocationReplaceDO; |
|
|
import com.win.module.eam.dal.dataobject.itemlocationreplace.ItemLocationReplaceDO; |
|
|
import com.win.module.eam.dal.dataobject.itemnewturnin.ItemNewTurnInDO; |
|
|
import com.win.module.eam.dal.dataobject.itemnewturnin.ItemNewTurnInDO; |
|
|
import com.win.module.eam.dal.dataobject.location.LocationDO; |
|
|
import com.win.module.eam.dal.dataobject.location.LocationDO; |
|
@ -22,6 +24,8 @@ import com.win.module.eam.dal.mysql.itemnewturnin.ItemNewTurnInMapper; |
|
|
import com.win.module.eam.dal.mysql.location.LocationMapper; |
|
|
import com.win.module.eam.dal.mysql.location.LocationMapper; |
|
|
import com.win.module.eam.enums.basic.BooleanTypeEnum; |
|
|
import com.win.module.eam.enums.basic.BooleanTypeEnum; |
|
|
import com.win.module.eam.enums.itemAccount.ItemAccountStatusEnum; |
|
|
import com.win.module.eam.enums.itemAccount.ItemAccountStatusEnum; |
|
|
|
|
|
import com.win.module.eam.enums.transaction.TransactionEnum; |
|
|
|
|
|
import com.win.module.eam.service.transaction.TransactionService; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.validation.annotation.Validated; |
|
|
import org.springframework.validation.annotation.Validated; |
|
@ -35,6 +39,7 @@ import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
|
|
import static com.win.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
|
|
import static com.win.module.eam.enums.ErrorCodeConstants.*; |
|
|
import static com.win.module.eam.enums.ErrorCodeConstants.*; |
|
|
import static com.win.module.eam.enums.ErrorCodeConstants.CLASSTYPR_NO_NOMAL; |
|
|
import static com.win.module.eam.enums.ErrorCodeConstants.CLASSTYPR_NO_NOMAL; |
|
|
|
|
|
|
|
@ -62,31 +67,60 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { |
|
|
@Resource |
|
|
@Resource |
|
|
private ItemNewTurnInMapper itemNewTurnInMapper; |
|
|
private ItemNewTurnInMapper itemNewTurnInMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private TransactionService transactionService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|
|
|
@Transactional |
|
|
public Long createItemAccounts(ItemAccountsCreateReqVO createReqVO) { |
|
|
public Long createItemAccounts(ItemAccountsCreateReqVO createReqVO) { |
|
|
|
|
|
validate(createReqVO.getItemNumber(),createReqVO.getLocationNumber());//校验库位是否被使用
|
|
|
long id = 0; |
|
|
long id = 0; |
|
|
//校验
|
|
|
List<TransactionCreateReqVO> list = new ArrayList<>(); |
|
|
|
|
|
//账内校验
|
|
|
ItemAccountsDO itemAccountsDO = validateItemAndTypeAndLocation(createReqVO.getItemNumber(), createReqVO.getType(), createReqVO.getLocationNumber()); |
|
|
ItemAccountsDO itemAccountsDO = validateItemAndTypeAndLocation(createReqVO.getItemNumber(), createReqVO.getType(), createReqVO.getLocationNumber()); |
|
|
|
|
|
|
|
|
if(itemAccountsDO!=null){//存在则更新库存
|
|
|
if(itemAccountsDO!=null){//存在则更新库存
|
|
|
ItemAccountsDO updateObj = ItemAccountsConvert.INSTANCE.convert(createReqVO); |
|
|
ItemAccountsDO updateObj = ItemAccountsConvert.INSTANCE.convert(createReqVO); |
|
|
BigDecimal qty = itemAccountsDO.getQty(); |
|
|
BigDecimal qty = itemAccountsDO.getQty(); |
|
|
BigDecimal add = updateObj.getQty().add(qty); |
|
|
BigDecimal add = updateObj.getQty().add(qty); |
|
|
updateObj.setQty(add); |
|
|
updateObj.setQty(add); |
|
|
updateObj.setId(itemAccountsDO.getId()); |
|
|
// updateObj.setId(itemAccountsDO.getId());
|
|
|
itemAccountsMapper.updateById(updateObj); |
|
|
// itemAccountsMapper.updateById(updateObj);
|
|
|
id = updateObj.getId(); |
|
|
// id = updateObj.getId();
|
|
|
}else{ |
|
|
}else{ |
|
|
// 插入
|
|
|
// 插入
|
|
|
ItemAccountsDO itemAccounts = ItemAccountsConvert.INSTANCE.convert(createReqVO); |
|
|
//ItemAccountsDO itemAccounts = ItemAccountsConvert.INSTANCE.convert(createReqVO);
|
|
|
itemAccountsMapper.insert(itemAccounts); |
|
|
//itemAccountsMapper.insert(itemAccounts);
|
|
|
id = itemAccounts.getId(); |
|
|
//id = itemAccounts.getId();
|
|
|
} |
|
|
} |
|
|
|
|
|
//添加库存事务
|
|
|
|
|
|
TransactionCreateReqVO transactionCreateReqVO = new TransactionCreateReqVO(); |
|
|
|
|
|
transactionCreateReqVO.setItemNumber(createReqVO.getItemNumber()); |
|
|
|
|
|
transactionCreateReqVO.setLocationNumber(createReqVO.getLocationNumber()); |
|
|
|
|
|
transactionCreateReqVO.setAreaNumber(createReqVO.getAreaNumber()); |
|
|
|
|
|
transactionCreateReqVO.setTransactionType("IN"); |
|
|
|
|
|
transactionCreateReqVO.setQty(createReqVO.getQty()); |
|
|
|
|
|
|
|
|
|
|
|
transactionCreateReqVO.setOperator(null); |
|
|
|
|
|
transactionCreateReqVO.setCreator(getLoginUserId().toString()); |
|
|
|
|
|
transactionCreateReqVO.setAssociatedNumber(String.valueOf(id)); |
|
|
|
|
|
if(createReqVO.getType().equals(ItemAccountStatusEnum.NEW.getCode())){//新到货
|
|
|
|
|
|
transactionCreateReqVO.setInventoryAction(TransactionEnum.NEW_IN.getCode()); |
|
|
|
|
|
transactionCreateReqVO.setDescribes("备件新到货入库");//描述
|
|
|
|
|
|
} |
|
|
|
|
|
if(createReqVO.getType().equals(ItemAccountStatusEnum.IN.getCode())){//账内
|
|
|
|
|
|
transactionCreateReqVO.setInventoryAction(TransactionEnum.IN_IN.getCode()); |
|
|
|
|
|
transactionCreateReqVO.setDescribes("备件账内入库");//描述
|
|
|
|
|
|
} |
|
|
|
|
|
transactionCreateReqVO.setType(createReqVO.getType()); |
|
|
|
|
|
list.add(transactionCreateReqVO); |
|
|
|
|
|
transactionService.create(list); |
|
|
|
|
|
|
|
|
return id; |
|
|
return id; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|
|
|
@Transactional |
|
|
public Long createIn(ItemAccountsCreateReqVO createReqVO) { |
|
|
public Long createIn(ItemAccountsCreateReqVO createReqVO) { |
|
|
long id = 0; |
|
|
long id = 0; |
|
|
//校验
|
|
|
//校验
|
|
@ -117,6 +151,7 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { |
|
|
if(itemAccountsDO==null){//
|
|
|
if(itemAccountsDO==null){//
|
|
|
throw exception(ITEM_TYPE_LOCATION_EXIST);//新到货数据不存在
|
|
|
throw exception(ITEM_TYPE_LOCATION_EXIST);//新到货数据不存在
|
|
|
} |
|
|
} |
|
|
|
|
|
List<TransactionCreateReqVO> list = new ArrayList<>(); |
|
|
ItemNewTurnInDO itemNewTurnInDO = new ItemNewTurnInDO();//变更记录
|
|
|
ItemNewTurnInDO itemNewTurnInDO = new ItemNewTurnInDO();//变更记录
|
|
|
newqty = createReqVO.getQty(); |
|
|
newqty = createReqVO.getQty(); |
|
|
//查询有无账内库存
|
|
|
//查询有无账内库存
|
|
@ -127,16 +162,15 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { |
|
|
queryWrapper.eq("available","TRUE"); |
|
|
queryWrapper.eq("available","TRUE"); |
|
|
List<ItemAccountsDO> itemAccountsDOS = itemAccountsMapper.selectList(queryWrapper); |
|
|
List<ItemAccountsDO> itemAccountsDOS = itemAccountsMapper.selectList(queryWrapper); |
|
|
if(!itemAccountsDOS.isEmpty()){//有数据更新
|
|
|
if(!itemAccountsDOS.isEmpty()){//有数据更新
|
|
|
|
|
|
|
|
|
//往账内添加库存
|
|
|
//往账内添加库存
|
|
|
BigDecimal qty = itemAccountsDOS.get(0).getQty(); |
|
|
BigDecimal qty = itemAccountsDOS.get(0).getQty(); |
|
|
BigDecimal add = newqty.add(qty); |
|
|
BigDecimal add = newqty.add(qty); |
|
|
ItemAccountsDO itemAccountsDO1 = new ItemAccountsDO(); |
|
|
//ItemAccountsDO itemAccountsDO1 = new ItemAccountsDO();
|
|
|
itemAccountsDO1.setId(itemAccountsDOS.get(0).getId()); |
|
|
//itemAccountsDO1.setId(itemAccountsDOS.get(0).getId());
|
|
|
itemAccountsDO1.setQty(add); |
|
|
//itemAccountsDO1.setQty(add);
|
|
|
int i = itemAccountsMapper.updateById(itemAccountsDO1); |
|
|
//int i = itemAccountsMapper.updateById(itemAccountsDO1);
|
|
|
//记录新到货转账内
|
|
|
//记录新到货转账内
|
|
|
id = itemAccountsDO1.getId(); |
|
|
//id = itemAccountsDO1.getId();
|
|
|
itemNewTurnInDO.setType("3"); |
|
|
itemNewTurnInDO.setType("3"); |
|
|
itemNewTurnInDO.setItemNumber(createReqVO.getItemNumber()); |
|
|
itemNewTurnInDO.setItemNumber(createReqVO.getItemNumber()); |
|
|
itemNewTurnInDO.setAreaNumber(createReqVO.getAreaNumber()); |
|
|
itemNewTurnInDO.setAreaNumber(createReqVO.getAreaNumber()); |
|
@ -144,12 +178,27 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { |
|
|
itemNewTurnInDO.setNewQty(newqty); |
|
|
itemNewTurnInDO.setNewQty(newqty); |
|
|
itemNewTurnInDO.setInQty(itemAccountsDOS.get(0).getQty()); |
|
|
itemNewTurnInDO.setInQty(itemAccountsDOS.get(0).getQty()); |
|
|
itemNewTurnInDO.setQty(add); |
|
|
itemNewTurnInDO.setQty(add); |
|
|
|
|
|
|
|
|
|
|
|
//添加库存事务
|
|
|
|
|
|
TransactionCreateReqVO transactionCreateReqVO = new TransactionCreateReqVO(); |
|
|
|
|
|
transactionCreateReqVO.setItemNumber(createReqVO.getItemNumber()); |
|
|
|
|
|
transactionCreateReqVO.setLocationNumber(createReqVO.getLocationNumber()); |
|
|
|
|
|
transactionCreateReqVO.setAreaNumber(createReqVO.getAreaNumber()); |
|
|
|
|
|
transactionCreateReqVO.setTransactionType("IN"); |
|
|
|
|
|
transactionCreateReqVO.setQty(createReqVO.getQty()); |
|
|
|
|
|
transactionCreateReqVO.setDescribes("新到货转账内往账内添加数据");//描述
|
|
|
|
|
|
transactionCreateReqVO.setOperator(null); |
|
|
|
|
|
transactionCreateReqVO.setCreator(getLoginUserId().toString()); |
|
|
|
|
|
transactionCreateReqVO.setAssociatedNumber(String.valueOf(id)); |
|
|
|
|
|
transactionCreateReqVO.setInventoryAction(TransactionEnum.NEW_TURN_IN.getCode()); |
|
|
|
|
|
transactionCreateReqVO.setType(ItemAccountStatusEnum.IN.getCode()); |
|
|
|
|
|
list.add(transactionCreateReqVO); |
|
|
}else{//无数据插入
|
|
|
}else{//无数据插入
|
|
|
ItemAccountsDO itemAccounts = ItemAccountsConvert.INSTANCE.convert(createReqVO); |
|
|
ItemAccountsDO itemAccounts = ItemAccountsConvert.INSTANCE.convert(createReqVO); |
|
|
itemAccounts.setType(ItemAccountStatusEnum.IN.getCode()); |
|
|
itemAccounts.setType(ItemAccountStatusEnum.IN.getCode()); |
|
|
itemAccounts.setId(null); |
|
|
itemAccounts.setId(null); |
|
|
itemAccountsMapper.insert(itemAccounts); |
|
|
//itemAccountsMapper.insert(itemAccounts);
|
|
|
id = itemAccounts.getId(); |
|
|
//id = itemAccounts.getId();
|
|
|
itemNewTurnInDO.setType("2"); |
|
|
itemNewTurnInDO.setType("2"); |
|
|
itemNewTurnInDO.setItemNumber(itemAccounts.getItemNumber()); |
|
|
itemNewTurnInDO.setItemNumber(itemAccounts.getItemNumber()); |
|
|
itemNewTurnInDO.setAreaNumber(itemAccounts.getAreaNumber()); |
|
|
itemNewTurnInDO.setAreaNumber(itemAccounts.getAreaNumber()); |
|
@ -159,19 +208,27 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { |
|
|
} |
|
|
} |
|
|
//记录表
|
|
|
//记录表
|
|
|
itemNewTurnInMapper.insert(itemNewTurnInDO); |
|
|
itemNewTurnInMapper.insert(itemNewTurnInDO); |
|
|
|
|
|
|
|
|
|
|
|
//BigDecimal qty = itemAccountsDO.getQty();
|
|
|
|
|
|
//BigDecimal difference = qty.subtract(newqty);
|
|
|
|
|
|
//itemAccountsDO.setQty(difference);
|
|
|
|
|
|
//itemAccountsMapper.updateById(itemAccountsDO);
|
|
|
//更新新到货数量
|
|
|
//更新新到货数量
|
|
|
BigDecimal qty = itemAccountsDO.getQty(); |
|
|
//添加库存事务
|
|
|
// if(qty.compareTo(newqty) == 0){//等于删除
|
|
|
TransactionCreateReqVO transactionCreateReqVO = new TransactionCreateReqVO(); |
|
|
// itemAccountsMapper.deleteById(createReqVO.getId());
|
|
|
transactionCreateReqVO.setItemNumber(createReqVO.getItemNumber()); |
|
|
// }else{//更新数量
|
|
|
transactionCreateReqVO.setLocationNumber(createReqVO.getLocationNumber()); |
|
|
// BigDecimal difference = qty.subtract(newqty);
|
|
|
transactionCreateReqVO.setAreaNumber(createReqVO.getAreaNumber()); |
|
|
// itemAccountsDO.setQty(difference);
|
|
|
transactionCreateReqVO.setTransactionType("OUT"); |
|
|
// itemAccountsMapper.updateById(itemAccountsDO);
|
|
|
transactionCreateReqVO.setQty(createReqVO.getQty()); |
|
|
// }
|
|
|
transactionCreateReqVO.setDescribes("新到货转账内出库数量");//描述
|
|
|
BigDecimal difference = qty.subtract(newqty); |
|
|
transactionCreateReqVO.setOperator(null); |
|
|
itemAccountsDO.setQty(difference); |
|
|
transactionCreateReqVO.setType(ItemAccountStatusEnum.NEW.getCode()); |
|
|
itemAccountsMapper.updateById(itemAccountsDO); |
|
|
transactionCreateReqVO.setCreator(getLoginUserId().toString()); |
|
|
//itemAccountsMapper.deleteById(createReqVO.getId());
|
|
|
transactionCreateReqVO.setAssociatedNumber(String.valueOf(itemAccountsDO.getId())); |
|
|
|
|
|
transactionCreateReqVO.setInventoryAction(TransactionEnum.NEW_TURN_OUT.getCode()); |
|
|
|
|
|
list.add(transactionCreateReqVO); |
|
|
|
|
|
transactionService.create(list); |
|
|
return id; |
|
|
return id; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -393,19 +450,11 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public BigDecimal getAllByLocation(String locationNumber) { |
|
|
public BigDecimal getAllByLocation(String locationNumber) { |
|
|
BigDecimal qty = BigDecimal.ZERO; |
|
|
return itemAccountsMapper.getAllByLocation(locationNumber); |
|
|
QueryWrapper<ItemAccountsDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("location_number",locationNumber); |
|
|
|
|
|
queryWrapper.eq("available","TRUE"); |
|
|
|
|
|
List<ItemAccountsDO> itemDOS = itemAccountsMapper.selectList(queryWrapper); |
|
|
|
|
|
for(ItemAccountsDO en:itemDOS){ |
|
|
|
|
|
qty = qty.add(en.getQty()); |
|
|
|
|
|
} |
|
|
|
|
|
return qty; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 新增校验备件编号+类型+库位编码唯一 |
|
|
* 账内校验备件编号+类型+库位编码唯一 |
|
|
*/ |
|
|
*/ |
|
|
private ItemAccountsDO validateItemAndTypeAndLocation(String itemNumber,String type,String locationNumber) { |
|
|
private ItemAccountsDO validateItemAndTypeAndLocation(String itemNumber,String type,String locationNumber) { |
|
|
QueryWrapper<ItemAccountsDO> queryWrapper = new QueryWrapper<>(); |
|
|
QueryWrapper<ItemAccountsDO> queryWrapper = new QueryWrapper<>(); |
|
@ -416,4 +465,19 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { |
|
|
return itemAccountsMapper.selectOne(queryWrapper); |
|
|
return itemAccountsMapper.selectOne(queryWrapper); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 备件号和库位号是否存在 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void validate(String itemNumber,String locationNumber) { |
|
|
|
|
|
QueryWrapper<ItemAccountsDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.ne("item_number",itemNumber); |
|
|
|
|
|
queryWrapper.eq("location_number",locationNumber); |
|
|
|
|
|
queryWrapper.eq("available","TRUE"); |
|
|
|
|
|
List<ItemAccountsDO> itemAccountsDOS = itemAccountsMapper.selectList(queryWrapper); |
|
|
|
|
|
if(!itemAccountsDOS.isEmpty()){ |
|
|
|
|
|
throw exception(LOCATION_EXISTS); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|