feat: bug-905 从crm同步过来的设备,需要按设备编号覆盖手动添加的数据
This commit is contained in:
parent
d6ff7814fc
commit
0bca14aa1a
|
|
@ -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)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue