Commit 7b9dff6c authored by shiyu's avatar shiyu

数据同步

parent aab021b6
......@@ -110,7 +110,7 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/admin/auth/index", "anon");
filterChainDefinitionMap.put("/admin/auth/403", "anon");
filterChainDefinitionMap.put("/actuator/health", "anon");
// filterChainDefinitionMap.put("/admin/item/syn", "anon");
filterChainDefinitionMap.put("/admin/item/syn", "anon");
// filterChainDefinitionMap.put("/admin/**", "anon");
filterChainDefinitionMap.put("/admin/**", "authc");
......
......@@ -49,7 +49,7 @@ public class ItemController {
return result;
}
// @GetMapping("/syn")
@GetMapping("/syn")
public void syn() {
synCoinJob.execute();
}
......
package com.wwdz.ch.admin.job;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.admin.controller.AdminCollectController;
import com.wwdz.ch.core.consts.CommonEnum;
import com.wwdz.ch.db.dao.CoinsDao;
import com.wwdz.ch.db.dao.ItemManager;
import com.wwdz.ch.db.domain.Coins;
import com.wwdz.ch.db.domain.Item;
import com.wwdz.ch.db.dto.request.CoinRequestDto;
import com.wwdz.ch.db.mapper.ItemMapper;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.IntStream;
......@@ -33,6 +26,7 @@ public class SynCoinJob {
CoinsDao coinsDao;
public void execute() {
logger.info(">>>>>>>>>>>>>>>>>>>>>>> 同步coins表数据到item表, 开始执行 <<<<<<<<<<<<<<<<<<<<<");
try {
......@@ -48,7 +42,6 @@ public class SynCoinJob {
dto.setPage(i);
dto.setLimit(100);
List<Coins> coinsList = coinsDao.findList(dto);
// for (Coins coins : coinsList) {
coinsList.parallelStream().forEach(coins -> {
Item item = new Item();
item.setId(coins.getId());
......@@ -71,20 +64,16 @@ public class SynCoinJob {
item.setIsSetted(0);
item.setOriginalExtra(coins.getExtra());
item.setOriginalSourceUrl(coins.getSourceUrl());
item.setSource(coins.getSource());
itemManager.insert(item);
});
logger.info(">>>>>>>>>>>>>>>>> 同步数据的页码: {}, 同步成功 <<<<<<<<<<<<<<<<<", i);
/*try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}*/
logger.info(">>>>>>>>>>>>>>>>> 同步数据的页码: {}, 同步成功 <<<<<<<<<<<<<<<<<", i);
});
logger.info(">>>>>>>>>>>>>>>>>>>>>>> 同步coins表数据到item表, 执行完毕 <<<<<<<<<<<<<<<<<<<<<");
} catch (Exception e) {
logger.error("同步coins表数据到item表 error {}", e);
}
logger.info(">>>>>>>>>>>>>>>>>>>>>>> 同步coins表数据到item表, 执行完毕 <<<<<<<<<<<<<<<<<<<<<");
}
}
......@@ -10,7 +10,7 @@ import lombok.Data;
/**
* @author shiyu
* @date 2023/07/26
* @date 2023/07/27
*/
@Data
public class Item implements Entity {
......@@ -96,6 +96,11 @@ public class Item implements Entity {
*/
private String originalSourceUrl;
/**
* 来源(1,2,3,7,8,10,11):中国的
*/
private Integer source;
/**
* 钱币额外信息
*/
......@@ -141,6 +146,7 @@ public class Item implements Entity {
sb.append(", remark=").append(remark);
sb.append(", isSetted=").append(isSetted);
sb.append(", originalSourceUrl=").append(originalSourceUrl);
sb.append(", source=").append(source);
sb.append(", extra=").append(extra);
sb.append(", images=").append(images);
sb.append(", detail=").append(detail);
......@@ -179,6 +185,7 @@ public class Item implements Entity {
&& (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()))
&& (this.getIsSetted() == null ? other.getIsSetted() == null : this.getIsSetted().equals(other.getIsSetted()))
&& (this.getOriginalSourceUrl() == null ? other.getOriginalSourceUrl() == null : this.getOriginalSourceUrl().equals(other.getOriginalSourceUrl()))
&& (this.getSource() == null ? other.getSource() == null : this.getSource().equals(other.getSource()))
&& (this.getExtra() == null ? other.getExtra() == null : this.getExtra().equals(other.getExtra()))
&& (this.getImages() == null ? other.getImages() == null : this.getImages().equals(other.getImages()))
&& (this.getDetail() == null ? other.getDetail() == null : this.getDetail().equals(other.getDetail()))
......@@ -206,6 +213,7 @@ public class Item implements Entity {
result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
result = prime * result + ((getIsSetted() == null) ? 0 : getIsSetted().hashCode());
result = prime * result + ((getOriginalSourceUrl() == null) ? 0 : getOriginalSourceUrl().hashCode());
result = prime * result + ((getSource() == null) ? 0 : getSource().hashCode());
result = prime * result + ((getExtra() == null) ? 0 : getExtra().hashCode());
result = prime * result + ((getImages() == null) ? 0 : getImages().hashCode());
result = prime * result + ((getDetail() == null) ? 0 : getDetail().hashCode());
......@@ -238,6 +246,7 @@ public class Item implements Entity {
remark("remark", "remark", "VARCHAR", false),
isSetted("is_setted", "isSetted", "INTEGER", false),
originalSourceUrl("original_source_url", "originalSourceUrl", "VARCHAR", false),
source("source", "source", "INTEGER", true),
extra("extra", "extra", "LONGVARCHAR", false),
images("images", "images", "LONGVARCHAR", false),
detail("detail", "detail", "LONGVARCHAR", false),
......
......@@ -2451,6 +2451,138 @@ public class ItemExample {
addCriterion("original_source_url not between", value1, value2, "originalSourceUrl");
return (Criteria) this;
}
public Criteria andSourceIsNull() {
addCriterion("`source` is null");
return (Criteria) this;
}
public Criteria andSourceIsNotNull() {
addCriterion("`source` is not null");
return (Criteria) this;
}
public Criteria andSourceEqualTo(Integer value) {
addCriterion("`source` =", value, "source");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andSourceEqualToColumn(Item.Column column) {
addCriterion(new StringBuilder("`source` = ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andSourceNotEqualTo(Integer value) {
addCriterion("`source` <>", value, "source");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andSourceNotEqualToColumn(Item.Column column) {
addCriterion(new StringBuilder("`source` <> ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andSourceGreaterThan(Integer value) {
addCriterion("`source` >", value, "source");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andSourceGreaterThanColumn(Item.Column column) {
addCriterion(new StringBuilder("`source` > ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andSourceGreaterThanOrEqualTo(Integer value) {
addCriterion("`source` >=", value, "source");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andSourceGreaterThanOrEqualToColumn(Item.Column column) {
addCriterion(new StringBuilder("`source` >= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andSourceLessThan(Integer value) {
addCriterion("`source` <", value, "source");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andSourceLessThanColumn(Item.Column column) {
addCriterion(new StringBuilder("`source` < ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andSourceLessThanOrEqualTo(Integer value) {
addCriterion("`source` <=", value, "source");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andSourceLessThanOrEqualToColumn(Item.Column column) {
addCriterion(new StringBuilder("`source` <= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andSourceIn(List<Integer> values) {
addCriterion("`source` in", values, "source");
return (Criteria) this;
}
public Criteria andSourceNotIn(List<Integer> values) {
addCriterion("`source` not in", values, "source");
return (Criteria) this;
}
public Criteria andSourceBetween(Integer value1, Integer value2) {
addCriterion("`source` between", value1, value2, "source");
return (Criteria) this;
}
public Criteria andSourceNotBetween(Integer value1, Integer value2) {
addCriterion("`source` not between", value1, value2, "source");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {
......
......@@ -38,6 +38,11 @@ public class CoinRequestDto extends BaseRequestDto implements Entity {
*/
private Integer isStd;
/**
* 原始图片,以分号分割
*/
private String images;
/**
* 图片
*/
......
......@@ -6,6 +6,7 @@ import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface ItemMapper {
long countByExample(ItemExample example);
......
......@@ -19,6 +19,7 @@
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="is_setted" jdbcType="INTEGER" property="isSetted" />
<result column="original_source_url" jdbcType="VARCHAR" property="originalSourceUrl" />
<result column="source" jdbcType="INTEGER" property="source" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.wwdz.ch.db.domain.Item">
<result column="extra" jdbcType="LONGVARCHAR" property="extra" />
......@@ -86,7 +87,8 @@
</sql>
<sql id="Base_Column_List">
id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time,
source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url
source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url,
`source`
</sql>
<sql id="Blob_Column_List">
extra, images, detail, original_extra
......@@ -143,7 +145,7 @@
<otherwise>
id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time,
source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url,
extra, images, detail, original_extra
`source`, extra, images, detail, original_extra
</otherwise>
</choose>
from item
......@@ -178,7 +180,7 @@
<otherwise>
id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time,
source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url,
extra, images, detail, original_extra
`source`, extra, images, detail, original_extra
</otherwise>
</choose>
from item
......@@ -198,20 +200,22 @@
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into item (`name`, cid, is_on_sale,
insert into item_temp (`name`, cid, is_on_sale,
is_std, sort, share_image,
top_image, price, create_time,
source_type, update_time, is_deleted,
bid_time, remark, is_setted,
original_source_url, extra, images,
detail, original_extra)
original_source_url, `source`, extra,
images, detail, original_extra
)
values (#{name,jdbcType=VARCHAR}, #{cid,jdbcType=INTEGER}, #{isOnSale,jdbcType=BIT},
#{isStd,jdbcType=BIT}, #{sort,jdbcType=INTEGER}, #{shareImage,jdbcType=VARCHAR},
#{topImage,jdbcType=VARCHAR}, #{price,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP},
#{sourceType,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP}, #{isDeleted,jdbcType=BIT},
#{bidTime,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{isSetted,jdbcType=INTEGER},
#{originalSourceUrl,jdbcType=VARCHAR}, #{extra,jdbcType=LONGVARCHAR}, #{images,jdbcType=LONGVARCHAR},
#{detail,jdbcType=LONGVARCHAR}, #{originalExtra,jdbcType=LONGVARCHAR})
#{originalSourceUrl,jdbcType=VARCHAR}, #{source,jdbcType=INTEGER}, #{extra,jdbcType=LONGVARCHAR},
#{images,jdbcType=LONGVARCHAR}, #{detail,jdbcType=LONGVARCHAR}, #{originalExtra,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.Item">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
......@@ -267,6 +271,9 @@
<if test="originalSourceUrl != null">
original_source_url,
</if>
<if test="source != null">
`source`,
</if>
<if test="extra != null">
extra,
</if>
......@@ -329,6 +336,9 @@
<if test="originalSourceUrl != null">
#{originalSourceUrl,jdbcType=VARCHAR},
</if>
<if test="source != null">
#{source,jdbcType=INTEGER},
</if>
<if test="extra != null">
#{extra,jdbcType=LONGVARCHAR},
</if>
......@@ -403,6 +413,9 @@
<if test="record.originalSourceUrl != null">
original_source_url = #{record.originalSourceUrl,jdbcType=VARCHAR},
</if>
<if test="record.source != null">
`source` = #{record.source,jdbcType=INTEGER},
</if>
<if test="record.extra != null">
extra = #{record.extra,jdbcType=LONGVARCHAR},
</if>
......@@ -439,6 +452,7 @@
remark = #{record.remark,jdbcType=VARCHAR},
is_setted = #{record.isSetted,jdbcType=INTEGER},
original_source_url = #{record.originalSourceUrl,jdbcType=VARCHAR},
`source` = #{record.source,jdbcType=INTEGER},
extra = #{record.extra,jdbcType=LONGVARCHAR},
images = #{record.images,jdbcType=LONGVARCHAR},
detail = #{record.detail,jdbcType=LONGVARCHAR},
......@@ -465,7 +479,8 @@
bid_time = #{record.bidTime,jdbcType=VARCHAR},
remark = #{record.remark,jdbcType=VARCHAR},
is_setted = #{record.isSetted,jdbcType=INTEGER},
original_source_url = #{record.originalSourceUrl,jdbcType=VARCHAR}
original_source_url = #{record.originalSourceUrl,jdbcType=VARCHAR},
`source` = #{record.source,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
......@@ -521,6 +536,9 @@
<if test="originalSourceUrl != null">
original_source_url = #{originalSourceUrl,jdbcType=VARCHAR},
</if>
<if test="source != null">
`source` = #{source,jdbcType=INTEGER},
</if>
<if test="extra != null">
extra = #{extra,jdbcType=LONGVARCHAR},
</if>
......@@ -554,6 +572,7 @@
remark = #{remark,jdbcType=VARCHAR},
is_setted = #{isSetted,jdbcType=INTEGER},
original_source_url = #{originalSourceUrl,jdbcType=VARCHAR},
`source` = #{source,jdbcType=INTEGER},
extra = #{extra,jdbcType=LONGVARCHAR},
images = #{images,jdbcType=LONGVARCHAR},
detail = #{detail,jdbcType=LONGVARCHAR},
......@@ -577,7 +596,8 @@
bid_time = #{bidTime,jdbcType=VARCHAR},
remark = #{remark,jdbcType=VARCHAR},
is_setted = #{isSetted,jdbcType=INTEGER},
original_source_url = #{originalSourceUrl,jdbcType=VARCHAR}
original_source_url = #{originalSourceUrl,jdbcType=VARCHAR},
`source` = #{source,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
<select id="selectOneByExample" parameterType="com.wwdz.ch.db.domain.ItemExample" resultMap="BaseResultMap">
......@@ -635,7 +655,7 @@
<otherwise>
id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time,
source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url,
extra, images, detail, original_extra
`source`, extra, images, detail, original_extra
</otherwise>
</choose>
from item
......@@ -647,5 +667,4 @@
</if>
limit 1
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment