chen.lin
昨天 209878277a178ab91d48b523265e5ffb1b8cf7e6
rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/LocController.java
@@ -1,8 +1,6 @@
package com.vincent.rsf.server.manager.controller;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vincent.rsf.framework.common.Cools;
import com.vincent.rsf.framework.common.R;
@@ -15,11 +13,11 @@
import com.vincent.rsf.server.manager.controller.params.LocMastInitParam;
import com.vincent.rsf.server.manager.controller.params.LocModifyParams;
import com.vincent.rsf.server.manager.entity.Loc;
import com.vincent.rsf.server.manager.enums.CommonStatus;
import com.vincent.rsf.server.manager.enums.LocStsType;
import com.vincent.rsf.server.manager.service.LocService;
import com.vincent.rsf.server.system.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,7 +27,6 @@
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.stream.Collectors;
@@ -60,17 +57,66 @@
    }
    @PreAuthorize("hasAuthority('manager:loc:list')")
    @ApiOperation(("获取库位使用率"))
    @PostMapping("/loc/pie/list")
    public R locPie() {
        return R.ok().add(locService.getLocPies());
    }
    @PreAuthorize("hasAuthority('manager:loc:list')")
    @PostMapping("/loc/areaNoUse/list")
    public R areaNoUselist(@RequestBody Map<String, Object> map) {
        String locCode = map.get("locCode").toString();
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, locCode),false);
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, locCode)
                .last("LIMIT 1"));
        List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>()
                .eq(Loc::getAreaId, loc.getAreaId())
                .eq(Loc::getChannel,loc.getChannel())
//                .eq(!Objects.isNull(loc.getChannel()), Loc::getChannel,loc.getChannel())//
                .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
        );
        List<String> list1 = list.stream().map(obj -> obj.getCode()).collect(Collectors.toList());
        return R.ok(list1);
    }
    /** 同库区空闲库位分页,支持按库位号前缀过滤;用于下拉滚动分页或输入前缀实时加载 */
    @PreAuthorize("hasAuthority('manager:loc:list')")
    @PostMapping("/loc/areaNoUse/page")
    public R areaNoUsePage(@RequestBody Map<String, Object> map) {
        String locCode = (String) map.get("locCode");
        int current = map.get("current") != null ? Integer.parseInt(String.valueOf(map.get("current"))) : 1;
        int pageSize = map.get("pageSize") != null ? Integer.parseInt(String.valueOf(map.get("pageSize"))) : 50;
        if (Cools.isEmpty(locCode)) {
            Page<String> emptyPage = new Page<>(current, pageSize);
            emptyPage.setRecords(Collections.emptyList());
            emptyPage.setTotal(0L);
            return R.ok().add(emptyPage);
        }
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, locCode).last("LIMIT 1"));
        if (loc == null) {
            Page<String> emptyPage = new Page<>(current, pageSize);
            emptyPage.setRecords(Collections.emptyList());
            emptyPage.setTotal(0L);
            return R.ok().add(emptyPage);
        }
        String q = map.get("q") != null ? String.valueOf(map.get("q")).trim() : null;
        if (StringUtils.isBlank(q) && map.get("condition") != null) {
            q = String.valueOf(map.get("condition")).trim();
        }
        LambdaQueryWrapper<Loc> wrapper = new LambdaQueryWrapper<Loc>()
                .select(Loc::getCode)
                .eq(Loc::getAreaId, loc.getAreaId())
                .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                .orderByAsc(Loc::getCode);
        if (StringUtils.isNotBlank(q)) {
            wrapper.likeRight(Loc::getCode, q);
        }
        Page<Loc> page = new Page<>(current, pageSize);
        Page<Loc> result = locService.page(page, wrapper);
        List<String> records = result.getRecords().stream().map(Loc::getCode).collect(Collectors.toList());
        Page<String> pageOut = new Page<>(current, pageSize);
        pageOut.setRecords(records);
        pageOut.setTotal(result.getTotal());
        return R.ok().add(pageOut);
    }
    @PreAuthorize("hasAuthority('manager:loc:list')")
@@ -120,10 +166,17 @@
    public R update(@RequestBody Loc loc) {
        loc.setUpdateBy(getLoginUserId());
        String join = StringUtils.join(loc.getTypeIds(), ",");
        loc.setType(join);
        if (Objects.isNull(loc.getTypeIds())) {
            throw new CoolException("库位类型不能为空!!");
        if (!Objects.isNull(loc.getTypeIds())) {
            loc.setType(join);
        }
        if (Objects.isNull(loc.getTypeIds()) && !Objects.isNull(loc.getType())) {
            loc.setTypeIds(Arrays.asList(Long.valueOf(loc.getType())));
        }
        if (loc.getStatus().equals(CommonStatus.COMMONSTATUS_NO.val)) {
            loc.setUseStatus(LocStsType.LOC_STS_TYPE_X.type);
        }
        if (!locService.updateById(loc)) {
            return R.error("Update Fail");
        }
@@ -202,9 +255,6 @@
        }
        if (Objects.isNull(param.getTypeIds()) && param.getTypeIds().isEmpty()) {
            return R.error("库位类型不能为空!!");
        }
        if (Objects.isNull(param.getWarehouseId())) {
            return R.error("仓库ID不能为空!!");
        }
        if (Objects.isNull(param.getAreaId())) {
            return R.error("库区ID不能为空!!");