package org.jeecg.modules.tms.controller;
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import lombok.extern.slf4j.Slf4j;
|
import org.jeecg.common.system.base.controller.JeecgController;
|
import org.jeecg.common.api.vo.Result;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import org.springframework.web.servlet.ModelAndView;
|
import java.util.Arrays;
|
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.modules.tms.entity.TmsToolStocktakingDetail;
|
import org.jeecg.modules.tms.entity.TmsToolStocktaking;
|
import org.jeecg.modules.tms.service.ITmsToolStocktakingService;
|
import org.jeecg.modules.tms.service.ITmsToolStocktakingDetailService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
import org.apache.shiro.SecurityUtils;
|
import org.jeecg.common.system.vo.LoginUser;
|
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.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
import java.io.IOException;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* @Description: 工装盘点
|
* @Author: jeecg-boot
|
* @Date: 2025-07-28
|
* @Version: V1.0
|
*/
|
@Api(tags="工装盘点")
|
@RestController
|
@RequestMapping("/tms/tmsToolStocktaking")
|
@Slf4j
|
public class TmsToolStocktakingController extends JeecgController<TmsToolStocktaking, ITmsToolStocktakingService> {
|
|
@Autowired
|
private ITmsToolStocktakingService tmsToolStocktakingService;
|
|
@Autowired
|
private ITmsToolStocktakingDetailService tmsToolStocktakingDetailService;
|
|
|
/*---------------------------------主表处理-begin-------------------------------------*/
|
|
/**
|
* 分页列表查询
|
* @param tmsToolStocktaking
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
//@AutoLog(value = "工装盘点-分页列表查询")
|
@ApiOperation(value="工装盘点-分页列表查询", notes="工装盘点-分页列表查询")
|
@GetMapping(value = "/list")
|
public Result<IPage<TmsToolStocktaking>> queryPageList(TmsToolStocktaking tmsToolStocktaking,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
HttpServletRequest req) {
|
QueryWrapper<TmsToolStocktaking> queryWrapper = QueryGenerator.initQueryWrapper(tmsToolStocktaking, req.getParameterMap());
|
Page<TmsToolStocktaking> page = new Page<TmsToolStocktaking>(pageNo, pageSize);
|
IPage<TmsToolStocktaking> pageList = tmsToolStocktakingService.page(page, queryWrapper);
|
return Result.OK(pageList);
|
}
|
|
/**
|
* 添加
|
* @param tmsToolStocktaking
|
* @return
|
*/
|
@AutoLog(value = "工装盘点-添加")
|
@ApiOperation(value="工装盘点-添加", notes="工装盘点-添加")
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_stocktaking:add")
|
@PostMapping(value = "/add")
|
public Result<String> add(@RequestBody TmsToolStocktaking tmsToolStocktaking) {
|
tmsToolStocktakingService.save(tmsToolStocktaking);
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 编辑
|
* @param tmsToolStocktaking
|
* @return
|
*/
|
@AutoLog(value = "工装盘点-编辑")
|
@ApiOperation(value="工装盘点-编辑", notes="工装盘点-编辑")
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_stocktaking:edit")
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
public Result<String> edit(@RequestBody TmsToolStocktaking tmsToolStocktaking) {
|
tmsToolStocktakingService.updateById(tmsToolStocktaking);
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "工装盘点-通过id删除")
|
@ApiOperation(value="工装盘点-通过id删除", notes="工装盘点-通过id删除")
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_stocktaking:delete")
|
@DeleteMapping(value = "/delete")
|
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
tmsToolStocktakingService.delMain(id);
|
return Result.OK("删除成功!");
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@AutoLog(value = "工装盘点-批量删除")
|
@ApiOperation(value="工装盘点-批量删除", notes="工装盘点-批量删除")
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_stocktaking:deleteBatch")
|
@DeleteMapping(value = "/deleteBatch")
|
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
this.tmsToolStocktakingService.delBatchMain(Arrays.asList(ids.split(",")));
|
return Result.OK("批量删除成功!");
|
}
|
|
/**
|
* 导出
|
* @return
|
*/
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_stocktaking:exportXls")
|
@RequestMapping(value = "/exportXls")
|
public ModelAndView exportXls(HttpServletRequest request, TmsToolStocktaking tmsToolStocktaking) {
|
return super.exportXls(request, tmsToolStocktaking, TmsToolStocktaking.class, "工装盘点");
|
}
|
|
/**
|
* 导入
|
* @return
|
*/
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_stocktaking:importExcel")
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
return super.importExcel(request, response, TmsToolStocktaking.class);
|
}
|
/*---------------------------------主表处理-end-------------------------------------*/
|
|
|
/*--------------------------------子表处理-工装盘点明细-begin----------------------------------------------*/
|
/**
|
* 通过主表ID查询
|
* @return
|
*/
|
//@AutoLog(value = "工装盘点明细-通过主表ID查询")
|
@ApiOperation(value="工装盘点明细-通过主表ID查询", notes="工装盘点明细-通过主表ID查询")
|
@GetMapping(value = "/listTmsToolStocktakingDetailByMainId")
|
public Result<IPage<TmsToolStocktakingDetail>> listTmsToolStocktakingDetailByMainId(TmsToolStocktakingDetail tmsToolStocktakingDetail,
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
HttpServletRequest req) {
|
QueryWrapper<TmsToolStocktakingDetail> queryWrapper = QueryGenerator.initQueryWrapper(tmsToolStocktakingDetail, req.getParameterMap());
|
Page<TmsToolStocktakingDetail> page = new Page<TmsToolStocktakingDetail>(pageNo, pageSize);
|
IPage<TmsToolStocktakingDetail> pageList = tmsToolStocktakingDetailService.page(page, queryWrapper);
|
return Result.OK(pageList);
|
}
|
|
/**
|
* 添加
|
* @param tmsToolStocktakingDetail
|
* @return
|
*/
|
@AutoLog(value = "工装盘点明细-添加")
|
@ApiOperation(value="工装盘点明细-添加", notes="工装盘点明细-添加")
|
@PostMapping(value = "/addTmsToolStocktakingDetail")
|
public Result<String> addTmsToolStocktakingDetail(@RequestBody TmsToolStocktakingDetail tmsToolStocktakingDetail) {
|
tmsToolStocktakingDetailService.save(tmsToolStocktakingDetail);
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 编辑
|
* @param tmsToolStocktakingDetail
|
* @return
|
*/
|
@AutoLog(value = "工装盘点明细-编辑")
|
@ApiOperation(value="工装盘点明细-编辑", notes="工装盘点明细-编辑")
|
@RequestMapping(value = "/editTmsToolStocktakingDetail", method = {RequestMethod.PUT,RequestMethod.POST})
|
public Result<String> editTmsToolStocktakingDetail(@RequestBody TmsToolStocktakingDetail tmsToolStocktakingDetail) {
|
tmsToolStocktakingDetailService.updateById(tmsToolStocktakingDetail);
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "工装盘点明细-通过id删除")
|
@ApiOperation(value="工装盘点明细-通过id删除", notes="工装盘点明细-通过id删除")
|
@DeleteMapping(value = "/deleteTmsToolStocktakingDetail")
|
public Result<String> deleteTmsToolStocktakingDetail(@RequestParam(name="id",required=true) String id) {
|
tmsToolStocktakingDetailService.removeById(id);
|
return Result.OK("删除成功!");
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@AutoLog(value = "工装盘点明细-批量删除")
|
@ApiOperation(value="工装盘点明细-批量删除", notes="工装盘点明细-批量删除")
|
@DeleteMapping(value = "/deleteBatchTmsToolStocktakingDetail")
|
public Result<String> deleteBatchTmsToolStocktakingDetail(@RequestParam(name="ids",required=true) String ids) {
|
this.tmsToolStocktakingDetailService.removeByIds(Arrays.asList(ids.split(",")));
|
return Result.OK("批量删除成功!");
|
}
|
|
/**
|
* 导出
|
* @return
|
*/
|
@RequestMapping(value = "/exportTmsToolStocktakingDetail")
|
public ModelAndView exportTmsToolStocktakingDetail(HttpServletRequest request, TmsToolStocktakingDetail tmsToolStocktakingDetail) {
|
// Step.1 组装查询条件
|
QueryWrapper<TmsToolStocktakingDetail> queryWrapper = QueryGenerator.initQueryWrapper(tmsToolStocktakingDetail, request.getParameterMap());
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
// Step.2 获取导出数据
|
List<TmsToolStocktakingDetail> pageList = tmsToolStocktakingDetailService.list(queryWrapper);
|
List<TmsToolStocktakingDetail> exportList = null;
|
|
// 过滤选中数据
|
String selections = request.getParameter("selections");
|
if (oConvertUtils.isNotEmpty(selections)) {
|
List<String> selectionList = Arrays.asList(selections.split(","));
|
exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
|
} else {
|
exportList = pageList;
|
}
|
|
// Step.3 AutoPoi 导出Excel
|
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
//此处设置的filename无效,前端会重更新设置一下
|
mv.addObject(NormalExcelConstants.FILE_NAME, "工装盘点明细");
|
mv.addObject(NormalExcelConstants.CLASS, TmsToolStocktakingDetail.class);
|
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("工装盘点明细报表", "导出人:" + sysUser.getRealname(), "工装盘点明细"));
|
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
return mv;
|
}
|
|
/**
|
* 导入
|
* @return
|
*/
|
@RequestMapping(value = "/importTmsToolStocktakingDetail/{mainId}")
|
public Result<?> importTmsToolStocktakingDetail(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
// 获取上传文件对象
|
MultipartFile file = entity.getValue();
|
ImportParams params = new ImportParams();
|
params.setTitleRows(2);
|
params.setHeadRows(1);
|
params.setNeedSave(true);
|
try {
|
List<TmsToolStocktakingDetail> list = ExcelImportUtil.importExcel(file.getInputStream(), TmsToolStocktakingDetail.class, params);
|
for (TmsToolStocktakingDetail temp : list) {
|
temp.setOrderId(mainId);
|
}
|
long start = System.currentTimeMillis();
|
tmsToolStocktakingDetailService.saveBatch(list);
|
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
|
return Result.OK("文件导入成功!数据行数:" + list.size());
|
} catch (Exception e) {
|
log.error(e.getMessage(), e);
|
return Result.error("文件导入失败:" + e.getMessage());
|
} finally {
|
try {
|
file.getInputStream().close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
return Result.error("文件导入失败!");
|
}
|
|
/*--------------------------------子表处理-工装盘点明细-end----------------------------------------------*/
|
|
|
|
|
}
|