|
@@ -0,0 +1,239 @@
|
|
|
+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 javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+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.api.vo.Result;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.oa.entity.SyMaterialB;
|
|
|
+import org.jeecg.modules.oa.entity.SyMaterialC;
|
|
|
+import org.jeecg.modules.oa.entity.SyMaterial;
|
|
|
+import org.jeecg.modules.oa.vo.SyMaterialPage;
|
|
|
+import org.jeecg.modules.oa.service.ISyMaterialService;
|
|
|
+import org.jeecg.modules.oa.service.ISyMaterialBService;
|
|
|
+import org.jeecg.modules.oa.service.ISyMaterialCService;
|
|
|
+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;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 物资登记表
|
|
|
+ * @Author: jeecg-boot
|
|
|
+ * @Date: 2022-11-30
|
|
|
+ * @Version: V1.0
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/oa/syMaterial")
|
|
|
+@Slf4j
|
|
|
+public class SyMaterialController {
|
|
|
+ @Autowired
|
|
|
+ private ISyMaterialService syMaterialService;
|
|
|
+ @Autowired
|
|
|
+ private ISyMaterialBService syMaterialBService;
|
|
|
+ @Autowired
|
|
|
+ private ISyMaterialCService syMaterialCService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页列表查询
|
|
|
+ *
|
|
|
+ * @param syMaterial
|
|
|
+ * @param pageNo
|
|
|
+ * @param pageSize
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public Result<?> queryPageList(SyMaterial syMaterial,
|
|
|
+ @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
+ @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
+ QueryWrapper<SyMaterial> queryWrapper = QueryGenerator.initQueryWrapper(syMaterial, req.getParameterMap());
|
|
|
+ Page<SyMaterial> page = new Page<SyMaterial>(pageNo, pageSize);
|
|
|
+ IPage<SyMaterial> pageList = syMaterialService.page(page, queryWrapper);
|
|
|
+ return Result.ok(pageList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ *
|
|
|
+ * @param syMaterialPage
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/add")
|
|
|
+ public Result<?> add(@RequestBody SyMaterialPage syMaterialPage) {
|
|
|
+ SyMaterial syMaterial = new SyMaterial();
|
|
|
+ BeanUtils.copyProperties(syMaterialPage, syMaterial);
|
|
|
+ syMaterialService.saveMain(syMaterial, syMaterialPage.getSyMaterialBList(),syMaterialPage.getSyMaterialCList());
|
|
|
+ return Result.ok("添加成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ *
|
|
|
+ * @param syMaterialPage
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PutMapping(value = "/edit")
|
|
|
+ public Result<?> edit(@RequestBody SyMaterialPage syMaterialPage) {
|
|
|
+ SyMaterial syMaterial = new SyMaterial();
|
|
|
+ BeanUtils.copyProperties(syMaterialPage, syMaterial);
|
|
|
+ syMaterialService.updateMain(syMaterial, syMaterialPage.getSyMaterialBList(),syMaterialPage.getSyMaterialCList());
|
|
|
+ return Result.ok("编辑成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
+ public Result<?> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
+ syMaterialService.delMain(id);
|
|
|
+ return Result.ok("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @DeleteMapping(value = "/deleteBatch")
|
|
|
+ public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
|
+ this.syMaterialService.delBatchMain(Arrays.asList(ids.split(",")));
|
|
|
+ return Result.ok("批量删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
+ public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
+ SyMaterial syMaterial = syMaterialService.getById(id);
|
|
|
+ return Result.ok(syMaterial);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/querySyMaterialBByMainId")
|
|
|
+ public Result<?> querySyMaterialBListByMainId(@RequestParam(name="id",required=true) String id) {
|
|
|
+ List<SyMaterialB> syMaterialBList = syMaterialBService.selectByMainId(id);
|
|
|
+ return Result.ok(syMaterialBList);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/querySyMaterialCByMainId")
|
|
|
+ public Result<?> querySyMaterialCListByMainId(@RequestParam(name="id",required=true) String id) {
|
|
|
+ List<SyMaterialC> syMaterialCList = syMaterialCService.selectByMainId(id);
|
|
|
+ return Result.ok(syMaterialCList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param syMaterial
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/exportXls")
|
|
|
+ public ModelAndView exportXls(HttpServletRequest request, SyMaterial syMaterial) {
|
|
|
+ // Step.1 组装查询条件
|
|
|
+ QueryWrapper<SyMaterial> queryWrapper = QueryGenerator.initQueryWrapper(syMaterial, request.getParameterMap());
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+
|
|
|
+ //Step.2 获取导出数据
|
|
|
+ List<SyMaterialPage> pageList = new ArrayList<SyMaterialPage>();
|
|
|
+ List<SyMaterial> syMaterialList = syMaterialService.list(queryWrapper);
|
|
|
+ for (SyMaterial temp : syMaterialList) {
|
|
|
+ SyMaterialPage vo = new SyMaterialPage();
|
|
|
+ BeanUtils.copyProperties(temp, vo);
|
|
|
+ List<SyMaterialB> syMaterialBList = syMaterialBService.selectByMainId(temp.getId());
|
|
|
+ vo.setSyMaterialBList(syMaterialBList);
|
|
|
+ List<SyMaterialC> syMaterialCList = syMaterialCService.selectByMainId(temp.getId());
|
|
|
+ vo.setSyMaterialCList(syMaterialCList);
|
|
|
+ pageList.add(vo);
|
|
|
+ }
|
|
|
+ //Step.3 调用AutoPoi导出Excel
|
|
|
+ ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
+ mv.addObject(NormalExcelConstants.FILE_NAME, "物资登记表");
|
|
|
+ mv.addObject(NormalExcelConstants.CLASS, SyMaterialPage.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<SyMaterialPage> list = ExcelImportUtil.importExcel(file.getInputStream(), SyMaterialPage.class, params);
|
|
|
+ for (SyMaterialPage page : list) {
|
|
|
+ SyMaterial po = new SyMaterial();
|
|
|
+ BeanUtils.copyProperties(page, po);
|
|
|
+ syMaterialService.saveMain(po, page.getSyMaterialBList(),page.getSyMaterialCList());
|
|
|
+ }
|
|
|
+ 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("文件导入失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|