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.jeecg.modules.tms.vo.TmsToolInboundRequest;
|
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.lang.reflect.InvocationTargetException;
|
import java.util.Arrays;
|
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.modules.tms.entity.TmsToolInboundDetail;
|
import org.jeecg.modules.tms.entity.TmsToolInbound;
|
import org.jeecg.modules.tms.service.ITmsToolInboundService;
|
import org.jeecg.modules.tms.service.ITmsToolInboundDetailService;
|
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/tmsToolInbound")
|
@Slf4j
|
public class TmsToolInboundController extends JeecgController<TmsToolInbound, ITmsToolInboundService> {
|
|
@Autowired
|
private ITmsToolInboundService tmsToolInboundService;
|
|
@Autowired
|
private ITmsToolInboundDetailService tmsToolInboundDetailService;
|
|
|
/*---------------------------------主表处理-begin-------------------------------------*/
|
|
/**
|
* 分页列表查询
|
* @param tmsToolInbound
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
//@AutoLog(value = "工装入库-分页列表查询")
|
@ApiOperation(value="工装入库-分页列表查询", notes="工装入库-分页列表查询")
|
@GetMapping(value = "/list")
|
public Result<IPage<TmsToolInbound>> queryPageList(TmsToolInbound tmsToolInbound,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
HttpServletRequest req) {
|
QueryWrapper<TmsToolInbound> queryWrapper = QueryGenerator.initQueryWrapper(tmsToolInbound, req.getParameterMap());
|
Page<TmsToolInbound> page = new Page<TmsToolInbound>(pageNo, pageSize);
|
IPage<TmsToolInbound> pageList = tmsToolInboundService.page(page, queryWrapper);
|
return Result.OK(pageList);
|
}
|
|
/**
|
* 添加
|
* @param tmsToolInbound
|
* @return
|
*/
|
@AutoLog(value = "工装入库-添加")
|
@ApiOperation(value="工装入库-添加", notes="工装入库-添加")
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_inbound:add")
|
@PostMapping(value = "/add")
|
public Result<String> add(@RequestBody TmsToolInboundRequest tmsToolInboundRequest) {
|
try {
|
tmsToolInboundService.add(tmsToolInboundRequest);
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 编辑
|
* @param tmsToolInbound
|
* @return
|
*/
|
@AutoLog(value = "工装入库-编辑")
|
@ApiOperation(value="工装入库-编辑", notes="工装入库-编辑")
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_inbound:edit")
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
public Result<String> edit(@RequestBody TmsToolInboundRequest tmsToolInboundRequest) {
|
try {
|
tmsToolInboundService.update(tmsToolInboundRequest);
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "工装入库-通过id删除")
|
@ApiOperation(value="工装入库-通过id删除", notes="工装入库-通过id删除")
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_inbound:delete")
|
@DeleteMapping(value = "/delete")
|
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
tmsToolInboundService.delMain(id);
|
return Result.OK("删除成功!");
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@AutoLog(value = "工装入库-批量删除")
|
@ApiOperation(value="工装入库-批量删除", notes="工装入库-批量删除")
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_inbound:deleteBatch")
|
@DeleteMapping(value = "/deleteBatch")
|
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
this.tmsToolInboundService.delBatchMain(Arrays.asList(ids.split(",")));
|
return Result.OK("批量删除成功!");
|
}
|
|
/**
|
* 导出
|
* @return
|
*/
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_inbound:exportXls")
|
@RequestMapping(value = "/exportXls")
|
public ModelAndView exportXls(HttpServletRequest request, TmsToolInbound tmsToolInbound) {
|
return super.exportXls(request, tmsToolInbound, TmsToolInbound.class, "工装入库");
|
}
|
|
/**
|
* 导入
|
* @return
|
*/
|
//@RequiresPermissions("org.jeecg.modules:tms_tool_inbound:importExcel")
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
return super.importExcel(request, response, TmsToolInbound.class);
|
}
|
/*---------------------------------主表处理-end-------------------------------------*/
|
|
|
/*--------------------------------子表处理-工装入库明细-begin----------------------------------------------*/
|
/**
|
* 通过主表ID查询
|
* @return
|
*/
|
//@AutoLog(value = "工装入库明细-通过主表ID查询")
|
@ApiOperation(value="工装入库明细-通过主表ID查询", notes="工装入库明细-通过主表ID查询")
|
@GetMapping(value = "/listTmsToolInboundDetailByMainId")
|
public Result<IPage<TmsToolInboundDetail>> listTmsToolInboundDetailByMainId(TmsToolInboundDetail tmsToolInboundDetail,
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
HttpServletRequest req) {
|
Map<String, String[]> parameterMap = req.getParameterMap();
|
QueryWrapper<TmsToolInboundDetail> queryWrapper = QueryGenerator.initQueryWrapper(tmsToolInboundDetail, parameterMap);
|
Page<TmsToolInboundDetail> page = new Page<TmsToolInboundDetail>(pageNo, pageSize);
|
IPage<TmsToolInboundDetail> pageList = tmsToolInboundDetailService.queryPageList(page, parameterMap);
|
return Result.OK(pageList);
|
}
|
|
/**
|
* 添加
|
* @param tmsToolInboundDetail
|
* @return
|
*/
|
@AutoLog(value = "工装入库明细-添加")
|
@ApiOperation(value="工装入库明细-添加", notes="工装入库明细-添加")
|
@PostMapping(value = "/addTmsToolInboundDetail")
|
public Result<String> addTmsToolInboundDetail(@RequestBody TmsToolInboundDetail tmsToolInboundDetail) {
|
tmsToolInboundDetailService.save(tmsToolInboundDetail);
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 编辑
|
* @param tmsToolInboundDetail
|
* @return
|
*/
|
@AutoLog(value = "工装入库明细-编辑")
|
@ApiOperation(value="工装入库明细-编辑", notes="工装入库明细-编辑")
|
@RequestMapping(value = "/editTmsToolInboundDetail", method = {RequestMethod.PUT,RequestMethod.POST})
|
public Result<String> editTmsToolInboundDetail(@RequestBody TmsToolInboundDetail tmsToolInboundDetail) {
|
tmsToolInboundDetailService.updateById(tmsToolInboundDetail);
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "工装入库明细-通过id删除")
|
@ApiOperation(value="工装入库明细-通过id删除", notes="工装入库明细-通过id删除")
|
@DeleteMapping(value = "/deleteTmsToolInboundDetail")
|
public Result<String> deleteTmsToolInboundDetail(@RequestParam(name="id",required=true) String id) {
|
tmsToolInboundDetailService.removeById(id);
|
return Result.OK("删除成功!");
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@AutoLog(value = "工装入库明细-批量删除")
|
@ApiOperation(value="工装入库明细-批量删除", notes="工装入库明细-批量删除")
|
@DeleteMapping(value = "/deleteBatchTmsToolInboundDetail")
|
public Result<String> deleteBatchTmsToolInboundDetail(@RequestParam(name="ids",required=true) String ids) {
|
this.tmsToolInboundDetailService.removeByIds(Arrays.asList(ids.split(",")));
|
return Result.OK("批量删除成功!");
|
}
|
|
/**
|
* 导出
|
* @return
|
*/
|
@RequestMapping(value = "/exportTmsToolInboundDetail")
|
public ModelAndView exportTmsToolInboundDetail(HttpServletRequest request, TmsToolInboundDetail tmsToolInboundDetail) {
|
// Step.1 组装查询条件
|
QueryWrapper<TmsToolInboundDetail> queryWrapper = QueryGenerator.initQueryWrapper(tmsToolInboundDetail, request.getParameterMap());
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
// Step.2 获取导出数据
|
List<TmsToolInboundDetail> pageList = tmsToolInboundDetailService.list(queryWrapper);
|
List<TmsToolInboundDetail> 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, TmsToolInboundDetail.class);
|
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("工装入库明细报表", "导出人:" + sysUser.getRealname(), "工装入库明细"));
|
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
return mv;
|
}
|
|
/**
|
* 导入
|
* @return
|
*/
|
@RequestMapping(value = "/importTmsToolInboundDetail/{mainId}")
|
public Result<?> importTmsToolInboundDetail(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<TmsToolInboundDetail> list = ExcelImportUtil.importExcel(file.getInputStream(), TmsToolInboundDetail.class, params);
|
for (TmsToolInboundDetail temp : list) {
|
temp.setOrderId(mainId);
|
}
|
long start = System.currentTimeMillis();
|
tmsToolInboundDetailService.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----------------------------------------------*/
|
|
|
|
|
}
|