PdaController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. package com.jsh.erp.controller.pda;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  7. import com.jsh.erp.base.AjaxResult;
  8. import com.jsh.erp.base.BaseController;
  9. import com.jsh.erp.base.TableDataInfo;
  10. import com.jsh.erp.datasource.entities.DepotHead;
  11. import com.jsh.erp.datasource.entities.Supplier;
  12. import com.jsh.erp.datasource.entities.*;
  13. import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
  14. import com.jsh.erp.datasource.pda.dto.PDAInventoryDTO;
  15. import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingDTO;
  16. import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingItemDTO;
  17. import com.jsh.erp.datasource.pda.vo.*;
  18. import com.jsh.erp.datasource.vo.SpinnerVO;
  19. import com.jsh.erp.datasource.vo.TaskStocktakingVO;
  20. import com.jsh.erp.datasource.vo.TreeNode;
  21. import com.jsh.erp.exception.BusinessRunTimeException;
  22. import com.jsh.erp.query.LambdaQueryWrapperX;
  23. import com.jsh.erp.service.*;
  24. import com.jsh.erp.utils.StringUtil;
  25. import com.jsh.erp.utils.TreeNodeUtils;
  26. import io.swagger.annotations.Api;
  27. import io.swagger.annotations.ApiModelProperty;
  28. import io.swagger.annotations.ApiOperation;
  29. import org.springframework.http.HttpHeaders;
  30. import org.springframework.http.HttpStatus;
  31. import org.springframework.http.ResponseEntity;
  32. import org.springframework.web.bind.annotation.*;
  33. import javax.annotation.Resource;
  34. import javax.servlet.http.HttpServletRequest;
  35. import javax.servlet.http.HttpServletResponse;
  36. import java.io.*;
  37. import java.math.BigDecimal;
  38. import java.nio.file.Files;
  39. import java.nio.file.Path;
  40. import java.nio.file.Paths;
  41. import java.util.Date;
  42. import java.util.List;
  43. @RestController
  44. @RequestMapping(value = "/pda")
  45. @Api(tags = {"PDA接口"})
  46. public class PdaController extends BaseController {
  47. @Resource
  48. private DepotHeadService depotHeadService;
  49. @Resource
  50. private DepotItemService depotItemService;
  51. @Resource
  52. private SupplierService supplierService;
  53. @Resource
  54. private MaterialService materialService;
  55. @Resource
  56. private TaskStocktakingService taskStocktakingService;
  57. @Resource
  58. private TaskStocktakingItemService taskStocktakingItemService;
  59. @Resource
  60. private UserService userService;
  61. @Resource
  62. private MaterialCategoryService materialCategoryService;
  63. @Resource
  64. private MaterialExtendService materialExtendService;
  65. @Resource
  66. private ApkVersionService apkVersionService;
  67. @Resource
  68. private DepotService depotService;
  69. @Resource
  70. private MaterialBatchService materialBatchService;
  71. @PostMapping ("/purchaseInventory")
  72. @ApiOperation(value = "采购入库")
  73. public TableDataInfo purchaseInventory(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO) {
  74. pdaDepotHeadDTO.setSubType("采购订单");
  75. startPage();
  76. List<PDADepotHeadVO> pdaDepotHeadVOList = depotHeadService.pdaList(pdaDepotHeadDTO);
  77. return getDataTable(pdaDepotHeadVOList);
  78. }
  79. @PostMapping("/saleOrder")
  80. @ApiOperation(value = "检货任务")
  81. public TableDataInfo saleOrder(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO) {
  82. pdaDepotHeadDTO.setSubType("销售订单");
  83. startPage();
  84. List<PDADepotHeadVO> pdaDepotHeadVOList = depotHeadService.pdaList(pdaDepotHeadDTO);
  85. return getDataTable(pdaDepotHeadVOList);
  86. }
  87. @ApiModelProperty(value = "订单详情")
  88. @GetMapping("/orderInfo/{id}")
  89. public AjaxResult orderInfo(@PathVariable("id") Long id){
  90. DepotHead depotHead = depotHeadService.getOne(new LambdaQueryWrapperX<DepotHead>().eq(DepotHead::getId, id));
  91. if (depotHead.getOrganId() != null) {
  92. depotHead.setSupplierName(supplierService.getOne(new LambdaQueryWrapperX<Supplier>().eq(Supplier::getId, depotHead.getOrganId())).getSupplier());
  93. }
  94. if (depotHead.getCreator() != null) {
  95. depotHead.setCreateName(userService.getOne(new LambdaQueryWrapperX<User>().eq(User::getId, depotHead.getCreator())).getUsername());
  96. }
  97. if (depotHead.getOperId() != null) {
  98. depotHead.setOperName(userService.getOne(new LambdaQueryWrapperX<User>().eq(User::getId, depotHead.getOperId())).getUsername());
  99. }
  100. return AjaxResult.success(depotHead);
  101. }
  102. @GetMapping("/orderDetail/{id}")
  103. @ApiOperation("订单明细")
  104. public TableDataInfo orderDetail(@PathVariable("id") Long id) throws Exception {
  105. startPage();
  106. List<PDADepotItemVO> list = depotItemService.pdaList(id);
  107. return getDataTable(list);
  108. }
  109. @ApiOperation("订单开始处理")
  110. @GetMapping("/orderStartHandle/{id}")
  111. public AjaxResult orderStartHandle(@PathVariable("id") Long id) {
  112. depotHeadService.update(new UpdateWrapper<DepotHead>().set("status", "4").eq("id", id));
  113. return AjaxResult.success();
  114. }
  115. @ApiOperation("商品详情")
  116. @GetMapping("/materialDetail/{id}/{depotId}")
  117. public AjaxResult materialDetail(@PathVariable("id") Long id, @PathVariable("depotId") Long depotId) throws Exception {
  118. return AjaxResult.success(depotItemService.pdaDetail(id));
  119. }
  120. @ApiOperation("商品库存详情")
  121. @GetMapping("/materialDepotDetail/{type}/{materialId}/{depotId}")
  122. public TableDataInfo materialDepotDetail(@PathVariable("type") String type, @PathVariable("materialId") Long materialId,@PathVariable("depotId") Long depotId) {
  123. startPage();
  124. if ("in".equals(type)) {
  125. type = "入库";
  126. } else {
  127. type = "出库";
  128. }
  129. List<PDADepotItemVO> list = depotItemService.materialDepotDetail(type, materialId);
  130. return getDataTable(list);
  131. }
  132. @ApiOperation("盘点任务列表")
  133. @PostMapping("/taskStocktakingList")
  134. public TableDataInfo taskStocktakingList(@RequestBody PDATaskStocktakingDTO pdaTaskStocktakingDTO) {
  135. startPage();
  136. List<PDATaskStocktakingVO> list = taskStocktakingService.pdaList(pdaTaskStocktakingDTO.getNumber(), pdaTaskStocktakingDTO.getStatus(), pdaTaskStocktakingDTO.getDepotId());
  137. return getDataTable(list);
  138. }
  139. @ApiOperation(value = "盘点任务详情-商品列表")
  140. @PostMapping("/taskStocktakingItemList")
  141. public TableDataInfo taskStocktakingItemList(@RequestBody PDATaskStocktakingItemDTO pdaTaskStocktakingItemDTO){
  142. startPage();
  143. List<PDATaskStocktakingItemVO> list = taskStocktakingService.pdaItemList(pdaTaskStocktakingItemDTO);
  144. return getDataTable(list);
  145. }
  146. @ApiOperation("盘点任务详情")
  147. @GetMapping("/taskStocktakingDetail/{taskId}")
  148. public AjaxResult taskStocktakingDetail(@PathVariable("taskId") Long taskId) throws Exception{
  149. TaskStocktakingVO taskStocktakingVO = taskStocktakingService.pdaDetail(taskId);
  150. return AjaxResult.success(taskStocktakingVO);
  151. }
  152. /**
  153. * 获取商品类别树数据
  154. * @Param:
  155. * @return
  156. */
  157. @ApiOperation(value = "获取商品类别树数据")
  158. @GetMapping(value = "/getMaterialCategoryTree")
  159. public JSONArray getMaterialCategoryTree(@RequestParam("id") Long id) throws Exception{
  160. List<TreeNode> materialCategoryTree = materialCategoryService.getMaterialCategoryTree(id);
  161. return TreeNodeUtils.conversion(materialCategoryTree);
  162. }
  163. @ApiOperation("开始任务")
  164. @GetMapping("/startTask/{id}")
  165. public AjaxResult startTask(@PathVariable("id") Long id){
  166. taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>()
  167. .set("task_status", 2)
  168. .eq("id", id));
  169. return AjaxResult.success();
  170. }
  171. @ApiOperation("任务完成")
  172. @GetMapping("/taskComplete/{id}")
  173. public AjaxResult taskComplete(@PathVariable("id") Long id) throws Exception {
  174. User currentUser = userService.getCurrentUser();
  175. taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>().set("task_status", 3)
  176. .set("oper_time", new Date())
  177. .set("oper_by", currentUser.getId())
  178. .eq("id", id));
  179. return AjaxResult.success();
  180. }
  181. @ApiOperation("盘点")
  182. @PostMapping("/stocktaking")
  183. public AjaxResult stocktaking(@RequestBody TaskStocktakingItem taskStocktakingItem) throws Exception{
  184. User currentUser = userService.getCurrentUser();
  185. MaterialBatch materialBatch = materialBatchService.getById(taskStocktakingItem.getMaterialItemId());
  186. if (materialBatch == null) {
  187. return AjaxResult.error("商品信息不存在");
  188. }
  189. UpdateWrapper<TaskStocktakingItem> updateWrapper = new UpdateWrapper<>();
  190. updateWrapper.eq("id", taskStocktakingItem.getId())
  191. .set("creator", currentUser.getId())
  192. .set("oper_time", new Date());
  193. if (ObjectUtil.isNotEmpty(taskStocktakingItem.getNewInventory())) {
  194. updateWrapper.set("new_inventory", taskStocktakingItem.getNewInventory());
  195. BigDecimal subtract = taskStocktakingItem.getNewInventory().subtract(materialBatch.getInventory());
  196. updateWrapper.set("difference_count", subtract);
  197. //差异数量,设置盘点状态为1.未盘,2.盘盈,3.盘亏 4.无差异
  198. if (subtract.compareTo(BigDecimal.ZERO) > 0) {
  199. updateWrapper.set("status", 2);
  200. } else if (subtract.compareTo(BigDecimal.ZERO) < 0) {
  201. updateWrapper.set("status", 3);
  202. } else {
  203. updateWrapper.set("status", 4);
  204. }
  205. }
  206. if (ObjectUtil.isNotEmpty(taskStocktakingItem.getNewPosition())) {
  207. updateWrapper.set("new_position", taskStocktakingItem.getNewPosition());
  208. }
  209. if (ObjectUtil.isNotEmpty(taskStocktakingItem.getDifferenceCount())) {
  210. updateWrapper.set("difference_count", taskStocktakingItem.getDifferenceCount());
  211. }
  212. if (ObjectUtil.isNotEmpty(taskStocktakingItem.getDifferenceReason())){
  213. updateWrapper.set("difference_reason", taskStocktakingItem.getDifferenceReason());
  214. }
  215. taskStocktakingItemService.update(updateWrapper);
  216. return AjaxResult.success();
  217. }
  218. @ApiOperation("负责人下拉列表")
  219. @GetMapping("/creatorSpinnerList/{taskId}")
  220. public AjaxResult creatorSpinnerList(@PathVariable("taskId") Long taskId) {
  221. List<SpinnerVO> spinnerVOList = taskStocktakingItemService.creatorSpinnerList(taskId);
  222. return AjaxResult.success(spinnerVOList);
  223. }
  224. /**
  225. * PDA订单提交
  226. */
  227. @PostMapping ("/orderSubmit")
  228. @ApiOperation(value = "订单提交")
  229. public AjaxResult orderSubmit(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO) {
  230. try {
  231. depotHeadService.pdaOrderSubmit(pdaDepotHeadDTO);
  232. }catch (BusinessRunTimeException e) {
  233. return AjaxResult.error(e.getMessage());
  234. }catch (Exception e) {
  235. e.printStackTrace();
  236. return AjaxResult.error("入库失败");
  237. }
  238. return AjaxResult.success();
  239. }
  240. @PostMapping("/inventoryInquiry")
  241. @ApiOperation("存货查询-商品存货查询")
  242. public TableDataInfo inventoryInquiry(@RequestBody PDAInventoryDTO pdaInventoryDTO){
  243. if (StringUtil.isNotEmpty(pdaInventoryDTO.getPosition())){
  244. pdaInventoryDTO.setMaterialIds(materialService.selectMaterialIdByPosition(pdaInventoryDTO.getPosition()));
  245. }
  246. //查询类型id的子类型
  247. pdaInventoryDTO.setCategoryIds(materialService.selectCategoryIds(pdaInventoryDTO.getCategoryId()));
  248. startPage();
  249. List<PDADepotItemVO> list = materialService.inventoryInquiry(pdaInventoryDTO);
  250. return getDataTable(list);
  251. }
  252. @ApiOperation("存货查询-库位树查询")
  253. @GetMapping("/inventoryPositionTree")
  254. public AjaxResult inventoryPositionTree(@RequestParam("depotId") Long depotId) throws Exception {
  255. return AjaxResult.success(materialService.selectPosition(depotId));
  256. }
  257. @ApiOperation("存货查询-类型树查询")
  258. @GetMapping("/inventoryTypeTree")
  259. public AjaxResult inventoryTypeTree() throws Exception {
  260. return AjaxResult.success(materialCategoryService.getMaterialCategoryTree(null));
  261. }
  262. @ApiOperation("仓库下拉框")
  263. @GetMapping("/depotSpinnerList")
  264. public AjaxResult depotSpinnerList() {
  265. return AjaxResult.success(depotService.depotSpinnerList());
  266. }
  267. @ApiOperation("下载安装包")
  268. @PostMapping("/downloadApk")
  269. public ResponseEntity downloadApk(@RequestBody ApkVersion apkVersion, HttpServletRequest request, HttpServletResponse response) throws Exception {
  270. // 将文件路径转换为 Path 对象
  271. Path path = Paths.get(apkVersion.getUrl()).toAbsolutePath().normalize();
  272. File file = path.toFile();
  273. String fileUrl = apkVersion.getUrl();
  274. long size = Files.size(path);
  275. response.setHeader("Content-Length",size+"");
  276. // 检查文件是否存在
  277. if (!file.exists() || !file.isFile()) {
  278. return null;
  279. }
  280. InputStream inputStream = null;
  281. OutputStream outputStream = null;
  282. inputStream = new BufferedInputStream(new FileInputStream(fileUrl));
  283. outputStream = response.getOutputStream();
  284. byte[] buf = new byte[1024];
  285. int len;
  286. while ((len = inputStream.read(buf)) > 0) {
  287. outputStream.write(buf, 0, len);
  288. }
  289. response.flushBuffer();
  290. if (inputStream != null) {
  291. try {
  292. inputStream.close();
  293. } catch (IOException e) {
  294. logger.error(e.getMessage(), e);
  295. }
  296. }
  297. if (outputStream != null) {
  298. try {
  299. outputStream.close();
  300. } catch (IOException e) {
  301. logger.error(e.getMessage(), e);
  302. }
  303. }
  304. HttpHeaders headers = new HttpHeaders();
  305. headers.setContentLength(size);
  306. return new ResponseEntity<>(null, headers, HttpStatus.OK);
  307. }
  308. @ApiOperation("查询版本信息")
  309. @GetMapping("/selectVersion")
  310. public AjaxResult selectVersion() {
  311. ApkVersion apkVersion = apkVersionService.getOne(new LambdaQueryWrapperX<ApkVersion>().orderByDesc(ApkVersion::getId).last("limit 1"));
  312. return AjaxResult.success(apkVersion);
  313. }
  314. @ApiOperation("查询商品打印信息")
  315. @GetMapping("/printMaterial")
  316. public AjaxResult printMaterial(@RequestParam("id") Long id) {
  317. PDAPrintVo pdaPrintVo = depotItemService.pdaPrintMaterial(id);
  318. return AjaxResult.success(pdaPrintVo);
  319. }
  320. }