WarehouseController.java 14.2 KB
Newer Older
苗卫卫 committed
1 2 3 4 5 6 7
package com.boco.nbd.wios.manage.controller;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.boco.nbd.cams.core.constant.CamsConstant;
import com.boco.nbd.cams.core.constant.MessageConstant;
import com.boco.nbd.wios.manage.contants.WiosConstant;
8 9
import com.boco.nbd.wios.manage.entity.bo.Materials;
import com.boco.nbd.wios.manage.entity.bo.MaterialsEx;
苗卫卫 committed
10 11
import com.boco.nbd.wios.manage.entity.bo.SingleSaveQuery2;
import com.boco.nbd.wios.manage.entity.dto.*;
12
import com.boco.nbd.wios.manage.mapper.extdb.MaterialsMapperEx;
苗卫卫 committed
13 14 15 16 17 18 19 20
import com.boco.nbd.wios.manage.service.impl.WarehouseService;
import com.boco.nbd.wios.manage.util.NumberUtil;
import com.ihidea.component.api.v2.BaseResponse;
import com.ihidea.core.support.exception.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
21
import lombok.extern.slf4j.Slf4j;
苗卫卫 committed
22 23 24 25 26
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

27
import javax.annotation.Resource;
苗卫卫 committed
28
import javax.servlet.http.HttpServletRequest;
29
import java.math.BigDecimal;
苗卫卫 committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;

/**
 * 仓库管理接口
 *
 * @Author 吉日木图
 * @Date 2022/6/23 16:39
 */

@RestController
@RequestMapping("api")
@Api(tags = "仓库管理接口")
44
@Slf4j
苗卫卫 committed
45 46 47 48 49 50 51 52 53
public class WarehouseController {

    @Value("${sap.username}")
    private String sapUsername;
    @Value("${sap.password}")
    private String sapPassword;

    @Autowired
    private WarehouseService warehouseService;
54 55
    @Resource
    MaterialsMapperEx materialsMapperEx;
苗卫卫 committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101


    /**
     * 添加/修改仓库
     *
     * @param entity
     * @return
     */
    @PostMapping(value = "warehouse/save")
    @ApiOperation(value = "添加/修改仓库")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accountId", value = "账户id", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "appkey", value = "appkey", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "warehouseAttribution", value = "仓库归属 1:CAMS 2:安装服务商", dataType = "String", paramType = "query", required = true),
    })
    public BaseResponse<Void> add(WarehouseSaveQuery entity) {
        warehouseService.saveWarehouse(entity);
        return new BaseResponse<>();
    }


    /**
     * 新增/修改仓库等级
     *
     * @param warehouseLevenSaveQuery
     * @return
     */
    @PostMapping(value = "warehouselevel/save")
    @ApiOperation(value = "新增/修改仓库等级")
    public BaseResponse<Void> saveWarehouseLevel(WarehouseLevenSaveQuery warehouseLevenSaveQuery) {
        if (warehouseLevenSaveQuery.getName().length() > WiosConstant.MAX_WAREHOUSE_NAME_LENGTH) {
            throw new ServiceException("名称过长");
        }
        warehouseService.saveWarehouseLevel(warehouseLevenSaveQuery);
        return new BaseResponse<>();
    }

    /**
     * 查询仓库
     *
     * @param warehouseQuery2
     * @return
     */
    @GetMapping(value = "warehouse/all")
    @ApiOperation(value = "查询仓库")
    public BaseResponse<List<WarehouseDTO2>> qryWarehouseList(WarehouseQuery2 warehouseQuery2) {
102 103 104 105 106 107 108 109 110 111 112 113 114 115
        warehouseQuery2.setIsWarehousePage(1);
        List<WarehouseDTO2> list = warehouseService.qryWarehouseDetailList(warehouseQuery2);
        return new BaseResponse<List<WarehouseDTO2>>(list);
    }
    /**
     * 查询仓库不分页
     *
     * @param warehouseQuery2
     * @return
     */
    @GetMapping(value = "warehouse/allNoPage")
    @ApiOperation(value = "查询仓库")
    public BaseResponse<List<WarehouseDTO2>> qryWarehouseListNoPage(WarehouseQuery2 warehouseQuery2) {
        warehouseQuery2.setIsWarehousePage(2);
苗卫卫 committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
        List<WarehouseDTO2> list = warehouseService.qryWarehouseDetailList(warehouseQuery2);
        return new BaseResponse<List<WarehouseDTO2>>(list);
    }


    /**
     * 查询仓库等级
     *
     * @param name
     * @param serviceProvider
     * @param parentId
     * @return
     */
    @GetMapping(value = "warehouselevel/all")
    @ApiOperation(value = "查询仓库等级")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serviceProvider", value = "服务商id", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "parentId", value = "父级id", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false),})
    public BaseResponse<List<WarehouseLevelDTO2>> qryWarehouseLevel(String serviceProvider, Integer parentId, String name) {
        List<WarehouseLevelDTO2> list = warehouseService.qryWarehouseLevel(serviceProvider, parentId, name);
        return new BaseResponse<List<WarehouseLevelDTO2>>(list);
    }


    /**
     * 查询仓库等级详情
     *
     * @param id
     * @return
     */
    @GetMapping(value = "warehouselevel/detail")
    @ApiOperation(value = "查询仓库等级详情")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "int", paramType = "query", required = false),})
    public BaseResponse<WarehouseLevenDTO> qryWarehouseLevelDetail(Integer id) {
        WarehouseLevenDTO qryLevelDetail = warehouseService.qryLevelDetail(id);
        return new BaseResponse<WarehouseLevenDTO>(qryLevelDetail);
    }


    /**
     * 新增调拨单
     *
     * @param singleSaveQuery
     * @return
     */
    @PostMapping(value = "single/save")
    @ApiOperation(value = "新增调拨单")
    public BaseResponse<Void> saveSingle(SingleSaveQuery2 singleSaveQuery) {
        warehouseService.saveSingle(singleSaveQuery);
        return new BaseResponse<Void>();
    }

    /**
     * 查询调拨单
     *
     * @param singleQuery
     * @return
     */
    @GetMapping(value = "single/all")
    @ApiOperation(value = "查询调拨单")
    public BaseResponse<List<SingleDTO>> saveSingle(SingleQuery singleQuery) {
        List<SingleDTO> list = warehouseService.qrySingal(singleQuery);
        return new BaseResponse<List<SingleDTO>>(list);
    }


    /**
     * 查询单据物料
     *
     * @param singleId
     * @param page
     * @param pagecount
     * @return
     */
    @GetMapping(value = "singleMaterials/all")
    @ApiOperation(value = "查询单据物料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "singleId", value = "单据id", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pagecount", value = "一页显示数量", dataType = "int", paramType = "query", required = true),
    })
    public BaseResponse<List<SingleMaterialsDTO>> qrySingleMaterialsBySingleId(String singleId, Integer page, Integer pagecount) {
        List<SingleMaterialsDTO> list = warehouseService.qrySingleMaterialsBySingleId(singleId, page, pagecount);
        return new BaseResponse<List<SingleMaterialsDTO>>(list);
    }


    /**
     * 新增物料
     *
     * @param materialsListQueryJson
     * @return
     */
    @PostMapping(value = "materials/add")
    @ApiOperation(value = "新增物料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "materialsListQueryJson", value = "物料json", dataType = "String", paramType = "query", required = true),})
    public BaseResponse<Void> saveMaterials(String materialsListQueryJson) {
        Assert.notNull(materialsListQueryJson, MessageConstant.MISSING_PARAM);
        warehouseService.saveMaterials(materialsListQueryJson);
        return new BaseResponse<>();
    }

    @PostMapping(value = "sap/materials/add")
    @ApiOperation(value = "SAP新增物料")
    public BaseResponse<Void> sapSaveMaterials(@RequestBody MaterialsSaveQuery materialsSaveQuery, HttpServletRequest request) {
        String authorization = request.getHeader("authorization");
        if (StrUtil.isBlank(authorization)) {
            throw new ServiceException(403, "权限不足");
        }
        byte[] encode = Base64.getEncoder().encode((sapUsername + ":" + sapPassword).getBytes(StandardCharsets.UTF_8));
        if (!authorization.equals(WiosConstant.AUTHORIZATION_FLAG + new String(encode))) {
            throw new ServiceException(403, "权限不足");
        }

        Assert.notNull(materialsSaveQuery.getMaterialsCode(), "缺少物料编码");
        Assert.notNull(materialsSaveQuery.getMaterialsName(), "缺少物料名称");
        Assert.notNull(materialsSaveQuery.getRegularModel(), "缺少规则型号");
        Assert.notNull(materialsSaveQuery.getUnit(), "缺少单位");
        Assert.notNull(materialsSaveQuery.getType(), "缺少类别");
        warehouseService.saveMaterials(materialsSaveQuery);
        return new BaseResponse<>();
    }

    /**
     * 更新物料
     *
     * @param materialsSaveQuery
     * @return
     */
    @PostMapping(value = "materials/update")
    @ApiOperation(value = "更新物料")
    public BaseResponse<Void> saveMaterials(MaterialsSaveQuery materialsSaveQuery) {
        Assert.notNull(materialsSaveQuery.getId(), MessageConstant.MISSING_PARAM);
        warehouseService.updateMaterial(materialsSaveQuery);
        return new BaseResponse<>();
    }

    /**
     * 查询物料
     *
     * @param materialsQuery
     * @return
     */
    @GetMapping(value = "materials/all")
    @ApiOperation(value = "查询物料")
    public BaseResponse<List<MaterialsDTO>> qryMaterials(MaterialsQuery materialsQuery) {
        List<MaterialsDTO> list = warehouseService.qryMaterials(materialsQuery);
        return new BaseResponse<>(list);
    }

    /**
     * 删除物料
     *
     * @param materialsId
     * @return
     */
    @PostMapping(value = "materials/delete")
    @ApiOperation(value = "删除物料物料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "materialsId", value = "物料id", dataType = "String", paramType = "query", required = true),
    })
    public BaseResponse<Void> delMaterials(String materialsId) {
        Assert.notNull(materialsId, MessageConstant.MISSING_PARAM);
        warehouseService.delMaterials(materialsId);
        return new BaseResponse<>();
    }

    /**
     * 删除仓库
     *
     * @param id
     * @return
     */
    @PostMapping(value = "warehouse/delById")
    @ApiOperation(value = "删除仓库")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "仓库id", dataType = "String", paramType = "query", required = true),})
    public BaseResponse<Void> delWarehouseById(String id) {
        Assert.notNull(id,MessageConstant.MISSING_PARAM);
        warehouseService.delWarehouseById(id);
        return new BaseResponse<>();
    }

    /**
     * 删除仓库等级
     *
     * @param id
     * @return
     */
    @PostMapping(value = "warehouselevel/delById")
    @ApiOperation(value = "删除仓库等级")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "仓库等级id", dataType = "int", paramType = "query", required = true),})
    public BaseResponse<Void> delWarehouseById(Integer id) {
        Assert.notNull(id, MessageConstant.MISSING_PARAM);
        warehouseService.delWarehouseLevelById(id);
        return new BaseResponse<>();
    }

    /**
     * 仓库启用/禁用
     *
     * @param id
     * @param enable
     * @return
     */
    @PostMapping(value = "warehouse/updateEnable")
    @ApiOperation(value = "仓库启用/禁用")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "仓库id", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "enable", value = "0:禁用 1:启用", dataType = "int", paramType = "query", required = true),})
    public BaseResponse<Void> delWarehouseById(String id, Integer enable) {
        Assert.notNull(id, MessageConstant.MISSING_PARAM);
        Assert.notNull(enable, MessageConstant.MISSING_PARAM);
        warehouseService.updateEnable(id, enable);
        return new BaseResponse<>();
    }

    /**
     * 组装查询数据
     *
     * @param id
     * @return
     */
    @GetMapping(value = "warehouse/combineSelectorData")
    @ApiOperation(value = "组装查询数据")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "仓库等级id", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "type", value = "类型 1:只显示总仓", dataType = "int", paramType = "query", required = false),})
    public BaseResponse<List<WarehouseSelectorData>> combineSelectorData(Integer id, Integer type) {
        List<WarehouseSelectorData> list = warehouseService.combineSelectorData(id, type);
        return new BaseResponse<List<WarehouseSelectorData>>(list);
    }

    /**
     * 查询库存物料
     *
     * @param materialsQuery
     * @return
     */
    @GetMapping(value = "materials/stock/all")
    @ApiOperation(value = "查询库存物料")
    public BaseResponse<List<MaterialsDTO>> qryStockMaterials(MaterialsQuery materialsQuery) {
        List<MaterialsDTO> list = warehouseService.qryStockMaterials(materialsQuery);
        // id唯一 给前端用的
        for (MaterialsDTO dto : list) {
            dto.setId(dto.getId() + CamsConstant.UNDER_LINE + NumberUtil.getRandomNumbers(5));
        }
        return new BaseResponse<List<MaterialsDTO>>(list);
    }

365
    /**
366
     * 确认退货之后恢复库存数量
367 368 369 370
     *
     * @param materialsQuery
     * @return
     */
371
    @PostMapping(value = "reject/restoreInventoryQuantity")
372
    @ApiOperation(value = "确认退货之后更新库存数量")
373
    public BaseResponse<Void> restoreInventoryQuantity(MaterialsQuery materialsQuery) {
374 375 376 377
        MaterialsEx materials=materialsMapperEx.materialsByMaterialsCode(materialsQuery.getMaterialsCode());
        if (materials==null){
            throw new ServiceException("物料不存在");
        }
378
        materialsMapperEx.RestoreInventoryQuantity(materialsQuery.getWarehouseId(),materials.getId(), BigDecimal.valueOf(1));
379 380
        return new BaseResponse<>();
    }
苗卫卫 committed
381
}