|
|
@@ -0,0 +1,67 @@
|
|
|
+package cn.reghao.autodop.dmaster.app3.service.crud;
|
|
|
+
|
|
|
+import cn.reghao.autodop.common.utils.data.db.CrudOps;
|
|
|
+import cn.reghao.autodop.common.utils.data.db.PageList;
|
|
|
+import cn.reghao.autodop.dmaster.app3.entity.App3Bak;
|
|
|
+import cn.reghao.autodop.dmaster.app3.repository.App3BakRepository;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2020-11-10 21:58:00
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class App3BakCrudService implements CrudOps<App3Bak> {
|
|
|
+ private App3BakRepository app3BakRepository;
|
|
|
+
|
|
|
+ public App3BakCrudService(App3BakRepository app3BakRepository) {
|
|
|
+ this.app3BakRepository = app3BakRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addOrModify(App3Bak app3Bak) {
|
|
|
+ App3Bak app3BakEntity = app3BakRepository.findByIsDeleteFalseAndApp3Name(app3Bak.getApp3Name());
|
|
|
+ if (app3BakEntity != null) {
|
|
|
+ // 若是新增,这三项值数据库会自动生成
|
|
|
+ app3Bak.setId(app3BakEntity.getId());
|
|
|
+ app3Bak.setCreateTime(app3BakEntity.getCreateTime());
|
|
|
+ app3Bak.setUpdateTime(LocalDateTime.now());
|
|
|
+ }
|
|
|
+
|
|
|
+ app3Bak.setIsDelete(false);
|
|
|
+ app3BakRepository.save(app3Bak);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageList<App3Bak> getByPage(int page, int size) {
|
|
|
+ // 默认按更新时间倒序
|
|
|
+ PageRequest pageRequest =
|
|
|
+ PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
|
|
|
+ Page<App3Bak> app3BakPage = app3BakRepository.findAll(pageRequest);
|
|
|
+
|
|
|
+ PageList<App3Bak> pageList = new PageList<>();
|
|
|
+ pageList.setTotalSize(app3BakPage.getTotalElements());
|
|
|
+ pageList.setTotalPages(app3BakPage.getTotalPages());
|
|
|
+ pageList.setList(app3BakPage.getContent());
|
|
|
+
|
|
|
+ return pageList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(String uniqueKey) throws Exception {
|
|
|
+ App3Bak app3BakEntity = app3BakRepository.findByIsDeleteFalseAndApp3Name(uniqueKey);
|
|
|
+ if (app3BakEntity == null) {
|
|
|
+ throw new Exception(uniqueKey + " 不存在...");
|
|
|
+ }
|
|
|
+
|
|
|
+ app3BakEntity.setUpdateTime(LocalDateTime.now());
|
|
|
+ // TODO 只做逻辑删除,但如何复用 unique key?
|
|
|
+ app3BakEntity.setIsDelete(false);
|
|
|
+ app3BakRepository.save(app3BakEntity);
|
|
|
+ }
|
|
|
+}
|