MobileConfigController.java 10.6 KB
package com.huaheng.config.mobile;

import com.alibaba.fastjson.JSONException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.common.core.utils.StringUtils;
import com.huaheng.common.core.web.controller.BaseController;
import com.huaheng.common.core.web.domain.AjaxResult;
import com.huaheng.common.core.web.page.TableDataInfo;
import com.huaheng.common.security.utils.SecurityUtils;
import com.huaheng.config.api.domain.*;
import com.huaheng.config.container.service.ContainerService;
import com.huaheng.config.location.service.LocationService;
import com.huaheng.config.material.service.MaterialService;
import com.huaheng.config.material.service.MaterialTypeService;
import com.huaheng.config.receipt.service.ReceiptTypeService;
import com.huaheng.config.shipment.service.ShipmentTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Api(tags= "物料")
@RestController
@RequestMapping("/mobile")
public class MobileConfigController extends BaseController {

    @Resource
    private MaterialService materialService;
    @Resource
    private MaterialTypeService  materialTypeService;
    @Resource
    private LocationService locationService;
    @Resource
    private ContainerService containerService;
    @Resource
    private ReceiptTypeService receiptTypeService;
    @Resource
    private ShipmentTypeService shipmentTypeService;

    @PostMapping("/searchMaterialInCondition")
    @ApiOperation("移动端查询物料信息")
    public TableDataInfo searchMaterialInCondition(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
//        List<String> companyCodeList =  StringUtils.stringToLIST(param.get("companyCode"));
        String code = param.get("code");
        String name = param.get("name");
        String spec = param.get("spec");
        String startTime = param.get("startTime");
        String endTime = param.get("endTime");
        Integer pageNum = Integer.parseInt(param.get("pageNum"));
        Integer pageSize =  Integer.parseInt(param.get("pageSize"));
        LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
        materialLambdaQueryWrapper
                .eq(Material::getWarehouseCode, SecurityUtils.getWarehouseCode())
                .eq(Material::getDeleted, false)
                .like(StringUtils.isNotEmpty(code), Material::getCode, code)
                .like(StringUtils.isNotEmpty(name), Material::getName, name)
                .like(StringUtils.isNotEmpty(spec), Material::getSpec, spec)
                .gt(StringUtils.isNotEmpty(startTime), Material::getCreated, startTime)
                .le(StringUtils.isNotEmpty(endTime), Material::getCreated, endTime)
                .orderByDesc(Material::getCreated);
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            Page<Material> page = new Page<>(pageNum, pageSize);
            IPage<Material> iPage = materialService.page(page, materialLambdaQueryWrapper);
            return getMpDataTable(iPage.getRecords(), iPage.getTotal());
        } else {
            List<Material> list = materialService.list(materialLambdaQueryWrapper);
            return getDataTable(list);
        }
    }

    @PostMapping("/addMaterial")
    @ApiOperation("移动端增加物料信息")
    public AjaxResult addMaterial(@RequestBody @ApiParam(value = "物料号") Material material) throws Exception {
        AjaxResult result = materialService.addSave(material);
        return result;
    }

    @PostMapping("/getMaterialType")
    @ApiOperation("移动端获取物料类型")
    public AjaxResult getMaterialType(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        LambdaQueryWrapper<MaterialType> materialTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
        List<MaterialType> materialTypes = materialTypeService.list(materialTypeLambdaQueryWrapper);
        return AjaxResult.success(materialTypes);
    }

    @PostMapping("/createMaterialCode")
    @ApiOperation("移动端创建物料编码")
    public AjaxResult createMaterialCode(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
        String code = null;
        Date now = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        String day = df.format(now);
        LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
        materialLambdaQueryWrapper.like(Material::getCode, day);
        materialLambdaQueryWrapper.orderByDesc(Material::getId);
        List<Material> materials = materialService.list(materialLambdaQueryWrapper);
        int length = materials.size();
        //如果指定类型的最后的code存在,并且日期一致。那么 code = 入库单类型 + 年月日 + (排序号 + 1)
        if (length > 0) {
            String maxCode =  materials.get(0).getCode();
            Integer count = Integer.valueOf(maxCode.substring(maxCode.length() - 3, maxCode.length()));
            code = day + String.format("%03d", count + 1);
        } else {
            code = day + "001";
        }
        return AjaxResult.success("创建物料成功",code);
    }

    @PostMapping( "/isLocation")
    @ApiOperation("判断是不是库位")
    @ResponseBody
    public AjaxResult isLocation(@RequestBody @ApiParam(value="任务id") Map<String, String> param) {
        String code = param.get("code");
        if (StringUtils.isEmpty(code)) {
            return AjaxResult.error("location不能为空");
        }
        LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Location::getCode, code);
        Location location = locationService.getOne(queryWrapper);
        if(location == null) {
            return AjaxResult.error("没有这个库位");
        }
        return AjaxResult.success("库位存在",code);
    }

    @PostMapping( "/isContainer")
    @ApiOperation("判断是不是库位")
    @ResponseBody
    public AjaxResult isContainer(@RequestBody @ApiParam(value="任务id") Map<String, String> param) {
        String code = param.get("code");
        if (StringUtils.isEmpty(code)) {
            return AjaxResult.error("location不能为空");
        }
        LambdaQueryWrapper<Container> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Container::getCode, code);
        Container container = containerService.getOne(queryWrapper);
        if(container == null) {
            return AjaxResult.error("没有这个容器");
        }
        return AjaxResult.success("容器存在",code);
    }

    @PostMapping("/getReceiptType")
    @ApiOperation("移动端查询入库类型")
    public AjaxResult getReceiptType(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
        LambdaQueryWrapper<ReceiptType> receiptTypeLambda = Wrappers.lambdaQuery();
        List<ReceiptType> receiptType = receiptTypeService.list(receiptTypeLambda);
        return AjaxResult.success(receiptType);
    }

    @PostMapping("/findMaterial")
    @ApiOperation("移动端查询物料信息")
    public TableDataInfo findMaterial(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        Integer pageNum = Integer.parseInt(param.get("pageNum"));
        Integer pageSize =  Integer.parseInt(param.get("pageSize"));
        LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
        materialLambdaQueryWrapper.eq(Material::getDeleted, false)
                .orderByDesc(Material::getCreated);
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            Page<Material> page = new Page<>(pageNum, pageSize);
            IPage<Material> iPage = materialService.page(page, materialLambdaQueryWrapper);
            return getMpDataTable(iPage.getRecords(), iPage.getTotal());
        } else {
            List<Material> list = materialService.list(materialLambdaQueryWrapper);
            return getDataTable(list);
        }
    }

    @PostMapping("/getMaterial")
    @ApiOperation("移动端获取物料信息")
    public AjaxResult getMaterial(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        if (param.get("code") == null || param.get("code").trim().length() < 1) {
            throw new JSONException("容器号(code)不能为空");
        }
        Material material = materialService.findAllByCode(param.get("code"));
        if (material == null) {
            return AjaxResult.error("没有该物料");
        }
        MaterialInfo materialInfo = new MaterialInfo();
        materialInfo.setMaterialCode(material.getCode());
        materialInfo.setMaterialName(material.getName());
        materialInfo.setType(material.getSpec());

        return AjaxResult.success(materialInfo);
    }

    @PostMapping("/getShipmentType")
    @ApiOperation("移动端查询入库类型")
    public AjaxResult getShipmentType(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
        LambdaQueryWrapper<ShipmentType> shipmentTypeLambda = Wrappers.lambdaQuery();
        List<ShipmentType> shipmentTypes = shipmentTypeService.list(shipmentTypeLambda);
        return AjaxResult.success(shipmentTypes);
    }

    @PostMapping("/getLocationFromContainer")
    @ApiOperation("手机扫描容器获得库位号")
    public AjaxResult getLocationFromContainer(@RequestBody @ApiParam(value="容器号") Map<String, String> param) throws Exception {
        if  (param.get("containerCode") == null || param.get("containerCode").trim().length() < 1) {
            throw new JSONException("容器号(containerCode)不能为空");
        }
        String containerCode = param.get("containerCode");
        Location location = locationService.getLocationByContainerCode(containerCode);
        if(location == null) {
            return AjaxResult.error("没有该库位");
        }
        return AjaxResult.success("获取成功",location.getCode());
    }


    @PostMapping("/getEmptyContainerInLocation")
    @ApiOperation("选取空托出库的库位")
    public AjaxResult getEmptyContainerInLocation(@RequestBody Map<String, String> param) {
        List<Location> list = containerService.getEmptyContainerInLocation(null,null,SecurityUtils.getWarehouseCode());
        return  AjaxResult.success(list);
    }
}