Bladeren bron

物流查询多运单号-新增物流信息定时任务

xdd 1 maand geleden
bovenliggende
commit
67b442bc6f

+ 55 - 0
fs-admin/src/main/java/com/fs/express/FsStoreDeliversController.java

@@ -0,0 +1,55 @@
+package com.fs.express;
+
+import com.fs.common.core.domain.R;
+import com.fs.store.domain.FsStoreDelivers;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 物流信息管理
+ * @author xdd
+ */
+@RestController
+@RequestMapping("/fsStoreDelivers")
+public class FsStoreDeliversController {
+
+    @Autowired
+    private FsStoreDeliversService fsStoreDeliversService;
+
+    /**
+     * 根据ID查询
+     */
+    @GetMapping("/{id}")
+    public R getById(@PathVariable Integer id) {
+        FsStoreDelivers fsStoreDelivers = fsStoreDeliversService.findById(id);
+        return R.ok();
+    }
+    /**
+     * 根据orderId查询
+     */
+    @GetMapping("/getByOrderId/{orderId}")
+    public R getByOrderId(@PathVariable Long orderId) {
+        List<FsStoreDelivers> byOrderId = fsStoreDeliversService.findByOrderId(orderId);
+        return R.ok().put("data",byOrderId);
+    }
+
+    /**
+     * 新增
+     */
+    @PostMapping
+    public R create(@RequestBody FsStoreDelivers fsStoreDelivers) {
+        FsStoreDelivers savedFsStoreDelivers = fsStoreDeliversService.save(fsStoreDelivers);
+        return R.ok().put("data",savedFsStoreDelivers);
+    }
+     /**
+     *全部更新
+     */
+    @PutMapping("/{id}")
+    public R update(@PathVariable Long id, @RequestBody FsStoreDelivers fsStoreDelivers) {
+        fsStoreDelivers.setId(id); // Ensure ID is set for update
+        boolean updated = fsStoreDeliversService.update(fsStoreDelivers);
+        return R.ok();
+    }
+}

+ 38 - 0
fs-admin/src/main/java/com/fs/task/ExpressTask.java

@@ -0,0 +1,38 @@
+package com.fs.task;
+
+import com.fs.express.IExpressService;
+import com.fs.store.service.IFsStoreOrderService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * 物流信息定时任务
+ */
+@Slf4j
+@Component("expressTask")
+public class ExpressTask {
+
+    @Autowired
+    private IExpressService expressService;
+    /**
+     * 推送物流信息到快递鸟定时任务
+     */
+    public void subscribeExpress(){
+        long startTime = System.currentTimeMillis();
+        log.info("定时任务【推送物流信息到快递鸟】开始执行, 开始时间: {}", startTime);
+
+        try {
+            expressService.subscribeExpress();
+            log.info("定时任务【推送物流信息到快递鸟】执行成功");
+        } catch (Exception e) {
+            log.error("定时任务【推送物流信息到快递鸟】执行失败, 异常信息: {}", e.getMessage(), e);
+            throw e;
+        } finally {
+            long endTime = System.currentTimeMillis();
+            long costTime = endTime - startTime;
+            log.info("定时任务【推送物流信息到快递鸟】执行结束, 结束时间: {}, 耗时: {}ms", endTime, costTime);
+        }
+    }
+
+}

+ 43 - 0
fs-service-system/src/main/java/com/fs/express/FsStoreDeliversService.java

@@ -0,0 +1,43 @@
+package com.fs.express;
+
+
+import com.fs.store.domain.FsStoreDelivers;
+
+import java.util.List;
+
+/**
+ * 物流信息查询类
+ * @author xdd
+ */
+public interface FsStoreDeliversService {
+
+    /**
+     * 根据ID查询发货信息
+     *
+     * @param id 主键ID
+     * @return 发货信息
+     */
+    FsStoreDelivers findById(Integer id);
+
+    /**
+     * 保存发货信息
+     *
+     * @param fsStoreDelivers 发货信息对象
+     * @return 插入后的发货信息对象(包含自动生成的主键)
+     */
+    FsStoreDelivers save(FsStoreDelivers fsStoreDelivers);
+
+    /**
+     * 更新发货信息
+     *
+     * @param fsStoreDelivers 发货信息对象
+     * @return 更新是否成功
+     */
+    boolean update(FsStoreDelivers fsStoreDelivers);
+     /**
+     * 根据orderId查询
+     * @param orderId 订单id
+     * @return List<FsStoreDelivers>
+     */
+    List<FsStoreDelivers> findByOrderId(Long orderId);
+}

+ 51 - 0
fs-service-system/src/main/java/com/fs/express/impl/FsStoreDeliversServiceImpl.java

@@ -0,0 +1,51 @@
+package com.fs.express.impl;
+
+import com.fs.express.FsStoreDeliversService;
+import com.fs.store.domain.FsStoreDelivers;
+import com.fs.store.mapper.FsStoreDeliversMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * 物流信息查询类
+ * @author xdd
+ */
+@Service
+public class FsStoreDeliversServiceImpl implements FsStoreDeliversService {
+
+    @Autowired
+    private FsStoreDeliversMapper fsStoreDeliversMapper;
+
+    @Override
+    public FsStoreDelivers findById(Integer id) {
+        return fsStoreDeliversMapper.findById(id);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public FsStoreDelivers save(FsStoreDelivers fsStoreDelivers) {
+        if (fsStoreDelivers.getId() == null) {
+            fsStoreDelivers.setCreateTime(LocalDateTime.now());
+            fsStoreDeliversMapper.insert(fsStoreDelivers);
+
+        }
+        return fsStoreDelivers;
+    }
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean update(FsStoreDelivers fsStoreDelivers)
+    {
+        fsStoreDelivers.setUpdateTime(LocalDateTime.now());
+       return fsStoreDeliversMapper.update(fsStoreDelivers) > 0;
+
+    }
+
+    @Override
+    public List<FsStoreDelivers> findByOrderId(Long orderId) {
+        return fsStoreDeliversMapper.findByOrderId(orderId);
+    }
+}