Compare commits
2 Commits
50b2d81ec5
...
0bca14aa1a
| Author | SHA1 | Date |
|---|---|---|
|
|
0bca14aa1a | |
|
|
d6ff7814fc |
|
|
@ -41,6 +41,7 @@ import org.ttzero.excel.entity.Workbook;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
@ -770,4 +771,20 @@ public class DeviceController extends ControllerBase {
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备机型
|
||||||
|
* @param deviceNo 设备编号
|
||||||
|
* @return 设备机型
|
||||||
|
*/
|
||||||
|
@GetMapping("/getModelNo")
|
||||||
|
public ApiResult<String> getModelNo(@RequestParam @NotBlank String deviceNo) {
|
||||||
|
Device device = deviceService.lambdaQuery()
|
||||||
|
.eq(Device::getDeviceNo, deviceNo)
|
||||||
|
.orderByDesc(Device::getDeviceState)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
VUtils.trueThrowBusinessError(Objects.isNull(device)).throwMessage("设备编号无效");
|
||||||
|
return ApiResult.success(device.getModelNo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
||||||
import com.nflg.mobilebroken.common.util.VUtils;
|
import com.nflg.mobilebroken.common.util.VUtils;
|
||||||
import com.nflg.mobilebroken.repository.entity.Device;
|
import com.nflg.mobilebroken.repository.entity.Device;
|
||||||
import com.nflg.mobilebroken.repository.service.IDeviceService;
|
import com.nflg.mobilebroken.repository.service.IDeviceService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
@ -24,6 +25,7 @@ import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class AdminDeviceService {
|
public class AdminDeviceService {
|
||||||
|
|
||||||
|
|
@ -70,7 +72,6 @@ public class AdminDeviceService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入
|
* 导入
|
||||||
*
|
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
|
@ -106,7 +107,6 @@ public class AdminDeviceService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步CRM 数据
|
* 同步CRM 数据
|
||||||
*
|
|
||||||
* @param dateParam
|
* @param dateParam
|
||||||
* @param dateParam
|
* @param dateParam
|
||||||
*/
|
*/
|
||||||
|
|
@ -129,31 +129,46 @@ public class AdminDeviceService {
|
||||||
Map<String, Device> deviceMap = deviceList.stream().collect(Collectors.toMap(Device::getSourceId, device -> device));
|
Map<String, Device> deviceMap = deviceList.stream().collect(Collectors.toMap(Device::getSourceId, device -> device));
|
||||||
|
|
||||||
crmDeviceList.forEach(u -> {
|
crmDeviceList.forEach(u -> {
|
||||||
if (StrUtil.isNotBlank(u.getMachine_Number__c())) {
|
if (StrUtil.isBlank(u.getProductLine5__c())) {
|
||||||
Device ent = deviceMap.get(u.getId());
|
log.error("设备机型为空,{}", JSONUtil.toJsonStr(u));
|
||||||
if (Objects.nonNull(ent)) {
|
} else {
|
||||||
ent.setUpdateBy("crm");
|
if (StrUtil.isNotBlank(u.getMachine_Number__c())) {
|
||||||
ent.setUpdateTime(LocalDateTime.now());
|
Device ent = deviceMap.get(u.getId());
|
||||||
} else {
|
if (Objects.nonNull(ent)) {
|
||||||
ent = new Device();
|
ent.setUpdateBy("crm");
|
||||||
ent.setSourceId(u.getId());
|
ent.setUpdateTime(LocalDateTime.now());
|
||||||
ent.setCreateBy("crm");
|
} else {
|
||||||
ent.setCreateTime(LocalDateTime.now());
|
ent = deviceService.lambdaQuery()
|
||||||
|
.eq(Device::getDeviceNo, u.getMachine_Number__c())
|
||||||
|
.eq(Device::getSourceFrom, DeviceSourceFromEnum.MANUAL_ADD.getSourceKey())
|
||||||
|
.orderByDesc(Device::getDeviceState)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
if (Objects.nonNull(ent)) {
|
||||||
|
ent.setUpdateBy("crm");
|
||||||
|
ent.setUpdateTime(LocalDateTime.now());
|
||||||
|
} else {
|
||||||
|
ent = new Device();
|
||||||
|
ent.setCustomerId(0);
|
||||||
|
ent.setCreateBy("crm");
|
||||||
|
ent.setCreateTime(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
ent.setSourceId(u.getId());
|
||||||
|
}
|
||||||
|
ent.setDeviceState(u.getCfsStatus__c());
|
||||||
|
ent.setDeviceNo(u.getMachine_Number__c());
|
||||||
|
ent.setDeviceType(u.getAssetProductLine3__c());
|
||||||
|
ent.setDeviceTypeSub(u.getAssetProductLine4__c());
|
||||||
|
ent.setModelNo(u.getProductLine5__c());
|
||||||
|
if (StrUtil.isNotBlank(u.getAccount())) {
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(u.getAccount());
|
||||||
|
String cname = jsonObject.getStr("Name");
|
||||||
|
ent.setCustomerName(cname);
|
||||||
|
ent.setCustomerId(0);
|
||||||
|
}
|
||||||
|
ent.setSourceFrom(DeviceSourceFromEnum.FROM_CRM.getSourceKey());
|
||||||
|
result.add(ent);
|
||||||
}
|
}
|
||||||
ent.setDeviceState(u.getCfsStatus__c());
|
|
||||||
ent.setDeviceNo(u.getMachine_Number__c());
|
|
||||||
ent.setDeviceType(u.getAssetProductLine3__c());
|
|
||||||
ent.setDeviceTypeSub(u.getAssetProductLine4__c());
|
|
||||||
ent.setModelNo(u.getProductLine5__c());
|
|
||||||
if (StrUtil.isNotBlank(u.getAccount())) {
|
|
||||||
JSONObject jsonObject = JSONUtil.parseObj(u.getAccount());
|
|
||||||
String cname = jsonObject.getStr("Name");
|
|
||||||
ent.setCustomerName(cname);
|
|
||||||
}
|
|
||||||
|
|
||||||
ent.setSourceFrom(DeviceSourceFromEnum.FROM_CRM.getSourceKey());
|
|
||||||
ent.setCustomerId(0);
|
|
||||||
result.add(ent);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (CollUtil.isNotEmpty(result)) {
|
if (CollUtil.isNotEmpty(result)) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,6 @@ public class DeviceQRCodeService {
|
||||||
|
|
||||||
public byte[] generate(String deviceNo, String modelNo) throws Exception {
|
public byte[] generate(String deviceNo, String modelNo) throws Exception {
|
||||||
ParamConfig config = paramConfigService.lambdaQuery().eq(ParamConfig::getCode, "DeviceQRCodeHost").one();
|
ParamConfig config = paramConfigService.lambdaQuery().eq(ParamConfig::getCode, "DeviceQRCodeHost").one();
|
||||||
return QRCodeUtil.generateDeviceQRCode(deviceNo ,StrUtil.format(config.getValue(), deviceNo,modelNo),200, 200);
|
return QRCodeUtil.generateDeviceQRCode(deviceNo, StrUtil.format(config.getValue(), deviceNo, modelNo), 550, 550);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
public class QRCodeUtil {
|
public class QRCodeUtil {
|
||||||
|
|
@ -48,16 +49,16 @@ public class QRCodeUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为图片添加边框和文字
|
* 为图片添加边框和文字
|
||||||
*
|
|
||||||
* @param qrImage 原始二维码图片
|
* @param qrImage 原始二维码图片
|
||||||
* @param text 要添加的文字
|
* @param text 要添加的文字
|
||||||
* @return 带边框和文字的新图片
|
* @return 带边框和文字的新图片
|
||||||
*/
|
*/
|
||||||
private static BufferedImage addBorderAndText(BufferedImage qrImage, String text) {
|
private static BufferedImage addBorderAndText(BufferedImage qrImage, String text) throws Exception {
|
||||||
int borderSize = 1;
|
int borderSize = 1;
|
||||||
int extend=10;
|
int extend1 = 10;
|
||||||
int newWidth = qrImage.getWidth() + extend;
|
int extend2 = 50;
|
||||||
int newHeight = qrImage.getHeight() + extend;
|
int newWidth = qrImage.getWidth() + extend1;
|
||||||
|
int newHeight = qrImage.getHeight() + extend2;
|
||||||
// 创建新画布(扩大尺寸以容纳边框)
|
// 创建新画布(扩大尺寸以容纳边框)
|
||||||
BufferedImage newImage = new BufferedImage(
|
BufferedImage newImage = new BufferedImage(
|
||||||
newWidth,
|
newWidth,
|
||||||
|
|
@ -65,11 +66,12 @@ public class QRCodeUtil {
|
||||||
BufferedImage.TYPE_INT_RGB
|
BufferedImage.TYPE_INT_RGB
|
||||||
);
|
);
|
||||||
Graphics2D g = newImage.createGraphics();
|
Graphics2D g = newImage.createGraphics();
|
||||||
|
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
// 填充边框颜色
|
// 填充边框颜色
|
||||||
g.setColor(Color.WHITE);
|
g.setColor(Color.WHITE);
|
||||||
g.fillRect(0, 0, newWidth, newHeight);
|
g.fillRect(0, 0, newWidth, newHeight);
|
||||||
// 绘制原始二维码(居中)
|
// 绘制原始二维码(居中)
|
||||||
g.drawImage(qrImage, borderSize + extend / 2, borderSize, null);
|
g.drawImage(qrImage, borderSize + extend1 / 2, borderSize, null);
|
||||||
// 绘制边框
|
// 绘制边框
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.setStroke(new BasicStroke(borderSize));
|
g.setStroke(new BasicStroke(borderSize));
|
||||||
|
|
@ -79,13 +81,14 @@ public class QRCodeUtil {
|
||||||
g.drawLine(0, newHeight - borderSize, newWidth, newHeight - borderSize);
|
g.drawLine(0, newHeight - borderSize, newWidth, newHeight - borderSize);
|
||||||
// 添加文字(居中显示)
|
// 添加文字(居中显示)
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.setFont(new Font("Arial", Font.PLAIN, 14));
|
InputStream is = QRCodeUtil.class.getResourceAsStream("/fonts/simsun.ttc");
|
||||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
Font baseFont = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(Font.BOLD, 45.0f);
|
||||||
|
g.setFont(baseFont);
|
||||||
FontMetrics fm = g.getFontMetrics();
|
FontMetrics fm = g.getFontMetrics();
|
||||||
int textWidth = fm.stringWidth(text);
|
int textWidth = fm.stringWidth(text);
|
||||||
int x = (newImage.getWidth() - textWidth) / 2;
|
int x = (newImage.getWidth() - textWidth) / 2;
|
||||||
int y = newImage.getHeight() - 15;
|
g.drawString(text, x, qrImage.getHeight() + (extend2 - fm.getAscent()) / 2);
|
||||||
g.drawString(text, x, y);
|
is.close();
|
||||||
g.dispose();
|
g.dispose();
|
||||||
return newImage;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue