| | |
| | | package org.jeecg.modules.eam.controller; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.system.query.QueryGenerator; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.query.QueryGenerator; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.eam.constant.BusinessCodeConst; |
| | | import org.jeecg.modules.eam.entity.EamSparePartInventory; |
| | | import org.jeecg.modules.eam.entity.EamSparePartReceive; |
| | | import org.jeecg.modules.eam.entity.EamSparePartReceiveDetail; |
| | | import org.jeecg.modules.eam.entity.EamSparePartRequisition; |
| | | import org.jeecg.modules.eam.service.IEamSparePartInventoryService; |
| | | import org.jeecg.modules.eam.service.IEamSparePartReceiveDetailService; |
| | | import org.jeecg.modules.eam.service.IEamSparePartReceiveService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | import io.swagger.annotations.Api; |
| | |
| | | @Resource |
| | | private IEamSparePartReceiveService eamSparePartReceiveService; |
| | | |
| | | @Resource |
| | | private IEamSparePartReceiveDetailService sparePartReceiveDetailService; |
| | | |
| | | @Resource |
| | | private IEamSparePartInventoryService sparePartInventoryService; |
| | | |
| | | /** |
| | | * 分页列表查询 |
| | | * |
| | |
| | | @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, |
| | | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, |
| | | HttpServletRequest req) { |
| | | QueryWrapper<EamSparePartReceive> queryWrapper = QueryGenerator.initQueryWrapper(eamSparePartReceive, req.getParameterMap()); |
| | | // QueryWrapper<EamSparePartReceive> queryWrapper = QueryGenerator.initQueryWrapper(eamSparePartReceive, req.getParameterMap()); |
| | | QueryWrapper<EamSparePartReceive> queryWrapper = new QueryWrapper<>(); |
| | | String receiveCode = eamSparePartReceive.getReceiveCode(); |
| | | if(StringUtils.isNotBlank(receiveCode)){ |
| | | queryWrapper.like("receive_code",receiveCode); |
| | | } |
| | | String receiveStatus = eamSparePartReceive.getReceiveStatus(); |
| | | if(StringUtils.isNotBlank(receiveStatus)){ |
| | | queryWrapper.eq("receive_status",receiveStatus); |
| | | } |
| | | String receiveUser = eamSparePartReceive.getReceiveUser(); |
| | | if(StringUtils.isNotBlank(receiveUser)){ |
| | | queryWrapper.like("receive_user",receiveUser); |
| | | } |
| | | queryWrapper.orderByDesc("create_time"); |
| | | Page<EamSparePartReceive> page = new Page<EamSparePartReceive>(pageNo, pageSize); |
| | | IPage<EamSparePartReceive> pageList = eamSparePartReceiveService.page(page, queryWrapper); |
| | | for (EamSparePartReceive record : pageList.getRecords()) { |
| | | List<EamSparePartReceiveDetail> details = sparePartReceiveDetailService.lambdaQuery() |
| | | .eq(EamSparePartReceiveDetail::getSparePartReceiveId, record.getId()).list(); |
| | | record.setSparePartReceiveDetails(details); |
| | | } |
| | | return Result.OK(pageList); |
| | | } |
| | | |
| | |
| | | */ |
| | | @ApiOperation(value = "备品备件领用单-添加", notes = "备品备件领用单-添加") |
| | | @PostMapping(value = "/add") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> add(@RequestBody EamSparePartReceive eamSparePartReceive) { |
| | | eamSparePartReceive.setReceiveStatus(BusinessCodeConst.receive_status_1); |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String realName = user.getRealname(); |
| | | eamSparePartReceive.setReceiveUser(realName); |
| | | eamSparePartReceiveService.save(eamSparePartReceive); |
| | | List<EamSparePartReceiveDetail> sparePartReceiveDetails = eamSparePartReceive.getSparePartReceiveDetails(); |
| | | for (EamSparePartReceiveDetail sparePartReceiveDetail : sparePartReceiveDetails) { |
| | | sparePartReceiveDetail.setSparePartReceiveId(eamSparePartReceive.getId()); |
| | | sparePartReceiveDetailService.saveOrUpdate(sparePartReceiveDetail); |
| | | } |
| | | return Result.OK("添加成功!"); |
| | | } |
| | | |
| | |
| | | */ |
| | | @ApiOperation(value = "备品备件领用单-编辑", notes = "备品备件领用单-编辑") |
| | | @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> edit(@RequestBody EamSparePartReceive eamSparePartReceive) { |
| | | eamSparePartReceiveService.updateById(eamSparePartReceive); |
| | | List<EamSparePartReceiveDetail> details = sparePartReceiveDetailService.lambdaQuery().eq(EamSparePartReceiveDetail::getSparePartReceiveId, eamSparePartReceive.getId()).list(); |
| | | for (EamSparePartReceiveDetail detail : details) { |
| | | sparePartReceiveDetailService.removeById(detail); |
| | | } |
| | | List<EamSparePartReceiveDetail> sparePartReceiveDetails = eamSparePartReceive.getSparePartReceiveDetails(); |
| | | for (EamSparePartReceiveDetail sparePartReceiveDetail : sparePartReceiveDetails) { |
| | | sparePartReceiveDetail.setSparePartReceiveId(eamSparePartReceive.getId()); |
| | | sparePartReceiveDetailService.saveOrUpdate(sparePartReceiveDetail); |
| | | } |
| | | return Result.OK("编辑成功!"); |
| | | } |
| | | |
| | |
| | | */ |
| | | @ApiOperation(value = "备品备件领用单-通过id删除", notes = "备品备件领用单-通过id删除") |
| | | @DeleteMapping(value = "/delete") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> delete(@RequestParam(name = "id", required = true) String id) { |
| | | List<EamSparePartReceiveDetail> details = sparePartReceiveDetailService.lambdaQuery() |
| | | .eq(EamSparePartReceiveDetail::getSparePartReceiveId,id).list(); |
| | | for (EamSparePartReceiveDetail detail : details) { |
| | | sparePartReceiveDetailService.removeById(detail); |
| | | } |
| | | eamSparePartReceiveService.removeById(id); |
| | | return Result.OK("删除成功!"); |
| | | } |
| | |
| | | */ |
| | | @ApiOperation(value = "备品备件领用单-批量删除", notes = "备品备件领用单-批量删除") |
| | | @DeleteMapping(value = "/deleteBatch") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) { |
| | | List<String> strings = Arrays.asList(ids.split(",")); |
| | | for (String s : strings) { |
| | | List<EamSparePartReceiveDetail> details = sparePartReceiveDetailService.lambdaQuery() |
| | | .eq(EamSparePartReceiveDetail::getSparePartReceiveId,s).list(); |
| | | for (EamSparePartReceiveDetail detail : details) { |
| | | sparePartReceiveDetailService.removeById(detail); |
| | | } |
| | | } |
| | | this.eamSparePartReceiveService.removeByIds(Arrays.asList(ids.split(","))); |
| | | return Result.OK("批量删除成功!"); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 提交 |
| | | * |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "备件领用-提交") |
| | | @ApiOperation(value = "备件领用-提交", notes = "备件领用-提交") |
| | | @PostMapping(value = "/submit") |
| | | public Result<?> submitSparePartReceive(@RequestBody EamSparePartReceive eamSparePartReceive) { |
| | | eamSparePartReceive.setReceiveStatus(BusinessCodeConst.receive_status_2); |
| | | boolean b = eamSparePartReceiveService.updateById(eamSparePartReceive); |
| | | if (!b) { |
| | | return Result.error("提交失败!"); |
| | | } |
| | | return Result.OK("提交成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 确认 |
| | | * |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "备件领用-确认") |
| | | @ApiOperation(value = "备件领用-确认", notes = "备件领用-确认") |
| | | @PostMapping(value = "/confirm") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> confirmSparePartReceive(@RequestBody EamSparePartReceive eamSparePartReceive) { |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | throw new JeecgBootException("当前用户无法确认备件领用!"); |
| | | } |
| | | List<EamSparePartReceiveDetail> details = sparePartReceiveDetailService.lambdaQuery().eq(EamSparePartReceiveDetail::getSparePartReceiveId, eamSparePartReceive.getId()).list(); |
| | | for (EamSparePartReceiveDetail detail : details) { |
| | | EamSparePartInventory eamSparePartInventory = new EamSparePartInventory(); |
| | | eamSparePartInventory.setSparePartId(detail.getPartId()); |
| | | eamSparePartInventory.setInventory(detail.getReceiveNum().negate()); |
| | | eamSparePartInventory.setSparePartIntoType("2");//库存来源类型 1.入库 2.领料出库 3.归还入库 |
| | | sparePartInventoryService.save(eamSparePartInventory); |
| | | } |
| | | eamSparePartReceive.setApprovalUser(sysUser.getRealname()); |
| | | eamSparePartReceive.setApprovalTime(new Date()); |
| | | eamSparePartReceive.setReceiveStatus(BusinessCodeConst.receive_status_3); |
| | | boolean b = eamSparePartReceiveService.updateById(eamSparePartReceive); |
| | | if (!b) { |
| | | return Result.error("确认失败!"); |
| | | } |
| | | return Result.OK("确认成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 归还 |
| | | * |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "备件领用-归还") |
| | | @ApiOperation(value = "备件领用-归还", notes = "备件领用-归还") |
| | | @PostMapping(value = "/return") |
| | | public Result<?> returnSparePartReceive(@RequestBody EamSparePartReceive eamSparePartReceive) { |
| | | eamSparePartReceive.setReceiveStatus(BusinessCodeConst.receive_status_4); |
| | | boolean b = eamSparePartReceiveService.updateById(eamSparePartReceive); |
| | | if (!b) { |
| | | return Result.error("归还失败!"); |
| | | } |
| | | return Result.OK("归还成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 归还确认 |
| | | * |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "备件领用-归还确认") |
| | | @ApiOperation(value = "备件领用-归还确认", notes = "备件领用-归还确认") |
| | | @PostMapping(value = "/returnConfirm") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> returnConfirmSparePartReceive(@RequestBody EamSparePartReceive eamSparePartReceive) { |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | throw new JeecgBootException("当前用户无法确认备件归还!"); |
| | | } |
| | | List<EamSparePartReceiveDetail> details = sparePartReceiveDetailService.lambdaQuery().eq(EamSparePartReceiveDetail::getSparePartReceiveId, eamSparePartReceive.getId()).list(); |
| | | for (EamSparePartReceiveDetail detail : details) { |
| | | EamSparePartInventory eamSparePartInventory = new EamSparePartInventory(); |
| | | eamSparePartInventory.setSparePartId(detail.getPartId()); |
| | | eamSparePartInventory.setInventory(detail.getReceiveNum()); |
| | | eamSparePartInventory.setSparePartIntoType("3");//库存来源类型 1.入库 2.领料出库 3.归还入库 |
| | | sparePartInventoryService.save(eamSparePartInventory); |
| | | } |
| | | eamSparePartReceive.setReceiveStatus(BusinessCodeConst.receive_status_5); |
| | | boolean b = eamSparePartReceiveService.updateById(eamSparePartReceive); |
| | | if (!b) { |
| | | return Result.error("归还确认失败!"); |
| | | } |
| | | return Result.OK("归还确认成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 导出excel |
| | | * |
| | | * @param request |