ShipmentHeaderServiceImpl.java 2.63 KB
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;
    }
}