添加2d模型草稿发布接口

添加2d模型数据管理接口
This commit is contained in:
walker-sheng 2021-06-23 10:39:51 +08:00
parent 427299528f
commit 8f55119b8b
12 changed files with 398 additions and 11 deletions

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.constants;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import lombok.Getter;
@Getter
@ -15,4 +16,14 @@ public enum StatusEnum {
this.code = code;
this.msg = msg;
}
public static StatusEnum getByCode(String code) {
for (StatusEnum value : StatusEnum.values()) {
if (value.getCode().equals(code)) {
return value;
}
}
throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL
.exception(String.format("不存在code为[%s]的StatusEnum", code));
}
}

View File

@ -6,16 +6,18 @@ import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.model2d.Model2dCreateCheck;
import club.joylink.rtss.vo.model2d.Model2dQueryVO;
import club.joylink.rtss.vo.model2d.Model2dVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 2d模型操作接口
* 2d模型草稿接口
*/
@RestController
@RequestMapping("/draft/model2d")
public class Model2dDraftController {
@Autowired
private Model2dDraftService model2dDraftService;
/**
@ -58,6 +60,15 @@ public class Model2dDraftController {
this.model2dDraftService.updateData(id, model2dVO, user);
}
/**
* 发布模型
* @param id
*/
@PostMapping("/{id}/publish")
public void publish(@PathVariable Long id, @RequestAttribute AccountVO user) {
this.model2dDraftService.publish(id, user);
}
/**
* 删除用户草稿2d模型
* @param id

View File

@ -0,0 +1,61 @@
package club.joylink.rtss.controller.model2d;
import club.joylink.rtss.services.model2d.Model2dService;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.model2d.Model2dQueryVO;
import club.joylink.rtss.vo.model2d.Model2dVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 2d模型数据管理接口
*/
@RestController
@RequestMapping("/api/model2d")
public class Model2dController {
@Autowired
private Model2dService model2dService;
/**
* 分页查询模型数据
* @param queryVO
* @return
*/
@GetMapping("/paging")
public PageVO<Model2dVO> pageQueryInfo(Model2dQueryVO queryVO) {
return model2dService.pageQueryInfo(queryVO);
}
/**
* 查询2d模型数据列表
* @param queryVO
* @return
*/
@GetMapping("/list")
public List<Model2dVO> queryDataList(Model2dQueryVO queryVO) {
return model2dService.queryDataList(queryVO);
}
/**
* 更新2d模型基础信息
* @param id 模型id
* @param model2dVO
* @param user
*/
@PutMapping("/{id}/basic")
public void updateBasicInfo(@PathVariable Long id, @RequestBody Model2dVO model2dVO, @RequestAttribute AccountVO user) {
this.model2dService.updateBasicInfo(id, model2dVO, user);
}
/**
* 更新状态
*/
@PutMapping("/{id}/state/{state}")
public void updateState(@PathVariable Long id, @PathVariable String state) {
this.model2dService.updateState(id, state);
}
}

View File

@ -23,6 +23,11 @@ public class Model2d implements Serializable {
*/
private String name;
/**
* 版本
*/
private Integer version;
/**
* 状态
*/

View File

@ -325,6 +325,66 @@ public class Model2dExample {
return (Criteria) this;
}
public Criteria andVersionIsNull() {
addCriterion("version is null");
return (Criteria) this;
}
public Criteria andVersionIsNotNull() {
addCriterion("version is not null");
return (Criteria) this;
}
public Criteria andVersionEqualTo(Integer value) {
addCriterion("version =", value, "version");
return (Criteria) this;
}
public Criteria andVersionNotEqualTo(Integer value) {
addCriterion("version <>", value, "version");
return (Criteria) this;
}
public Criteria andVersionGreaterThan(Integer value) {
addCriterion("version >", value, "version");
return (Criteria) this;
}
public Criteria andVersionGreaterThanOrEqualTo(Integer value) {
addCriterion("version >=", value, "version");
return (Criteria) this;
}
public Criteria andVersionLessThan(Integer value) {
addCriterion("version <", value, "version");
return (Criteria) this;
}
public Criteria andVersionLessThanOrEqualTo(Integer value) {
addCriterion("version <=", value, "version");
return (Criteria) this;
}
public Criteria andVersionIn(List<Integer> values) {
addCriterion("version in", values, "version");
return (Criteria) this;
}
public Criteria andVersionNotIn(List<Integer> values) {
addCriterion("version not in", values, "version");
return (Criteria) this;
}
public Criteria andVersionBetween(Integer value1, Integer value2) {
addCriterion("version between", value1, value2, "version");
return (Criteria) this;
}
public Criteria andVersionNotBetween(Integer value1, Integer value2) {
addCriterion("version not between", value1, value2, "version");
return (Criteria) this;
}
public Criteria andStateIsNull() {
addCriterion("`state` is null");
return (Criteria) this;

View File

@ -15,4 +15,11 @@ public interface Model2dDraftService {
void updateBasicInfo(Long id, Model2dVO model2dVO, AccountVO user);
void updateData(Long id, Model2dVO model2dVO, AccountVO user);
/**
* 发布2d模型
* @param id
* @param user
*/
void publish(Long id, AccountVO user);
}

View File

@ -20,6 +20,8 @@ import java.time.LocalDateTime;
public class Model2dDraftServiceImpl implements Model2dDraftService {
@Autowired
private Model2dDraftDAO model2dDraftDAO;
@Autowired
private Model2dService model2dService;
@Override
public String create(Model2dVO model2dVO, AccountVO user) {
@ -51,7 +53,7 @@ public class Model2dDraftServiceImpl implements Model2dDraftService {
}
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
Page<Model2dDraft> page = (Page<Model2dDraft>) this.model2dDraftDAO.selectByExample(example);
return PageVO.convert(page, Model2dVO.convert2VO(page.getResult()));
return PageVO.convert(page, Model2dVO.convertDraft2VOList(page.getResult()));
}
@Override
@ -82,6 +84,13 @@ public class Model2dDraftServiceImpl implements Model2dDraftService {
this.model2dDraftDAO.updateByPrimaryKeySelective(db);
}
@Override
public void publish(Long id, AccountVO user) {
Model2dDraft draft = this.getEntityById(id);
Model2dVO model2dVO = new Model2dVO(draft);
this.model2dService.publish(model2dVO, user);
}
private boolean isUserCodeExist(Long userId, String code) {
Model2dDraftExample example = new Model2dDraftExample();
example.createCriteria()

View File

@ -0,0 +1,41 @@
package club.joylink.rtss.services.model2d;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.model2d.Model2dQueryVO;
import club.joylink.rtss.vo.model2d.Model2dVO;
import java.util.List;
public interface Model2dService {
/**
* 查询2d模型数据列表
* @param queryVO
* @return
*/
List<Model2dVO> queryDataList(Model2dQueryVO queryVO);
/**
* 分页查询2d模型信息
* @param queryVO
* @return
*/
PageVO<Model2dVO> pageQueryInfo(Model2dQueryVO queryVO);
/**
* 2d模型数据发布
* @param model2dVO
* @param user
*/
void publish(Model2dVO model2dVO, AccountVO user);
/**
* 更新模型基础信息
* @param id
* @param model2dVO
* @param user
*/
void updateBasicInfo(Long id, Model2dVO model2dVO, AccountVO user);
void updateState(Long id, String state);
}

View File

@ -0,0 +1,126 @@
package club.joylink.rtss.services.model2d;
import club.joylink.rtss.constants.StatusEnum;
import club.joylink.rtss.dao.Model2dDAO;
import club.joylink.rtss.entity.Model2d;
import club.joylink.rtss.entity.Model2dExample;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.model2d.Model2dQueryVO;
import club.joylink.rtss.vo.model2d.Model2dVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.List;
@Service
public class Model2dServiceImpl implements Model2dService {
@Autowired
private Model2dDAO model2dDAO;
@Override
public List<Model2dVO> queryDataList(Model2dQueryVO queryVO) {
Model2dExample example = new Model2dExample();
Model2dExample.Criteria criteria = example.createCriteria();
criteria.andStateEqualTo(StatusEnum.Valid.getCode());
//其他条件
List<Model2d> list = this.model2dDAO.selectByExampleWithBLOBs(example);
return Model2dVO.convert2VOList(list);
}
@Override
public PageVO<Model2dVO> pageQueryInfo(Model2dQueryVO queryVO) {
Model2dExample example = new Model2dExample();
Model2dExample.Criteria criteria = example.createCriteria();
// criteria.andStateEqualTo(StatusEnum.Valid.getCode());
if (StringUtils.hasText(queryVO.getCode())) {
criteria.andCodeLike(String.format("%%%s%%", queryVO.getCode()));
}
if (StringUtils.hasText(queryVO.getName())) {
criteria.andNameLike(String.format("%%%s%%", queryVO.getName()));
}
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
Page<Model2d> page = (Page<Model2d>) this.model2dDAO.selectByExample(example);
return PageVO.convert(page, Model2dVO.convert2VOList(page.getResult()));
}
@Transactional
@Override
public void publish(Model2dVO model2dVO, AccountVO user) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(model2dVO.getCode());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(model2dVO.getName());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(model2dVO.getJsonData());
int version = 1;
// 根据code查询模型是否存在
if (this.isExistByCode(model2dVO.getCode())) {
version = this.getLargeVersionOfCode(model2dVO.getCode())+1;
// 删除当前在用版本
Model2d update = new Model2d();
update.setState(StatusEnum.Invalid.getCode());
Model2dExample example = new Model2dExample();
example.createCriteria().andCodeEqualTo(model2dVO.getCode());
this.model2dDAO.updateByExampleSelective(update, example);
}
// 创建新的模型数据
Model2d db = model2dVO.toDb();
db.setVersion(version);
db.setState(StatusEnum.Valid.getCode());
db.setCreateUserId(user.getId());
db.setCreateTime(LocalDateTime.now());
this.model2dDAO.insertSelective(db);
}
@Override
public void updateBasicInfo(Long id, Model2dVO model2dVO, AccountVO user) {
Model2d db = this.getEntityById(id);
db.setName(model2dVO.getName());
this.model2dDAO.updateByPrimaryKeySelective(db);
}
@Override
public void updateState(Long id, String state) {
Model2d update = new Model2d();
update.setId(id);
StatusEnum status = StatusEnum.getByCode(state);
update.setState(status.getCode());
this.model2dDAO.updateByPrimaryKeySelective(update);
}
private Model2d getEntityById(Long id) {
Model2d db = this.model2dDAO.selectByPrimaryKey(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(db,
String.format("不存在id为[%s]的2d模型数据", id));
return db;
}
private int getLargeVersionOfCode(String code) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(code,
String.format("code不能为null"));
Model2dExample example = new Model2dExample();
example.createCriteria()
.andCodeEqualTo(code);
example.setOrderByClause("version desc");
example.setLimit(1);
List<Model2d> list = this.model2dDAO.selectByExample(example);
if (!list.isEmpty()) {
return list.get(0).getVersion();
}
return 0;
}
private boolean isExistByCode(String code) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(code,
String.format("code不能为null")); Model2dExample example = new Model2dExample();
example.createCriteria()
.andCodeEqualTo(code);
return this.model2dDAO.countByExample(example) > 0;
}
}

View File

@ -17,5 +17,8 @@ public class Model2dQueryVO extends PageQueryVO {
* 模型名称
*/
private String name;
/**
* 类型
*/
private String type;
}

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.vo.model2d;
import club.joylink.rtss.entity.Model2d;
import club.joylink.rtss.entity.Model2dDraft;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
@ -31,6 +32,10 @@ public class Model2dVO {
*/
@NotBlank(message = "名称不能为空", groups = {Model2dCreateCheck.class})
private String name;
/**
* 版本
*/
private Integer version;
/**
* 状态
@ -63,7 +68,19 @@ public class Model2dVO {
this.updateTime = db.getUpdateTime();
}
public static List<Model2dVO> convert2VO(List<Model2dDraft> list) {
public Model2dVO(Model2d db) {
this.id = db.getId();
this.code = db.getCode();
this.name = db.getName();
this.jsonData = db.getJsonData();
this.version = db.getVersion();
this.createUserId = db.getCreateUserId();
this.createTime = db.getCreateTime();
this.updateUserId = db.getUpdateUserId();
this.updateTime = db.getUpdateTime();
}
public static List<Model2dVO> convertDraft2VOList(List<Model2dDraft> list) {
List<Model2dVO> voList = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
list.forEach(model2dDraft -> new Model2dVO(model2dDraft));
@ -71,6 +88,14 @@ public class Model2dVO {
return voList;
}
public static List<Model2dVO> convert2VOList(List<Model2d> list) {
List<Model2dVO> voList = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
list.forEach(model2d -> new Model2dVO(model2d));
}
return voList;
}
public Model2dDraft toDraftDB() {
Model2dDraft db = new Model2dDraft();
db.setName(this.name);
@ -78,4 +103,12 @@ public class Model2dVO {
db.setJsonData(this.jsonData);
return db;
}
public Model2d toDb() {
Model2d db = new Model2d();
db.setCode(this.code);
db.setName(this.name);
db.setJsonData(this.jsonData);
return db;
}
}

View File

@ -5,6 +5,7 @@
<id column="id" jdbcType="BIGINT" property="id" />
<result column="code" jdbcType="VARCHAR" property="code" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="version" jdbcType="INTEGER" property="version" />
<result column="state" jdbcType="VARCHAR" property="state" />
<result column="create_user_id" jdbcType="BIGINT" property="createUserId" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
@ -73,7 +74,8 @@
</where>
</sql>
<sql id="Base_Column_List">
id, code, `name`, `state`, create_user_id, create_time, update_user_id, update_time
id, code, `name`, version, `state`, create_user_id, create_time, update_user_id,
update_time
</sql>
<sql id="Blob_Column_List">
json_data
@ -143,12 +145,14 @@
</if>
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.Model2d" useGeneratedKeys="true">
insert into model_2d (code, `name`, `state`,
create_user_id, create_time, update_user_id,
update_time, json_data)
values (#{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{state,jdbcType=VARCHAR},
#{createUserId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateUserId,jdbcType=BIGINT},
#{updateTime,jdbcType=TIMESTAMP}, #{jsonData,jdbcType=LONGVARCHAR})
insert into model_2d (code, `name`, version,
`state`, create_user_id, create_time,
update_user_id, update_time, json_data
)
values (#{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{version,jdbcType=INTEGER},
#{state,jdbcType=VARCHAR}, #{createUserId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP},
#{updateUserId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, #{jsonData,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.Model2d" useGeneratedKeys="true">
insert into model_2d
@ -159,6 +163,9 @@
<if test="name != null">
`name`,
</if>
<if test="version != null">
version,
</if>
<if test="state != null">
`state`,
</if>
@ -185,6 +192,9 @@
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="version != null">
#{version,jdbcType=INTEGER},
</if>
<if test="state != null">
#{state,jdbcType=VARCHAR},
</if>
@ -223,6 +233,9 @@
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.version != null">
version = #{record.version,jdbcType=INTEGER},
</if>
<if test="record.state != null">
`state` = #{record.state,jdbcType=VARCHAR},
</if>
@ -251,6 +264,7 @@
set id = #{record.id,jdbcType=BIGINT},
code = #{record.code,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
version = #{record.version,jdbcType=INTEGER},
`state` = #{record.state,jdbcType=VARCHAR},
create_user_id = #{record.createUserId,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
@ -266,6 +280,7 @@
set id = #{record.id,jdbcType=BIGINT},
code = #{record.code,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
version = #{record.version,jdbcType=INTEGER},
`state` = #{record.state,jdbcType=VARCHAR},
create_user_id = #{record.createUserId,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
@ -284,6 +299,9 @@
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="version != null">
version = #{version,jdbcType=INTEGER},
</if>
<if test="state != null">
`state` = #{state,jdbcType=VARCHAR},
</if>
@ -309,6 +327,7 @@
update model_2d
set code = #{code,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
version = #{version,jdbcType=INTEGER},
`state` = #{state,jdbcType=VARCHAR},
create_user_id = #{createUserId,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
@ -321,6 +340,7 @@
update model_2d
set code = #{code,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
version = #{version,jdbcType=INTEGER},
`state` = #{state,jdbcType=VARCHAR},
create_user_id = #{createUserId,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=TIMESTAMP},