package org.jeecg.modules.tms.controller;
|
|
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.BaseTools;
|
import org.jeecg.modules.tms.entity.ToolsStocktakingBound;
|
import org.jeecg.modules.tms.entity.ToolsStocktakingBoundDetail;
|
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.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<IPage<ToolsStocktakingBound>> queryPageList(ToolsStocktakingBound toolsStocktakingBound,
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
HttpServletRequest req) {
|
QueryWrapper<ToolsStocktakingBound> queryWrapper = QueryGenerator.initQueryWrapper(toolsStocktakingBound, req.getParameterMap());
|
Page<ToolsStocktakingBound> page = new Page<ToolsStocktakingBound>(pageNo, pageSize);
|
IPage<ToolsStocktakingBound> 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<String> 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<ToolsStocktakingBoundDetail> 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<IPage<ToolsStocktakingBoundDetail>> listToolsStocktakingBoundControllerDetailsByMainId(BaseTools baseTools,
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
HttpServletRequest req) {
|
Map<String, String[]> parameterMap = req.getParameterMap();
|
Page<ToolsStocktakingBoundDetail> page = new Page<ToolsStocktakingBoundDetail>(pageNo, pageSize);
|
IPage<ToolsStocktakingBoundDetail> 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<String> 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<String> edit(@RequestBody ToolsStocktakingBound toolsStocktakingBound) {
|
if (toolsStocktakingBound == null || StringUtils.isBlank(toolsStocktakingBound.getId())) {
|
return Result.error("参数错误");
|
}
|
|
toolsStocktakingBoundDetailService.remove(new LambdaQueryWrapper<ToolsStocktakingBoundDetail>()
|
.eq(ToolsStocktakingBoundDetail::getStocktakingBoundId, toolsStocktakingBound.getId()));
|
|
ToolsStocktakingBound stocktakingBound = new ToolsStocktakingBound();
|
BeanUtils.copyProperties(stocktakingBound, toolsStocktakingBound);
|
toolsStocktakingBoundMapper.updateById(stocktakingBound);
|
|
|
List<ToolsStocktakingBoundDetail> detailList = toolsStocktakingBound.getToolsStocktakingBoundDetailList();
|
if (CollectionUtils.isEmpty(detailList)) {
|
return Result.error("明细不能为空");
|
}
|
|
detailList.forEach(item -> item.setStocktakingBoundId(stocktakingBound.getId()));
|
toolsStocktakingBoundDetailService.saveBatch(detailList);
|
|
return Result.OK("编辑成功");
|
}
|
|
|
/**
|
* 通过id删除
|
*
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "盘点单表-通过id删除")
|
@ApiOperation(value = "盘点单表-通过id删除", notes = "盘点单表-通过id删除")
|
@DeleteMapping(value = "/delete")
|
public Result<String> 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<String> 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<ToolsStocktakingBound> 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<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<ToolsStocktakingVo> 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("文件导入失败!");
|
}
|
|
}
|