PdaController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. package com.jsh.erp.controller.pda;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  5. import com.jsh.erp.base.AjaxResult;
  6. import com.jsh.erp.base.BaseController;
  7. import com.jsh.erp.base.TableDataInfo;
  8. import com.jsh.erp.datasource.entities.DepotHead;
  9. import com.jsh.erp.datasource.entities.Supplier;
  10. import com.jsh.erp.datasource.entities.*;
  11. import com.jsh.erp.datasource.pda.dto.*;
  12. import com.jsh.erp.datasource.pda.vo.*;
  13. import com.jsh.erp.datasource.vo.SpinnerVO;
  14. import com.jsh.erp.datasource.vo.TaskStocktakingVO;
  15. import com.jsh.erp.datasource.vo.TreeNode;
  16. import com.jsh.erp.exception.BusinessRunTimeException;
  17. import com.jsh.erp.query.LambdaQueryWrapperX;
  18. import com.jsh.erp.service.*;
  19. import com.jsh.erp.utils.StringUtil;
  20. import com.jsh.erp.utils.TreeNodeUtils;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiModelProperty;
  23. import io.swagger.annotations.ApiOperation;
  24. import org.springframework.http.HttpHeaders;
  25. import org.springframework.http.HttpStatus;
  26. import org.springframework.http.ResponseEntity;
  27. import org.springframework.web.bind.annotation.*;
  28. import javax.annotation.Resource;
  29. import javax.servlet.http.HttpServletRequest;
  30. import javax.servlet.http.HttpServletResponse;
  31. import java.io.*;
  32. import java.math.BigDecimal;
  33. import java.nio.file.Files;
  34. import java.nio.file.Path;
  35. import java.nio.file.Paths;
  36. import java.util.Date;
  37. import java.util.List;
  38. @RestController
  39. @RequestMapping(value = "/pda")
  40. @Api(tags = {"PDA接口"})
  41. public class PdaController extends BaseController {
  42. @Resource
  43. private DepotHeadService depotHeadService;
  44. @Resource
  45. private DepotItemService depotItemService;
  46. @Resource
  47. private SupplierService supplierService;
  48. @Resource
  49. private MaterialService materialService;
  50. @Resource
  51. private TaskStocktakingService taskStocktakingService;
  52. @Resource
  53. private TaskStocktakingItemService taskStocktakingItemService;
  54. @Resource
  55. private UserService userService;
  56. @Resource
  57. private MaterialCategoryService materialCategoryService;
  58. @Resource
  59. private ApkVersionService apkVersionService;
  60. @Resource
  61. private DepotService depotService;
  62. @Resource
  63. private MaterialBatchService materialBatchService;
  64. @Resource
  65. private MaterialInputService materialInputService;
  66. @Resource
  67. private MaterialExtendService materialExtendService;
  68. @Resource
  69. private MsgService msgService;
  70. @PostMapping ("/purchaseInventory")
  71. @ApiOperation(value = "采购入库")
  72. public TableDataInfo purchaseInventory(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO) {
  73. pdaDepotHeadDTO.setSubType("采购订单");
  74. startPage();
  75. List<PDADepotHeadVO> pdaDepotHeadVOList = depotHeadService.pdaList(pdaDepotHeadDTO);
  76. return getDataTable(pdaDepotHeadVOList);
  77. }
  78. @PostMapping("/saleOrder")
  79. @ApiOperation(value = "检货任务")
  80. public TableDataInfo saleOrder(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO) {
  81. pdaDepotHeadDTO.setSubType("销售订单");
  82. startPage();
  83. List<PDADepotHeadVO> pdaDepotHeadVOList = depotHeadService.pdaList(pdaDepotHeadDTO);
  84. return getDataTable(pdaDepotHeadVOList);
  85. }
  86. @ApiModelProperty(value = "订单详情")
  87. @GetMapping("/orderInfo/{id}")
  88. public AjaxResult orderInfo(@PathVariable("id") Long id){
  89. DepotHead depotHead = depotHeadService.getOne(new LambdaQueryWrapperX<DepotHead>().eq(DepotHead::getId, id));
  90. if (depotHead.getOrganId() != null) {
  91. depotHead.setSupplierName(supplierService.getOne(new LambdaQueryWrapperX<Supplier>().eq(Supplier::getId, depotHead.getOrganId())).getSupplier());
  92. }
  93. if (depotHead.getCreator() != null) {
  94. depotHead.setCreateName(userService.getOne(new LambdaQueryWrapperX<User>().eq(User::getId, depotHead.getCreator())).getUsername());
  95. }
  96. if (depotHead.getOperId() != null) {
  97. depotHead.setOperName(userService.getOne(new LambdaQueryWrapperX<User>().eq(User::getId, depotHead.getOperId())).getUsername());
  98. }
  99. if (depotHead.getAuditor() != null) {
  100. depotHead.setAuditorName(userService.getOne(new LambdaQueryWrapperX<User>().eq(User::getId, depotHead.getAuditor())).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}/{depotId}")
  119. public AjaxResult materialDetail(@PathVariable("id") Long id, @PathVariable("depotId") Long depotId) throws Exception {
  120. return AjaxResult.success(depotItemService.pdaDetail(id,depotId));
  121. }
  122. @ApiOperation("采购、拣货 - 出入库明细")
  123. @GetMapping("/materialDepotDetail/{type}/{materialId}/{depotId}")
  124. public TableDataInfo materialDepotDetail(@PathVariable("type") String type, @PathVariable("materialId") Long materialId,@PathVariable("depotId") Long depotId) {
  125. startPage();
  126. if ("in".equals(type)) {
  127. type = "入库";
  128. } else {
  129. type = "出库";
  130. }
  131. List<PDADepotItemVO> list = depotItemService.materialDepotDetail(type, materialId, depotId);
  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. List<PDATaskStocktakingItemVO> list = taskStocktakingService.pdaItemList(pdaTaskStocktakingItemDTO);
  145. return getDataTable(list);
  146. }
  147. @ApiOperation("盘点任务详情")
  148. @GetMapping("/taskStocktakingDetail/{taskId}")
  149. public AjaxResult taskStocktakingDetail(@PathVariable("taskId") Long taskId) throws Exception{
  150. TaskStocktakingVO taskStocktakingVO = taskStocktakingService.pdaDetail(taskId);
  151. return AjaxResult.success(taskStocktakingVO);
  152. }
  153. /**
  154. * 获取商品类别树数据
  155. * @Param:
  156. * @return
  157. */
  158. @ApiOperation(value = "获取商品类别树数据")
  159. @GetMapping(value = "/getMaterialCategoryTree")
  160. public JSONArray getMaterialCategoryTree(@RequestParam("id") Long id) throws Exception{
  161. List<TreeNode> materialCategoryTree = materialCategoryService.getMaterialCategoryTree(id);
  162. return TreeNodeUtils.conversion(materialCategoryTree);
  163. }
  164. @ApiOperation("开始任务")
  165. @GetMapping("/startTask/{id}")
  166. public AjaxResult startTask(@PathVariable("id") Long id){
  167. taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>()
  168. .set("task_status", 2)
  169. .eq("id", id));
  170. return AjaxResult.success();
  171. }
  172. @ApiOperation("任务完成")
  173. @GetMapping("/taskComplete/{id}")
  174. public AjaxResult taskComplete(@PathVariable("id") Long id) throws Exception {
  175. User currentUser = userService.getCurrentUser();
  176. taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>().set("task_status", 3)
  177. .set("oper_time", new Date())
  178. .set("oper_by", currentUser.getId())
  179. .eq("id", id));
  180. return AjaxResult.success();
  181. }
  182. @ApiOperation("盘点")
  183. @PostMapping("/stocktaking")
  184. public AjaxResult stocktaking(@RequestBody TaskStocktakingItem taskStocktakingItem) throws Exception{
  185. User currentUser = userService.getCurrentUser();
  186. MaterialBatch materialBatch = materialBatchService.getById(taskStocktakingItem.getMaterialItemId());
  187. if (materialBatch == null) {
  188. return AjaxResult.error("商品信息不存在");
  189. }
  190. UpdateWrapper<TaskStocktakingItem> updateWrapper = new UpdateWrapper<>();
  191. updateWrapper.eq("id", taskStocktakingItem.getId())
  192. .set("creator", currentUser.getId())
  193. .set("oper_time", new Date());
  194. if (ObjectUtil.isNotEmpty(taskStocktakingItem.getNewInventory())) {
  195. updateWrapper.set("new_inventory", taskStocktakingItem.getNewInventory());
  196. BigDecimal subtract = taskStocktakingItem.getNewInventory().subtract(materialBatch.getInventory());
  197. updateWrapper.set("difference_count", subtract);
  198. //差异数量,设置盘点状态为1.未盘,2.盘盈,3.盘亏 4.无差异
  199. if (subtract.compareTo(BigDecimal.ZERO) > 0) {
  200. updateWrapper.set("status", 2);
  201. } else if (subtract.compareTo(BigDecimal.ZERO) < 0) {
  202. updateWrapper.set("status", 3);
  203. } else {
  204. updateWrapper.set("status", 4);
  205. }
  206. }
  207. if (ObjectUtil.isNotEmpty(taskStocktakingItem.getNewPosition())) {
  208. updateWrapper.set("new_position", taskStocktakingItem.getNewPosition());
  209. }
  210. if (ObjectUtil.isNotEmpty(taskStocktakingItem.getDifferenceCount())) {
  211. updateWrapper.set("difference_count", taskStocktakingItem.getDifferenceCount());
  212. }
  213. if (ObjectUtil.isNotEmpty(taskStocktakingItem.getDifferenceReason())){
  214. updateWrapper.set("difference_reason", taskStocktakingItem.getDifferenceReason());
  215. }
  216. taskStocktakingItemService.update(updateWrapper);
  217. return AjaxResult.success();
  218. }
  219. @ApiOperation("负责人下拉列表")
  220. @GetMapping("/creatorSpinnerList/{taskId}")
  221. public AjaxResult creatorSpinnerList(@PathVariable("taskId") Long taskId) {
  222. List<SpinnerVO> spinnerVOList = taskStocktakingItemService.creatorSpinnerList(taskId);
  223. return AjaxResult.success(spinnerVOList);
  224. }
  225. @PostMapping ("/orderSubmit")
  226. @ApiOperation(value = "订单提交")
  227. public AjaxResult orderSubmit(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO) {
  228. try {
  229. long count = depotHeadService.count(new LambdaQueryWrapperX<DepotHead>()
  230. .eq(DepotHead::getLinkNumber,pdaDepotHeadDTO.getNumber())
  231. .eq(DepotHead::getDeleteFlag,false));
  232. if (count > 0){
  233. return AjaxResult.error("订单已提交");
  234. }
  235. depotHeadService.pdaOrderSubmit(pdaDepotHeadDTO);
  236. }catch (BusinessRunTimeException e) {
  237. return AjaxResult.error(e.getMessage());
  238. }catch (Exception e) {
  239. e.printStackTrace();
  240. return AjaxResult.error("提交失败");
  241. }
  242. return AjaxResult.success();
  243. }
  244. @PostMapping("/inventoryInquiry")
  245. @ApiOperation("存货查询-商品存货查询")
  246. public TableDataInfo inventoryInquiry(@RequestBody PDAInventoryDTO pdaInventoryDTO){
  247. //查询类型id的子类型
  248. pdaInventoryDTO.setCategoryIds(materialService.selectCategoryIds(pdaInventoryDTO.getCategoryId()));
  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. @ApiOperation("货物信息录入保存")
  321. @PostMapping("/goodsSave")
  322. public AjaxResult goodsSave(@RequestBody MaterialInput materialInput) {
  323. boolean b = materialInputService.add(materialInput);
  324. if (!b){
  325. return AjaxResult.error("保存失败");
  326. }
  327. return AjaxResult.success("保存成功");
  328. }
  329. @PostMapping("/goodsInputList")
  330. @ApiOperation("货物录入列表")
  331. public TableDataInfo goodsInputList(@RequestBody PDAGoodsInputDTO pdaInventoryDTO){
  332. startPage();
  333. List<MaterialInput> list = materialInputService.list(new LambdaQueryWrapperX<MaterialInput>().eq(MaterialInput::getDepotId,pdaInventoryDTO.getDepotId()));
  334. return getDataTable(list);
  335. }
  336. @PostMapping("/reviewTaskList")
  337. @ApiOperation("复核任务列表")
  338. public TableDataInfo reviewTaskList(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO){
  339. List<PDADepotHeadVO> list = depotHeadService.reviewTaskList(pdaDepotHeadDTO);
  340. return getDataTable(list);
  341. }
  342. @PostMapping("/setReviewTask")
  343. @ApiOperation("设置复核任务状态")
  344. public AjaxResult setReviewStatus(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO){
  345. Long userId = userService.getCurrentUser().getId();
  346. DepotHead depotHead = depotHeadService.getDepotHead(pdaDepotHeadDTO.getId());
  347. if (!depotHead.getStatus().equals("6")){
  348. return AjaxResult.error("该复核任务已被处理");
  349. }
  350. if (depotHead.getCreator() == userId){
  351. return AjaxResult.error("提交人不能和复核人为同一账号");
  352. }
  353. boolean b = depotHeadService.setReviewStatus(pdaDepotHeadDTO);
  354. if (!b){
  355. return AjaxResult.error("审核失败!");
  356. }
  357. return AjaxResult.success();
  358. }
  359. @GetMapping("/getSkuByUpc")
  360. @ApiOperation("根据upc获取sku")
  361. public AjaxResult getSkuByUpc(@RequestParam("upc") String upc){
  362. String sku = materialExtendService.getSkuByUpc(upc);
  363. if (StringUtil.isEmpty(sku)){
  364. return AjaxResult.error("系统没有找到对应的sku");
  365. }
  366. return AjaxResult.success("操作成功",sku);
  367. }
  368. @GetMapping("/getMsgList")
  369. @ApiOperation("获取用户消息列表")
  370. public TableDataInfo getMsgList(){
  371. List<PDAMsgListVO> list = msgService.pdaMsgList();
  372. return getDataTable(list);
  373. }
  374. }