ShipmentHeaderServiceImpl.java
2.63 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
package com.huaheng.pc.shipment.shipmentHeader.service;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.system.dict.service.IDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.mapper.ShipmentHeaderMapper;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
@Service
public class ShipmentHeaderServiceImpl extends ServiceImpl<ShipmentHeaderMapper, ShipmentHeader> implements ShipmentHeaderService{
@Autowired
private IDictDataService dictDataService;
@Resource
private ShipmentHeaderMapper shipmentHeaderMapper;
//新增出库主单
@Override
public AjaxResult<Boolean> saveHeader(ShipmentHeader shipmentHeader) {
if(dictDataService.checkConfig("shipmentType", shipmentHeader.getShipmentType()) == false)
{
return AjaxResult.error("没有对应的出库单类型");
}
String code = createCode(shipmentHeader.getShipmentType());
shipmentHeader.setId(null);
shipmentHeader.setFirstStatus(0);
shipmentHeader.setLastStatus(0);
shipmentHeader.setLastUpdated(null);
shipmentHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
shipmentHeader.setCreated(null);
shipmentHeader.setCreatedBy(ShiroUtils.getLoginName());
shipmentHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
shipmentHeader.setCode(code);
boolean result = this.save(shipmentHeader);
return AjaxResult.toAjax(result);
}
//根据单据类型建单据号
public String createCode(String shipmentType)
{
String code = null;
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String maxCode = shipmentHeaderMapper.createCode(shipmentType);
if (maxCode != null && maxCode.length() > 13 && maxCode.substring(maxCode.length() - 13, maxCode.length() - 5).equals(df.format(now)))
{
Integer Count = Integer.valueOf(maxCode.substring(maxCode.length() - 5, maxCode.length()));
code = shipmentType + df.format(now) + String.format("%05d", Count + 1);
}
else
{
code = shipmentType + df.format(now) + "00001";
}
return code;
}
}