|
@@ -0,0 +1,317 @@
|
|
|
|
|
+package com.webflux.launchadmin.mysql.service.tempAll;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import com.webflux.launchadmin.config.BaseContextHandler;
|
|
|
|
|
+import com.webflux.launchadmin.global.BaseException;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.controller.TempAllController.request.PageRequset;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.controller.takeawayController.res.TakeawayRes;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.takeaway.Takeaway;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.takeaway.dto.ColItem;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.tempAll.TempAll;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.tempAll.dto.TempAllDtoInfo;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.tempAll.dto.TempAllDtoNext;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.tempAll.dto.type1.TempAllDtoInfo1;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.tempAll.dto.type1.TempAllDtoNext1;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.tempAll.res.DeleteRes;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.tempAll.res.SaveOrUpdateRes;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.tempAll.res.TempAllRsNext;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.tempAll.res.Type1.TempAllRsNext1;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.repository.takeaway.TakeawayRepository;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.repository.tempAll.TempAllRepository;
|
|
|
|
|
+import com.webflux.launchcommon.returnObj.Paged;
|
|
|
|
|
+import com.webflux.launchcommon.returnObj.RStatus;
|
|
|
|
|
+import io.r2dbc.spi.Parameter;
|
|
|
|
|
+import jakarta.annotation.Resource;
|
|
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
|
|
+import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
|
|
|
+import org.springframework.data.relational.core.query.Criteria;
|
|
|
|
|
+import org.springframework.data.relational.core.query.Query;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.ZonedDateTime;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class TempAllServicesImpl implements TempAllServicesInterface{
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private TempAllRepository tempAllRepository;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private R2dbcEntityTemplate template;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<List<TempAllRsNext>>> getSelectList(String name,Integer type) {
|
|
|
|
|
+ Criteria empty = Criteria.where("type").is(type);
|
|
|
|
|
+ if (Objects.nonNull(name) && !"".equals(name)) {
|
|
|
|
|
+ empty = empty.and("takeaway_name").like("%"+name+"%");
|
|
|
|
|
+ }
|
|
|
|
|
+ Query query = Query.query(empty);
|
|
|
|
|
+ query.columns("id","name");
|
|
|
|
|
+ Mono<List<TempAllRsNext>> listMono = template.select(query, TempAll.class)
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("查异常:::" + throwable.getMessage())))
|
|
|
|
|
+ .map(f -> {
|
|
|
|
|
+ TempAllRsNext next = new TempAllRsNext();
|
|
|
|
|
+ next.setId(f.id());
|
|
|
|
|
+ next.setName(f.name());
|
|
|
|
|
+ return next;
|
|
|
|
|
+ }).collectList();
|
|
|
|
|
+ return RStatus.successList(listMono);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<Paged<TempAllRsNext>>> pageCommon(String name, int page, int size,Integer type) {
|
|
|
|
|
+ Criteria criteria = Criteria.where("type").is(type);
|
|
|
|
|
+ if (Objects.nonNull(name) && !"".equals(name.trim())) {
|
|
|
|
|
+ criteria = criteria.and("name").is(name);
|
|
|
|
|
+ }
|
|
|
|
|
+ Query query = Query.query(criteria);
|
|
|
|
|
+ int skip = (page - 1) *size;
|
|
|
|
|
+ Mono<Long> count = template.count(query, TempAll.class);
|
|
|
|
|
+ Mono<List<TempAll>> all = template.select(query
|
|
|
|
|
+ .offset(skip)
|
|
|
|
|
+ .limit(size)
|
|
|
|
|
+ .sort(Sort.by(Sort.Order.desc("created_at"))), TempAll.class)
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("查询失败::error::" + throwable.getMessage())))
|
|
|
|
|
+ .collectList();
|
|
|
|
|
+ Mono<Paged<TempAllRsNext>> id1 = Mono.zip(count, all).flatMap(f -> {
|
|
|
|
|
+ List<TempAll> t2 = f.getT2();
|
|
|
|
|
+ List<TempAllRsNext> collect = t2.stream().map(map -> {
|
|
|
|
|
+ TempAllRsNext res = new TempAllRsNext();
|
|
|
|
|
+ res.setId(map.id());
|
|
|
|
|
+ res.setName(map.name());
|
|
|
|
|
+ // Todo 如果需要进行转译
|
|
|
|
|
+ // Todo String s = map.jsonContent();
|
|
|
|
|
+ // FixMe 如果需要进行转译
|
|
|
|
|
+
|
|
|
|
|
+ res.setCreateUser(map.createUser());
|
|
|
|
|
+ res.setCreatedAt(map.createdAt());
|
|
|
|
|
+ res.setUpdatedAt(map.updatedAt());
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ Paged<TempAllRsNext> groupUsersPaged = new Paged<>(f.getT1(), collect, page, size);
|
|
|
|
|
+ return Mono.just(groupUsersPaged);
|
|
|
|
|
+ });
|
|
|
|
|
+ return RStatus.successList(id1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<Paged<TempAllRsNext>>> page(PageRequset requset, Integer type) {
|
|
|
|
|
+ String name = requset.getName();
|
|
|
|
|
+ int size = requset.getSize();
|
|
|
|
|
+ int page = requset.getPage();
|
|
|
|
|
+ Criteria criteria = Criteria.where("type").is(type);
|
|
|
|
|
+ if (Objects.nonNull(name) && !"".equals(name.trim())) {
|
|
|
|
|
+ criteria = criteria.and("name").is(name);
|
|
|
|
|
+ }
|
|
|
|
|
+ int skip = (page - 1) *size;
|
|
|
|
|
+ Mono<List<TempAll>> all = template.select(Query.query(criteria)
|
|
|
|
|
+ .sort(Sort.by(Sort.Order.desc("created_at"))), TempAll.class)
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("查询失败::error::" + throwable.getMessage())))
|
|
|
|
|
+ .collectList();
|
|
|
|
|
+ Mono<Paged<TempAllRsNext>> pagedMono = all.flatMap(t2 -> {
|
|
|
|
|
+ List<TempAll> collect1 = t2.stream().filter(ft -> {
|
|
|
|
|
+ String s = ft.jsonContent();
|
|
|
|
|
+
|
|
|
|
|
+ //对象
|
|
|
|
|
+ // FixMe JSONObject jsonObject = JSONUtil.parseObj(s);
|
|
|
|
|
+ // Todo 过滤符合条件的
|
|
|
|
|
+ // FixMe 过滤符合条件的
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ List<TempAll> paginatedList = collect1.stream()
|
|
|
|
|
+ .skip(skip) // 跳过前 skip 个元素
|
|
|
|
|
+ .limit(size) // 限制返回的元素数量
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ List<TempAllRsNext> collect = paginatedList.stream().map(map -> {
|
|
|
|
|
+ TempAllRsNext res = new TempAllRsNext();
|
|
|
|
|
+ res.setId(map.id());
|
|
|
|
|
+ res.setName(map.name());
|
|
|
|
|
+ // Todo 如果需要进行转译
|
|
|
|
|
+ // FixMe 如果需要进行转译
|
|
|
|
|
+ //String s = map.jsonContent();
|
|
|
|
|
+ res.setCreateUser(map.createUser());
|
|
|
|
|
+ res.setCreatedAt(map.createdAt());
|
|
|
|
|
+ res.setUpdatedAt(map.updatedAt());
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ Paged<TempAllRsNext> groupUsersPaged = new Paged<>(collect1.size(), collect, page, size);
|
|
|
|
|
+ return Mono.just(groupUsersPaged);
|
|
|
|
|
+ });
|
|
|
|
|
+ return RStatus.successList(pagedMono);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<DeleteRes<Long>>> deleteById(Long[] id) {
|
|
|
|
|
+ Mono<DeleteRes<Long>> deleteResMono = tempAllRepository.deleteAllById(List.of(id))
|
|
|
|
|
+ .then(Mono.just(new DeleteRes<>(List.of(id))))
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("删除异常:::" + throwable.getMessage())));
|
|
|
|
|
+ return RStatus.success(deleteResMono);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<TempAll>> saveOrUpdate(TempAllDtoNext request,Integer type) {
|
|
|
|
|
+ // FixMe 根据前段传值修改
|
|
|
|
|
+ String jsonContent = request.getJsonContent();
|
|
|
|
|
+ String s;
|
|
|
|
|
+ try {
|
|
|
|
|
+ s = JSONUtil.toJsonStr(jsonContent);
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ return Mono.error(new BaseException("解析错误Errrr::"+e.getMessage()));
|
|
|
|
|
+ }
|
|
|
|
|
+ // ToDo 保存
|
|
|
|
|
+ boolean b = Objects.isNull(request.getId());
|
|
|
|
|
+ String userName = BaseContextHandler.getUserName();
|
|
|
|
|
+ String userId = BaseContextHandler.getUserId();
|
|
|
|
|
+ Mono<TempAll> just;
|
|
|
|
|
+ if (b) {
|
|
|
|
|
+ just = Mono.just(TempAll.getNull());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ just = tempAllRepository.findById(request.getId())
|
|
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("Id错误 查询结果为空")))
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("findById errrrr::" + throwable.getMessage())));
|
|
|
|
|
+ }
|
|
|
|
|
+ Mono<TempAll> mono = just.flatMap(fm -> {
|
|
|
|
|
+ TempAll tempAll = new TempAll(fm.id(),
|
|
|
|
|
+ s,
|
|
|
|
|
+ request.getName(),
|
|
|
|
|
+ b ? userName : fm.createUser(),
|
|
|
|
|
+ b ? ZonedDateTime.now() : fm.createdAt(),
|
|
|
|
|
+ b ? null : ZonedDateTime.now(),
|
|
|
|
|
+ b ? userId : fm.createId(),
|
|
|
|
|
+ type);
|
|
|
|
|
+ return b ? template.insert(tempAll) : tempAllRepository.save(tempAll);
|
|
|
|
|
+ });
|
|
|
|
|
+ return RStatus.success(mono);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<TempAllDtoInfo>> getById(Long id) {
|
|
|
|
|
+ Mono<TempAll> mono = tempAllRepository.findById(id)
|
|
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("id查询结果为空")))
|
|
|
|
|
+ .onErrorResume(error ->
|
|
|
|
|
+ Mono.error(new BaseException(StrUtil.format("查询异常{} id:{}", error.getMessage(), id))));
|
|
|
|
|
+ return mono.flatMap(fm->{
|
|
|
|
|
+ // FixMe 需要根据实际情况解析
|
|
|
|
|
+ String s = fm.jsonContent();
|
|
|
|
|
+ TempAllDtoInfo next = new TempAllDtoInfo();
|
|
|
|
|
+ next.setId(fm.id());
|
|
|
|
|
+ //FixMe 这个可能会根据需求解析
|
|
|
|
|
+ next.setJsonContent(s);
|
|
|
|
|
+ next.setName(fm.name());
|
|
|
|
|
+ next.setUpdatedAt(fm.updatedAt());
|
|
|
|
|
+ next.setCreatedAt(fm.createdAt());
|
|
|
|
|
+ next.setCreateUser(fm.createUser());
|
|
|
|
|
+ next.setCreateId(fm.createId());
|
|
|
|
|
+ Mono<TempAllDtoInfo> takeawayOneResMono =Mono.just(next);
|
|
|
|
|
+ return RStatus.success(takeawayOneResMono);
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<Paged<TempAllRsNext1>>> pageCommon1(String name, int page, int size, Integer type) {
|
|
|
|
|
+ Criteria criteria = Criteria.where("type").is(type);
|
|
|
|
|
+ if (Objects.nonNull(name) && !"".equals(name.trim())) {
|
|
|
|
|
+ criteria = criteria.and("name").is(name);
|
|
|
|
|
+ }
|
|
|
|
|
+ Query query = Query.query(criteria);
|
|
|
|
|
+ int skip = (page - 1) *size;
|
|
|
|
|
+ Mono<Long> count = template.count(query, TempAll.class);
|
|
|
|
|
+ Mono<List<TempAll>> all = template.select(query
|
|
|
|
|
+ .offset(skip)
|
|
|
|
|
+ .limit(size)
|
|
|
|
|
+ .sort(Sort.by(Sort.Order.desc("created_at"))), TempAll.class)
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("查询失败::error::" + throwable.getMessage())))
|
|
|
|
|
+ .collectList();
|
|
|
|
|
+ Mono<Paged<TempAllRsNext1>> id1 = Mono.zip(count, all).flatMap(f -> {
|
|
|
|
|
+ List<TempAll> t2 = f.getT2();
|
|
|
|
|
+ List<TempAllRsNext1> collect = t2.stream().map(map -> {
|
|
|
|
|
+ TempAllRsNext1 res = new TempAllRsNext1();
|
|
|
|
|
+ res.setId(map.id());
|
|
|
|
|
+ res.setName(map.name());
|
|
|
|
|
+ // Todo 如果需要进行转译
|
|
|
|
|
+ // Todo String s = map.jsonContent();
|
|
|
|
|
+ // FixMe 如果需要进行转译
|
|
|
|
|
+
|
|
|
|
|
+ res.setCreateUser(map.createUser());
|
|
|
|
|
+ res.setCreatedAt(map.createdAt());
|
|
|
|
|
+ res.setUpdatedAt(map.updatedAt());
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ Paged<TempAllRsNext1> groupUsersPaged = new Paged<>(f.getT1(), collect, page, size);
|
|
|
|
|
+ return Mono.just(groupUsersPaged);
|
|
|
|
|
+ });
|
|
|
|
|
+ return RStatus.successList(id1);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<TempAll>> saveOrUpdate1(TempAllDtoNext1 request, Integer type) {
|
|
|
|
|
+ // FixMe 根据前段传值修改
|
|
|
|
|
+ String jsonContent = request.getJsonContent();
|
|
|
|
|
+ String s;
|
|
|
|
|
+ try {
|
|
|
|
|
+ s = JSONUtil.toJsonStr(jsonContent);
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ return Mono.error(new BaseException("解析错误Errrr::"+e.getMessage()));
|
|
|
|
|
+ }
|
|
|
|
|
+ // ToDo 保存
|
|
|
|
|
+ boolean b = Objects.isNull(request.getId());
|
|
|
|
|
+ String userName = BaseContextHandler.getUserName();
|
|
|
|
|
+ String userId = BaseContextHandler.getUserId();
|
|
|
|
|
+ Mono<TempAll> just;
|
|
|
|
|
+ if (b) {
|
|
|
|
|
+ just = Mono.just(TempAll.getNull());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ just = tempAllRepository.findById(request.getId())
|
|
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("Id错误 查询结果为空")))
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("findById errrrr::" + throwable.getMessage())));
|
|
|
|
|
+ }
|
|
|
|
|
+ Mono<TempAll> mono = just.flatMap(fm -> {
|
|
|
|
|
+ TempAll tempAll = new TempAll(fm.id(),
|
|
|
|
|
+ s,
|
|
|
|
|
+ request.getName(),
|
|
|
|
|
+ b ? userName : fm.createUser(),
|
|
|
|
|
+ b ? ZonedDateTime.now() : fm.createdAt(),
|
|
|
|
|
+ b ? null : ZonedDateTime.now(),
|
|
|
|
|
+ b ? userId : fm.createId(),
|
|
|
|
|
+ type);
|
|
|
|
|
+ return b ? template.insert(tempAll) : tempAllRepository.save(tempAll);
|
|
|
|
|
+ });
|
|
|
|
|
+ return RStatus.success(mono);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<TempAllDtoInfo1>> getById1(Long id) {
|
|
|
|
|
+ Mono<TempAll> mono = tempAllRepository.findById(id)
|
|
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("id查询结果为空")))
|
|
|
|
|
+ .onErrorResume(error ->
|
|
|
|
|
+ Mono.error(new BaseException(StrUtil.format("查询异常{} id:{}", error.getMessage(), id))));
|
|
|
|
|
+ return mono.flatMap(fm->{
|
|
|
|
|
+ // FixMe 需要根据实际情况解析
|
|
|
|
|
+ String s = fm.jsonContent();
|
|
|
|
|
+ TempAllDtoInfo1 next = new TempAllDtoInfo1();
|
|
|
|
|
+ next.setId(fm.id());
|
|
|
|
|
+ //FixMe 这个可能会根据需求解析
|
|
|
|
|
+ next.setJsonContent(s);
|
|
|
|
|
+ next.setName(fm.name());
|
|
|
|
|
+ next.setUpdatedAt(fm.updatedAt());
|
|
|
|
|
+ next.setCreatedAt(fm.createdAt());
|
|
|
|
|
+ next.setCreateUser(fm.createUser());
|
|
|
|
|
+ next.setCreateId(fm.createId());
|
|
|
|
|
+ Mono<TempAllDtoInfo1> takeawayOneResMono =Mono.just(next);
|
|
|
|
|
+ return RStatus.success(takeawayOneResMono);
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|