#
vincentlu
2 天以前 9cea4833f937cd6dfb49299d0240215581c79188
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java
@@ -2,7 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.acs.common.constant.CommonConstant;
import com.zy.acs.common.utils.QrCodeCodecSupport;
import com.zy.acs.common.utils.Utils;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.framework.common.R;
@@ -87,8 +87,8 @@
            return R.error("Save Fail");
        }
        Code startCode = codeService.getById(route.getStartCode());
        Code endCode = codeService.getById(route.getEndCode());
        Code startCode = codeService.getCacheById(route.getStartCode());
        Code endCode = codeService.getCacheById(route.getEndCode());
        if (null == startCode || null == endCode) {
            return R.error("Save Fail");
@@ -106,7 +106,12 @@
    @PreAuthorize("hasAuthority('manager:route:update')")
    @OperationLog("Update Route")
    @PostMapping("/route/update")
    @Transactional
    public R update(@RequestBody Route route) {
        Route origin = routeService.getById(route.getId());
        if (origin == null) {
            return R.error("Update Fail");
        }
        if (route.getStartCode().equals(route.getEndCode())) {
            return R.error("Update Fail");
        }
@@ -127,16 +132,53 @@
        if (!routeService.updateById(route)) {
            return R.error("Update Fail");
        }
        Code startCode = codeService.getCacheById(route.getStartCode());
        Code endCode = codeService.getCacheById(route.getEndCode());
        if (startCode != null && endCode != null) {
            codeGapService.createCodeGapByCode(startCode, endCode, getLoginUserId());
        }
        if (!isSameCode(origin, route)) {
            codeGapService.removeCodeGapIfUnused(origin.getStartCode(), origin.getEndCode());
        }
        List<Long> affectedCodeIds = new ArrayList<>();
        if (origin.getStartCode() != null) {
            affectedCodeIds.add(origin.getStartCode());
        }
        if (origin.getEndCode() != null) {
            affectedCodeIds.add(origin.getEndCode());
        }
        if (route.getStartCode() != null) {
            affectedCodeIds.add(route.getStartCode());
        }
        if (route.getEndCode() != null) {
            affectedCodeIds.add(route.getEndCode());
        }
        codeService.refreshCornerByCodeIds(affectedCodeIds);
        return R.ok("Update Success").add(route);
    }
    @PreAuthorize("hasAuthority('manager:route:remove')")
    @OperationLog("Delete Route")
    @PostMapping("/route/remove/{ids}")
    @Transactional
    public R remove(@PathVariable Long[] ids) {
        List<Route> routes = routeService.listByIds(Arrays.asList(ids));
        List<Long> affectedCodeIds = new ArrayList<>();
        for (Route route : routes) {
            if (route.getStartCode() != null) {
                affectedCodeIds.add(route.getStartCode());
            }
            if (route.getEndCode() != null) {
                affectedCodeIds.add(route.getEndCode());
            }
        }
        if (!routeService.removeByIds(Arrays.asList(ids))) {
            return R.error("Delete Fail");
        }
        for (Route route : routes) {
            codeGapService.removeCodeGapIfUnused(route.getStartCode(), route.getEndCode());
        }
        codeService.refreshCornerByCodeIds(affectedCodeIds);
        return R.ok("Delete Success").add(ids);
    }
@@ -177,10 +219,10 @@
                key = Utils.toCamelCase(key);
                one.put(key, entry.getValue());
            }
            RouteExcel excelDto = Cools.conver(one, RouteExcel.class);
            RouteExcel excelDto = Cools.convert(one, RouteExcel.class);
            Code code0 = codeService.selectByData(Utils.zeroFill(excelDto.getStartCode(), CommonConstant.QR_CODE_LEN));
            Code code1 = codeService.selectByData(Utils.zeroFill(excelDto.getEndCode(), CommonConstant.QR_CODE_LEN));
            Code code0 = codeService.getCacheByData(excelDto.getStartCode());
            Code code1 = codeService.getCacheByData(excelDto.getEndCode());
            if (null == code0 || null == code1) { continue; }
@@ -190,4 +232,11 @@
        return R.ok();
    }
    private boolean isSameCode(Route route0, Route route1) {
        return Objects.equals(route0.getStartCode(), route1.getStartCode())
                && Objects.equals(route0.getEndCode(), route1.getEndCode())
                || Objects.equals(route0.getStartCode(), route1.getEndCode())
                && Objects.equals(route0.getEndCode(), route1.getStartCode());
    }
}