You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-wms-java/src/main/java/com/glxp/api/controller/sync/SyncDataSetController.java

114 lines
4.4 KiB
Java

package com.glxp.api.controller.sync;
3 years ago
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
3 years ago
import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.constant.Constant;
import com.glxp.api.entity.system.SyncDataBustypeEntity;
import com.glxp.api.entity.system.SyncDataSetEntity;
import com.glxp.api.http.sync.SpGetHttpClient;
3 years ago
import com.glxp.api.res.system.SyncDataSetResponse;
import com.glxp.api.service.sync.SyncDataBustypeService;
import com.glxp.api.service.sync.SyncDataChangeBustypeService;
import com.glxp.api.service.sync.SyncDataSetService;
3 years ago
import com.glxp.api.util.RedisUtil;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
3 years ago
import java.util.List;
@RestController
public class SyncDataSetController {
@Resource
private SyncDataSetService syncDataSetService;
@Resource
private SyncDataBustypeService syncDataBustypeService;
@Resource
private SyncDataChangeBustypeService syncDataChangeBustypeService;
@Resource
3 years ago
private RedisUtil redisUtil;
@Resource
SpGetHttpClient spGetHttpClient;
3 years ago
@AuthRuleAnnotation("system/param/syncData/config")
@GetMapping("/system/param/syncData/config")
public BaseResponse list() {
Integer delaySyncTime = (Integer) redisUtil.get(Constant.DELAY_SYNC_TIME);
if (delaySyncTime != null) {
long time = redisUtil.getExpire(Constant.DELAY_SYNC_TIME);
delaySyncTime = Math.toIntExact(time) / 60;
}
SyncDataSetResponse syncDataSetResponse = syncDataSetService.selectSet();
syncDataSetResponse.setDelaySyncTime(delaySyncTime);
return ResultVOUtils.success(syncDataSetResponse);
}
@AuthRuleAnnotation("system/param/syncData/save")
@PostMapping("/system/param/syncData/save")
public BaseResponse save(@RequestBody @Valid SyncDataSetResponse syncDataSetResponse
) {
SyncDataSetEntity syncDataSetEntity = new SyncDataSetEntity();
BeanUtils.copyProperties(syncDataSetResponse, syncDataSetEntity);
syncDataSetEntity.setUpdateTime(new Date());
3 years ago
syncDataSetEntity.setId(1);
List<SyncDataBustypeEntity> busTypes = syncDataSetResponse.getBusTypes();
//重新生成id防止插入时单据类型被覆盖
for (SyncDataBustypeEntity s:busTypes) {
s.setId(IdUtil.getSnowflakeNextId());
}
syncDataBustypeService.deleteAll(1);
if (CollUtil.isNotEmpty(busTypes)) {
3 years ago
syncDataBustypeService.inserts(busTypes);
}
List<SyncDataBustypeEntity> toInBusTypes = syncDataSetResponse.getToInBusTypes();
for (SyncDataBustypeEntity s : toInBusTypes) {
s.setId(IdUtil.getSnowflakeNextId());
}
syncDataBustypeService.deleteAll(2);
if (CollUtil.isNotEmpty(toInBusTypes)) {
syncDataBustypeService.inserts(toInBusTypes);
}
if (CollUtil.isNotEmpty(syncDataSetResponse.getChangeBusTypes())) {
2 years ago
syncDataChangeBustypeService.deleteAll();
syncDataChangeBustypeService.inserts(syncDataSetResponse.getChangeBusTypes());
}
3 years ago
boolean b = syncDataSetService.insert(syncDataSetEntity);
if (syncDataSetResponse.getDelaySyncTime() != null &&
syncDataSetResponse.getDelaySyncTime() > 0) {
redisUtil.set(Constant.DELAY_SYNC_TIME, syncDataSetResponse.getDelaySyncTime(), (syncDataSetResponse.getDelaySyncTime() + 1) * 60);
redisUtil.set("SPS_SYNC_GEN_DATA", System.currentTimeMillis() + syncDataSetResponse.getDelaySyncTime() * 60 * 1000);
}
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
2 years ago
//todo 请立即同步至UDI管理系统
BaseResponse<String> baseResponse = spGetHttpClient.updateSynsSet(syncDataSetResponse);
if (baseResponse.getCode() == 20000) {
return baseResponse;
} else {
return ResultVOUtils.error(500, "UDI管理系统设置成功自助平台修改失败");
}
3 years ago
}
}