新火炬后端单体项目初始化代码
lixiangyu
4 小时以前 345941d946f5a48d31660a58dfc7911d7639a97d
feat(cms): 刀具库存统计

- 新增刀具库存统计功能,支持按刀具 ID 和状态进行分页查询
- 在 CuttingInventoryController 中添加 statistics 方法处理统计查询请求
- 在 CuttingInventoryMapper 中添加 statisticsByCuttingIdAndStatus 方法实现统计查询- 在 CuttingInventoryServiceImpl 中实现 statisticsByCuttingIdAndStatus 方法- 优化代码结构,删除未使用的导入和冗余代码
已修改5个文件
301 ■■■■■ 文件已修改
src/main/java/org/jeecg/modules/cms/controller/CuttingInventoryController.java 258 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/modules/cms/mapper/CuttingInventoryMapper.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/modules/cms/mapper/xml/CuttingInventoryMapper.xml 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/modules/cms/service/ICuttingInventoryService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/modules/cms/service/impl/CuttingInventoryServiceImpl.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/modules/cms/controller/CuttingInventoryController.java
@@ -3,15 +3,11 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.cms.entity.CuttingInventory;
import org.jeecg.modules.cms.service.ICuttingInventoryService;
@@ -20,141 +16,133 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
 /**
/**
 * @Description: 刀具库存
 * @Author: jeecg-boot
 * @Date:   2025-07-28
 * @Date: 2025-07-28
 * @Version: V1.0
 */
@Api(tags="刀具库存")
@Api(tags = "刀具库存")
@RestController
@RequestMapping("/cms/cuttingInventory")
@Slf4j
public class CuttingInventoryController extends JeecgController<CuttingInventory, ICuttingInventoryService> {
    @Autowired
    private ICuttingInventoryService cuttingInventoryService;
    /**
     * 分页列表查询
     *
     * @param cuttingInventory
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "刀具库存-分页列表查询")
    @ApiOperation(value="刀具库存-分页列表查询", notes="刀具库存-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<CuttingInventory>> queryPageList(CuttingInventory cuttingInventory,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<CuttingInventory> queryWrapper = QueryGenerator.initQueryWrapper(cuttingInventory, req.getParameterMap());
        Page<CuttingInventory> page = new Page<CuttingInventory>(pageNo, pageSize);
        IPage<CuttingInventory> pageList = cuttingInventoryService.page(page, queryWrapper);
        return Result.OK(pageList);
    }
    /**
     *   添加
     *
     * @param cuttingInventory
     * @return
     */
    @AutoLog(value = "刀具库存-添加")
    @ApiOperation(value="刀具库存-添加", notes="刀具库存-添加")
    //@RequiresPermissions("org.jeecg.modules:cms_cutting_inventory:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody CuttingInventory cuttingInventory) {
        cuttingInventoryService.save(cuttingInventory);
        return Result.OK("添加成功!");
    }
    /**
     *  编辑
     *
     * @param cuttingInventory
     * @return
     */
    @AutoLog(value = "刀具库存-编辑")
    @ApiOperation(value="刀具库存-编辑", notes="刀具库存-编辑")
    //@RequiresPermissions("org.jeecg.modules:cms_cutting_inventory:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<String> edit(@RequestBody CuttingInventory cuttingInventory) {
        cuttingInventoryService.updateById(cuttingInventory);
        return Result.OK("编辑成功!");
    }
    /**
     *   通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "刀具库存-通过id删除")
    @ApiOperation(value="刀具库存-通过id删除", notes="刀具库存-通过id删除")
    //@RequiresPermissions("org.jeecg.modules:cms_cutting_inventory:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name="id",required=true) String id) {
        cuttingInventoryService.removeById(id);
        return Result.OK("删除成功!");
    }
    /**
     *  批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "刀具库存-批量删除")
    @ApiOperation(value="刀具库存-批量删除", notes="刀具库存-批量删除")
    //@RequiresPermissions("org.jeecg.modules:cms_cutting_inventory:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        this.cuttingInventoryService.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<CuttingInventory> queryById(@RequestParam(name="id",required=true) String id) {
        CuttingInventory cuttingInventory = cuttingInventoryService.getById(id);
        if(cuttingInventory==null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(cuttingInventory);
    }
    @Autowired
    private ICuttingInventoryService cuttingInventoryService;
    /**
    * 导出excel
    *
    * @param request
    * @param cuttingInventory
    */
     * 分页列表查询
     *
     * @param cuttingInventory
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "刀具库存-分页列表查询")
    @ApiOperation(value = "刀具库存-分页列表查询", notes = "刀具库存-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<CuttingInventory>> queryPageList(CuttingInventory cuttingInventory,
                                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                         HttpServletRequest req) {
        QueryWrapper<CuttingInventory> queryWrapper = QueryGenerator.initQueryWrapper(cuttingInventory, req.getParameterMap());
        Page<CuttingInventory> page = new Page<CuttingInventory>(pageNo, pageSize);
        IPage<CuttingInventory> pageList = cuttingInventoryService.page(page, queryWrapper);
        return Result.OK(pageList);
    }
    /**
     * 添加
     *
     * @param cuttingInventory
     * @return
     */
    @AutoLog(value = "刀具库存-添加")
    @ApiOperation(value = "刀具库存-添加", notes = "刀具库存-添加")
    //@RequiresPermissions("org.jeecg.modules:cms_cutting_inventory:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody CuttingInventory cuttingInventory) {
        cuttingInventoryService.save(cuttingInventory);
        return Result.OK("添加成功!");
    }
    /**
     * 编辑
     *
     * @param cuttingInventory
     * @return
     */
    @AutoLog(value = "刀具库存-编辑")
    @ApiOperation(value = "刀具库存-编辑", notes = "刀具库存-编辑")
    //@RequiresPermissions("org.jeecg.modules:cms_cutting_inventory:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody CuttingInventory cuttingInventory) {
        cuttingInventoryService.updateById(cuttingInventory);
        return Result.OK("编辑成功!");
    }
    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "刀具库存-通过id删除")
    @ApiOperation(value = "刀具库存-通过id删除", notes = "刀具库存-通过id删除")
    //@RequiresPermissions("org.jeecg.modules:cms_cutting_inventory:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        cuttingInventoryService.removeById(id);
        return Result.OK("删除成功!");
    }
    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "刀具库存-批量删除")
    @ApiOperation(value = "刀具库存-批量删除", notes = "刀具库存-批量删除")
    //@RequiresPermissions("org.jeecg.modules:cms_cutting_inventory:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.cuttingInventoryService.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<CuttingInventory> queryById(@RequestParam(name = "id", required = true) String id) {
        CuttingInventory cuttingInventory = cuttingInventoryService.getById(id);
        if (cuttingInventory == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(cuttingInventory);
    }
    /**
     * 导出excel
     *
     * @param request
     * @param cuttingInventory
     */
    //@RequiresPermissions("org.jeecg.modules:cms_cutting_inventory:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, CuttingInventory cuttingInventory) {
@@ -162,16 +150,30 @@
    }
    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("cms_cutting_inventory:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, CuttingInventory.class);
    }
    /**
     * 刀具库存统计
     */
    @ApiOperation(value = "刀具库存-统计分页查询", notes = "刀具库存-统计分页查询")
    @GetMapping(value = "/statistics")
    public Result<IPage<Map<String, Object>>> statistics(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<Map<String, Object>> page = new Page<>(pageNo, pageSize);
        IPage<Map<String, Object>> pageList = cuttingInventoryService.statisticsByCuttingIdAndStatus(page);
        return Result.OK(pageList);
    }
}
src/main/java/org/jeecg/modules/cms/mapper/CuttingInventoryMapper.java
@@ -1,8 +1,9 @@
package org.jeecg.modules.cms.mapper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.cms.entity.CuttingInventory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@@ -13,5 +14,4 @@
 * @Version: V1.0
 */
public interface CuttingInventoryMapper extends BaseMapper<CuttingInventory> {
}
    IPage<Map<String, Object>> statisticsByCuttingIdAndStatus(Page<Map<String, Object>> page);}
src/main/java/org/jeecg/modules/cms/mapper/xml/CuttingInventoryMapper.xml
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.cms.mapper.CuttingInventoryMapper">
    <select id="statisticsByCuttingIdAndStatus" resultType="map">
        SELECT
            t1.cutting_id as cuttingId,
            count(*) AS cuttingIdNumber,
            t1.inventory_status as inventoryStatus,
            t2.cutting_code AS cuttingCode
        FROM
            cms_cutting_inventory t1
        LEFT JOIN cms_cutting_tool t2 ON t1.cutting_id = t2.id AND t2.del_flag = 0
        GROUP BY cutting_id, inventory_status, cutting_code
    </select>
</mapper>
src/main/java/org/jeecg/modules/cms/service/ICuttingInventoryService.java
@@ -1,7 +1,12 @@
package org.jeecg.modules.cms.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.cms.entity.CuttingInventory;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
/**
 * @Description: 刀具库存
@@ -11,4 +16,6 @@
 */
public interface ICuttingInventoryService extends IService<CuttingInventory> {
    IPage<Map<String, Object>> statisticsByCuttingIdAndStatus(Page<Map<String, Object>> page);
}
src/main/java/org/jeecg/modules/cms/service/impl/CuttingInventoryServiceImpl.java
@@ -1,11 +1,21 @@
package org.jeecg.modules.cms.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.cms.entity.CuttingInventory;
import org.jeecg.modules.cms.mapper.CuttingInventoryMapper;
import org.jeecg.modules.cms.mapper.CuttingToolMapper;
import org.jeecg.modules.cms.service.ICuttingInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
 * @Description: 刀具库存
@@ -15,5 +25,9 @@
 */
@Service
public class CuttingInventoryServiceImpl extends ServiceImpl<CuttingInventoryMapper, CuttingInventory> implements ICuttingInventoryService {
    @Override
    public IPage<Map<String, Object>> statisticsByCuttingIdAndStatus(Page<Map<String, Object>> page) {        // 执行分页统计查询
        IPage<Map<String, Object>> result = baseMapper.statisticsByCuttingIdAndStatus(page);
        return result;
    }
}