PdaController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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.MaterialVo4Unit;
  12. import com.jsh.erp.datasource.entities.Supplier;
  13. import com.jsh.erp.datasource.entities.*;
  14. import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
  15. import com.jsh.erp.datasource.pda.dto.PDAInventoryDTO;
  16. import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingDTO;
  17. import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingItemDTO;
  18. import com.jsh.erp.datasource.pda.vo.PDADepotHeadVO;
  19. import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
  20. import com.jsh.erp.datasource.pda.vo.PDATaskStocktakingItemVO;
  21. import com.jsh.erp.datasource.pda.vo.PDATaskStocktakingVO;
  22. import com.jsh.erp.datasource.vo.SpinnerVO;
  23. import com.jsh.erp.datasource.vo.TaskStocktakingVO;
  24. import com.jsh.erp.datasource.vo.TreeNode;
  25. import com.jsh.erp.query.LambdaQueryWrapperX;
  26. import com.jsh.erp.service.*;
  27. import com.jsh.erp.utils.FileUtils;
  28. import io.swagger.annotations.Api;
  29. import io.swagger.annotations.ApiModelProperty;
  30. import io.swagger.annotations.ApiOperation;
  31. import org.springframework.http.HttpStatus;
  32. import org.springframework.http.ResponseEntity;
  33. import org.springframework.web.bind.annotation.*;
  34. import javax.annotation.Resource;
  35. import javax.servlet.http.HttpServletRequest;
  36. import javax.servlet.http.HttpServletResponse;
  37. import java.io.*;
  38. import java.math.BigDecimal;
  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. /**
  68. * 采购入库
  69. * @return
  70. */
  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. depotHead.setSupplierName(supplierService.getOne(new LambdaQueryWrapperX<Supplier>().eq(Supplier::getId, depotHead.getOrganId())).getSupplier());
  92. return AjaxResult.success(depotHead);
  93. }
  94. @GetMapping("/orderDetail/{id}")
  95. @ApiOperation("订单明细")
  96. public TableDataInfo orderDetail(@PathVariable("id") Long id) {
  97. startPage();
  98. List<PDADepotItemVO> list = depotItemService.pdaList(id);
  99. return getDataTable(list);
  100. }
  101. @ApiOperation("订单开始处理")
  102. @GetMapping("/orderStartHandle/{id}")
  103. public AjaxResult orderStartHandle(@PathVariable("id") Long id) {
  104. depotHeadService.update(new UpdateWrapper<DepotHead>().set("status", "4").eq("id", id));
  105. return AjaxResult.success();
  106. }
  107. @ApiOperation("商品详情")
  108. @GetMapping("/materialDetail/{id}")
  109. public AjaxResult materialDetail(@PathVariable("id") Long id) {
  110. return AjaxResult.success(depotItemService.pdaDetail(id));
  111. }
  112. @ApiOperation("商品库存详情")
  113. @GetMapping("/materialDepotDetail/{type}/{materialId}")
  114. public TableDataInfo materialDepotDetail(@PathVariable("type") String type, @PathVariable("materialId") Long materialId) {
  115. startPage();
  116. if ("out".equals(type)) {
  117. type = "入库";
  118. } else {
  119. type = "出库";
  120. }
  121. List<PDADepotItemVO> list = depotItemService.materialDepotDetail(type , materialId);
  122. return getDataTable(list);
  123. }
  124. @ApiOperation("盘点任务列表")
  125. @PostMapping("/taskStocktakingList")
  126. public TableDataInfo taskStocktakingList(@RequestBody PDATaskStocktakingDTO pdaTaskStocktakingDTO) {
  127. startPage();
  128. List<PDATaskStocktakingVO> list = taskStocktakingService.pdaList(pdaTaskStocktakingDTO.getNumber(), pdaTaskStocktakingDTO.getStatus());
  129. return getDataTable(list);
  130. }
  131. @ApiOperation(value = "盘点任务详情-商品列表")
  132. @PostMapping("/taskStocktakingItemList")
  133. public TableDataInfo taskStocktakingItemList(@RequestBody PDATaskStocktakingItemDTO pdaTaskStocktakingItemDTO){
  134. startPage();
  135. List<PDATaskStocktakingItemVO> list = taskStocktakingService.pdaItemList(pdaTaskStocktakingItemDTO);
  136. return getDataTable(list);
  137. }
  138. @ApiOperation("盘点任务详情")
  139. @GetMapping("/taskStocktakingDetail/{taskId}")
  140. public AjaxResult taskStocktakingDetail(@PathVariable("taskId") Long taskId) throws Exception{
  141. TaskStocktakingVO taskStocktakingVO = taskStocktakingService.pdaDetail(taskId);
  142. return AjaxResult.success(taskStocktakingVO);
  143. }
  144. /**
  145. * 获取商品类别树数据
  146. * @Param:
  147. * @return com.alibaba.fastjson.JSONArray
  148. */
  149. @ApiOperation(value = "获取商品类别树数据")
  150. @GetMapping(value = "/getMaterialCategoryTree")
  151. public JSONArray getMaterialCategoryTree(@RequestParam("id") Long id) throws Exception{
  152. JSONArray arr=new JSONArray();
  153. List<TreeNode> materialCategoryTree = materialCategoryService.getMaterialCategoryTree(id);
  154. if(materialCategoryTree!=null&&materialCategoryTree.size()>0){
  155. for(TreeNode node:materialCategoryTree){
  156. String str= JSON.toJSONString(node);
  157. JSONObject obj=JSON.parseObject(str);
  158. arr.add(obj) ;
  159. }
  160. }
  161. return arr;
  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. MaterialExtend materialExtend = materialExtendService.getMaterialExtend(taskStocktakingItem.getMaterialItemId());
  186. if (materialExtend == 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(materialExtend.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. @ApiOperation("订单-用于返回字段说明")
  225. @GetMapping("test")
  226. public AjaxResult test(PDADepotItemVO pdaDepotItemVO) {
  227. return AjaxResult.success();
  228. }
  229. @ApiOperation("盘点-用于字段返回说明")
  230. @GetMapping("taskTest")
  231. public AjaxResult taskTest(PDATaskStocktakingVO pdaTaskStocktakingVO){
  232. return AjaxResult.success();
  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) throws Exception {
  251. startPage();
  252. List<PDADepotItemVO> list = materialService.inventoryInquiry(pdaInventoryDTO);
  253. return getDataTable(list);
  254. }
  255. @ApiOperation("存货查询-库位树查询")
  256. @GetMapping("/inventoryPositionTree")
  257. public AjaxResult inventoryPositionTree() throws Exception {
  258. return AjaxResult.success(materialService.selectPosition());
  259. }
  260. @ApiOperation("存货查询-类型树查询")
  261. @GetMapping("/inventoryTypeTree")
  262. public AjaxResult inventoryTypeTree() throws Exception {
  263. return AjaxResult.success(materialCategoryService.getMaterialCategoryTree(null));
  264. }
  265. @ApiOperation("下载安装包")
  266. @PostMapping("/downloadApk")
  267. public void downloadApk(@RequestBody ApkVersion apkVersion, HttpServletRequest request, HttpServletResponse response) throws Exception {
  268. // 将文件路径转换为 Path 对象
  269. Path path = Paths.get(apkVersion.getUrl()).toAbsolutePath().normalize();
  270. File file = path.toFile();
  271. String fileUrl = apkVersion.getUrl();
  272. // 检查文件是否存在
  273. if (!file.exists() || !file.isFile()) {
  274. return;
  275. }
  276. InputStream inputStream = null;
  277. OutputStream outputStream = null;
  278. inputStream = new BufferedInputStream(new FileInputStream(fileUrl));
  279. outputStream = response.getOutputStream();
  280. byte[] buf = new byte[1024];
  281. int len;
  282. while ((len = inputStream.read(buf)) > 0) {
  283. outputStream.write(buf, 0, len);
  284. }
  285. response.flushBuffer();
  286. if (inputStream != null) {
  287. try {
  288. inputStream.close();
  289. } catch (IOException e) {
  290. logger.error(e.getMessage(), e);
  291. }
  292. }
  293. if (outputStream != null) {
  294. try {
  295. outputStream.close();
  296. } catch (IOException e) {
  297. logger.error(e.getMessage(), e);
  298. }
  299. }
  300. }
  301. @ApiOperation("查询版本信息")
  302. @GetMapping("selectVersion")
  303. public AjaxResult selectVersion() {
  304. ApkVersion apkVersion = apkVersionService.getOne(new LambdaQueryWrapperX<ApkVersion>().orderByDesc(ApkVersion::getId).last("limit 1"));
  305. return AjaxResult.success(apkVersion);
  306. }
  307. }