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.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
@ -770,4 +771,20 @@ public class DeviceController extends ControllerBase {
|
|||
}
|
||||
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.repository.entity.Device;
|
||||
import com.nflg.mobilebroken.repository.service.IDeviceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -24,6 +25,7 @@ import java.time.LocalDateTime;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AdminDeviceService {
|
||||
|
||||
|
|
@ -70,7 +72,6 @@ public class AdminDeviceService {
|
|||
|
||||
/**
|
||||
* 导入
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
|
@ -106,7 +107,6 @@ public class AdminDeviceService {
|
|||
|
||||
/**
|
||||
* 同步CRM 数据
|
||||
*
|
||||
* @param dateParam
|
||||
* @param dateParam
|
||||
*/
|
||||
|
|
@ -129,31 +129,46 @@ public class AdminDeviceService {
|
|||
Map<String, Device> deviceMap = deviceList.stream().collect(Collectors.toMap(Device::getSourceId, device -> device));
|
||||
|
||||
crmDeviceList.forEach(u -> {
|
||||
if (StrUtil.isNotBlank(u.getMachine_Number__c())) {
|
||||
Device ent = deviceMap.get(u.getId());
|
||||
if (Objects.nonNull(ent)) {
|
||||
ent.setUpdateBy("crm");
|
||||
ent.setUpdateTime(LocalDateTime.now());
|
||||
} else {
|
||||
ent = new Device();
|
||||
ent.setSourceId(u.getId());
|
||||
ent.setCreateBy("crm");
|
||||
ent.setCreateTime(LocalDateTime.now());
|
||||
if (StrUtil.isBlank(u.getProductLine5__c())) {
|
||||
log.error("设备机型为空,{}", JSONUtil.toJsonStr(u));
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(u.getMachine_Number__c())) {
|
||||
Device ent = deviceMap.get(u.getId());
|
||||
if (Objects.nonNull(ent)) {
|
||||
ent.setUpdateBy("crm");
|
||||
ent.setUpdateTime(LocalDateTime.now());
|
||||
} else {
|
||||
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)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue