package org.jeecg.modules.tms.controller; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils; 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.jeecg.common.api.vo.Result; import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; import org.jeecg.modules.tms.entity.*; import org.jeecg.modules.tms.entity.dto.LossBoundFlowDto; import org.jeecg.modules.tms.entity.dto.StocktakingBoundFlowDto; import org.jeecg.modules.tms.entity.vo.ToolsStocktakingVo; import org.jeecg.modules.tms.enums.OutBillStatus; import org.jeecg.modules.tms.mapper.ToolsStocktakingBoundMapper; import org.jeecg.modules.tms.service.IToolsStocktakingBoundDetailService; import org.jeecg.modules.tms.service.IToolsStocktakingBoundService; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.entity.ImportParams; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.math.BigDecimal; import java.util.Arrays; import java.util.List; import java.util.Map; /** * @Description: 盘点单表 * @Author: houjie * @Date: 2025-05-16 * @Version: V1.0 */ @Api(tags = "盘点单表") @RestController @RequestMapping("/tms/toolsStocktakingBound") @Slf4j public class ToolsStocktakingBoundController { @Autowired private IToolsStocktakingBoundService toolsStocktakingBoundService; @Autowired private IToolsStocktakingBoundDetailService toolsStocktakingBoundDetailService; @Autowired private ToolsStocktakingBoundMapper toolsStocktakingBoundMapper; @Autowired private ISysBusinessCodeRuleService businessCodeRuleService; /** * 分页列表查询 * * @param toolsStocktakingBound * @param pageNo * @param pageSize * @param req * @return */ //@AutoLog(value = "盘点单表-分页列表查询") @ApiOperation(value = "盘点单表-分页列表查询", notes = "盘点单表-分页列表查询") @GetMapping(value = "/list") public Result> queryPageList(ToolsStocktakingBound toolsStocktakingBound, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) { QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(toolsStocktakingBound, req.getParameterMap()); Page page = new Page(pageNo, pageSize); IPage pageList = toolsStocktakingBoundService.page(page, queryWrapper); return Result.OK(pageList); } /** * 添加 * * @param toolsStocktakingBound * @return */ @AutoLog(value = "tms_stocktaking_bound-添加") @ApiOperation(value = "tms_stocktaking_bound-添加", notes = "tms_stocktaking_bound-添加") @PostMapping(value = "/add") @Transactional(rollbackFor = {Exception.class}) public Result add(@RequestBody ToolsStocktakingBound toolsStocktakingBound) { toolsStocktakingBound.setApprovalStatus(OutBillStatus.DRAFT.getValue()); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); if (sysUser != null) { toolsStocktakingBound.setHandler(sysUser.getId()); } toolsStocktakingBound.setOrderCode(businessCodeRuleService.generateBusinessCodeSeq("stocktakingBound")); //校验物料在原材料周转库存不存在 List toolsStocktakingBoundDetailList = toolsStocktakingBound.getToolsStocktakingBoundDetailList(); toolsStocktakingBoundService.save(toolsStocktakingBound); for (int i = 0; i < toolsStocktakingBoundDetailList.size(); i++) { ToolsStocktakingBoundDetail toolsStocktakingBoundDetail = toolsStocktakingBoundDetailList.get(i); toolsStocktakingBoundDetail.setAvailableQuantity(toolsStocktakingBoundDetail.getBookQuantity()); toolsStocktakingBoundDetail.setPracticalQuantity(toolsStocktakingBoundDetail.getPracticalQuantity()); toolsStocktakingBoundDetail.setSurplusDeficit(toolsStocktakingBoundDetail.getSurplusDeficit()); toolsStocktakingBoundDetail.setStocktakingDate(toolsStocktakingBoundDetail.getStocktakingDate()); toolsStocktakingBoundDetail.setRemark(toolsStocktakingBoundDetail.getRemark()); toolsStocktakingBoundDetail.setToolId(toolsStocktakingBoundDetail.getToolId()); toolsStocktakingBoundDetail.setToolCode(toolsStocktakingBoundDetail.getToolCode()); toolsStocktakingBoundDetail.setStocktakingBoundId(toolsStocktakingBound.getId()); toolsStocktakingBoundDetailService.save(toolsStocktakingBoundDetail); } return Result.OK(); } @ApiOperation(value = "工具盘点明细-通过主表ID查询", notes = "工具盘点明细-通过主表ID查询") @GetMapping(value = "/listToolsStocktakingBoundControllerDetailsByMainId") public Result> listToolsStocktakingBoundControllerDetailsByMainId(BaseTools baseTools, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) { Map parameterMap = req.getParameterMap(); Page page = new Page(pageNo, pageSize); IPage pageList = toolsStocktakingBoundDetailService.selectByMainId(page, parameterMap); return Result.OK(pageList); } @AutoLog(value = "tms_stocktaking_bound-提交盘点单") @ApiOperation(value = "tms_stocktaking_bound-提交盘点单", notes = "tms_stocktaking_bound-提交盘点单") @GetMapping(value = "/submit") public Result submit(@RequestParam(name = "id") String id) { toolsStocktakingBoundService.submintOrder(id); return Result.OK("提交成功"); } /** * 审批流程 * @param stocktakingBoundFlowDto * @return */ @AutoLog(value = "审批流程") @ApiOperation(value = "报损单-审批流程", notes = "报损单-审批流程") @PostMapping("/approval") public Result approval(@RequestBody StocktakingBoundFlowDto stocktakingBoundFlowDto) { toolsStocktakingBoundService.approvalProcess(stocktakingBoundFlowDto); return Result.OK("操作成功"); } /** * 编辑 * * @param toolsStocktakingBound * @return */ @AutoLog(value = "盘点单表-编辑") @ApiOperation(value = "盘点单表-编辑", notes = "盘点单表-编辑") @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) @Transactional(rollbackFor = {Exception.class}) public Result edit(@RequestBody ToolsStocktakingBound toolsStocktakingBound) { toolsStocktakingBoundService.updateById(toolsStocktakingBound); // 删除申请单明细数据 toolsStocktakingBoundDetailService.remove(new LambdaQueryWrapper() .eq(ToolsStocktakingBoundDetail::getStocktakingBoundId, toolsStocktakingBound.getId())); List detailList = toolsStocktakingBound.getToolsStocktakingBoundDetailList(); if (CollectionUtils.isEmpty(detailList)) { return Result.error("明细不能为空"); } for (ToolsStocktakingBoundDetail item : detailList) { item.setStocktakingBoundId(toolsStocktakingBound.getId()); item.setToolId(item.getToolId()); item.setToolCode(item.getToolCode()); item.setRemark(item.getRemark()); item.setStocktakingDate(item.getStocktakingDate()); item.setBookQuantity(item.getBookQuantity()); item.setAvailableQuantity(item.getAvailableQuantity()); item.setPracticalQuantity(item.getPracticalQuantity()); item.setSurplusDeficit(item.getSurplusDeficit()); item.setDifferenceValue(item.getDifferenceValue()); item.setParamaTableName(item.getParamaTableName()); item.setForeignLanguageName(item.getForeignLanguageName()); item.setChineseName(item.getChineseName()); item.setSupplierId(item.getSupplierId()); item.setStorageLocation(item.getStorageLocation()); item.setToolMaterial(item.getToolMaterial()); item.setToolModel(item.getToolModel()); item.setPositionCode(item.getPositionCode()); item.setClassifyId(item.getClassifyId()); item.setApplicationType(item.getApplicationType()); toolsStocktakingBoundDetailService.saveOrUpdate(item); } toolsStocktakingBoundDetailService.saveOrUpdateBatch(detailList); 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) { toolsStocktakingBoundService.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.toolsStocktakingBoundService.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) { ToolsStocktakingBound toolsStocktakingBound = toolsStocktakingBoundService.getById(id); if (toolsStocktakingBound == null) { return Result.error("未找到对应数据"); } return Result.OK(toolsStocktakingBound); } /** * 通过excel导入数据 * * @param request * @param response * @return */ @RequestMapping(value = "/importExcel", method = RequestMethod.POST) public Result importExcel(HttpServletRequest request, HttpServletResponse response) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map fileMap = multipartRequest.getFileMap(); for (Map.Entry entity : fileMap.entrySet()) { // 获取上传文件对象 MultipartFile file = entity.getValue(); ImportParams params = new ImportParams(); params.setTitleRows(2); params.setHeadRows(1); params.setNeedSave(true); try { List list = ExcelImportUtil.importExcel(file.getInputStream(), ToolsStocktakingVo.class, params); for (ToolsStocktakingVo page : list) { ToolsStocktakingBound po = new ToolsStocktakingBound(); BeanUtils.copyProperties(page, po); toolsStocktakingBoundService.saveMain(po, page.getToolsStocktakingBoundDetailList()); } 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("文件导入失败!"); } /** * 工具台账-盘点子页面列表查询 * * @param toolsStocktakingBound * @param pageNo * @param pageSize * @param query * @return */ @ApiOperation(value="工具台账-盘点子页面列表查询", notes="工具台账-盘点子页面列表查询") @GetMapping(value = "/toolsStocktakingList") public Result toolsStocktakingList(ToolsStocktakingBound toolsStocktakingBound, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, @RequestParam Map query) { IPage> pageList = toolsStocktakingBoundDetailService.toolsStocktakingList(pageNo,pageSize, query); return Result.OK(pageList); } }