|
|
@@ -0,0 +1,123 @@
|
|
|
+package com.zhongshu.card.server.core.service.devices.permiss;
|
|
|
+
|
|
|
+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.permiss.PermissSettingModel;
|
|
|
+import com.zhongshu.card.client.model.devices.permiss.PermissSettingParam;
|
|
|
+import com.zhongshu.card.client.model.devices.permiss.PermissSettingSearch;
|
|
|
+import com.zhongshu.card.client.type.DataState;
|
|
|
+import com.zhongshu.card.server.core.dao.devices.PermissSettingDao;
|
|
|
+import com.zhongshu.card.server.core.dao.devices.PermissTimeSlotDao;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
+import com.zhongshu.card.server.core.domain.devices.permiss.PermissSetting;
|
|
|
+import com.zhongshu.card.server.core.domain.devices.permiss.PermissTimeSlot;
|
|
|
+import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+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 org.springframework.util.Assert;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 权限时间段管理
|
|
|
+ *
|
|
|
+ * @author TRX
|
|
|
+ * @date 2024/12/19
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PermissSettingService extends SuperService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PermissTimeSlotDao permissTimeSlotDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PermissSettingDao permissSettingDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PermissTimeSlotService permissTimeSlotService;
|
|
|
+
|
|
|
+ public ResultContent saveInfo(PermissSettingParam param) {
|
|
|
+ Assert.hasText(param.getProjectOid(), "projectOid不能为空");
|
|
|
+ if (StringUtils.isEmpty(param.getTimeSlotId())) {
|
|
|
+ return ResultContent.buildFail("所属时段不能为空");
|
|
|
+ }
|
|
|
+ PermissTimeSlot timeSlot = permissTimeSlotDao.findTopById(param.getTimeSlotId());
|
|
|
+ if (ObjectUtils.isEmpty(timeSlot)) {
|
|
|
+ return ResultContent.buildFail("所属时段不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ PermissSetting entity = null;
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ entity = permissSettingDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ initUpdateEntity(entity);
|
|
|
+ } else {
|
|
|
+ entity = new PermissSetting();
|
|
|
+ initEntityNoCheckOid(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+ entity.setTimeSlot(timeSlot);
|
|
|
+ permissSettingDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<Page<PermissSettingModel>> page(PermissSettingSearch param, Pageable pageable) {
|
|
|
+ String projectOid = param.getProjectOid();
|
|
|
+ Organization organization = organizationDao.findTopByOid(projectOid);
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail("projectOid不存在");
|
|
|
+ }
|
|
|
+ Page<PermissSetting> page = permissSettingDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent deleteInfo(String id) {
|
|
|
+ PermissSetting entity = permissSettingDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ permissSettingDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<PermissSettingModel> getDetailInfo(String id) {
|
|
|
+ PermissSetting entity = permissSettingDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent changeState(String id, DataState state) {
|
|
|
+ PermissSetting entity = permissSettingDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ entity.setState(state);
|
|
|
+ permissSettingDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ private PermissSettingModel toModel(PermissSetting entity) {
|
|
|
+ PermissSettingModel model = new PermissSettingModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ model.setTimeSlot(permissTimeSlotService.toSimpleModel(entity.getTimeSlot()));
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|