diff --git a/src/main/java/club/joylink/rtss/constants/StatusEnum.java b/src/main/java/club/joylink/rtss/constants/StatusEnum.java index 18ff7980a..5b2453c91 100644 --- a/src/main/java/club/joylink/rtss/constants/StatusEnum.java +++ b/src/main/java/club/joylink/rtss/constants/StatusEnum.java @@ -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)); + } } diff --git a/src/main/java/club/joylink/rtss/controller/draft/Model2dDraftController.java b/src/main/java/club/joylink/rtss/controller/draft/Model2dDraftController.java index 0b6de2905..111a8f6cd 100644 --- a/src/main/java/club/joylink/rtss/controller/draft/Model2dDraftController.java +++ b/src/main/java/club/joylink/rtss/controller/draft/Model2dDraftController.java @@ -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 diff --git a/src/main/java/club/joylink/rtss/controller/model2d/Model2dController.java b/src/main/java/club/joylink/rtss/controller/model2d/Model2dController.java new file mode 100644 index 000000000..90eaf8691 --- /dev/null +++ b/src/main/java/club/joylink/rtss/controller/model2d/Model2dController.java @@ -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 pageQueryInfo(Model2dQueryVO queryVO) { + return model2dService.pageQueryInfo(queryVO); + } + + /** + * 查询2d模型数据列表 + * @param queryVO + * @return + */ + @GetMapping("/list") + public List 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); + } +} diff --git a/src/main/java/club/joylink/rtss/entity/Model2d.java b/src/main/java/club/joylink/rtss/entity/Model2d.java index 27e58c009..709155885 100644 --- a/src/main/java/club/joylink/rtss/entity/Model2d.java +++ b/src/main/java/club/joylink/rtss/entity/Model2d.java @@ -23,6 +23,11 @@ public class Model2d implements Serializable { */ private String name; + /** + * 版本 + */ + private Integer version; + /** * 状态 */ diff --git a/src/main/java/club/joylink/rtss/entity/Model2dExample.java b/src/main/java/club/joylink/rtss/entity/Model2dExample.java index 29ded623e..c0eb0ab4c 100644 --- a/src/main/java/club/joylink/rtss/entity/Model2dExample.java +++ b/src/main/java/club/joylink/rtss/entity/Model2dExample.java @@ -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 values) { + addCriterion("version in", values, "version"); + return (Criteria) this; + } + + public Criteria andVersionNotIn(List 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; diff --git a/src/main/java/club/joylink/rtss/services/model2d/Model2dDraftService.java b/src/main/java/club/joylink/rtss/services/model2d/Model2dDraftService.java index f3d3af9bf..1ba5c0aec 100644 --- a/src/main/java/club/joylink/rtss/services/model2d/Model2dDraftService.java +++ b/src/main/java/club/joylink/rtss/services/model2d/Model2dDraftService.java @@ -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); } diff --git a/src/main/java/club/joylink/rtss/services/model2d/Model2dDraftServiceImpl.java b/src/main/java/club/joylink/rtss/services/model2d/Model2dDraftServiceImpl.java index 609826f7b..52ec79c29 100644 --- a/src/main/java/club/joylink/rtss/services/model2d/Model2dDraftServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/model2d/Model2dDraftServiceImpl.java @@ -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 page = (Page) 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() diff --git a/src/main/java/club/joylink/rtss/services/model2d/Model2dService.java b/src/main/java/club/joylink/rtss/services/model2d/Model2dService.java new file mode 100644 index 000000000..5ca04f853 --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/model2d/Model2dService.java @@ -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 queryDataList(Model2dQueryVO queryVO); + + /** + * 分页查询2d模型信息 + * @param queryVO + * @return + */ + PageVO 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); +} diff --git a/src/main/java/club/joylink/rtss/services/model2d/Model2dServiceImpl.java b/src/main/java/club/joylink/rtss/services/model2d/Model2dServiceImpl.java new file mode 100644 index 000000000..0f2a21e61 --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/model2d/Model2dServiceImpl.java @@ -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 queryDataList(Model2dQueryVO queryVO) { + Model2dExample example = new Model2dExample(); + Model2dExample.Criteria criteria = example.createCriteria(); + criteria.andStateEqualTo(StatusEnum.Valid.getCode()); + //其他条件 + List list = this.model2dDAO.selectByExampleWithBLOBs(example); + return Model2dVO.convert2VOList(list); + } + + @Override + public PageVO 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 page = (Page) 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 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; + } + + +} diff --git a/src/main/java/club/joylink/rtss/vo/model2d/Model2dQueryVO.java b/src/main/java/club/joylink/rtss/vo/model2d/Model2dQueryVO.java index aaa49dba8..06541c96d 100644 --- a/src/main/java/club/joylink/rtss/vo/model2d/Model2dQueryVO.java +++ b/src/main/java/club/joylink/rtss/vo/model2d/Model2dQueryVO.java @@ -17,5 +17,8 @@ public class Model2dQueryVO extends PageQueryVO { * 模型名称 */ private String name; - + /** + * 类型 + */ + private String type; } diff --git a/src/main/java/club/joylink/rtss/vo/model2d/Model2dVO.java b/src/main/java/club/joylink/rtss/vo/model2d/Model2dVO.java index 08e8da144..01dbc35e1 100644 --- a/src/main/java/club/joylink/rtss/vo/model2d/Model2dVO.java +++ b/src/main/java/club/joylink/rtss/vo/model2d/Model2dVO.java @@ -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 convert2VO(List 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 convertDraft2VOList(List list) { List 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 convert2VOList(List list) { + List 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; + } } diff --git a/src/main/resources/mybatis/mapper/Model2dDAO.xml b/src/main/resources/mybatis/mapper/Model2dDAO.xml index 96403c940..107f6edcc 100644 --- a/src/main/resources/mybatis/mapper/Model2dDAO.xml +++ b/src/main/resources/mybatis/mapper/Model2dDAO.xml @@ -5,6 +5,7 @@ + @@ -73,7 +74,8 @@ - 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 json_data @@ -143,12 +145,14 @@ - 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 into model_2d @@ -159,6 +163,9 @@ `name`, + + version, + `state`, @@ -185,6 +192,9 @@ #{name,jdbcType=VARCHAR}, + + #{version,jdbcType=INTEGER}, + #{state,jdbcType=VARCHAR}, @@ -223,6 +233,9 @@ `name` = #{record.name,jdbcType=VARCHAR}, + + version = #{record.version,jdbcType=INTEGER}, + `state` = #{record.state,jdbcType=VARCHAR}, @@ -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 @@ `name` = #{name,jdbcType=VARCHAR}, + + version = #{version,jdbcType=INTEGER}, + `state` = #{state,jdbcType=VARCHAR}, @@ -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},