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

138 lines
5.7 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.glxp.api.controller.sync;
import org.springframework.beans.BeanUtils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageInfo;
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.SyncDataChangeBustypesEntity;
import com.glxp.api.entity.system.SyncDataSetEntity;
import com.glxp.api.http.sync.SpGetHttpClient;
import com.glxp.api.req.basic.FilterBussinessTypeRequest;
import com.glxp.api.res.basic.BasicBussinessTypeResponse;
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;
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.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
@RestController
public class SyncDataSetController {
@Resource
private SyncDataSetService syncDataSetService;
@Resource
private SyncDataBustypeService syncDataBustypeService;
@Resource
private SyncDataChangeBustypeService syncDataChangeBustypeService;
@Resource
private RedisUtil redisUtil;
@Resource
SpGetHttpClient spGetHttpClient;
@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());
syncDataSetEntity.setId(1);
List<SyncDataBustypeEntity> busTypes = syncDataSetResponse.getBusTypes();
//重新生成id防止插入时单据类型被覆盖
for (SyncDataBustypeEntity s:busTypes) {
s.setId(IdUtil.getSnowflakeNextId());
}
syncDataBustypeService.deleteAll(1);
if (CollUtil.isNotEmpty(busTypes)) {
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())) {
syncDataChangeBustypeService.deleteAll();
syncDataChangeBustypeService.inserts(syncDataSetResponse.getChangeBusTypes());
}
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);
}
//todo 请立即同步至UDI管理系统
BaseResponse<String> baseResponse = spGetHttpClient.updateSynsSet(syncDataSetResponse);
if (baseResponse.getCode() == 20000) {
return baseResponse;
} else {
return ResultVOUtils.error(500, "UDI管理系统设置成功自助平台修改失败");
}
}
@AuthRuleAnnotation("system/param/syncData/selectedToInBus")
@GetMapping("/system/param/syncData/selectedToInBus")
public BaseResponse filterselectedToInBus(SyncDataBustypeEntity syncDataBustypeEntity) {
syncDataBustypeEntity.setDirect(2);
List<SyncDataBustypeEntity> list = syncDataBustypeService.filterSelected(syncDataBustypeEntity);
PageInfo<SyncDataBustypeEntity> pageInfo = new PageInfo<>(list);
return ResultVOUtils.page(pageInfo);
}
@AuthRuleAnnotation("system/param/syncData/selectedBus")
@GetMapping("/system/param/syncData/selectedBus")
public BaseResponse filterselectedBus(SyncDataBustypeEntity syncDataBustypeEntity) {
syncDataBustypeEntity.setDirect(1);
List<SyncDataBustypeEntity> list = syncDataBustypeService.filterSelected(syncDataBustypeEntity);
PageInfo<SyncDataBustypeEntity> pageInfo = new PageInfo<>(list);
return ResultVOUtils.page(pageInfo);
}
}