|
|
@@ -0,0 +1,144 @@
|
|
|
+package com.zhongshu.card.server.core.service.school;
|
|
|
+
|
|
|
+import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
+import com.zhongshu.card.client.model.org.ProjectOrgModel;
|
|
|
+import com.zhongshu.card.client.model.school.*;
|
|
|
+import com.zhongshu.card.client.ret.ResultContent;
|
|
|
+import com.zhongshu.card.client.ret.ResultMessage;
|
|
|
+import com.zhongshu.card.server.core.dao.school.CardInfoPoolDao;
|
|
|
+import com.zhongshu.card.server.core.domain.school.CardInfoPool;
|
|
|
+import com.zhongshu.card.server.core.domain.school.DeviceBind;
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author TRX
|
|
|
+ * @date 2024/7/30
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class CardInfoPoolService extends SuperService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CardInfoPoolDao cardInfoPoolDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationServiceImpl organizationService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存卡片信息
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent saveCardInfoPool(CardInfoPoolParam param) {
|
|
|
+ initDefaultUserAndOid(param);
|
|
|
+ CardInfoPool entity = null;
|
|
|
+ // 这是学校的oid
|
|
|
+ String oid = param.getOid();
|
|
|
+ ResultContent<ProjectOrgModel> projectContent = organizationService.getSchoolProjectDetail(oid);
|
|
|
+ // 查询出项目的oid
|
|
|
+ String projectOid = "";
|
|
|
+ if (projectContent.isSuccess()) {
|
|
|
+ projectOid = projectContent.getContent().getOid();
|
|
|
+ }
|
|
|
+ // 学校唯一
|
|
|
+ CardInfoPool temp = cardInfoPoolDao.findTopByCodeAndOid(param.getCode(), oid);
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ entity = cardInfoPoolDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(entity.getId())) {
|
|
|
+ return ResultContent.buildFail(String.format("卡号已存在:%s", param.getCode()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ entity = new CardInfoPool();
|
|
|
+ if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format("卡号已存在:%s", param.getCode()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+ entity.setProjectOid(projectOid);
|
|
|
+ if (entity.getIsUsed() == null) {
|
|
|
+ entity.setIsUsed(Boolean.FALSE);
|
|
|
+ }
|
|
|
+ cardInfoPoolDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页列表,给web端用
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<Page<CardInfoPoolModel>> page(CardInfoPoolSearch param, Pageable pageable) {
|
|
|
+ initOidSearchParam(param);
|
|
|
+ Page<CardInfoPool> page = cardInfoPoolDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询卡片详情
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<CardInfoPoolModel> getCardInfoPoolDetail(String id) {
|
|
|
+ CardInfoPool entity = cardInfoPoolDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 恢复卡片
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<CardInfoPoolModel> restoreCardInfoPool(CardInfoPoolRestoreParam param) {
|
|
|
+ CardInfoPool entity = cardInfoPoolDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ entity.setIsUsed(Boolean.FALSE);
|
|
|
+ cardInfoPoolDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除卡片
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent deleteCardInfoPool(String id) {
|
|
|
+ CardInfoPool entity = cardInfoPoolDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ cardInfoPoolDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public CardInfoPoolModel toModel(CardInfoPool entity) {
|
|
|
+ CardInfoPoolModel model = null;
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model = new CardInfoPoolModel();
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+}
|