PdaController.java 14 KB

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