| | |
| | | import org.jeecg.modules.lsw.entity.LswMaterial; |
| | | import org.jeecg.modules.lsw.enums.MaterialCategoryEnum; |
| | | import org.jeecg.modules.lsw.service.ILswMaterialService; |
| | | import org.jeecg.modules.lsw.vo.MaterialScanResultVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | |
| | | List<LswMaterial> lswMaterialList = lswMaterialService.list(queryWrapper); |
| | | return Result.ok(lswMaterialList); |
| | | } |
| | | |
| | | @ApiOperation(value = "线边库物料信息-扫码", notes = "线边库物料信息-扫码") |
| | | @GetMapping(value = "/scan") |
| | | public Result<?> scan(@RequestParam("qrCode") String qrCode) { |
| | | if (StringUtils.isBlank(qrCode)) { |
| | | return Result.error("扫码信息为空!"); |
| | | } |
| | | MaterialScanResultVO result = parseQrCode(qrCode); |
| | | //查询物料数据 |
| | | LswMaterial material = lswMaterialService.queryByMaterialNumber(result.getMaterialNumber()); |
| | | if(material == null) { |
| | | return Result.error("根据物料编号未查询到物料!"); |
| | | } |
| | | result.setMaterialName(material.getMaterialName()); |
| | | result.setMaterialCategory(material.getMaterialCategory()); |
| | | return Result.OK(result); |
| | | } |
| | | |
| | | /** |
| | | * 解析二维码字符串 |
| | | * @param qrCode |
| | | * @return |
| | | */ |
| | | private static MaterialScanResultVO parseQrCode(String qrCode) { |
| | | MaterialScanResultVO vo = new MaterialScanResultVO(); |
| | | String[] split = qrCode.split("#"); |
| | | for (String str : split) { |
| | | if (StringUtils.isBlank(str)) { |
| | | //不符合规则 |
| | | continue; |
| | | } |
| | | String[] pairs = str.split("="); |
| | | if (pairs.length != 2) { |
| | | //不符合规则 |
| | | continue; |
| | | } |
| | | String key = pairs[0]; |
| | | String value = pairs[1]; |
| | | switch (key) { |
| | | case "FactoryCode": |
| | | vo.setFactoryCode(value); |
| | | break; |
| | | case "SkuCode": |
| | | vo.setMaterialNumber(value); |
| | | break; |
| | | case "Quantity": |
| | | vo.setQuantity(new BigDecimal(value)); |
| | | break; |
| | | case "TrackLot": |
| | | case "ProductionTracklot": |
| | | case "SupplierTrackLot": |
| | | vo.setBatchNumber(value); |
| | | break; |
| | | case "Section": |
| | | vo.setSection(value); |
| | | break; |
| | | } |
| | | } |
| | | return vo; |
| | | } |
| | | |
| | | } |