|
|
|
@ -9,6 +9,8 @@ import com.gaotao.modules.app.entity.UserEntity; |
|
|
|
import com.gaotao.modules.label.entity.PrintLabelRecord; |
|
|
|
import com.gaotao.modules.label.mapper.PrintLabelRecordMapper; |
|
|
|
import com.gaotao.modules.label.service.PrintLabelRecordService; |
|
|
|
import com.gaotao.modules.part.entity.ExternalPartPicture; |
|
|
|
import com.gaotao.modules.part.service.ExternalPartPictureService; |
|
|
|
import com.gaotao.modules.sys.entity.SysUserEntity; |
|
|
|
import com.gaotao.modules.sys.service.SysMsgService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
@ -19,12 +21,13 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
@ -33,6 +36,9 @@ public class PrintLabelRecordServiceImpl extends ServiceImpl<PrintLabelRecordMap |
|
|
|
@Autowired |
|
|
|
private SysMsgService sysMsgService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ExternalPartPictureService externalPartPictureService; |
|
|
|
|
|
|
|
@Value("${label.boxNum}") |
|
|
|
private int boxNum; |
|
|
|
|
|
|
|
@ -75,11 +81,28 @@ public class PrintLabelRecordServiceImpl extends ServiceImpl<PrintLabelRecordMap |
|
|
|
// 获得当前登录用户 |
|
|
|
SysUserEntity userEntity = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
// 判断是否需要打印SN |
|
|
|
Map<String,String> pictureMap = new HashMap<>(); |
|
|
|
if ("Alpha/Hard Tag-Serials".equalsIgnoreCase(printLabelRecord.getCategory()) && "Y".equalsIgnoreCase(userEntity.getAutoSerialNumber())){ |
|
|
|
printLabelRecord.setCreateTime(new Date()); |
|
|
|
// 获取SN |
|
|
|
list = baseMapper.autoCreateSerialNumber(printLabelRecord, cartonCount.intValue()); |
|
|
|
|
|
|
|
// 获取 认证 |
|
|
|
List<ExternalPartPicture> pictureList = externalPartPictureService.lambdaQuery() |
|
|
|
.eq(ExternalPartPicture::getPartNo, printLabelRecord.getPartNo()) |
|
|
|
.eq(ExternalPartPicture::getSite, printLabelRecord.getSite()) |
|
|
|
.eq(ExternalPartPicture::getTemplateNo, printLabelRecord.getTemplateNo()) |
|
|
|
.eq(ExternalPartPicture::getPictureClassify, "ProPicture") |
|
|
|
.list(); |
|
|
|
for (ExternalPartPicture picture : pictureList) { |
|
|
|
// 通过URL转Base64 |
|
|
|
String pictureUrl = picture.getPictureUrl(); |
|
|
|
File file = new File(pictureUrl); |
|
|
|
try { |
|
|
|
pictureMap.put(picture.getPicturePosition(),"data:image/png;base64,"+encodeFileToBase64(file)); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 打印张数 |
|
|
|
for (int i = 1; i <= cartonCount.intValue(); i++) { |
|
|
|
@ -94,7 +117,8 @@ public class PrintLabelRecordServiceImpl extends ServiceImpl<PrintLabelRecordMap |
|
|
|
if (!list.isEmpty()){ |
|
|
|
target.setSerialNumber(list.get(i-1).getSerialNumber()); |
|
|
|
target.setDateStr(list.get(i-1).getDateStr()); |
|
|
|
|
|
|
|
target.setPictureMap(pictureMap); |
|
|
|
target.setDateStr(list.get(i-1).getDateStr()); |
|
|
|
} |
|
|
|
save(target); |
|
|
|
printLabelRecordList.add(target); |
|
|
|
@ -102,9 +126,39 @@ public class PrintLabelRecordServiceImpl extends ServiceImpl<PrintLabelRecordMap |
|
|
|
return printLabelRecordList; |
|
|
|
} |
|
|
|
|
|
|
|
public static String encodeFileToBase64(File file) throws IOException { |
|
|
|
byte[] fileContent = Files.readAllBytes(file.toPath()); |
|
|
|
return Base64.getEncoder().encodeToString(fileContent); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public IPage<PrintLabelRecord> selectPrintLabelRecordPage(PrintLabelRecord printLabelRecord, Integer no, Integer size) { |
|
|
|
Page<PrintLabelRecord> page = new Page<>(no, size); |
|
|
|
return baseMapper.selectPrintLabelRecordPage(page,printLabelRecord); |
|
|
|
IPage<PrintLabelRecord> iPage = baseMapper.selectPrintLabelRecordPage(page, printLabelRecord); |
|
|
|
for (PrintLabelRecord record : iPage.getRecords()) { |
|
|
|
if (!"Alpha/Hard Tag-Serials".equals(record.getCategory())){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 获取 认证 |
|
|
|
List<ExternalPartPicture> pictureList = externalPartPictureService.lambdaQuery() |
|
|
|
.eq(ExternalPartPicture::getPartNo, record.getPartNo()) |
|
|
|
.eq(ExternalPartPicture::getSite, record.getSite()) |
|
|
|
.eq(ExternalPartPicture::getTemplateNo, record.getTemplateNo()) |
|
|
|
.eq(ExternalPartPicture::getPictureClassify, "ProPicture") |
|
|
|
.list(); |
|
|
|
Map<String,String> pictureMap = new HashMap<>(); |
|
|
|
for (ExternalPartPicture picture : pictureList) { |
|
|
|
// 通过URL转Base64 |
|
|
|
String pictureUrl = picture.getPictureUrl(); |
|
|
|
File file = new File(pictureUrl); |
|
|
|
try { |
|
|
|
pictureMap.put(picture.getPicturePosition(),"data:image/png;base64,"+encodeFileToBase64(file)); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
record.setPictureMap(pictureMap); |
|
|
|
} |
|
|
|
return iPage; |
|
|
|
} |
|
|
|
} |