|
@@ -57,108 +57,113 @@ public class TestTableServiceImpl extends ServiceImpl<TestTableMapper, TestTable
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String addTestTable(TestTable addTestTable) throws ServiceException {
|
|
|
- //查询相同条件是否已添加过
|
|
|
- TestTable testTable=testTableMapper.selectOne(new QueryWrapper<TestTable>()
|
|
|
- .eq("type",addTestTable.getType())
|
|
|
- .eq("banci",addTestTable.getBanci())
|
|
|
- .eq("banzu",addTestTable.getBanzu())
|
|
|
- .eq("date",addTestTable.getDate()));
|
|
|
- boolean flag;
|
|
|
- InventoryTable inventoryTable=inventoryTableMapper.selectOne(new QueryWrapper<InventoryTable>()
|
|
|
- .eq("date",addTestTable.getDate()));
|
|
|
- //编辑
|
|
|
- if (testTable!=null){
|
|
|
- addTestTable.setUpdateTime(new Date());
|
|
|
- addTestTable.setId(testTable.getId());
|
|
|
- LocalDate today = addTestTable.getDate();
|
|
|
- //入库
|
|
|
- if ("入库".equals(addTestTable.getType())){
|
|
|
- inventoryTable.setInNum(addTestTable.getInNum());
|
|
|
- //库存=当天库存减原入库加新入库
|
|
|
- inventoryTable.setInventory(inventoryTable.getInventory()-testTable.getInNum()+addTestTable.getInNum());
|
|
|
- }
|
|
|
- //出库
|
|
|
- else{
|
|
|
- //出库量先减原出库量再进行累加
|
|
|
- inventoryTable.setOutNum(inventoryTable.getOutNum()-testTable.getTotal()+addTestTable.getTotal());
|
|
|
- //库存=当天库存加原出库减新出库
|
|
|
- inventoryTable.setInventory(inventoryTable.getInventory()+testTable.getTotal()-addTestTable.getTotal());
|
|
|
- }
|
|
|
- inventoryTable.setUpdateTime(new Date());
|
|
|
- inventoryTableMapper.updateById(inventoryTable);
|
|
|
- flag= this.updateById(addTestTable);
|
|
|
+ if (!"zlty".equals(addTestTable.getPassword())){
|
|
|
+ throw new ServiceException(ExceptionDefinition.PASSWORD_ERROR);
|
|
|
}
|
|
|
- //新增
|
|
|
else {
|
|
|
- addTestTable.setCreateTime(new Date());
|
|
|
- addTestTable.setUpdateTime(new Date());
|
|
|
- //获取本条数据日期
|
|
|
- LocalDate today = addTestTable.getDate();
|
|
|
- //获取前一天日期 查询前一天库存
|
|
|
- LocalDate yesterday = today.minusDays(1);
|
|
|
- InventoryTable inventoryTable1=inventoryTableMapper.selectOne(new QueryWrapper<InventoryTable>()
|
|
|
- .eq("date",yesterday));
|
|
|
- //入库
|
|
|
- if ("入库".equals(addTestTable.getType())){
|
|
|
- if (inventoryTable!=null){
|
|
|
+ //查询相同条件是否已添加过
|
|
|
+ TestTable testTable=testTableMapper.selectOne(new QueryWrapper<TestTable>()
|
|
|
+ .eq("type",addTestTable.getType())
|
|
|
+ .eq("banci",addTestTable.getBanci())
|
|
|
+ .eq("banzu",addTestTable.getBanzu())
|
|
|
+ .eq("date",addTestTable.getDate()));
|
|
|
+ boolean flag;
|
|
|
+ InventoryTable inventoryTable=inventoryTableMapper.selectOne(new QueryWrapper<InventoryTable>()
|
|
|
+ .eq("date",addTestTable.getDate()));
|
|
|
+ //编辑
|
|
|
+ if (testTable!=null){
|
|
|
+ addTestTable.setUpdateTime(new Date());
|
|
|
+ addTestTable.setId(testTable.getId());
|
|
|
+ LocalDate today = addTestTable.getDate();
|
|
|
+ //入库
|
|
|
+ if ("入库".equals(addTestTable.getType())){
|
|
|
inventoryTable.setInNum(addTestTable.getInNum());
|
|
|
- //库存=当天库存加入库
|
|
|
- inventoryTable.setInventory(inventoryTable.getInventory()+addTestTable.getInNum());
|
|
|
- inventoryTable.setUpdateTime(new Date());
|
|
|
- inventoryTableMapper.updateById(inventoryTable);
|
|
|
+ //库存=当天库存减原入库加新入库
|
|
|
+ inventoryTable.setInventory(inventoryTable.getInventory()-testTable.getInNum()+addTestTable.getInNum());
|
|
|
}
|
|
|
+ //出库
|
|
|
else{
|
|
|
- InventoryTable inventoryTable2=new InventoryTable();
|
|
|
- inventoryTable2.setCreateTime(new Date());
|
|
|
- inventoryTable2.setUpdateTime(new Date());
|
|
|
- inventoryTable2.setDate(addTestTable.getDate());
|
|
|
- inventoryTable2.setInNum(addTestTable.getInNum());
|
|
|
- //库存=前一天库存加入库
|
|
|
- if (inventoryTable1!=null){
|
|
|
- inventoryTable2.setInventory(inventoryTable1.getInventory()+addTestTable.getInNum());
|
|
|
+ //出库量先减原出库量再进行累加
|
|
|
+ inventoryTable.setOutNum(inventoryTable.getOutNum()-testTable.getTotal()+addTestTable.getTotal());
|
|
|
+ //库存=当天库存加原出库减新出库
|
|
|
+ inventoryTable.setInventory(inventoryTable.getInventory()+testTable.getTotal()-addTestTable.getTotal());
|
|
|
+ }
|
|
|
+ inventoryTable.setUpdateTime(new Date());
|
|
|
+ inventoryTableMapper.updateById(inventoryTable);
|
|
|
+ flag= this.updateById(addTestTable);
|
|
|
+ }
|
|
|
+ //新增
|
|
|
+ else {
|
|
|
+ addTestTable.setCreateTime(new Date());
|
|
|
+ addTestTable.setUpdateTime(new Date());
|
|
|
+ //获取本条数据日期
|
|
|
+ LocalDate today = addTestTable.getDate();
|
|
|
+ //获取前一天日期 查询前一天库存
|
|
|
+ LocalDate yesterday = today.minusDays(1);
|
|
|
+ InventoryTable inventoryTable1=inventoryTableMapper.selectOne(new QueryWrapper<InventoryTable>()
|
|
|
+ .eq("date",yesterday));
|
|
|
+ //入库
|
|
|
+ if ("入库".equals(addTestTable.getType())){
|
|
|
+ if (inventoryTable!=null){
|
|
|
+ inventoryTable.setInNum(addTestTable.getInNum());
|
|
|
+ //库存=当天库存加入库
|
|
|
+ inventoryTable.setInventory(inventoryTable.getInventory()+addTestTable.getInNum());
|
|
|
+ inventoryTable.setUpdateTime(new Date());
|
|
|
+ inventoryTableMapper.updateById(inventoryTable);
|
|
|
}
|
|
|
else{
|
|
|
- throw new ServiceException(ExceptionDefinition.NOT_YESTERDAY_INVENTORY);
|
|
|
+ InventoryTable inventoryTable2=new InventoryTable();
|
|
|
+ inventoryTable2.setCreateTime(new Date());
|
|
|
+ inventoryTable2.setUpdateTime(new Date());
|
|
|
+ inventoryTable2.setDate(addTestTable.getDate());
|
|
|
+ inventoryTable2.setInNum(addTestTable.getInNum());
|
|
|
+ //库存=前一天库存加入库
|
|
|
+ if (inventoryTable1!=null){
|
|
|
+ inventoryTable2.setInventory(inventoryTable1.getInventory()+addTestTable.getInNum());
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ throw new ServiceException(ExceptionDefinition.NOT_YESTERDAY_INVENTORY);
|
|
|
|
|
|
+ }
|
|
|
+ inventoryTableMapper.insert(inventoryTable2);
|
|
|
}
|
|
|
- inventoryTableMapper.insert(inventoryTable2);
|
|
|
- }
|
|
|
- }
|
|
|
- //出库
|
|
|
- else{
|
|
|
- if (inventoryTable!=null){
|
|
|
- //出库量累加
|
|
|
- inventoryTable.setOutNum(inventoryTable.getOutNum()+addTestTable.getTotal());
|
|
|
- //库存=当天库存减出库
|
|
|
- inventoryTable.setInventory(inventoryTable.getInventory()-addTestTable.getTotal());
|
|
|
- inventoryTable.setUpdateTime(new Date());
|
|
|
- inventoryTableMapper.updateById(inventoryTable);
|
|
|
}
|
|
|
+ //出库
|
|
|
else{
|
|
|
- InventoryTable inventoryTable2=new InventoryTable();
|
|
|
- inventoryTable2.setCreateTime(new Date());
|
|
|
- inventoryTable2.setUpdateTime(new Date());
|
|
|
- inventoryTable2.setDate(addTestTable.getDate());
|
|
|
- inventoryTable2.setOutNum(addTestTable.getTotal());
|
|
|
- //库存=前一天库存减出库
|
|
|
- if (inventoryTable1!=null){
|
|
|
- inventoryTable2.setInventory(inventoryTable1.getInventory()-addTestTable.getTotal());
|
|
|
+ if (inventoryTable!=null){
|
|
|
+ //出库量累加
|
|
|
+ inventoryTable.setOutNum(inventoryTable.getOutNum()+addTestTable.getTotal());
|
|
|
+ //库存=当天库存减出库
|
|
|
+ inventoryTable.setInventory(inventoryTable.getInventory()-addTestTable.getTotal());
|
|
|
+ inventoryTable.setUpdateTime(new Date());
|
|
|
+ inventoryTableMapper.updateById(inventoryTable);
|
|
|
}
|
|
|
else{
|
|
|
- throw new ServiceException(ExceptionDefinition.NOT_YESTERDAY_INVENTORY);
|
|
|
+ InventoryTable inventoryTable2=new InventoryTable();
|
|
|
+ inventoryTable2.setCreateTime(new Date());
|
|
|
+ inventoryTable2.setUpdateTime(new Date());
|
|
|
+ inventoryTable2.setDate(addTestTable.getDate());
|
|
|
+ inventoryTable2.setOutNum(addTestTable.getTotal());
|
|
|
+ //库存=前一天库存减出库
|
|
|
+ if (inventoryTable1!=null){
|
|
|
+ inventoryTable2.setInventory(inventoryTable1.getInventory()-addTestTable.getTotal());
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ throw new ServiceException(ExceptionDefinition.NOT_YESTERDAY_INVENTORY);
|
|
|
|
|
|
+ }
|
|
|
+ inventoryTableMapper.insert(inventoryTable2);
|
|
|
}
|
|
|
- inventoryTableMapper.insert(inventoryTable2);
|
|
|
}
|
|
|
+ flag= this.save(addTestTable);
|
|
|
}
|
|
|
- flag= this.save(addTestTable);
|
|
|
- }
|
|
|
|
|
|
- if(flag){
|
|
|
- return "ok";
|
|
|
- }
|
|
|
- else{
|
|
|
- throw new ServiceException(ExceptionDefinition.ADD_DATA_EXCEPTION);
|
|
|
+ if(flag){
|
|
|
+ return "ok";
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ throw new ServiceException(ExceptionDefinition.ADD_DATA_EXCEPTION);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|