ShipmentDetailServiceImpl.java
5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.huaheng.pc.shipment.shipmentDetail.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.utils.DataUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.general.material.domain.Material;
import com.huaheng.pc.general.material.service.MaterialService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.shipment.shipmentDetail.mapper.ShipmentDetailMapper;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import org.springframework.transaction.annotation.Transactional;
@Service
public class ShipmentDetailServiceImpl extends ServiceImpl<ShipmentDetailMapper, ShipmentDetail> implements ShipmentDetailService{
@Autowired
private ShipmentHeaderService shipmentHeaderService;
@Autowired
private MaterialService materialService;
@Resource
private ShipmentDetailMapper shipmentDetailMapper;
/**
* 新增出库明细
*
* @param shipmentDetail
* @return
*/
@Override
public AjaxResult insertDetail(ShipmentDetail shipmentDetail) {
//查看主单是否存在
LambdaQueryWrapper<ShipmentHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ShipmentHeader::getId,shipmentDetail.getShipmentId())
.eq(ShipmentHeader::getWarehouseCode,ShiroUtils.getWarehouseCode());
ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(lambdaQueryWrapper);
if (shipmentHeader == null) {
return AjaxResult.error("找不到主单据");
}
if (shipmentHeader.getFirstStatus() > 100) {
//表示已经加入了波次
return AjaxResult.error("主单据状态不允许新增明细");
}
//查找物料
LambdaQueryWrapper<Material> lam = Wrappers.lambdaQuery();
lam.eq(Material::getCode,shipmentDetail.getMaterialCode())
.eq(Material::getWarehouseCode,ShiroUtils.getWarehouseCode());
Material material = materialService.getOne(lam);
if (material == null) {
return AjaxResult.error("物料未找到");
}
if (StringUtils.isNotEmpty(material.getCompanyCode()) &&
ShiroUtils.getCompanyCodeList().contains(material.getCompanyCode()) == false)
{
return AjaxResult.error("物料不属于当前货主!");
}
shipmentDetail.setId(null);
shipmentDetail.setWarehouseCode(ShiroUtils.getWarehouseCode());
shipmentDetail.setMaterialCode(material.getCode());
shipmentDetail.setMaterialName(material.getName());
shipmentDetail.setReferCode(shipmentHeader.getReferCode());
shipmentDetail.setReferId(shipmentHeader.getReferId());
shipmentDetail.setMaterialSpec(material.getSpec());
shipmentDetail.setMaterialUnit(material.getUnit());
shipmentDetail.setCreated(null);
shipmentDetail.setCreatedBy(ShiroUtils.getLoginName());
shipmentDetail.setLastUpdated(null);
shipmentDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
if (this.save(shipmentDetail)==true){
//更新单据总行数与总数量
shipmentHeader.setTotalLines(shipmentHeader.getTotalLines() + 1);
shipmentHeader.setTotalQty(shipmentHeader.getTotalQty().add(shipmentDetail.getShipQty()));
shipmentHeaderService.saveOrUpdate(shipmentHeader);
return AjaxResult.success("新增单据明细成功");
}
else
return AjaxResult.error("新增单据明细失败");
}
/**
* 删除出库单据明细
*
* @param id
* @return
*/
@Override
@Transactional
public AjaxResult deleteDetail(String id) {
if (StringUtils.isEmpty(id))
return AjaxResult.error("id不能为空");
String[] ids = id.split(",");
List<Map<String,Integer>> list = shipmentDetailMapper.SelectFirstStatus(id);
if (list.size() < 1) {
return AjaxResult.error("找不到主单据!");
}
if (list.size() > 1) {
return AjaxResult.error("有多个主单据,不能一起删除!");
}
if (list.get(0).get("firstStatus") > 100) {
return AjaxResult.error("单据状进入订单池,不允许删除明细");
}
Integer result = shipmentDetailMapper.batchDelete(ids);
if (result > 0) {
Integer headerId=list.get(0).get("id");
Map<String,String> map= shipmentDetailMapper.StatisticalByReceiptId(headerId);
if(DataUtils.getInteger(map.get("totalLines")) <= 0) {
shipmentHeaderService.removeById(headerId);
}
else {
//更新表头的总行数和总数量统计
ShipmentHeader shipmentHeader = new ShipmentHeader();
shipmentHeader.setId(headerId);
shipmentHeader.setTotalLines(DataUtils.getInteger(map.get("totalLines")));
shipmentHeader.setTotalQty(DataUtils.getBigDecimal(map.get("totalQty")));
shipmentHeaderService.saveOrUpdate(shipmentHeader);
}
return AjaxResult.success("删除单据明细成功");
}
else
return AjaxResult.error("删除单据明细失败");
}
@Override
public Integer countUnCompleted(Integer shipmentId) {
return shipmentDetailMapper.countUnCompleted(shipmentId);
}
}