32197351@qq.com 1 年之前
父节点
当前提交
498db79111

+ 145 - 130
itdmServer/module-iTDM/src/main/java/org/jeecg/modules/inventory/controller/ItdmInventoryBarcodeController.java

@@ -42,140 +42,155 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.aspect.annotation.AutoLog;
 
 
- /**
+/**
  * @Description: 库存条码
  * @Description: 库存条码
  * @Author: jeecg-boot
  * @Author: jeecg-boot
- * @Date:   2023-06-26
+ * @Date: 2023-06-26
  * @Version: V1.0
  * @Version: V1.0
  */
  */
-@Api(tags="库存条码")
+@Api(tags = "库存条码")
 @RestController
 @RestController
 @RequestMapping("/inventory/itdmInventoryBarcode")
 @RequestMapping("/inventory/itdmInventoryBarcode")
 @Slf4j
 @Slf4j
 public class ItdmInventoryBarcodeController extends JeecgController<ItdmInventoryBarcode, IItdmInventoryBarcodeService> {
 public class ItdmInventoryBarcodeController extends JeecgController<ItdmInventoryBarcode, IItdmInventoryBarcodeService> {
-	@Autowired
-	private IItdmInventoryBarcodeService itdmInventoryBarcodeService;
-	 @Autowired
-	 private IItdmSampleInventoryService itdmSampleInventoryService;
-	/**
-	 * 分页列表查询
-	 *
-	 * @param itdmInventoryBarcode
-	 * @param pageNo
-	 * @param pageSize
-	 * @param req
-	 * @return
-	 */
-	//@AutoLog(value = "库存条码-分页列表查询")
-	@ApiOperation(value="库存条码-分页列表查询", notes="库存条码-分页列表查询")
-	@GetMapping(value = "/list")
-	public Result<IPage<ItdmInventoryBarcode>> queryPageList(ItdmInventoryBarcode itdmInventoryBarcode,
-								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
-								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
-								   HttpServletRequest req) {
-		QueryWrapper<ItdmInventoryBarcode> queryWrapper = QueryGenerator.initQueryWrapper(itdmInventoryBarcode, req.getParameterMap());
-		Page<ItdmInventoryBarcode> page = new Page<ItdmInventoryBarcode>(pageNo, pageSize);
-		IPage<ItdmInventoryBarcode> pageList = itdmInventoryBarcodeService.page(page, queryWrapper);
-		return Result.OK(pageList);
-	}
-	
-	/**
-	 *   添加
-	 *
-	 * @param itdmInventoryBarcode
-	 * @return
-	 */
-	@AutoLog(value = "库存条码-添加")
-	@ApiOperation(value="库存条码-添加", notes="库存条码-添加")
-	//@RequiresPermissions("org.jeecg.modules:itdm_inventory_barcode:add")
-	@PostMapping(value = "/add")
-	@Transactional
-	public Result<String> add(@RequestBody ItdmInventoryBarcode itdmInventoryBarcode) {
-		ItdmSampleInventory itdmSampleInventory = itdmSampleInventoryService.getById(itdmInventoryBarcode.getInventoryId());
-
-		long count= itdmInventoryBarcodeService.count(Wrappers.lambdaQuery(ItdmInventoryBarcode.class).eq(ItdmInventoryBarcode::getInventoryId, itdmInventoryBarcode.getInventoryId()));
-
-
-
-		itdmInventoryBarcode.setBarCode(itdmSampleInventory.getBatchNumber() + String.format("%04d", count + 1));
-		itdmInventoryBarcode.setDisableStatus("0");
-		itdmInventoryBarcode.setUseStatus("0");
-		itdmInventoryBarcode.setNum("1");
-		itdmInventoryBarcodeService.save(itdmInventoryBarcode);
-		return Result.OK("添加成功!");
-	}
-	
-	/**
-	 *  编辑
-	 *
-	 * @param itdmInventoryBarcode
-	 * @return
-	 */
-	@AutoLog(value = "库存条码-编辑")
-	@ApiOperation(value="库存条码-编辑", notes="库存条码-编辑")
-	//@RequiresPermissions("org.jeecg.modules:itdm_inventory_barcode:edit")
-	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
-	public Result<String> edit(@RequestBody ItdmInventoryBarcode itdmInventoryBarcode) {
-		itdmInventoryBarcodeService.updateById(itdmInventoryBarcode);
-		return Result.OK("编辑成功!");
-	}
-	
-	/**
-	 *   通过id删除
-	 *
-	 * @param id
-	 * @return
-	 */
-	@AutoLog(value = "库存条码-通过id删除")
-	@ApiOperation(value="库存条码-通过id删除", notes="库存条码-通过id删除")
-	//@RequiresPermissions("org.jeecg.modules:itdm_inventory_barcode:delete")
-	@DeleteMapping(value = "/delete")
-	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
-
-
-
-		itdmInventoryBarcodeService.removeById(id);
-		return Result.OK("删除成功!");
-	}
-	
-	/**
-	 *  批量删除
-	 *
-	 * @param ids
-	 * @return
-	 */
-	@AutoLog(value = "库存条码-批量删除")
-	@ApiOperation(value="库存条码-批量删除", notes="库存条码-批量删除")
-	//@RequiresPermissions("org.jeecg.modules:itdm_inventory_barcode:deleteBatch")
-	@DeleteMapping(value = "/deleteBatch")
-	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
-		this.itdmInventoryBarcodeService.removeByIds(Arrays.asList(ids.split(",")));
-		return Result.OK("批量删除成功!");
-	}
-	
-	/**
-	 * 通过id查询
-	 *
-	 * @param id
-	 * @return
-	 */
-	//@AutoLog(value = "库存条码-通过id查询")
-	@ApiOperation(value="库存条码-通过id查询", notes="库存条码-通过id查询")
-	@GetMapping(value = "/queryById")
-	public Result<ItdmInventoryBarcode> queryById(@RequestParam(name="id",required=true) String id) {
-		ItdmInventoryBarcode itdmInventoryBarcode = itdmInventoryBarcodeService.getById(id);
-		if(itdmInventoryBarcode==null) {
-			return Result.error("未找到对应数据");
-		}
-		return Result.OK(itdmInventoryBarcode);
-	}
+    @Autowired
+    private IItdmInventoryBarcodeService itdmInventoryBarcodeService;
+    @Autowired
+    private IItdmSampleInventoryService itdmSampleInventoryService;
 
 
     /**
     /**
-    * 导出excel
-    *
-    * @param request
-    * @param itdmInventoryBarcode
-    */
+     * 分页列表查询
+     *
+     * @param itdmInventoryBarcode
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    //@AutoLog(value = "库存条码-分页列表查询")
+    @ApiOperation(value = "库存条码-分页列表查询", notes = "库存条码-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<ItdmInventoryBarcode>> queryPageList(ItdmInventoryBarcode itdmInventoryBarcode,
+                                                             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                             HttpServletRequest req) {
+        QueryWrapper<ItdmInventoryBarcode> queryWrapper = QueryGenerator.initQueryWrapper(itdmInventoryBarcode, req.getParameterMap());
+        Page<ItdmInventoryBarcode> page = new Page<ItdmInventoryBarcode>(pageNo, pageSize);
+        IPage<ItdmInventoryBarcode> pageList = itdmInventoryBarcodeService.page(page, queryWrapper);
+        return Result.OK(pageList);
+    }
+
+    /**
+     * 添加
+     *
+     * @param itdmInventoryBarcode
+     * @return
+     */
+    @AutoLog(value = "库存条码-添加")
+    @ApiOperation(value = "库存条码-添加", notes = "库存条码-添加")
+    //@RequiresPermissions("org.jeecg.modules:itdm_inventory_barcode:add")
+    @PostMapping(value = "/add")
+    @Transactional
+    public Result<String> add(@RequestBody ItdmInventoryBarcode itdmInventoryBarcode) {
+        ItdmSampleInventory itdmSampleInventory = itdmSampleInventoryService.getById(itdmInventoryBarcode.getInventoryId());
+
+        ItdmInventoryBarcode itdmInventoryBarcodeServiceOne = itdmInventoryBarcodeService.getOne(Wrappers.lambdaQuery(ItdmInventoryBarcode.class)
+                .eq(ItdmInventoryBarcode::getInventoryId, itdmInventoryBarcode.getInventoryId()).orderByDesc(ItdmInventoryBarcode::getId).last("limit 1"));
+
+
+        if (itdmInventoryBarcodeServiceOne == null) {
+            itdmInventoryBarcode.setBarCode(itdmSampleInventory.getBatchNumber() + String.format("%04d", 1));
+
+        } else {
+            int start = itdmInventoryBarcodeServiceOne.getBarCode().length() - 4;
+
+            int end = itdmInventoryBarcodeServiceOne.getBarCode().length();
+
+            Integer l = Integer.valueOf(itdmInventoryBarcodeServiceOne.getBarCode().substring(start, end));
+
+            itdmInventoryBarcode.setBarCode(itdmSampleInventory.getBatchNumber() + String.format("%04d", l + 1));
+
+        }
+
+        itdmInventoryBarcode.setDisableStatus("0");
+        itdmInventoryBarcode.setUseStatus("0");
+        itdmInventoryBarcode.setNum("1");
+        itdmInventoryBarcodeService.save(itdmInventoryBarcode);
+        return Result.OK("添加成功!");
+    }
+
+
+
+    /**
+     * 编辑
+     *
+     * @param itdmInventoryBarcode
+     * @return
+     */
+    @AutoLog(value = "库存条码-编辑")
+    @ApiOperation(value = "库存条码-编辑", notes = "库存条码-编辑")
+    //@RequiresPermissions("org.jeecg.modules:itdm_inventory_barcode:edit")
+    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
+    public Result<String> edit(@RequestBody ItdmInventoryBarcode itdmInventoryBarcode) {
+        itdmInventoryBarcodeService.updateById(itdmInventoryBarcode);
+        return Result.OK("编辑成功!");
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "库存条码-通过id删除")
+    @ApiOperation(value = "库存条码-通过id删除", notes = "库存条码-通过id删除")
+    //@RequiresPermissions("org.jeecg.modules:itdm_inventory_barcode:delete")
+    @DeleteMapping(value = "/delete")
+    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
+
+
+        itdmInventoryBarcodeService.removeById(id);
+        return Result.OK("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "库存条码-批量删除")
+    @ApiOperation(value = "库存条码-批量删除", notes = "库存条码-批量删除")
+    //@RequiresPermissions("org.jeecg.modules:itdm_inventory_barcode:deleteBatch")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        this.itdmInventoryBarcodeService.removeByIds(Arrays.asList(ids.split(",")));
+        return Result.OK("批量删除成功!");
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    //@AutoLog(value = "库存条码-通过id查询")
+    @ApiOperation(value = "库存条码-通过id查询", notes = "库存条码-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<ItdmInventoryBarcode> queryById(@RequestParam(name = "id", required = true) String id) {
+        ItdmInventoryBarcode itdmInventoryBarcode = itdmInventoryBarcodeService.getById(id);
+        if (itdmInventoryBarcode == null) {
+            return Result.error("未找到对应数据");
+        }
+        return Result.OK(itdmInventoryBarcode);
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param itdmInventoryBarcode
+     */
     //@RequiresPermissions("org.jeecg.modules:itdm_inventory_barcode:exportXls")
     //@RequiresPermissions("org.jeecg.modules:itdm_inventory_barcode:exportXls")
     @RequestMapping(value = "/exportXls")
     @RequestMapping(value = "/exportXls")
     public ModelAndView exportXls(HttpServletRequest request, ItdmInventoryBarcode itdmInventoryBarcode) {
     public ModelAndView exportXls(HttpServletRequest request, ItdmInventoryBarcode itdmInventoryBarcode) {
@@ -183,12 +198,12 @@ public class ItdmInventoryBarcodeController extends JeecgController<ItdmInventor
     }
     }
 
 
     /**
     /**
-      * 通过excel导入数据
-    *
-    * @param request
-    * @param response
-    * @return
-    */
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
     //@RequiresPermissions("itdm_inventory_barcode:importExcel")
     //@RequiresPermissions("itdm_inventory_barcode:importExcel")
     @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
     @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
     public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
     public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {