WarehouseController.java 15.4 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
import com.boco.nbd.wios.manage.entity.bo.*;
苗卫卫 committed
9
import com.boco.nbd.wios.manage.entity.dto.*;
10
import com.boco.nbd.wios.manage.mapper.extdb.MaterialsMapperEx;
11
import com.boco.nbd.wios.manage.mapper.extdb.WarehouseMapperEx;
苗卫卫 committed
12 13 14 15
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;
16 17
import com.ihidea.core.util.HttpClientUtils;
import com.ihidea.core.util.XMLUtilsEx;
苗卫卫 committed
18 19 20 21
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
22
import lombok.extern.slf4j.Slf4j;
23
import org.apache.http.Header;
苗卫卫 committed
24 25 26 27 28
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;

29
import javax.annotation.Resource;
30
import javax.crypto.spec.PSource;
苗卫卫 committed
31
import javax.servlet.http.HttpServletRequest;
32
import java.math.BigDecimal;
苗卫卫 committed
33 34 35
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
36
import java.util.Map;
苗卫卫 committed
37 38 39 40 41 42 43 44 45 46 47

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

@RestController
@RequestMapping("api")
@Api(tags = "仓库管理接口")
48
@Slf4j
苗卫卫 committed
49 50 51 52 53 54 55 56 57
public class WarehouseController {

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

    @Autowired
    private WarehouseService warehouseService;
58 59
    @Resource
    MaterialsMapperEx materialsMapperEx;
60 61
    @Autowired
    private WarehouseMapperEx warehouseMapperEx;
苗卫卫 committed
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 102 103 104 105 106 107


    /**
     * 添加/修改仓库
     *
     * @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) {
108 109 110 111 112 113 114 115 116 117 118 119 120 121
        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
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 365 366 367 368 369 370
        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);
    }

371
    /**
372
     * 库存增加
373 374
     *@param warehouseId
     * @param materialsCode
375
     * @param quantity
376 377
     * @return
     */
378
    @PostMapping(value = "reject/increaseInventoryQuantity")
379
    @ApiOperation(value = "确认退货之后更新库存数量")
380
    public BaseResponse<Void> increaseInventoryQuantity(String warehouseId,String materialsCode,String quantity) {
381
        MaterialsEx materials=materialsMapperEx.materialsByMaterialsCode(materialsCode);
382 383 384
        if (materials==null){
            throw new ServiceException("物料不存在");
        }
385
        materialsMapperEx.increaseInventoryQuantity(warehouseId,materials.getId(), new BigDecimal(quantity));
386 387 388
        return new BaseResponse<>();
    }
    /**
389
     * 库存减少
390 391
     *@param warehouseId
     * @param materialsCode
392
     * @param quantity
393 394 395
     * @return
     */
    @PostMapping(value = "reject/reduceInventoryQuantity")
396 397
    @ApiOperation(value = "确认收货之后发货库存扣减")
    public BaseResponse<Void> reduceInventoryQuantity(String warehouseId,String materialsCode,String quantity) {
398
        MaterialsEx materials=materialsMapperEx.materialsByMaterialsCode(materialsCode);
399 400 401
        if (materials==null){
            throw new ServiceException("物料不存在");
        }
402
        materialsMapperEx.reduceInventoryQuantity(warehouseId,materials.getId(), new BigDecimal(quantity));
403 404
        return new BaseResponse<>();
    }
405 406 407 408 409 410 411 412 413 414 415 416
    /**
     * 查询仓库详情
     *
     * @param id
     * @return
     */
    @PostMapping(value = "warehouse/detail")
    @ApiOperation(value = "查询仓库详情")
    public BaseResponse<WarehouseDetail> warehouseDetail(String id) {
        WarehouseDetail warehouseDetail = warehouseMapperEx.warehouseDetailById(id);
        return new BaseResponse<WarehouseDetail>(warehouseDetail);
    }
苗卫卫 committed
417
}