Commit b9085301 authored by tianbo's avatar tianbo

feature(cylinder):气站卸液量对接接口更新

parent 64a99137
package com.yeejoin.amos.api.openapi.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@AllArgsConstructor
@Getter
public enum CylinderOffloadingFieldEnum {
offloadingVolume(true, false),
creditCode(true, true),
syncDate(true, true),
syncState(true, false);
private final boolean isRequire;
private final boolean isUnique;
public static List<String> getAllRequireKeys() {
return Arrays.stream(values()).filter(e -> e.isRequire).map(Enum::name).collect(Collectors.toList());
}
public static List<String> getAllUniqueKeys() {
return Arrays.stream(values()).filter(e -> e.isUnique).map(Enum::name).collect(Collectors.toList());
}
}
......@@ -52,5 +52,10 @@ public class UniqueFieldsQueryBuilder implements QueryConditionBuilder{
queryWrapper.in("app_id", fillingBeforeList.stream().map(AbstractBaseEntity::getAppId).collect(Collectors.toList()));
queryWrapper.in("sequence_code", fillingBeforeList.stream().map(TmCylinderFillingCheck::getSequenceCode).collect(Collectors.toList()));
}
if (entity instanceof TmCylinderOffloading) {
List<TmCylinderOffloading> tmCylinderOffloadingList = (List<TmCylinderOffloading>) entityList;
queryWrapper.in("credit_code", tmCylinderOffloadingList.stream().map(TmCylinderOffloading::getCreditCode).collect(Collectors.toList()));
queryWrapper.in("statistics_sync_date", tmCylinderOffloadingList.stream().map(TmCylinderOffloading::getStatisticsSyncDate).collect(Collectors.toList()));
}
}
}
package com.yeejoin.amos.api.openapi.face.model;
import java.util.Date;
import org.typroject.tyboot.core.rdbms.model.BaseModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.typroject.tyboot.core.rdbms.model.BaseModel;
import java.util.Date;
@EqualsAndHashCode(callSuper = true)
@Data
public abstract class AbstractBaseModel extends BaseModel{
......
package com.yeejoin.amos.api.openapi.face.model;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDate;
/**
* 气站卸液量记录表
* @author tb
*
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class TmCylinderOffloadingModel extends AbstractBaseModel {
private static final long serialVersionUID = 1L;
private String offloadingVolume; //卸液量(单位吨)
private String creditCode; //对接单位统一信用代码
protected String version = "v1"; //对接接口版本
@ApiModelProperty(value = "统计同步时间 yyyy-MM-dd")
private LocalDate statisticsSyncDate;
}
package com.yeejoin.amos.api.openapi.face.orm.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.api.openapi.face.orm.entity.TmCylinderOffloading;
/**
*
* <pre>
* 气站卸液量记录表 Mapper 接口
* </pre>
*
* @author gwb
* @version $Id: TmCylinderOffloadingMapper.java, v 0.1 2024年7月5日 下午3:28:31 tb Exp $
*/
public interface TmCylinderOffloadingMapper extends BaseMapper<TmCylinderOffloading>
{
}
\ No newline at end of file
package com.yeejoin.amos.api.openapi.face.orm.entity;
import java.util.Date;
import org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity;
import java.util.Date;
@EqualsAndHashCode(callSuper = true)
@Data
public abstract class AbstractBaseEntity extends BaseEntity{
......@@ -17,9 +15,9 @@ public abstract class AbstractBaseEntity extends BaseEntity{
*/
private static final long serialVersionUID = 1L;
@TableField("sync_date")
protected Date SyncDate;//同步时间 yyyy-MM-dd HH24:mi:ss
protected Date syncDate;//同步时间 yyyy-MM-dd HH24:mi:ss
@TableField("sync_state")
protected int SyncState;//同步状态(0-新增 1-更新 2-删除)
protected int syncState;//同步状态(0-新增 1-更新 2-删除)
/**
* 对接公司编码
*/
......
package com.yeejoin.amos.api.openapi.face.orm.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDate;
/**
* 气站卸液量记录表
* @author kinky
*
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("tm_cylinder_offloading")
public class TmCylinderOffloading extends AbstractBaseEntity{
private static final long serialVersionUID = 1L;
@TableField("offloading_volume")
private String offloadingVolume; //卸液量(单位吨)
@TableField("credit_code")
private String creditCode; //对接单位统一信用代码
@ApiModelProperty(value = "对接接口版本")
protected String version = "v1";
@ApiModelProperty(value = "统计同步时间 yyyy-MM-dd")
private LocalDate statisticsSyncDate;
}
......@@ -81,6 +81,9 @@ public class SyncCylinderDataService {
@Autowired
TmCylinderInfoService tmCylinderInfoService;
@Autowired
CylinderOffloadingMapper cylinderOffloadingMapper;
@Value("${cylinder.filling.insert.topic:cylinder/filling/insert/topic}")
private String insertTopic;
......@@ -261,4 +264,8 @@ public class SyncCylinderDataService {
}
}
public void syncCylinderOffloading(List<TmCylinderOffloadingModel> tmCylinderOffloadingList) {
List<CylinderOffloading> cylinderOffloadingList = Bean.toModels(tmCylinderOffloadingList, CylinderOffloading.class);
cylinderOffloadingMapper.saveOrUpdateBatch(cylinderOffloadingList);
}
}
package com.yeejoin.amos.api.openapi.face.service;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.api.openapi.face.model.TmCylinderOffloadingModel;
import com.yeejoin.amos.api.openapi.face.orm.dao.TmCylinderOffloadingMapper;
import com.yeejoin.amos.api.openapi.face.orm.entity.TmCylinderOffloading;
import com.yeejoin.amos.api.openapi.service.MyBaseServiceImpl;
import com.yeejoin.amos.api.openapi.util.MultiFieldKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
/**
* <pre>
* 气站卸液量记录表 服务类
* </pre>
*
* @author gwb
* @version $Id: TmCylinderOffloadingService.java, v 0.1 2024年7月5日 下午3:28:55 tb Exp $
*/
@Component
@Slf4j
public class TmCylinderOffloadingService extends MyBaseServiceImpl<TmCylinderOffloadingModel, TmCylinderOffloading, TmCylinderOffloadingMapper> {
@Autowired
private SyncCylinderDataService syncCylinderDataService;
@DSTransactional
public String createCylinderOffloading(List<TmCylinderOffloadingModel> model) {
if (ValidationUtil.isEmpty(model))
throw new BadRequest("气站卸液量信息数据为空.");
String appId = getAppId();
Date now = new Date();
for (TmCylinderOffloadingModel tmCylinderOffloadingModel : model) {
tmCylinderOffloadingModel.setSequenceNbr(null);
tmCylinderOffloadingModel.setRecDate(now);
tmCylinderOffloadingModel.setAppId(appId);
LocalDate localDate = tmCylinderOffloadingModel.getSyncDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
tmCylinderOffloadingModel.setStatisticsSyncDate(localDate);
}
// 同步到业务库
syncCylinderOffloadingModel(model);
List<TmCylinderOffloading> tmCylinderOffloadingList = Bean.toModels(model, TmCylinderOffloading.class);
this.saveOrUpdateBatchByUniqueFields(
tmCylinderOffloadingList,
tmCylinderOffloading -> new LambdaQueryWrapper<TmCylinderOffloading>()
.eq(TmCylinderOffloading::getCreditCode, tmCylinderOffloading.getCreditCode())
.eq(TmCylinderOffloading::getStatisticsSyncDate, tmCylinderOffloading.getStatisticsSyncDate()),
entity -> new MultiFieldKey(entity.getCreditCode(), entity.getStatisticsSyncDate()),
"creditCode", "statisticsSyncDate");
return "OK";
}
/**
* 同步气站信息至气瓶服务
* @param model
*/
private void syncCylinderOffloadingModel(List<TmCylinderOffloadingModel> model) {
syncCylinderDataService.syncCylinderOffloading(model);
}
}
spring.profiles.active=vb
server.compression.enabled=true
spring.jackson.dateFormat=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=Asia/Shanghai
logging.config=classpath:logback-${spring.profiles.active}.xml
#设置文件上传的大小限制
......@@ -13,3 +14,8 @@ mybatis-plus.mapper-locations=classpath*:mapper/*Mapper.xml
mybatis-plus.type-aliases-super-type=org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity
mybatis-plus.global-config.db-config.id-type=ID_WORKER
spring.main.allow-bean-definition-overriding=true
amos.system.user.user-name=jg_admin
amos.system.user.password=a1234560
amos.system.user.product=AMOS_STUDIO_WEB
amos.system.user.app-key=AMOS_STUDIO
\ No newline at end of file
package com.yeejoin.amos.boot.module.cylinder.flc.api.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity;
import java.time.LocalDate;
import java.util.Date;
/**
* 气站卸液量记录表
* @author kinky
*
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("tz_cylinder_offloading")
public class CylinderOffloading extends BaseEntity {
private static final long serialVersionUID = 1L;
@TableField("offloading_volume")
private String offloadingVolume; //卸液量(单位吨)
@TableField("credit_code")
private String creditCode; //对接单位统一信用代码
@ApiModelProperty(value = "对接接口版本")
protected String version = "v1";
@ApiModelProperty(value = "对接公司编码")
@TableField("app_id")
private String appId;
@ApiModelProperty(value = "同步时间 yyyy-MM-dd HH24:mi:ss")
private Date syncDate;
@ApiModelProperty(value = "统计同步时间 yyyy-MM-dd")
private LocalDate statisticsSyncDate;
@ApiModelProperty(value = "0-新增")
private Integer syncState;
}
package com.yeejoin.amos.boot.module.cylinder.flc.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderOffloading;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <pre>
* 气站卸液量记录表 Mapper 接口
* </pre>
*
* @author gwb
* @version $Id: TmCylinderOffloadingMapper.java, v 0.1 2024年7月5日 下午3:28:31 tb Exp $
*/
public interface CylinderOffloadingMapper extends BaseMapper<CylinderOffloading> {
void saveOrUpdateBatch(@Param("list") List<CylinderOffloading> cylinderOffloadingList);
}
\ No newline at end of file
<?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.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderOffloadingMapper">
<insert id="saveOrUpdateBatch" parameterType="com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderOffloading">
INSERT INTO "tz_cylinder_offloading"(
sequence_nbr,
app_id,
offloading_volume,
rec_date,
rec_user_id,
sync_date,
sync_state,
version,
credit_code,
statistics_sync_date)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.sequenceNbr},
#{item.appId},
#{item.offloadingVolume},
#{item.recDate},
#{item.recUserId},
#{item.syncDate},
#{item.syncState},
#{item.version},
#{item.creditCode},
#{item.statisticsSyncDate})
</foreach>
on conflict (credit_code,statistics_sync_date) do update set
"app_id" = EXCLUDED."app_id",
"offloading_volume" = EXCLUDED."offloading_volume",
"rec_date" = EXCLUDED."rec_date",
"rec_user_id" = EXCLUDED."rec_user_id",
"sync_date" = EXCLUDED."sync_date",
"sync_state" = EXCLUDED."sync_state",
"version" = EXCLUDED."version",
"credit_code" = EXCLUDED."credit_code",
"statistics_sync_date" = EXCLUDED."statistics_sync_date"
</insert>
</mapper>
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