|
@@ -0,0 +1,261 @@
|
|
|
+package org.jeecg.modules.oa.controller;
|
|
|
+
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+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.vo.LoginUser;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.oa.entity.MaterialInDetail;
|
|
|
+import org.jeecg.modules.oa.entity.MaterialIn;
|
|
|
+import org.jeecg.modules.oa.vo.MaterialInPage;
|
|
|
+import org.jeecg.modules.oa.service.IMaterialInService;
|
|
|
+import org.jeecg.modules.oa.service.IMaterialInDetailService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
+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 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: 2023-05-21
|
|
|
+ * @Version: V1.0
|
|
|
+ */
|
|
|
+@Api(tags="物料入库等级")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/oa/materialIn")
|
|
|
+@Slf4j
|
|
|
+public class MaterialInController {
|
|
|
+ @Autowired
|
|
|
+ private IMaterialInService materialInService;
|
|
|
+ @Autowired
|
|
|
+ private IMaterialInDetailService materialInDetailService;
|
|
|
+
|
|
|
+
|
|
|
+ * 分页列表查询
|
|
|
+ *
|
|
|
+ * @param materialIn
|
|
|
+ * @param pageNo
|
|
|
+ * @param pageSize
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "物料入库等级-分页列表查询")
|
|
|
+ @ApiOperation(value="物料入库等级-分页列表查询", notes="物料入库等级-分页列表查询")
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public Result<?> queryPageList(MaterialIn materialIn,
|
|
|
+ @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
+ @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
+ QueryWrapper<MaterialIn> queryWrapper = QueryGenerator.initQueryWrapper(materialIn, req.getParameterMap());
|
|
|
+ Page<MaterialIn> page = new Page<MaterialIn>(pageNo, pageSize);
|
|
|
+ IPage<MaterialIn> pageList = materialInService.page(page, queryWrapper);
|
|
|
+ return Result.ok(pageList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 添加
|
|
|
+ *
|
|
|
+ * @param materialInPage
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "物料入库等级-添加")
|
|
|
+ @ApiOperation(value="物料入库等级-添加", notes="物料入库等级-添加")
|
|
|
+ @PostMapping(value = "/add")
|
|
|
+ public Result<?> add(@RequestBody MaterialInPage materialInPage) {
|
|
|
+ MaterialIn materialIn = new MaterialIn();
|
|
|
+ BeanUtils.copyProperties(materialInPage, materialIn);
|
|
|
+ materialInService.saveMain(materialIn, materialInPage.getMaterialInDetailList());
|
|
|
+ return Result.ok("添加成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 编辑
|
|
|
+ *
|
|
|
+ * @param materialInPage
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "物料入库等级-编辑")
|
|
|
+ @ApiOperation(value="物料入库等级-编辑", notes="物料入库等级-编辑")
|
|
|
+ @PutMapping(value = "/edit")
|
|
|
+ public Result<?> edit(@RequestBody MaterialInPage materialInPage) {
|
|
|
+ MaterialIn materialIn = new MaterialIn();
|
|
|
+ BeanUtils.copyProperties(materialInPage, materialIn);
|
|
|
+ MaterialIn materialInEntity = materialInService.getById(materialIn.getId());
|
|
|
+ if(materialInEntity==null) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ materialInService.updateMain(materialIn, materialInPage.getMaterialInDetailList());
|
|
|
+ return Result.ok("编辑成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 通过id删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "物料入库等级-通过id删除")
|
|
|
+ @ApiOperation(value="物料入库等级-通过id删除", notes="物料入库等级-通过id删除")
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
+ public Result<?> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
+ materialInService.delMain(id);
|
|
|
+ return Result.ok("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 批量删除
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "物料入库等级-批量删除")
|
|
|
+ @ApiOperation(value="物料入库等级-批量删除", notes="物料入库等级-批量删除")
|
|
|
+ @DeleteMapping(value = "/deleteBatch")
|
|
|
+ public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
|
+ this.materialInService.delBatchMain(Arrays.asList(ids.split(",")));
|
|
|
+ return Result.ok("批量删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "物料入库等级-通过id查询")
|
|
|
+ @ApiOperation(value="物料入库等级-通过id查询", notes="物料入库等级-通过id查询")
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
+ public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
+ MaterialIn materialIn = materialInService.getById(id);
|
|
|
+ if(materialIn==null) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ return Result.ok(materialIn);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "物料入库明细集合-通过id查询")
|
|
|
+ @ApiOperation(value="物料入库明细集合-通过id查询", notes="物料入库明细-通过id查询")
|
|
|
+ @GetMapping(value = "/queryMaterialInDetailByMainId")
|
|
|
+ public Result<?> queryMaterialInDetailListByMainId(@RequestParam(name="id",required=true) String id) {
|
|
|
+ List<MaterialInDetail> materialInDetailList = materialInDetailService.selectByMainId(id);
|
|
|
+ return Result.ok(materialInDetailList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param materialIn
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/exportXls")
|
|
|
+ public ModelAndView exportXls(HttpServletRequest request, MaterialIn materialIn) {
|
|
|
+
|
|
|
+ QueryWrapper<MaterialIn> queryWrapper = QueryGenerator.initQueryWrapper(materialIn, request.getParameterMap());
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+
|
|
|
+
|
|
|
+ List<MaterialIn> queryList = materialInService.list(queryWrapper);
|
|
|
+
|
|
|
+ String selections = request.getParameter("selections");
|
|
|
+ List<MaterialIn> materialInList = new ArrayList<MaterialIn>();
|
|
|
+ if(oConvertUtils.isEmpty(selections)) {
|
|
|
+ materialInList = queryList;
|
|
|
+ }else {
|
|
|
+ List<String> selectionList = Arrays.asList(selections.split(","));
|
|
|
+ materialInList = queryList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<MaterialInPage> pageList = new ArrayList<MaterialInPage>();
|
|
|
+ for (MaterialIn main : materialInList) {
|
|
|
+ MaterialInPage vo = new MaterialInPage();
|
|
|
+ BeanUtils.copyProperties(main, vo);
|
|
|
+ List<MaterialInDetail> materialInDetailList = materialInDetailService.selectByMainId(main.getId());
|
|
|
+ vo.setMaterialInDetailList(materialInDetailList);
|
|
|
+ pageList.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
+ mv.addObject(NormalExcelConstants.FILE_NAME, "物料入库等级列表");
|
|
|
+ mv.addObject(NormalExcelConstants.CLASS, MaterialInPage.class);
|
|
|
+ mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("物料入库等级数据", "导出人:"+sysUser.getRealname(), "物料入库等级"));
|
|
|
+ mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
|
|
+ return mv;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 通过excel导入数据
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
+ public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ 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<MaterialInPage> list = ExcelImportUtil.importExcel(file.getInputStream(), MaterialInPage.class, params);
|
|
|
+ for (MaterialInPage page : list) {
|
|
|
+ MaterialIn po = new MaterialIn();
|
|
|
+ BeanUtils.copyProperties(page, po);
|
|
|
+ materialInService.saveMain(po, page.getMaterialInDetailList());
|
|
|
+ }
|
|
|
+ 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.ok("文件导入失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|