|
@@ -7,38 +7,55 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.jeecg.common.api.CommonAPI;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
-import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.RedisUtil;
|
|
|
import org.jeecg.common.util.TokenUtils;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.sparePartsConsumables.inventoryManagement.entity.InventoryCount;
|
|
|
+import org.jeecg.modules.sparePartsConsumables.inventoryManagement.entity.InventoryInfo;
|
|
|
import org.jeecg.modules.sparePartsConsumables.inventoryManagement.service.IInventoryCountService;
|
|
|
+import org.jeecg.modules.sparePartsConsumables.inventoryManagement.service.IInventoryInfoService;
|
|
|
+import org.jeecg.modules.sparePartsConsumables.inventoryManagement.vo.InventoryCountPage;
|
|
|
+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.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
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 javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @Description: 库存盘点
|
|
|
* @Author: jeecg-boot
|
|
|
- * @Date: 2025-05-22
|
|
|
+ * @Date: 2025-05-23
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
@Api(tags = "库存盘点")
|
|
|
@RestController
|
|
|
@RequestMapping("/sparePartsConsumables/inventoryCount")
|
|
|
@Slf4j
|
|
|
-public class InventoryCountController extends JeecgController<InventoryCount, IInventoryCountService> {
|
|
|
+public class InventoryCountController {
|
|
|
|
|
|
@Lazy
|
|
|
@Resource
|
|
@@ -50,6 +67,8 @@ public class InventoryCountController extends JeecgController<InventoryCount, II
|
|
|
|
|
|
@Autowired
|
|
|
private IInventoryCountService inventoryCountService;
|
|
|
+ @Autowired
|
|
|
+ private IInventoryInfoService inventoryInfoService;
|
|
|
|
|
|
/**
|
|
|
* 分页列表查询
|
|
@@ -76,30 +95,38 @@ public class InventoryCountController extends JeecgController<InventoryCount, II
|
|
|
/**
|
|
|
* 添加
|
|
|
*
|
|
|
- * @param inventoryCount
|
|
|
+ * @param inventoryCountPage
|
|
|
* @return
|
|
|
*/
|
|
|
@AutoLog(value = "库存盘点-添加")
|
|
|
@ApiOperation(value = "库存盘点-添加", notes = "库存盘点-添加")
|
|
|
@RequiresPermissions("sparePartsConsumables:sbsmzq_inventory_count:add")
|
|
|
@PostMapping(value = "/add")
|
|
|
- public Result<String> add(@RequestBody InventoryCount inventoryCount) {
|
|
|
- inventoryCountService.save(inventoryCount);
|
|
|
+ public Result<String> add(@RequestBody InventoryCountPage inventoryCountPage) {
|
|
|
+ InventoryCount inventoryCount = new InventoryCount();
|
|
|
+ BeanUtils.copyProperties(inventoryCountPage, inventoryCount);
|
|
|
+ inventoryCountService.saveMain(inventoryCount, inventoryCountPage.getInventoryInfoList());
|
|
|
return Result.OK("添加成功!");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 编辑
|
|
|
*
|
|
|
- * @param inventoryCount
|
|
|
+ * @param inventoryCountPage
|
|
|
* @return
|
|
|
*/
|
|
|
@AutoLog(value = "库存盘点-编辑")
|
|
|
@ApiOperation(value = "库存盘点-编辑", notes = "库存盘点-编辑")
|
|
|
@RequiresPermissions("sparePartsConsumables:sbsmzq_inventory_count:edit")
|
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
|
|
- public Result<String> edit(@RequestBody InventoryCount inventoryCount) {
|
|
|
- inventoryCountService.updateById(inventoryCount);
|
|
|
+ public Result<String> edit(@RequestBody InventoryCountPage inventoryCountPage) {
|
|
|
+ InventoryCount inventoryCount = new InventoryCount();
|
|
|
+ BeanUtils.copyProperties(inventoryCountPage, inventoryCount);
|
|
|
+ InventoryCount inventoryCountEntity = inventoryCountService.getById(inventoryCount.getId());
|
|
|
+ if (inventoryCountEntity == null) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ inventoryCountService.updateMain(inventoryCount, inventoryCountPage.getInventoryInfoList());
|
|
|
return Result.OK("编辑成功!");
|
|
|
}
|
|
|
|
|
@@ -114,7 +141,7 @@ public class InventoryCountController extends JeecgController<InventoryCount, II
|
|
|
@RequiresPermissions("sparePartsConsumables:sbsmzq_inventory_count:delete")
|
|
|
@DeleteMapping(value = "/delete")
|
|
|
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
|
|
- inventoryCountService.removeById(id);
|
|
|
+ inventoryCountService.delMain(id);
|
|
|
return Result.OK("删除成功!");
|
|
|
}
|
|
|
|
|
@@ -129,8 +156,8 @@ public class InventoryCountController extends JeecgController<InventoryCount, II
|
|
|
@RequiresPermissions("sparePartsConsumables:sbsmzq_inventory_count:deleteBatch")
|
|
|
@DeleteMapping(value = "/deleteBatch")
|
|
|
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
|
|
- this.inventoryCountService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
- return Result.OK("批量删除成功!");
|
|
|
+ this.inventoryCountService.delBatchMain(Arrays.asList(ids.split(",")));
|
|
|
+ return Result.OK("批量删除成功!");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -148,6 +175,21 @@ public class InventoryCountController extends JeecgController<InventoryCount, II
|
|
|
return Result.error("未找到对应数据");
|
|
|
}
|
|
|
return Result.OK(inventoryCount);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "盘点信息通过主表ID查询")
|
|
|
+ @ApiOperation(value = "盘点信息主表ID查询", notes = "盘点信息-通主表ID查询")
|
|
|
+ @GetMapping(value = "/queryInventoryInfoByMainId")
|
|
|
+ public Result<List<InventoryInfo>> queryInventoryInfoListByMainId(@RequestParam(name = "id", required = true) String id) {
|
|
|
+ List<InventoryInfo> inventoryInfoList = inventoryInfoService.selectByMainId(id);
|
|
|
+ return Result.OK(inventoryInfoList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -159,7 +201,36 @@ public class InventoryCountController extends JeecgController<InventoryCount, II
|
|
|
@RequiresPermissions("sparePartsConsumables:sbsmzq_inventory_count:exportXls")
|
|
|
@RequestMapping(value = "/exportXls")
|
|
|
public ModelAndView exportXls(HttpServletRequest request, InventoryCount inventoryCount) {
|
|
|
- return super.exportXls(request, inventoryCount, InventoryCount.class, "库存盘点");
|
|
|
+ // Step.1 组装查询条件查询数据
|
|
|
+ QueryWrapper<InventoryCount> queryWrapper = QueryGenerator.initQueryWrapper(inventoryCount, request.getParameterMap());
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+
|
|
|
+ //配置选中数据查询条件
|
|
|
+ String selections = request.getParameter("selections");
|
|
|
+ if (oConvertUtils.isNotEmpty(selections)) {
|
|
|
+ List<String> selectionList = Arrays.asList(selections.split(","));
|
|
|
+ queryWrapper.in("id", selectionList);
|
|
|
+ }
|
|
|
+ //Step.2 获取导出数据
|
|
|
+ List<InventoryCount> inventoryCountList = inventoryCountService.list(queryWrapper);
|
|
|
+
|
|
|
+ // Step.3 组装pageList
|
|
|
+ List<InventoryCountPage> pageList = new ArrayList<InventoryCountPage>();
|
|
|
+ for (InventoryCount main : inventoryCountList) {
|
|
|
+ InventoryCountPage vo = new InventoryCountPage();
|
|
|
+ BeanUtils.copyProperties(main, vo);
|
|
|
+ List<InventoryInfo> inventoryInfoList = inventoryInfoService.selectByMainId(main.getId());
|
|
|
+ vo.setInventoryInfoList(inventoryInfoList);
|
|
|
+ pageList.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Step.4 AutoPoi 导出Excel
|
|
|
+ ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
+ mv.addObject(NormalExcelConstants.FILE_NAME, "库存盘点列表");
|
|
|
+ mv.addObject(NormalExcelConstants.CLASS, InventoryCountPage.class);
|
|
|
+ mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("库存盘点数据", "导出人:" + sysUser.getRealname(), "库存盘点"));
|
|
|
+ mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
|
|
+ return mv;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -172,10 +243,37 @@ public class InventoryCountController extends JeecgController<InventoryCount, II
|
|
|
@RequiresPermissions("sparePartsConsumables:sbsmzq_inventory_count:importExcel")
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
- return super.importExcel(request, response, InventoryCount.class);
|
|
|
+ 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<InventoryCountPage> list = ExcelImportUtil.importExcel(file.getInputStream(), InventoryCountPage.class, params);
|
|
|
+ for (InventoryCountPage page : list) {
|
|
|
+ InventoryCount po = new InventoryCount();
|
|
|
+ BeanUtils.copyProperties(page, po);
|
|
|
+ inventoryCountService.saveMain(po, page.getInventoryInfoList());
|
|
|
+ }
|
|
|
+ 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("文件导入失败!");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 分页列表查询(与我相关)
|
|
|
*
|