26 changed files with 395 additions and 91 deletions
@ -0,0 +1,51 @@ |
|||
package com.base.springcloud.aspect.config; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; |
|||
import com.fasterxml.jackson.annotation.PropertyAccessor; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping; |
|||
import org.springframework.cache.annotation.CachingConfigurerSupport; |
|||
import org.springframework.cache.annotation.EnableCaching; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
|||
import org.springframework.data.redis.core.RedisTemplate; |
|||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; |
|||
import org.springframework.data.redis.serializer.RedisSerializer; |
|||
import org.springframework.data.redis.serializer.StringRedisSerializer; |
|||
|
|||
import javax.annotation.Resource; |
|||
|
|||
@Configuration |
|||
@EnableCaching // 开启缓存支持
|
|||
public class RedisConfig extends CachingConfigurerSupport { |
|||
|
|||
@Resource |
|||
private LettuceConnectionFactory lettuceConnectionFactory; |
|||
|
|||
/** |
|||
* RedisTemplate配置 |
|||
* |
|||
* @param lettuceConnectionFactory |
|||
* @return |
|||
*/ |
|||
@Bean |
|||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) { |
|||
// 设置序列化
|
|||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class); |
|||
ObjectMapper om = new ObjectMapper(); |
|||
om.setVisibility(PropertyAccessor.ALL, Visibility.ANY); |
|||
om.enableDefaultTyping(DefaultTyping.NON_FINAL); |
|||
jackson2JsonRedisSerializer.setObjectMapper(om); |
|||
// 配置redisTemplate
|
|||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>(); |
|||
redisTemplate.setConnectionFactory(lettuceConnectionFactory); |
|||
RedisSerializer<?> stringSerializer = new StringRedisSerializer(); |
|||
redisTemplate.setKeySerializer(stringSerializer);// key序列化
|
|||
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);// value序列化
|
|||
redisTemplate.setHashKeySerializer(stringSerializer);// Hash key序列化
|
|||
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);// Hash value序列化
|
|||
redisTemplate.afterPropertiesSet(); |
|||
return redisTemplate; |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package com.base.springcloud.dao; |
|||
|
|||
import com.base.springcloud.entity.OrderBill; |
|||
import org.springframework.stereotype.Repository; |
|||
|
|||
@Repository |
|||
public interface OrderBillMapper { |
|||
int deleteByPrimaryKey(String id); |
|||
|
|||
int insert(OrderBill record); |
|||
|
|||
int insertSelective(OrderBill record); |
|||
|
|||
OrderBill selectByPrimaryKey(String id); |
|||
|
|||
int updateByPrimaryKeySelective(OrderBill record); |
|||
|
|||
int updateByPrimaryKey(OrderBill record); |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
package com.base.springcloud.entity; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
public class OrderBill { |
|||
|
|||
private String id; |
|||
|
|||
private String orderId; |
|||
|
|||
private String billId; |
|||
|
|||
private String soureBillId; |
|||
|
|||
private String createId; |
|||
|
|||
private Date createTime; |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
package com.base.springcloud.service; |
|||
|
|||
import com.base.springcloud.bo.OrderBO; |
|||
|
|||
public interface OrderBillService { |
|||
|
|||
|
|||
/** |
|||
* 登记销售单据和订单关联 |
|||
* @param orderBO |
|||
*/ |
|||
void registerOrderBill(OrderBO orderBO); |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
package com.base.springcloud.service.imp; |
|||
|
|||
import com.base.springcloud.bo.OrderBO; |
|||
import com.base.springcloud.dao.OrderBillMapper; |
|||
import com.base.springcloud.entity.Order; |
|||
import com.base.springcloud.entity.OrderBill; |
|||
import com.base.springcloud.entity.SaleBill; |
|||
import com.base.springcloud.service.OrderBillService; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
@Service |
|||
public class OrderBillServiceImp implements OrderBillService { |
|||
|
|||
Logger logger = LoggerFactory.getLogger(OrderBillServiceImp.class); |
|||
|
|||
@Autowired |
|||
private OrderBillMapper orderBillMapper; |
|||
|
|||
/** |
|||
* 登记销售单据和订单关联 |
|||
* |
|||
* @param orderBO |
|||
*/ |
|||
@Override |
|||
public void registerOrderBill(OrderBO orderBO) { |
|||
Order order = orderBO.getOrder(); |
|||
List<SaleBill> saleBillList = orderBO.getSaleBillList(); |
|||
saleBillList.forEach(item -> { |
|||
OrderBill orderBill = new OrderBill(); |
|||
orderBill.setId(UUID.randomUUID().toString().replace("-", "")); |
|||
orderBill.setCreateTime(new Date()); |
|||
orderBill.setSoureBillId(item.getSourceId()); |
|||
orderBill.setBillId(item.getId()); |
|||
orderBill.setOrderId(order.getId()); |
|||
orderBillMapper.insert(orderBill); |
|||
}); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,106 @@ |
|||
<?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.base.springcloud.dao.OrderBillMapper"> |
|||
<resultMap id="BaseResultMap" type="com.base.springcloud.entity.OrderBill"> |
|||
<id column="id" jdbcType="VARCHAR" property="id" /> |
|||
<result column="order_id" jdbcType="VARCHAR" property="orderId" /> |
|||
<result column="bill_id" jdbcType="VARCHAR" property="billId" /> |
|||
<result column="soure_bill_id" jdbcType="VARCHAR" property="soureBillId" /> |
|||
<result column="create_id" jdbcType="VARCHAR" property="createId" /> |
|||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
|||
</resultMap> |
|||
<sql id="Base_Column_List"> |
|||
id, order_id, bill_id, soure_bill_id, create_id, create_time |
|||
</sql> |
|||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> |
|||
select |
|||
<include refid="Base_Column_List" /> |
|||
from pay_order_bill |
|||
where id = #{id,jdbcType=VARCHAR} |
|||
</select> |
|||
<delete id="deleteByPrimaryKey" parameterType="java.lang.String"> |
|||
delete from pay_order_bill |
|||
where id = #{id,jdbcType=VARCHAR} |
|||
</delete> |
|||
<insert id="insert" parameterType="com.base.springcloud.entity.OrderBill"> |
|||
insert into pay_order_bill (id, order_id, bill_id, |
|||
soure_bill_id, create_id, create_time |
|||
) |
|||
values (#{id,jdbcType=VARCHAR}, #{orderId,jdbcType=VARCHAR}, #{billId,jdbcType=VARCHAR}, |
|||
#{soureBillId,jdbcType=VARCHAR}, #{createId,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP} |
|||
) |
|||
</insert> |
|||
<insert id="insertSelective" parameterType="com.base.springcloud.entity.OrderBill"> |
|||
insert into pay_order_bill |
|||
<trim prefix="(" suffix=")" suffixOverrides=","> |
|||
<if test="id != null"> |
|||
id, |
|||
</if> |
|||
<if test="orderId != null"> |
|||
order_id, |
|||
</if> |
|||
<if test="billId != null"> |
|||
bill_id, |
|||
</if> |
|||
<if test="soureBillId != null"> |
|||
soure_bill_id, |
|||
</if> |
|||
<if test="createId != null"> |
|||
create_id, |
|||
</if> |
|||
<if test="createTime != null"> |
|||
create_time, |
|||
</if> |
|||
</trim> |
|||
<trim prefix="values (" suffix=")" suffixOverrides=","> |
|||
<if test="id != null"> |
|||
#{id,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="orderId != null"> |
|||
#{orderId,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="billId != null"> |
|||
#{billId,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="soureBillId != null"> |
|||
#{soureBillId,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="createId != null"> |
|||
#{createId,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="createTime != null"> |
|||
#{createTime,jdbcType=TIMESTAMP}, |
|||
</if> |
|||
</trim> |
|||
</insert> |
|||
<update id="updateByPrimaryKeySelective" parameterType="com.base.springcloud.entity.OrderBill"> |
|||
update pay_order_bill |
|||
<set> |
|||
<if test="orderId != null"> |
|||
order_id = #{orderId,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="billId != null"> |
|||
bill_id = #{billId,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="soureBillId != null"> |
|||
soure_bill_id = #{soureBillId,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="createId != null"> |
|||
create_id = #{createId,jdbcType=VARCHAR}, |
|||
</if> |
|||
<if test="createTime != null"> |
|||
create_time = #{createTime,jdbcType=TIMESTAMP}, |
|||
</if> |
|||
</set> |
|||
where id = #{id,jdbcType=VARCHAR} |
|||
</update> |
|||
<update id="updateByPrimaryKey" parameterType="com.base.springcloud.entity.OrderBill"> |
|||
update pay_order_bill |
|||
set order_id = #{orderId,jdbcType=VARCHAR}, |
|||
bill_id = #{billId,jdbcType=VARCHAR}, |
|||
soure_bill_id = #{soureBillId,jdbcType=VARCHAR}, |
|||
create_id = #{createId,jdbcType=VARCHAR}, |
|||
create_time = #{createTime,jdbcType=TIMESTAMP} |
|||
where id = #{id,jdbcType=VARCHAR} |
|||
</update> |
|||
</mapper> |
|||
Loading…
Reference in new issue