package com.chinaztt.mes.production.controller; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.chinaztt.mes.common.wrapper.QueryWrapperUtil; import com.chinaztt.mes.production.dto.FeedingDTO; import com.chinaztt.mes.production.dto.FeedingInDTO; import com.chinaztt.mes.production.entity.Feeding; import com.chinaztt.mes.production.service.FeedingService; import com.chinaztt.mes.warehouse.dto.FeedingStockDTO; import com.chinaztt.mes.warehouse.service.StockService; import com.chinaztt.ztt.common.core.util.R; import com.chinaztt.ztt.common.log.annotation.SysLog; import com.chinaztt.ztt.common.security.annotation.Inner; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; /** * 投料登记 * * @author cxf * @date 2020-11-12 10:48:37 */ @RestController @AllArgsConstructor @RequestMapping("/feeding") @Api(value = "feeding", tags = "投料登记管理") public class FeedingController { private final FeedingService feedingService; private final StockService stockService; /** * 查询投料信息 * * @param feedingDTO 投料登记 * @return */ @ApiOperation(value = "查询投料信息", notes = "查询投料信息") @GetMapping("/getFeedingByWorkstationId") public R getFeedingByWorkstationId(FeedingDTO feedingDTO) { return R.ok(feedingService.getFeedingByWorkstationId(QueryWrapperUtil.gen(feedingDTO))); } /** * 分页查询 * * @param page 分页对象 * @param feeding 投料登记 * @return */ @ApiOperation(value = "分页查询", notes = "分页查询") @GetMapping("/page") public R getOptaskFeedingPage(Page page, Feeding feeding) { return R.ok(feedingService.page(page, Wrappers.query(feeding))); } /** * 通过id查询投料登记 * * @param id id * @return R */ @ApiOperation(value = "通过id查询", notes = "通过id查询") @GetMapping("/{id}") public R getById(@PathVariable("id") Long id) { return R.ok(feedingService.getById(id)); } /** * 投料 * * @param feedingInDTO 投料登记 * @return R */ @ApiOperation(value = "投料", notes = "投料") @SysLog("投料") @PostMapping public R saveList(@RequestBody FeedingInDTO feedingInDTO) { return R.ok(feedingService.feeding(feedingInDTO)); } /** * 退料 * * @param feedingList 投料登记 * @return R */ @ApiOperation(value = "退料", notes = "退料") @SysLog("退料") @PutMapping public R update(@RequestBody List feedingList) { return R.ok(feedingService.rejectFeeding(feedingList)); } /** * 通过id删除投料登记 * * @param id id * @return R */ @ApiOperation(value = "通过id删除投料登记", notes = "通过id删除投料登记") @SysLog("通过id删除投料登记") @DeleteMapping("/{id}") public R removeById(@PathVariable Long id) { return R.ok(feedingService.removeById(id)); } /** * PDA查询所有 * * @param feedingStockDTO 投料 * @return */ @ApiOperation(value = "PDA查询所有", notes = "PDA查询所有") @GetMapping("/pda/list") @Inner(false) public R pdaList(FeedingStockDTO feedingStockDTO) { return R.ok(stockService.pdaList(QueryWrapperUtil.gen(feedingStockDTO))); } /** * PDA投料 * * @param feedingStockDTOList 投料登记 * @return R */ @ApiOperation(value = "PDA投料", notes = "PDA投料") @PostMapping("/pda/add") public R pdaAdd(@RequestBody List feedingStockDTOList) { List result = new ArrayList(); String msg = ""; for (FeedingStockDTO feedingStockDTO : feedingStockDTOList) { try { feedingService.pdaAdd(feedingStockDTO); } catch (RuntimeException e) { msg += feedingStockDTO.getPartNo() + "#" + feedingStockDTO.getPartBatchNo() + ":" + e.getMessage() + "\n"; result.add(feedingStockDTO.getSid()); } catch (Exception e) { msg += feedingStockDTO.getPartNo() + "#" + feedingStockDTO.getPartBatchNo() + ":系统错误\n"; result.add(feedingStockDTO.getSid()); } } if (CollectionUtil.isNotEmpty(result)) { return R.failed(result, msg); } else { return R.ok(); } } /** * PDA退料 * * @param stockDTOList 投料登记 * @return R */ @ApiOperation(value = "PDA退料", notes = "PDA退料") @PostMapping("/pda/return") public R pdaReturn(@RequestBody List stockDTOList) { List result = new ArrayList(); String msg = ""; for (FeedingStockDTO feedingStockDTO : stockDTOList) { try { feedingService.pdaReturn(feedingStockDTO); } catch (RuntimeException e) { msg += feedingStockDTO.getPartNo() + "#" + feedingStockDTO.getPartBatchNo() + ":" + e.getMessage() + "\n"; result.add(feedingStockDTO.getSid()); } catch (Exception e) { msg += feedingStockDTO.getPartNo() + "#" + feedingStockDTO.getPartBatchNo() + ":系统错误\n"; result.add(feedingStockDTO.getSid()); } } if (CollectionUtil.isNotEmpty(result)) { return R.failed(result, msg); } else { return R.ok(); } } @GetMapping(value = "/getReturnLocations/{workstationId}") public R getReturnLocations(@PathVariable("workstationId") Long workstationId) { return R.ok(feedingService.getReturnLocations(workstationId)); } }