Browse Source

后端测试接口

master
songguoqiang 7 months ago
parent
commit
f3a6d7e911
  1. 2
      Dockerfile
  2. 65
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/dal/mysql/itemaccounts/ItemAccountsMapper.java
  3. 72
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/itemaccounts/ItemAccountsServiceImpl.java
  4. 9
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/transaction/TransactionServiceImpl.java
  5. 14
      win-server/src/main/resources/application-test.yaml

2
Dockerfile

@ -17,7 +17,7 @@ ENV JAVA_OPTS=""
ENV ARGS=""
## 暴露后端项目的 25210 端口
EXPOSE 25210
EXPOSE 28029
## 启动后端项目
CMD java ${JAVA_OPTS} -jar win-server.jar $ARGS

65
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/dal/mysql/itemaccounts/ItemAccountsMapper.java

@ -13,6 +13,7 @@ import com.win.module.eam.controller.itemaccounts.vo.ItemAccountsExportReqVO;
import com.win.module.eam.controller.itemaccounts.vo.ItemAccountsPageReqVO;
import com.win.module.eam.convert.itemaccounts.ItemAccountsConvert;
import com.win.module.eam.dal.dataobject.itemaccounts.ItemAccountsDO;
import com.win.module.eam.dal.dataobject.transaction.TransactionDO;
import com.win.module.eam.enums.itemAccount.ItemAccountStatusEnum;
import com.win.module.eam.enums.transaction.TransactionEnum;
import com.win.module.eam.enums.transactionType.TransactionTypeEnum;
@ -20,6 +21,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -38,8 +40,9 @@ public interface ItemAccountsMapper extends BaseMapperX<ItemAccountsDO> {
/**
* 更新库存余额数量出库qty是负数
*/
default Boolean updateItemAccountsQty(ItemAccountsCreateReqVO param, String transactionType, String InventoryAction) {
default List<TransactionDO> updateItemAccountsQty(ItemAccountsCreateReqVO param, String transactionType, String InventoryAction) {
int result = 0;
List<TransactionDO> list = new ArrayList<>();
BigDecimal qtyNew = param.getQty();//增减数量
if (TransactionTypeEnum.TransactionType_OUT.getCode().equals(transactionType)) {//出库操作
if (TransactionEnum.REQUISITION_OUT.getCode().equals(InventoryAction)) {//领用出库优先账外 账内 新到货
@ -68,11 +71,21 @@ public interface ItemAccountsMapper extends BaseMapperX<ItemAccountsDO> {
if (outQty.compareTo(BigDecimal.ZERO) > 0) {//说明账外库存在且数据不为0 需要先把账外库清空
outLocation.setQty(outQty);
result = this.updateById(outLocation);
//添加库存事务
TransactionDO transactionDO = new TransactionDO();
transactionDO.setQty(outLocation.getQty());
transactionDO.setType(outLocation.getType());
list.add(transactionDO);
BigDecimal subtractOutQty = qtyNew.subtract(outQty);//差几个零件
if (inQty.compareTo(BigDecimal.ZERO) > 0 && inQty.compareTo(subtractOutQty) >= 0) {//账内库存在且大于0足够差额
BigDecimal subtractInQty = inQty.subtract(subtractOutQty);//减去之后的数量
inLocation.setQty(subtractInQty);
result = this.updateById(inLocation);
//添加库存事务
TransactionDO transactionDO1 = new TransactionDO();
transactionDO1.setQty(inLocation.getQty());
transactionDO1.setType(inLocation.getType());
list.add(transactionDO1);
}
if (inQty.compareTo(BigDecimal.ZERO) > 0 && inQty.compareTo(subtractOutQty) < 0) {//账内库存在且不足差额
inLocation.setQty(inQty);
@ -81,7 +94,12 @@ public interface ItemAccountsMapper extends BaseMapperX<ItemAccountsDO> {
if (inQty.compareTo(BigDecimal.ZERO) > 0 && inQty.compareTo(subtractInQty) >= 0) {//新到货存在且足够差额
BigDecimal subtractNewQty = newQty.subtract(subtractInQty);//减去之后的数量
newLocation.setQty(subtractNewQty);
//添加库存事务
result = this.updateById(newLocation);
TransactionDO transactionDO2 = new TransactionDO();
transactionDO2.setQty(newLocation.getQty());
transactionDO2.setType(newLocation.getType());
list.add(transactionDO2);
} else {
throw exception(COUNT_IS_HAVA);
}
@ -91,6 +109,11 @@ public interface ItemAccountsMapper extends BaseMapperX<ItemAccountsDO> {
BigDecimal subtractNewQty = newQty.subtract(subtractOutQty);//减去之后的数量
newLocation.setQty(subtractNewQty);
result = this.updateById(newLocation);
//添加库存事务
TransactionDO transactionDO3 = new TransactionDO();
transactionDO3.setQty(newLocation.getQty());
transactionDO3.setType(newLocation.getType());
list.add(transactionDO3);
} else {
throw exception(COUNT_IS_HAVA);
}
@ -101,15 +124,30 @@ public interface ItemAccountsMapper extends BaseMapperX<ItemAccountsDO> {
BigDecimal subtractInQty = inQty.subtract(qtyNew);//减去之后的数量
inLocation.setQty(subtractInQty);
result = this.updateById(inLocation);
//添加库存事务
TransactionDO transactionDO4 = new TransactionDO();
transactionDO4.setQty(inLocation.getQty());
transactionDO4.setType(inLocation.getType());
list.add(transactionDO4);
}
if (inQty.compareTo(BigDecimal.ZERO) > 0 && inQty.compareTo(qtyNew) < 0) {//账内库存在且不足差额
inLocation.setQty(inQty);
result = this.updateById(inLocation);
//添加库存事务
TransactionDO transactionDO5 = new TransactionDO();
transactionDO5.setQty(inLocation.getQty());
transactionDO5.setType(inLocation.getType());
list.add(transactionDO5);
BigDecimal subtractInQty = qtyNew.subtract(inQty);//减去之后的数量
if (inQty.compareTo(BigDecimal.ZERO) > 0 && inQty.compareTo(subtractInQty) >= 0) {//新到货存在且足够差额
BigDecimal subtractNewQty = newQty.subtract(subtractInQty);//减去之后的数量
newLocation.setQty(subtractNewQty);
result = this.updateById(newLocation);
//添加库存事务
TransactionDO transactionDO6 = new TransactionDO();
transactionDO6.setQty(newLocation.getQty());
transactionDO6.setType(newLocation.getType());
list.add(transactionDO6);
} else {
throw exception(COUNT_IS_HAVA);
}
@ -119,6 +157,11 @@ public interface ItemAccountsMapper extends BaseMapperX<ItemAccountsDO> {
BigDecimal subtractNewQty = newQty.subtract(qtyNew);//减去之后的数量
newLocation.setQty(subtractNewQty);
result = this.updateById(newLocation);
//添加库存事务
TransactionDO transactionDO7 = new TransactionDO();
transactionDO7.setQty(newLocation.getQty());
transactionDO7.setType(newLocation.getType());
list.add(transactionDO7);
} else {
throw exception(COUNT_IS_HAVA);
}
@ -128,6 +171,11 @@ public interface ItemAccountsMapper extends BaseMapperX<ItemAccountsDO> {
BigDecimal subtractOutQty = outQty.subtract(qtyNew);//减去之后的数量
outLocation.setQty(subtractOutQty);
result = this.updateById(outLocation);
//添加库存事务
TransactionDO transactionDO8 = new TransactionDO();
transactionDO8.setQty(outLocation.getQty());
transactionDO8.setType(outLocation.getType());
list.add(transactionDO8);
}
} else {//非领用出库
QueryWrapper<ItemAccountsDO> queryWrapper = new QueryWrapper<>();
@ -141,6 +189,10 @@ public interface ItemAccountsMapper extends BaseMapperX<ItemAccountsDO> {
BigDecimal subtractNewQty = itemAccountsDO.getQty().subtract(qtyNew);//减去之后的数量
itemAccountsDO.setQty(subtractNewQty);
result = this.updateById(itemAccountsDO);
TransactionDO transactionDO = new TransactionDO();
transactionDO.setQty(subtractNewQty);
transactionDO.setType(itemAccountsDO.getType());
list.add(transactionDO);
}
}
if (TransactionTypeEnum.TransactionType_IN.getCode().equals(transactionType)) {//入库操作
@ -152,15 +204,22 @@ public interface ItemAccountsMapper extends BaseMapperX<ItemAccountsDO> {
if (itemAccountsDO == null) {//不存在新增
itemAccountsDO = ItemAccountsConvert.INSTANCE.convert(param);
result = this.insert(itemAccountsDO);
TransactionDO transactionDO = new TransactionDO();
transactionDO.setQty(itemAccountsDO.getQty());
transactionDO.setType(itemAccountsDO.getType());
list.add(transactionDO);
} else {//更新
BigDecimal qty = itemAccountsDO.getQty();
BigDecimal add = qty.add(param.getQty());
itemAccountsDO.setQty(add);
result = updateById(itemAccountsDO);
TransactionDO transactionDO = new TransactionDO();
transactionDO.setQty(itemAccountsDO.getQty());
transactionDO.setType(itemAccountsDO.getType());
list.add(transactionDO);
}
}
return result > 0;
return list;
}
default PageResult<ItemAccountsDO> selectPage(ItemAccountsPageReqVO reqVO) {

72
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/itemaccounts/ItemAccountsServiceImpl.java

@ -104,7 +104,7 @@ public class ItemAccountsServiceImpl implements ItemAccountsService {
transactionCreateReqVO.setOperator(null);
transactionCreateReqVO.setCreator(getLoginUserId().toString());
transactionCreateReqVO.setAssociatedNumber(String.valueOf(id));
transactionCreateReqVO.setAssociatedNumber(null);
if(createReqVO.getType().equals(ItemAccountStatusEnum.NEW.getCode())){//新到货
transactionCreateReqVO.setInventoryAction(TransactionEnum.NEW_IN.getCode());
transactionCreateReqVO.setDescribes("备件新到货入库");//描述
@ -190,7 +190,7 @@ public class ItemAccountsServiceImpl implements ItemAccountsService {
transactionCreateReqVO.setDescribes("新到货转账内往账内添加数据");//描述
transactionCreateReqVO.setOperator(null);
transactionCreateReqVO.setCreator(getLoginUserId().toString());
transactionCreateReqVO.setAssociatedNumber(String.valueOf(id));
transactionCreateReqVO.setAssociatedNumber(null);
transactionCreateReqVO.setInventoryAction(TransactionEnum.NEW_TURN_IN.getCode());
transactionCreateReqVO.setType(ItemAccountStatusEnum.IN.getCode());
list.add(transactionCreateReqVO);
@ -347,11 +347,10 @@ public class ItemAccountsServiceImpl implements ItemAccountsService {
if (CollUtil.isEmpty(datas)) {
throw exception(ITEM_NEW_TURN_IN_IMPORT_LIST_IS_EMPTY);//导入数据不能为空
}
List<TransactionCreateReqVO> list = new ArrayList<>();
List<ItemAccountsImportExcelVO> errorList = new ArrayList<>();
datas.forEach(item -> {
//判断该备件是否在备件基础数据中无则报错
validate(item.getItemNumber(),item.getLocationNumber());//校验库位是否被使用
QueryWrapper<ItemDO> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("number",item.getItemNumber());
queryWrapper.eq("available","TRUE");
@ -372,16 +371,6 @@ public class ItemAccountsServiceImpl implements ItemAccountsService {
errorList.add(convert);
return;
}
try {
validate(item.getItemNumber(),item.getLocationNumber());//校验库位是否被使用
} catch (Exception e) {
ItemAccountsErrorVO convert = ItemAccountsConvert.INSTANCE.convert(item);
convert.setImportStatus("失败");
convert.setImportRemark("该库位已存在其他类型数据");
errorList.add(convert);
return;
}
try {
validate(item.getItemNumber(),item.getLocationNumber());//校验库位是否被使用
} catch (Exception e) {
@ -402,14 +391,63 @@ public class ItemAccountsServiceImpl implements ItemAccountsService {
if(mode != 2){// 如果存在,判断是否允许更新
ItemAccountsDO itemAccountsDO1 = ItemAccountsConvert.INSTANCE.convert1(item);
itemAccountsDO1.setId(itemAccountsDO.getId());
itemAccountsMapper.updateById(itemAccountsDO1);
//itemAccountsMapper.updateById(itemAccountsDO1);
//添加库存事务
TransactionCreateReqVO transactionCreateReqVO = new TransactionCreateReqVO();
transactionCreateReqVO.setItemNumber(itemAccountsDO1.getItemNumber());
transactionCreateReqVO.setLocationNumber(itemAccountsDO1.getLocationNumber());
transactionCreateReqVO.setAreaNumber(itemAccountsDO.getAreaNumber());
transactionCreateReqVO.setTransactionType("IN");
transactionCreateReqVO.setQty(itemAccountsDO1.getQty());
transactionCreateReqVO.setOperator(null);
transactionCreateReqVO.setCreator(getLoginUserId().toString());
transactionCreateReqVO.setAssociatedNumber(null);
if(itemAccountsDO1.getType().equals(ItemAccountStatusEnum.NEW.getCode())){//新到货
transactionCreateReqVO.setInventoryAction(TransactionEnum.NEW_IN.getCode());
transactionCreateReqVO.setDescribes("备件导入新到货入库");//描述
}
if(itemAccountsDO1.getType().equals(ItemAccountStatusEnum.IN.getCode())){//账内
transactionCreateReqVO.setInventoryAction(TransactionEnum.IN_IN.getCode());
transactionCreateReqVO.setDescribes("备件导入账内入库");//描述
}
if(itemAccountsDO1.getType().equals(ItemAccountStatusEnum.OUT.getCode())){//账外
transactionCreateReqVO.setInventoryAction(TransactionEnum.IN_IN.getCode());
transactionCreateReqVO.setDescribes("备件导入账外入库");//描述
}
transactionCreateReqVO.setType(itemAccountsDO1.getType());
list.add(transactionCreateReqVO);
}
if(itemAccountsDO==null&&mode != 3){//数据库中不存在值且不是覆盖走新增
//根据库位查询库区
ItemAccountsDO itemAccountsDO1 = ItemAccountsConvert.INSTANCE.convert1(item);
itemAccountsDO1.setAreaNumber(locationDO.getAreaNumber());
itemAccountsMapper.insert(itemAccountsDO1);
//itemAccountsMapper.insert(itemAccountsDO1);
//添加库存事务
TransactionCreateReqVO transactionCreateReqVO = new TransactionCreateReqVO();
transactionCreateReqVO.setItemNumber(itemAccountsDO1.getItemNumber());
transactionCreateReqVO.setLocationNumber(itemAccountsDO1.getLocationNumber());
transactionCreateReqVO.setAreaNumber(itemAccountsDO1.getAreaNumber());
transactionCreateReqVO.setTransactionType("IN");
transactionCreateReqVO.setQty(itemAccountsDO1.getQty());
transactionCreateReqVO.setOperator(null);
transactionCreateReqVO.setCreator(getLoginUserId().toString());
transactionCreateReqVO.setAssociatedNumber(null);
if(itemAccountsDO1.getType().equals(ItemAccountStatusEnum.NEW.getCode())){//新到货
transactionCreateReqVO.setInventoryAction(TransactionEnum.NEW_IN.getCode());
transactionCreateReqVO.setDescribes("备件导入新到货入库");//描述
}
if(itemAccountsDO1.getType().equals(ItemAccountStatusEnum.IN.getCode())){//账内
transactionCreateReqVO.setInventoryAction(TransactionEnum.IN_IN.getCode());
transactionCreateReqVO.setDescribes("备件导入账内入库");//描述
}
if(itemAccountsDO1.getType().equals(ItemAccountStatusEnum.OUT.getCode())){//账外
transactionCreateReqVO.setInventoryAction(TransactionEnum.IN_IN.getCode());
transactionCreateReqVO.setDescribes("备件导入账外入库");//描述
}
transactionCreateReqVO.setType(itemAccountsDO1.getType());
list.add(transactionCreateReqVO);
}
transactionService.create(list);
} catch (Exception e) {
ItemAccountsErrorVO convert = ItemAccountsConvert.INSTANCE.convert(item);
convert.setImportStatus("失败");
@ -419,7 +457,7 @@ public class ItemAccountsServiceImpl implements ItemAccountsService {
});
//错误不为空并非部分更新,手工回滚
if(!errorList.isEmpty() && !updatePart) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//不需要捕获异常
}
return errorList;
}

9
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/transaction/TransactionServiceImpl.java

@ -68,10 +68,15 @@ public class TransactionServiceImpl implements TransactionService {
itemDOQueryWrapper.eq("number", transactionDO.getItemNumber());
ItemDO itemDO = itemMapper.selectOne(itemDOQueryWrapper);
transactionDO.setUom(itemDO.getUom());
result += Mapper.insert(transactionDO);
//result += Mapper.insert(transactionDO);
ItemAccountsCreateReqVO itemAccountsCreateReqVO = new ItemAccountsCreateReqVO();
BeanUtils.copyProperties(transactionDO, itemAccountsCreateReqVO);
Boolean b = itemAccountsMapper.updateItemAccountsQty(itemAccountsCreateReqVO, transactionDO.getTransactionType(), transactionDO.getInventoryAction());
List<TransactionDO> transactionDOS = itemAccountsMapper.updateItemAccountsQty(itemAccountsCreateReqVO, transactionDO.getTransactionType(), transactionDO.getInventoryAction());
for(TransactionDO en:transactionDOS){//循环出库存记录
transactionDO.setType(en.getType());
transactionDO.setQty(en.getQty());
result += Mapper.insert(transactionDO);
}
}
return result;
}

14
win-server/src/main/resources/application-test.yaml

@ -1,5 +1,5 @@
server:
port: 25210
port: 25029
--- #################### 数据库相关配置 ####################
@ -22,22 +22,22 @@ spring:
master:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://dev.ccwin-in.com:23113/eam?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: eam
url: jdbc:mysql://dev.ccwin-in.com:23113/tianhe?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: tianhe
password: Microsoft@2023
# 读数据源
slave0:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://dev.ccwin-in.com:23113/eam?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: eam
url: jdbc:mysql://dev.ccwin-in.com:23113/tianhe?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: tianhe
password: Microsoft@2023
# 读数据源
slave1:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://dev.ccwin-in.com:23113/eam?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: eam
url: jdbc:mysql://dev.ccwin-in.com:23113/tianhe?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: tianhe
password: Microsoft@2023
# 读写分离类型,如: Static,Dynamic
rules:

Loading…
Cancel
Save