PdaController.java 13 KB

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