package com.gk.firework.Service.ServiceImpl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gk.firework.Domain.*;
|
import com.gk.firework.Domain.Enum.CertificatePersonType;
|
import com.gk.firework.Domain.Enum.CertificateStatus;
|
import com.gk.firework.Domain.Exception.BusinessException;
|
import com.gk.firework.Domain.Utils.*;
|
import com.gk.firework.Domain.Utils.Properties;
|
import com.gk.firework.Domain.Vo.TransportArrivalVo;
|
import com.gk.firework.Mapper.TransportCertificateMapper;
|
import com.gk.firework.Service.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.ResourceUtils;
|
|
import java.io.File;
|
import java.io.FileNotFoundException;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
|
@Service("transportCertificateService")
|
public class TransportCertificateServiceImpl extends ServiceImpl<TransportCertificateMapper, TransportCertificate> implements TransportCertificateService {
|
|
//最少行数限制
|
private final static Integer rowMinSizeLimit = 12;
|
private final static SimpleDateFormat TransportDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
|
|
@Autowired
|
private TransportCertificateMapper transportCertificateMapper;
|
@Autowired
|
private TransportCertificatePersonService transportCertificatePersonService;
|
@Autowired
|
private TransportCertificateProductService transportCertificateProductService;
|
@Autowired
|
private TransportCertificateApproachService transportCertificateApproachService;
|
@Autowired
|
private TransportCertificateFileService transportCertificateFileService;
|
@Autowired
|
private TransportCertificateArrivalRecordService transportCertificateArrivalRecordService;
|
@Autowired
|
private UserService userService;
|
@Autowired
|
private EnterpriseService enterpriseService;
|
|
@Override
|
public IPage selectPages(Page<TransportCertificate> page, Map filter, UserInfo userInfo) {
|
UserInfo user = userService.getById(userInfo.getId());
|
Map<String, Object> params = new HashMap<>();
|
//可见权限
|
{
|
params.put("enterprisenumber", user.getCompanynumber());
|
params.put("province", user.getProvince());
|
params.put("city", user.getCity());
|
params.put("district", user.getArea());
|
params.put("street", user.getTown());
|
params.put("committee", user.getCommunity());
|
}
|
//基本
|
params.put("filterProvince", filter.get("province"));
|
params.put("filterCity", filter.get("city"));
|
params.put("filterDistrict",filter.get("district"));
|
params.put("filterStreet", filter.get("street"));
|
params.put("filterCommittee", filter.get("committee"));
|
params.put("code", filter.get("code"));
|
params.put("enterprisename", filter.get("enterprisename"));
|
params.put("page", filter.get("page"));
|
params.put("tosubmmit", CertificateStatus.TOSUBMIT);
|
List<TransportCertificate> list = transportCertificateMapper.selectPages(page, params);
|
return page.setRecords(list);
|
}
|
|
/**
|
* @Description: 新增运输证
|
* @date 2021/4/1 13:02
|
*/
|
@Override
|
@Transactional
|
public void addCertificateApply(TransportCertificate transportCertificate, UserInfo user) {
|
|
UserInfo userInfo = userService.getById(user.getId());
|
if (StringUtils.isBlank(userInfo.getCompanynumber())){
|
throw new BusinessException("没有权限创建运输证");
|
}
|
//新增运输证基本信息
|
{
|
String code = "TC-" + System.currentTimeMillis();
|
transportCertificate.setCode(code);
|
transportCertificate.setCertstatus("未入库");
|
transportCertificate.setCreateby(user.getId());
|
transportCertificate.setCreatebyname(user.getUsername());
|
transportCertificate.setEnterprisenumber(userInfo.getCompanynumber());
|
transportCertificate.setCreatetime(new Date());
|
transportCertificate.setValidflag(true);
|
transportCertificate.setStatus(CertificateStatus.TOSUBMIT);
|
this.save(transportCertificate);
|
}
|
//新增驾驶员和押运人
|
{
|
|
List<TransportCertificatePerson> person = transportCertificate.getTransportPerson();
|
if (person != null && person.size() > 0) {
|
for (TransportCertificatePerson p : person) {
|
p.setCertificatecode(transportCertificate.getCode());
|
p.setValidflag(true);
|
}
|
transportCertificatePersonService.saveBatch(person);
|
}
|
}
|
|
//新建产品信息
|
{
|
List<TransportCertificateProduct> products = transportCertificate.getTransportProduct();
|
if (products != null && products.size() > 0) {
|
for (TransportCertificateProduct p : products) {
|
p.setCertificatecode(transportCertificate.getCode());
|
p.setArrivalnum(0);
|
p.setValidflag(true);
|
}
|
transportCertificateProductService.saveBatch(products);
|
}
|
}
|
//新增途径地
|
|
{
|
List<TransportCertificateApproach> approach = transportCertificate.getTransportApproach();
|
if (approach != null && approach.size() > 0) {
|
for (TransportCertificateApproach a : approach) {
|
a.setCertificatecode(transportCertificate.getCode());
|
a.setValidflag(true);
|
}
|
transportCertificateApproachService.saveBatch(approach);
|
|
}
|
}
|
//新增图片
|
{
|
TransportCertificateFile files = transportCertificate.getTransportFile();
|
if (files != null) {
|
files.setId(null);
|
files.setCertificatecode(transportCertificate.getCode());
|
files.setValidflag(true);
|
transportCertificateFileService.save(files);
|
}
|
}
|
|
}
|
|
/**
|
* @Description: 修改运输证
|
* @date 2021/4/2 14:49
|
*/
|
@Override
|
@Transactional
|
public void modCertificateApply(TransportCertificate transportCertificate, UserInfo user) {
|
|
|
//1.判断单子状态
|
TransportCertificate certificate = this.getById(transportCertificate.getId());
|
if (certificate.getStatus() != CertificateStatus.TOSUBMIT){
|
throw new BusinessException("非待提交状态不能修改");
|
}
|
//修改运输证基本信息
|
{
|
transportCertificate.setUpdateby(user.getId());
|
transportCertificate.setUpdatebyname(user.getUsername());
|
transportCertificate.setUpdatetime(new Date());
|
this.updateById(transportCertificate);
|
}
|
|
//修改驾驶员和押运人
|
{
|
//1.删除所有已关联驾驶员和押运人
|
transportCertificatePersonService.deleteByCertificateCode(transportCertificate.getCode());
|
//2.新增关联驾驶员和押运人
|
List<TransportCertificatePerson> person = transportCertificate.getTransportPerson();
|
if (person != null && person.size() > 0) {
|
for (TransportCertificatePerson p : person) {
|
p.setId(null);
|
p.setCertificatecode(transportCertificate.getCode());
|
p.setValidflag(true);
|
}
|
transportCertificatePersonService.saveBatch(person);
|
}
|
}
|
|
//修改产品信息
|
{
|
|
//1.删除所有关联产品信息
|
transportCertificateProductService.deleteByCertificateCode(transportCertificate.getCode());
|
//2.新增关联驾驶员和押运人
|
List<TransportCertificateProduct> products = transportCertificate.getTransportProduct();
|
if (products != null && products.size() > 0) {
|
for (TransportCertificateProduct p : products) {
|
p.setId(null);
|
p.setCertificatecode(transportCertificate.getCode());
|
p.setValidflag(true);
|
}
|
transportCertificateProductService.saveBatch(products);
|
}
|
}
|
|
//修改产品信息
|
{
|
|
//1.删除所有关联产品信息
|
transportCertificateProductService.deleteByCertificateCode(transportCertificate.getCode());
|
//2.新增关联产品信息
|
List<TransportCertificateProduct> products = transportCertificate.getTransportProduct();
|
if (products != null && products.size() > 0) {
|
for (TransportCertificateProduct p : products) {
|
p.setCertificatecode(transportCertificate.getCode());
|
p.setValidflag(true);
|
}
|
transportCertificateProductService.saveBatch(products);
|
}
|
}
|
|
//修改途径地
|
{
|
//1.删除所有途径地
|
transportCertificateApproachService.deleteByCertificateCode(transportCertificate.getCode());
|
//2.新增关联途径地
|
List<TransportCertificateApproach> approach = transportCertificate.getTransportApproach();
|
if (approach != null && approach.size() > 0) {
|
for (TransportCertificateApproach a : approach) {
|
a.setId(null);
|
a.setCertificatecode(transportCertificate.getCode());
|
a.setValidflag(true);
|
}
|
transportCertificateApproachService.saveBatch(approach);
|
}
|
}
|
|
//修改途径地
|
{
|
//1.删除所有途径地
|
transportCertificateApproachService.deleteByCertificateCode(transportCertificate.getCode());
|
//2.新增关联途径地
|
List<TransportCertificateApproach> approach = transportCertificate.getTransportApproach();
|
if (approach != null && approach.size() > 0) {
|
for (TransportCertificateApproach a : approach) {
|
a.setId(null);
|
a.setCertificatecode(transportCertificate.getCode());
|
a.setValidflag(true);
|
}
|
transportCertificateApproachService.saveBatch(approach);
|
|
}
|
}
|
|
|
//修改图片
|
{
|
//1.删除所有图片
|
transportCertificateFileService.deleteByCertificateCode(transportCertificate.getCode());
|
//2.新增关联图片
|
TransportCertificateFile files = transportCertificate.getTransportFile();
|
if (files != null) {
|
files.setId(null);
|
files.setCertificatecode(transportCertificate.getCode());
|
files.setValidflag(true);
|
transportCertificateFileService.save(files);
|
}
|
|
}
|
|
}
|
|
/**
|
* @Description: 删除运输证
|
* @date 2021/4/2 16:16
|
*/
|
@Override
|
public void delCertificate(Long id, UserInfo user) {
|
TransportCertificate certificate = new TransportCertificate();
|
certificate.setId(id);
|
certificate.setUpdatetime(new Date());
|
certificate.setUpdatebyname(user.getUsername());
|
certificate.setUpdateby(user.getId());
|
certificate.setValidflag(false);
|
this.updateById(certificate);
|
}
|
|
|
/**
|
* @Description: 根据id获取运输证信息
|
* @date 2021/5/11 17:48
|
*/
|
@Override
|
public TransportCertificate getOneById(Long id) {
|
return transportCertificateMapper.getOneById(id);
|
}
|
|
|
/**
|
* @Description: 提交单子
|
* @date 2021/5/11 16:05
|
*/
|
@Override
|
public void summitApply(Long id, UserInfo user) {
|
TransportCertificate certificate = new TransportCertificate();
|
certificate.setId(id);
|
certificate.setUpdatetime(new Date());
|
certificate.setUpdatebyname(user.getUsername());
|
certificate.setUpdateby(user.getId());
|
certificate.setValidflag(true);
|
certificate.setStatus(CertificateStatus.PENDING);
|
this.updateById(certificate);
|
}
|
|
|
/**
|
* @Description: 监管部门审批
|
* @date 2021/5/11 16:10
|
*/
|
@Override
|
public void approveApply(JSONObject params, UserInfo user) {
|
Long id = params.getLong("id");
|
String signperson = params.getString("signperson");
|
String issueperson = params.getString("issueperson");
|
String issuepersonphone = params.getString("issuepersonphone");
|
Date deadline = params.getDate("deadline");
|
//简单校验
|
{
|
if (id == null) {
|
throw new BusinessException("审批错误,请联系管理员");
|
}
|
|
if (StringUtils.isBlank(signperson)) {
|
throw new BusinessException("请填写签发人员");
|
}
|
|
if (StringUtils.isBlank(issueperson)) {
|
throw new BusinessException("请填写填发人员");
|
}
|
|
if (StringUtils.isBlank(issuepersonphone)) {
|
throw new BusinessException("请填写填发人员联系电话");
|
}
|
|
if (deadline == null) {
|
throw new BusinessException("请填写填发预期到达日期");
|
}
|
}
|
|
//判断托运人和收货人的许可证是否过期
|
TransportCertificate transportCertificate = this.getOneById(id);
|
Enterprise shipper = enterpriseService.selectEnterpriseByName(transportCertificate.getShippercompanyname());
|
Enterprise receiver = enterpriseService.selectEnterpriseByName(transportCertificate.getReceivercompanyname());
|
Date date = new Date();
|
if (shipper == null){
|
throw new BusinessException("托运单位不存在");
|
}
|
if (receiver == null){
|
throw new BusinessException("收货单位不存在");
|
}
|
if (shipper.getValidendtime().getTime() < date.getTime()){
|
throw new BusinessException("托运单位运输证已过期");
|
}
|
if (receiver.getValidendtime().getTime() < date.getTime()){
|
throw new BusinessException("收货单位运输证已过期");
|
}
|
|
|
//修改信息
|
TransportCertificate certificate = new TransportCertificate();
|
certificate.setId(id);
|
certificate.setUpdatetime(new Date());
|
certificate.setUpdatebyname(user.getUsername());
|
certificate.setUpdateby(user.getId());
|
certificate.setValidflag(true);
|
certificate.setStatus(CertificateStatus.APPROVED);
|
certificate.setSignperson(signperson);
|
certificate.setIssueperson(issueperson);
|
certificate.setIssuepersonphone(issuepersonphone);
|
certificate.setDeadline(deadline);
|
this.updateById(certificate);
|
}
|
|
/**
|
* @Description: 监管部门回拒单子-》待提交状态
|
* @date 2021/5/11 16:14
|
*/
|
@Override
|
public void refuseApply(Long id, UserInfo user) {
|
TransportCertificate certificate = new TransportCertificate();
|
certificate.setId(id);
|
certificate.setUpdatetime(new Date());
|
certificate.setUpdatebyname(user.getUsername());
|
certificate.setUpdateby(user.getId());
|
certificate.setValidflag(true);
|
certificate.setStatus(CertificateStatus.TOSUBMIT);
|
this.updateById(certificate);
|
}
|
|
/**
|
* @Description: 导出运输许可证 三联
|
* @date 2021/5/11 17:14
|
*/
|
@Override
|
public String exportCertificate(Long id) {
|
|
TransportCertificate certificate = this.getOneById(id);
|
if (certificate.getStatus() != CertificateStatus.APPROVED) {
|
throw new BusinessException("未审批不能导出相关许可证");
|
}
|
//如果已经生成旧不需要生成了
|
String fileUrl = Properties.transportCertificatePath + certificate.getCode()+".docx";
|
String fileUrlReturn = Properties.transportCertificate+ certificate.getCode()+".docx";
|
if (new File(fileUrl).exists()) {
|
return fileUrlReturn;
|
}
|
|
try {
|
// File file = ResourceUtils.getFile("classpath:printTemplate/certificatelicense.docx");
|
ClassPathResource classPathResource = new ClassPathResource("printTemplate/certificatelicense.docx");
|
InputStream inputStream = classPathResource.getInputStream();
|
WordTemplate wordTemplate = new WordTemplate();
|
wordTemplate.loadTemplate(null,inputStream);
|
//参数
|
Map<String, String> params = new HashMap<>();
|
//编号
|
params.put("ordercode",certificate.getCode());
|
//托运人:单位名称
|
params.put("shippercompanyname",certificate.getShippercompanyname());
|
//收货人:单位名称
|
params.put("receivercompanyname",certificate.getReceivercompanyname());
|
//承运人:单位名称
|
params.put("carriercompanyname",certificate.getCarriercompanyname());
|
//承运人:联系电话
|
params.put("carrierprincipalphone",certificate.getCarrierprincipalphone());
|
//截止日期
|
Date deadline = certificate.getDeadline();
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(deadline);
|
//年
|
params.put("endyear", calendar.get(Calendar.YEAR) + "");
|
//月
|
params.put("endmonth", calendar.get(Calendar.MONTH) + "");
|
//日
|
params.put("endday", calendar.get(Calendar.DATE) + "");
|
//运输车辆牌号
|
params.put("carriercarnumber",certificate.getCarriercarnumber());
|
//运输起始地
|
params.put("startplace", certificate.getOtherdeparture());
|
//运输目的地
|
params.put("endplace", certificate.getOtherdestination());
|
//运输途径地 任意一处
|
params.put("byway", certificate.getOtherdeparture());
|
List<TransportCertificateApproach> approachList = certificate.getTransportApproach();
|
if (approachList != null && approachList.size() > 0) {
|
params.put("byway", approachList.get(0).getCity());
|
}
|
//签发人
|
params.put("signperson", certificate.getSignperson());
|
//填发人
|
params.put("issueperson", certificate.getIssueperson());
|
//填发人联系方式
|
params.put("issuepersonphone", certificate.getIssuepersonphone());
|
params.put("first", "第一联 公安局存查联");
|
params.put("second", "第二联 托运人存查联");
|
params.put("third", "第三联 承运人存查联");
|
|
//产品信息
|
List<String[]> productPrintList= new ArrayList<>();
|
List<TransportCertificateProduct> productList = certificate.getTransportProduct();
|
assert productList.size() > 0;
|
|
for (TransportCertificateProduct product : productList) {
|
productPrintList.add(new String[]
|
{
|
//种类
|
product.getType(),
|
//规格
|
product.getSpecification(),
|
//数量
|
product.getNum()+"(箱)",
|
//备注 暂无字段,默认为空
|
""
|
});
|
}
|
//至少10行
|
int size = productList.size();
|
if (size < rowMinSizeLimit) {
|
for (int i = 0; i < rowMinSizeLimit - size; i++) {
|
productPrintList.add(new String[]{"","","",""});
|
}
|
}
|
String[] rowParams = {"type", "specification", "num", "memo"};
|
HashMap<String,WordTemplate.Table> tables = new HashMap<>();
|
WordTemplate.Table t1 = new WordTemplate.Table(rowParams,productPrintList);
|
tables.put("mainTable", t1);
|
wordTemplate.replaceDocument(tables, params);
|
//存一份到本地
|
wordTemplate.saveFileAndQRCode(fileUrl,certificate.getCode());
|
return fileUrlReturn;
|
} catch (FileNotFoundException e) {
|
e.printStackTrace();
|
throw new BusinessException("找不到模板文件路径");
|
} catch (IOException e) {
|
e.printStackTrace();
|
throw new BusinessException("发生错误,请联系管理员");
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return fileUrlReturn;
|
}
|
|
/**
|
* @Description: 校验运输证信息
|
* @date 2021/5/12 14:09
|
*/
|
@Override
|
public void checkAddApply(TransportCertificate transportCertificate) {
|
|
if (transportCertificate.getTransportProduct() == null || transportCertificate.getTransportProduct().size() < 1) {
|
throw new BusinessException("产品不能为空");
|
}
|
|
if (StringUtils.isBlank(transportCertificate.getOtherdeparture())) {
|
throw new BusinessException("运输起始地不能为空");
|
}
|
|
if (StringUtils.isBlank(transportCertificate.getOtherdestination())) {
|
throw new BusinessException("运输到达地不能为空");
|
}
|
|
if (StringUtils.isBlank(transportCertificate.getReceivercompanyname())) {
|
throw new BusinessException("收货单位不能为空");
|
}
|
|
if (StringUtils.isBlank(transportCertificate.getShippercompanyname())) {
|
throw new BusinessException("托运单位不能为空");
|
}
|
|
//承运人负责人电话
|
if (StringUtils.isBlank(transportCertificate.getCarrierprincipalname())) {
|
throw new BusinessException("承运单位负责联系电话不能为空");
|
}
|
|
if (StringUtils.isBlank(transportCertificate.getCarriercarnumber())) {
|
throw new BusinessException("承运单位运输车牌号不能为空");
|
}
|
|
if (StringUtils.isBlank(transportCertificate.getCarriernumber())) {
|
throw new BusinessException("承运单位资格证编号不能为空");
|
}
|
|
if (StringUtils.isBlank(transportCertificate.getCarrierroadnumber())) {
|
throw new BusinessException("承运单位道路运输证编号不能为空");
|
}
|
|
|
|
}
|
|
@Override
|
public String exportCertificateApply(Long id) {
|
|
TransportCertificate certificate = this.getOneById(id);
|
if (certificate.getStatus() == CertificateStatus.PENDING) {
|
throw new BusinessException("未提交单子不能导出");
|
}
|
//如果已经生成旧不需要生成了
|
String fileUrl = Properties.transportCertificatePath + certificate.getCode()+"-apply.docx";
|
String fileUrlReturn = Properties.transportCertificate+certificate.getCode()+"-apply.docx";
|
if (new File(fileUrl).exists()) {
|
return fileUrlReturn;
|
}
|
|
try {
|
// File file = ResourceUtils.getFile("classpath:printTemplate/certificatelicenseApply.docx");
|
ClassPathResource classPathResource = new ClassPathResource("printTemplate/certificatelicenseapply.docx");
|
InputStream inputStream =classPathResource.getInputStream();;
|
WordTemplate wordTemplate = new WordTemplate();
|
wordTemplate.loadTemplate(null,inputStream);
|
//参数
|
Map<String, String> params = new HashMap<>();
|
//编号
|
params.put("ordercode",certificate.getCode());
|
//托运人
|
{
|
//托运人:单位名称
|
params.put("shippercompanyname",certificate.getShippercompanyname());
|
//托运人:单位地址
|
params.put("shipperaddress",certificate.getShipperaddress());
|
//托运人:负责人姓名
|
params.put("shipperprincipalname",certificate.getShipperprincipalname());
|
//托运人:负责人联系电话
|
params.put("shipperprincipalphone",certificate.getShipperprincipalphone());
|
//托运人:经办人姓名
|
params.put("shippermanagername",certificate.getShippermanagername());
|
//托运人:经办人身份证号
|
params.put("shippermanageridentify",certificate.getShippermanageridentify());
|
//托运人:经办人联系电话
|
params.put("shippermanagerphone",certificate.getShippermanagerphone());
|
}
|
|
//销售单位
|
params.put("salecompanyname",certificate.getSalecompanyname());
|
//收货人
|
{
|
//收货人:单位名称
|
params.put("receivercompanyname",certificate.getReceivercompanyname());
|
//收货人:地址
|
params.put("receiveraddress",certificate.getReceiveraddress());
|
//收货人:负责人姓名
|
params.put("receiverprincipalname",certificate.getReceiverprincipalname());
|
//收货人:负责人联系电话
|
params.put("receiverprincipalphone",certificate.getReceiverprincipalphone());
|
}
|
//承运人
|
{
|
//承运人:单位名称
|
params.put("carriercompanyname",certificate.getCarriercompanyname());
|
//承运人:单位地址
|
params.put("carrieraddress",certificate.getCarrieraddress());
|
//承运人:单位地址
|
params.put("carriernumber",certificate.getCarriernumber());
|
//承运人:负责人
|
params.put("carrierprincipalname",certificate.getCarrierprincipalname());
|
//承运人:负责人联系电话
|
params.put("carrierprincipalphone",certificate.getCarrierprincipalphone());
|
//承运人:负责人联系电话
|
params.put("carriercarnumber",certificate.getCarriercarnumber());
|
}
|
//运输
|
{
|
//运输起始地
|
params.put("startplace", certificate.getOtherdeparture());
|
//运输目的地
|
params.put("endplace", certificate.getOtherdestination());
|
//运输开始时间
|
params.put("othershipstarttime", TransportDateFormat.format(certificate.getOthershipstarttime()));
|
//运输结束时间
|
params.put("othershipendtime", TransportDateFormat.format(certificate.getOthershipendtime()));
|
//承运人:资质证明编号没有这个字段
|
params.put("carrierroadnumber", certificate.getCarrierroadnumber());
|
//运输途径地 任意一处
|
params.put("byway", certificate.getOtherdeparture());
|
List<TransportCertificateApproach> approachList = certificate.getTransportApproach();
|
if (approachList != null && approachList.size() > 0) {
|
params.put("byway", approachList.get(0).getCity());
|
}
|
//
|
}
|
//驾驶员和押运员
|
{
|
List<TransportCertificatePerson> transportPersons = certificate.getTransportPerson();
|
params.put("driver1", "");
|
params.put("driver1id", "");
|
params.put("driver1license", "");
|
params.put("driver2", "");
|
params.put("driver2id", "");
|
params.put("driver2license", "");
|
params.put("escort1", "");
|
params.put("escort1id", "");
|
params.put("escort1license", "");
|
params.put("escort2", "");
|
params.put("escort2id", "");
|
params.put("escort2license", "");
|
List<TransportCertificatePerson> drivers = new ArrayList<>();
|
List<TransportCertificatePerson> escorts = new ArrayList<>();
|
if (transportPersons != null && transportPersons.size() > 0) {
|
for (TransportCertificatePerson person : transportPersons) {
|
if (person.getType().equals(CertificatePersonType.DRIVER.getMsg())) {
|
drivers.add(person);
|
}
|
if (person.getType().equals(CertificatePersonType.ESCORT.getMsg())) {
|
escorts.add(person);
|
}
|
|
}
|
}
|
if (drivers.size() == 1) {
|
params.put("driver1", drivers.get(0).getPersonname());
|
params.put("driver1id", drivers.get(0).getPersonidentify());
|
params.put("driver1license", drivers.get(0).getNumber());
|
}
|
if (drivers.size() > 1) {
|
params.put("driver2", drivers.get(1).getPersonname());
|
params.put("driver2id", drivers.get(1).getPersonidentify());
|
params.put("driver2license", drivers.get(1).getNumber());
|
}
|
if (escorts.size() == 1) {
|
params.put("escort1", escorts.get(0).getPersonname());
|
params.put("escort2id", escorts.get(0).getPersonidentify());
|
params.put("escort2license", escorts.get(0).getNumber());
|
}
|
if (escorts.size() > 1) {
|
params.put("escort1", escorts.get(1).getPersonname());
|
params.put("escort2id", escorts.get(1).getPersonidentify());
|
params.put("escort2license", escorts.get(1).getNumber());
|
}
|
}
|
//产品信息
|
{
|
List<String[]> productPrintList= new ArrayList<>();
|
List<TransportCertificateProduct> productList = certificate.getTransportProduct();
|
assert productList.size() > 0;
|
|
for (TransportCertificateProduct product : productList) {
|
productPrintList.add(new String[]
|
{
|
//种类
|
product.getType(),
|
//规格
|
product.getSpecification(),
|
//数量
|
product.getNum()+"(箱)",
|
});
|
}
|
|
String[] rowParams = {"type", "specification", "num"};
|
HashMap<String,WordTemplate.Table> tables = new HashMap<>();
|
WordTemplate.Table t1 = new WordTemplate.Table(rowParams,productPrintList);
|
tables.put("mainTable", t1);
|
wordTemplate.replaceDocument2(tables, params);
|
}
|
//存一份到本地
|
wordTemplate.saveFile(fileUrl);
|
|
} catch (FileNotFoundException e) {
|
e.printStackTrace();
|
throw new BusinessException("找不到模板文件路径");
|
} catch (IOException e) {
|
e.printStackTrace();
|
throw new BusinessException("发生错误,请联系管理员");
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return fileUrlReturn;
|
}
|
|
|
/**
|
* @Description: 获取运输证信息
|
* @date 2021/5/14 19:04
|
*/
|
@Override
|
public TransportCertificate getByCode(String code) {
|
if (StringUtils.isBlank(code)) {
|
throw new BusinessException("运输证编号不能为空");
|
}
|
return transportCertificateMapper.selectByCode(code);
|
}
|
|
/**
|
* @Description: 修改运输证产品的到货数量
|
* @date 2021/5/14 19:54
|
*/
|
@Override
|
@Transactional
|
public synchronized void modTransportProductArrivalNum(TransportArrivalVo transportArrivalVo, UserInfo userInfo) {
|
|
if (StringUtils.isBlank(transportArrivalVo.getCode())) {
|
throw new BusinessException("运输证的单位编号不能为空");
|
}
|
List<TransportCertificateProduct> productList = transportArrivalVo.getProductList();
|
if (productList == null || productList.size() < 1) {
|
throw new BusinessException("产品信息不能为空");
|
}
|
|
for (TransportCertificateProduct product : productList) {
|
//更新产品到货量信息
|
TransportCertificateProduct oldProduct = transportCertificateProductService.getById(product.getId());
|
Integer oldArrivalNum = oldProduct.getArrivalnum();
|
Integer newArrivalNum = oldArrivalNum + product.getArrivalnum();
|
oldProduct.setArrivalnum(newArrivalNum);
|
if (oldProduct.getNum() < newArrivalNum) {
|
throw new BusinessException("该次操作使得总到货量超过产品预计到货量,操作失败。");
|
}
|
transportCertificateProductService.updateById(oldProduct);
|
//插入发送到货数的记录信息
|
TransportCertificateArrivalRecord record = new TransportCertificateArrivalRecord();
|
record.setCertificatecode(transportArrivalVo.getCode());
|
record.setProductcode(oldProduct.getProductcode());
|
record.setProductname(oldProduct.getName());
|
record.setCreateby(userInfo.getId());
|
record.setCreatebyname(userInfo.getUsername());
|
record.setCreatetime(new Date());
|
record.setArrivalnum(product.getArrivalnum());
|
record.setValidflag(true);
|
transportCertificateArrivalRecordService.save(record);
|
}
|
|
//获取单子所有产品
|
List<TransportCertificateProduct> list = transportCertificateProductService.getListByTransportCode(transportArrivalVo.getCode());
|
boolean flag = true;
|
if (list.size() > 0) {
|
for (TransportCertificateProduct product : list) {
|
if (!product.getNum().equals(product.getArrivalnum())) {
|
flag = false;
|
}
|
}
|
}
|
|
//数量全相等
|
if (flag) {
|
this.updateByCode(transportArrivalVo.getCode(),"全部入库");
|
}else{
|
this.updateByCode(transportArrivalVo.getCode(),"部分入库");
|
}
|
}
|
|
@Override
|
public void updateByCode(String code,String certstatus) {
|
LambdaUpdateWrapper<TransportCertificate> updateWrapper = new LambdaUpdateWrapper<>();
|
updateWrapper.set(TransportCertificate::getCertstatus, certstatus).eq(TransportCertificate::getCode,code);
|
this.update(updateWrapper);
|
}
|
|
@Override
|
public List<TransportCertificate> selectWarnList(Date start, Date end) {
|
return transportCertificateMapper.selectWarnList(start,end);
|
}
|
|
|
// @Override
|
// public IPage selectTransportArrivalPages(Page<Object> page, UserInfo user) {
|
// return null;
|
// }
|
}
|