ソースを参照

调用美云商品编码接口

sh4wmoo 3 年 前
コミット
026d7cc594

+ 20 - 0
src/main/java/com/dk/mnls_mp/controller/mnls/IbossGoodsCodeController.java

@@ -0,0 +1,20 @@
+package com.dk.mnls_mp.controller.mnls;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ * iBOSS商品编码表 前端控制器
+ * </p>
+ *
+ * @author 张潇木
+ * @since 2022-09-23
+ */
+@RestController
+@RequestMapping("/iboss-goods-code")
+public class IbossGoodsCodeController {
+
+}

+ 14 - 0
src/main/java/com/dk/mnls_mp/mapper/mnls/IbossGoodsCodeMapper.java

@@ -0,0 +1,14 @@
+package com.dk.mnls_mp.mapper.mnls;
+
+import com.dk.mnls_mp.model.pojo.mnls.IbossGoodsCode;
+import com.dk.mnls_mp.infrastructure.base.MPBaseMapper;
+import org.springframework.stereotype.Repository;
+
+/**
+*  iBOSS商品编码表 Mapper
+*/
+@Repository
+public interface IbossGoodsCodeMapper extends MPBaseMapper<IbossGoodsCode>{
+	
+}
+

+ 141 - 0
src/main/java/com/dk/mnls_mp/mapper/mnls/IbossGoodsCodeMapper.xml

@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.dk.mnls_mp.mapper.mnls.IbossGoodsCodeMapper">
+
+    <!-- 通用设置 -->
+    <!-- 通用查询列 -->
+    <sql id="Base_Column_List">
+        id, item_id, only_code, code, goods_name, specification, package_num, kind_name, series_name, variety_name, create_time
+    </sql>
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.dk.mnls_mp.model.pojo.mnls.IbossGoodsCode">
+        <id column="id" property="id"/>
+                <result column="item_id" property="itemId"/>
+                <result column="only_code" property="onlyCode"/>
+                <result column="code" property="code"/>
+                <result column="goods_name" property="goodsName"/>
+                <result column="specification" property="specification"/>
+                <result column="package_num" property="packageNum"/>
+                <result column="kind_name" property="kindName"/>
+                <result column="series_name" property="seriesName"/>
+                <result column="variety_name" property="varietyName"/>
+    </resultMap>
+
+    <!-- 通用条件列 -->
+    <sql id="Condition">
+        <where>
+            <if test="itemId != null">
+                AND item_id = #{itemId}
+            </if>
+            <if test="onlyCode != null and onlyCode != ''">
+                AND only_code = #{onlyCode}
+            </if>
+            <if test="code != null and code != ''">
+                AND code = #{code}
+            </if>
+            <if test="goodsName != null and goodsName != ''">
+                AND goods_name = #{goodsName}
+            </if>
+            <if test="specification != null and specification != ''">
+                AND specification = #{specification}
+            </if>
+            <if test="packageNum != null">
+                AND package_num = #{packageNum}
+            </if>
+            <if test="kindName != null and kindName != ''">
+                AND kind_name = #{kindName}
+            </if>
+            <if test="seriesName != null and seriesName != ''">
+                AND series_name = #{seriesName}
+            </if>
+            <if test="varietyName != null and varietyName != ''">
+                AND variety_name = #{varietyName}
+            </if>
+            <if test="createTime != null">
+                AND create_time = #{createTime}
+            </if>
+        </where>
+    </sql>
+
+    <sql id="idsForeach">
+        <!-- 根据主键id批量操作 -->
+        WHERE id in
+        <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
+            #{item}
+        </foreach>
+    </sql>
+
+    <!-- 查询表t_iboss_goods_code,(条件查询+分页)列表 -->
+    <select id="selectByCond" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM t_iboss_goods_code
+        <include refid="Condition"/>
+        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
+            limit #{end} offset #{start}
+        </if>
+    </select>
+
+    <!-- 查询表t_iboss_goods_code,(条件查询)个数 -->
+    <select id="countByCond" resultType="Long">
+        SELECT
+        count(1)
+        FROM t_iboss_goods_code
+        <include refid="Condition"/>
+    </select>
+
+
+    <!-- 根据主键锁定表t_iboss_goods_code的一行数据 -->
+    <select id="selectByIdForUpdate" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM t_iboss_goods_code
+        WHERE id = #{id}
+        for update
+    </select>
+
+    <!-- 根据主键锁定表t_iboss_goods_code的多行数据 -->
+    <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM t_iboss_goods_code
+        <include refid="idsForeach"/>
+        for update
+    </select>
+
+    <insert id="insertBatch">
+        insert into t_iboss_goods_code
+        (
+        <trim suffixOverrides=",">
+            item_id,
+            only_code,
+            code,
+            goods_name,
+            specification,
+            package_num,
+            kind_name,
+            series_name,
+            variety_name,
+            create_time,
+        </trim>
+        )
+        values
+        <foreach collection="list" index="index" item="item" separator=",">
+            (
+            <trim suffixOverrides=",">
+                #{item.itemId},
+                #{item.onlyCode},
+                #{item.code},
+                #{item.goodsName},
+                #{item.specification},
+                #{item.packageNum},
+                #{item.kindName},
+                #{item.seriesName},
+                #{item.varietyName},
+                #{item.createTime},
+            </trim>
+            )
+        </foreach>
+    </insert>
+</mapper>

+ 94 - 0
src/main/java/com/dk/mnls_mp/model/pojo/mnls/IbossGoodsCode.java

@@ -0,0 +1,94 @@
+package com.dk.mnls_mp.model.pojo.mnls;
+
+import com.baomidou.mybatisplus.annotation.*;
+import java.io.Serializable;
+
+import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+
+/**
+ *  iBOSS商品编码表
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Accessors(chain = true)
+@TableName(value = "t_iboss_goods_code", autoResultMap = true)
+public class IbossGoodsCode implements Serializable {
+
+    /**
+     * 主键id
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+
+    /**
+     * 美云商品信息唯一键
+     */
+    private Long itemId;
+
+
+    /**
+     * iBOSS唯一编码
+     */
+    private String onlyCode;
+
+
+    /**
+     * iBOSS商品编码
+     */
+    private String code;
+
+
+    /**
+     * iBOSS商品名称
+     */
+    private String goodsName;
+
+
+    /**
+     * iBOSS规格
+     */
+    private String specification;
+
+
+    /**
+     * 包装数
+     */
+    private BigDecimal packageNum;
+
+
+    /**
+     * 种类
+     */
+    private String kindName;
+
+
+    /**
+     * 系列
+     */
+    private String seriesName;
+
+
+    /**
+     * 品种
+     */
+    private String varietyName;
+
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+
+    private static final long serialVersionUID = 1L;
+
+}

+ 23 - 0
src/main/java/com/dk/mnls_mp/service/mnls/IbossGoodsCodeService.java

@@ -0,0 +1,23 @@
+package com.dk.mnls_mp.service.mnls;
+
+import com.dk.mnls_mp.model.pojo.mnls.IbossGoodsCode;
+import com.dk.mnls_mp.mapper.mnls.IbossGoodsCodeMapper;
+import com.dk.mnls_mp.infrastructure.base.MPBaseService;
+import com.dk.mnls_mp.infrastructure.base.MPBaseMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional
+public class IbossGoodsCodeService extends MPBaseService<IbossGoodsCode> {
+
+	@Override
+	public MPBaseMapper<IbossGoodsCode> getRepository() {
+		return ibossGoodsCodeMapper;
+	}
+
+	@Autowired
+	private IbossGoodsCodeMapper ibossGoodsCodeMapper;
+
+}

+ 74 - 0
src/main/java/com/dk/mnls_mp/service/mnls/PullFacGoodsCodeService.java

@@ -0,0 +1,74 @@
+package com.dk.mnls_mp.service.mnls;
+
+import com.dk.mnls_mp.infrastructure.config.Config;
+import com.dk.mnls_mp.infrastructure.util.HttpHelper;
+import com.dk.mnls_mp.mapper.basic.CodeFacRecordMapper;
+import com.dk.mnls_mp.model.pojo.basic.*;
+import com.dongke.base.exceptionHandler.ResponseResultUtil;
+import com.dongke.base.exceptionHandler.ResponseResultVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @desc   : 拉取厂家商品编码业务类
+ * @author : 张潇木
+ * @date   : 2022/9/23 16:53
+ */
+@Slf4j
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class PullFacGoodsCodeService {
+
+    @Autowired
+    Config config;
+
+    @Autowired
+    CodeFacRecordMapper pullFacCodeRecordMapper;
+
+    /**
+     * @desc   : 拉取厂家商品编码
+     * @author : 张潇木
+     * @date   : 2022/9/23 16:54
+     */
+    public ResponseResultVO pullFacGoodsCode() {
+        try {
+            //定义上次拉取成功时间
+            String historyDate= DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
+            //查询上次拉取成功时间
+            List<CodeFacRecord> historyDateList = pullFacCodeRecordMapper.selectCodeHistoryTime();
+            //上次拉取成功时间赋值
+            if (historyDateList != null && historyDateList.size() > 0) {
+                historyDate = historyDateList.get(0).getCreateTime();
+            }
+            Date startTime = new Date();
+            //todo
+            ResponseResultVO responseResultVO = HttpHelper.postMY(config.getMyGoodsCodeUrl(), null);
+            Date endTime = new Date();
+            log.info("任务{},耗时{}毫秒(ms)", "厂家产品主信息", endTime.getTime() - startTime.getTime());
+
+            return ResponseResultUtil.success();
+        } catch (Exception ex) {
+            TransactionAspectSupport.currentTransactionStatus()
+                    .setRollbackOnly();
+            log.error(ex.getMessage(), ex);
+            //返回错误数据
+            return ResponseResultUtil.error(666, "抓取并更新标准商品编码失败");
+        }
+    }
+    /**
+     * @desc   : 记录拉取履历
+     * @author : 张潇木
+     * @date   : 2022/9/23 16:54
+     */
+    public void recordPullDetail(){
+
+    }
+}