|
|
@@ -0,0 +1,134 @@
|
|
|
+package com.zhongshu.card.server.core.service.visitor;
|
|
|
+
|
|
|
+import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
+import com.github.microservice.net.ResultMessage;
|
|
|
+import com.zhongshu.card.client.model.devices.DeviceInfoSimpleModel;
|
|
|
+import com.zhongshu.card.client.model.visitor.VisitorMainModel;
|
|
|
+import com.zhongshu.card.client.model.visitor.VisitorMainParam;
|
|
|
+import com.zhongshu.card.client.model.visitor.VisitorMainSearch;
|
|
|
+import com.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
|
|
|
+import com.zhongshu.card.server.core.dao.scene.SceneComponentDao;
|
|
|
+import com.zhongshu.card.server.core.dao.visitor.VisitorMainDao;
|
|
|
+import com.zhongshu.card.server.core.domain.scene.SceneComponent;
|
|
|
+import com.zhongshu.card.server.core.domain.visitor.VisitorMain;
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.service.devices.DeviceInfoServiceImpl;
|
|
|
+import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author TRX
|
|
|
+ * @date 2025/2/11
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class VisitorMainService extends SuperService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private VisitorMainDao visitorMainDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceInfoDao deviceInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceInfoServiceImpl deviceInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserAccountServiceImpl userAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SceneComponentDao sceneComponentDao;
|
|
|
+
|
|
|
+ public ResultContent saveInfo(VisitorMainParam param) {
|
|
|
+ if (StringUtils.isEmpty(param.getSceneComponentId())) {
|
|
|
+ return ResultContent.buildFail("sceneComponentId 不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(param.getSceneComponentId())) {
|
|
|
+ return ResultContent.buildFail("sceneComponentId 不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ String sceneComponentId = param.getSceneComponentId();
|
|
|
+ SceneComponent sceneComponent = sceneComponentDao.findTopById(sceneComponentId);
|
|
|
+ if (ObjectUtils.isEmpty(sceneComponent)) {
|
|
|
+ return ResultContent.buildFail("组件不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ VisitorMain entity = null;
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ entity = visitorMainDao.findTopById(param.getId());
|
|
|
+ if (entity == null) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ initUpdateEntity(entity);
|
|
|
+ } else {
|
|
|
+ initEntityNoCheckOid(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(param, param);
|
|
|
+
|
|
|
+ visitorMainDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent getInfo(String id) {
|
|
|
+ VisitorMain entity = visitorMainDao.findTopById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除数据
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent deleteInfo(String id) {
|
|
|
+ VisitorMain entity = visitorMainDao.findTopById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ visitorMainDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<Page<VisitorMainModel>> page(VisitorMainSearch param, Pageable pageable) {
|
|
|
+ Page<VisitorMain> page = visitorMainDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ public VisitorMainModel toModel(VisitorMain entity) {
|
|
|
+ VisitorMainModel model = null;
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model = new VisitorMainModel();
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+
|
|
|
+ // 用户信息
|
|
|
+ model.setVisitorUserAccount(userAccountService.toSimpleModel(entity.getVisitorUserAccount()));
|
|
|
+ model.setApplyUserAccount(userAccountService.toSimpleModel(entity.getApplyUserAccount()));
|
|
|
+
|
|
|
+ // 设备信息
|
|
|
+ List<DeviceInfoSimpleModel> deviceInfos = new ArrayList<>();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity.getDeviceInfos())) {
|
|
|
+ deviceInfos = entity.getDeviceInfos().stream().map(deviceInfoService::toSimpleModel).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ model.setDeviceInfos(deviceInfos);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|