#
vincentlu
1 天以前 11e44b3012e829ff7c85363ce1a7c2c0457c72f0
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java
@@ -6,6 +6,7 @@
import com.zy.acs.common.utils.Utils;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.framework.common.R;
import com.zy.acs.framework.exception.CoolException;
import com.zy.acs.manager.common.annotation.OperationLog;
import com.zy.acs.manager.common.domain.BaseParam;
import com.zy.acs.manager.common.domain.KeyValVo;
@@ -20,6 +21,7 @@
import com.zy.acs.manager.system.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
@@ -67,13 +69,36 @@
    @PreAuthorize("hasAuthority('manager:route:save')")
    @OperationLog("Create Route")
    @PostMapping("/route/save")
    @Transactional
    public R save(@RequestBody Route route) {
        route.setCreateBy(getLoginUserId());
        route.setCreateTime(new Date());
        route.setUpdateBy(getLoginUserId());
        route.setUpdateTime(new Date());
        if (!routeService.save(route)) {
        if (route.getStartCode() == null || route.getEndCode() == null) {
            return R.error("Save Fail");
        }
        if (route.getStartCode().equals(route.getEndCode())) {
            return R.error("Save Fail");
        }
        if (routeService.count(new LambdaQueryWrapper<Route>()
                .eq(Route::getStartCode, route.getStartCode())
                .eq(Route::getEndCode, route.getEndCode())) > 0 ||
                routeService.count(new LambdaQueryWrapper<Route>()
                        .eq(Route::getStartCode, route.getEndCode())
                        .eq(Route::getEndCode, route.getStartCode())) > 0
        ) {
            return R.error("Save Fail");
        }
        Code startCode = codeService.getCacheById(route.getStartCode());
        Code endCode = codeService.getCacheById(route.getEndCode());
        if (null == startCode || null == endCode) {
            return R.error("Save Fail");
        }
        Route result = routeService.createRouteByCode(startCode, endCode, route.getDirection(), getLoginUserId());
        codeGapService.createCodeGapByCode(startCode, endCode, getLoginUserId());
        if (null == result) {
            throw new CoolException("Save Fail");
        }
        return R.ok("Save Success").add(route);
    }
@@ -82,11 +107,44 @@
    @OperationLog("Update Route")
    @PostMapping("/route/update")
    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");
        }
        if (routeService.count(new LambdaQueryWrapper<Route>()
                .eq(Route::getStartCode, route.getStartCode())
                .eq(Route::getEndCode, route.getEndCode())
                .ne(Route::getId, route.getId())) > 0 ||
                routeService.count(new LambdaQueryWrapper<Route>()
                        .eq(Route::getStartCode, route.getEndCode())
                        .eq(Route::getEndCode, route.getStartCode())
                        .ne(Route::getId, route.getId())) > 0
        ) {
            return R.error("Update Fail");
        }
        route.setUpdateBy(getLoginUserId());
        route.setUpdateTime(new Date());
        if (!routeService.updateById(route)) {
            return R.error("Update Fail");
        }
        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);
    }
@@ -94,9 +152,20 @@
    @OperationLog("Delete Route")
    @PostMapping("/route/remove/{ids}")
    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");
        }
        codeService.refreshCornerByCodeIds(affectedCodeIds);
        return R.ok("Delete Success").add(ids);
    }
@@ -137,10 +206,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(Utils.zeroFill(excelDto.getStartCode(), CommonConstant.QR_CODE_LEN));
            Code code1 = codeService.getCacheByData(Utils.zeroFill(excelDto.getEndCode(), CommonConstant.QR_CODE_LEN));
            if (null == code0 || null == code1) { continue; }