|
|
@@ -1,9 +1,14 @@
|
|
|
package com.zhongshu.card.server.core.service.school;
|
|
|
|
|
|
+import com.github.microservice.auth.client.content.ResultState;
|
|
|
+import com.github.microservice.auth.client.service.UserService;
|
|
|
import com.zhongshu.card.client.model.school.CardInfoModel;
|
|
|
import com.zhongshu.card.client.model.school.CardInfoParam;
|
|
|
+import com.zhongshu.card.client.model.school.CardLossParam;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
+import com.zhongshu.card.client.ret.ResultMessage;
|
|
|
import com.zhongshu.card.client.service.school.CardInfoService;
|
|
|
+import com.zhongshu.card.client.utils.type.school.CardState;
|
|
|
import com.zhongshu.card.server.core.dao.CardInfoDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
@@ -17,6 +22,7 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
@@ -41,6 +47,9 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
@Autowired
|
|
|
UserCountDao userCountDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ UserService userService;
|
|
|
+
|
|
|
/**
|
|
|
* 添加或修改卡片信息
|
|
|
*
|
|
|
@@ -50,6 +59,7 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
@Override
|
|
|
public ResultContent addCardInfo(CardInfoParam param) {
|
|
|
initDefaultUserAndOid(param);
|
|
|
+
|
|
|
CardInfo cardInfo = null;
|
|
|
if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
cardInfo = cardInfoDao.findTopById(param.getId());
|
|
|
@@ -67,6 +77,11 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 得到当前用户所在 学校的所有卡片
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public ResultContent<List<CardInfoModel>> getCurrentUserOrgAll() {
|
|
|
String userId = getCurrentUserId();
|
|
|
@@ -84,6 +99,111 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
return models;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 删除卡片
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent deleteCardInfo(String id) {
|
|
|
+ Assert.hasText(id, "id不能为空");
|
|
|
+ CardInfo cardInfo = cardInfoDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(cardInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ cardInfoDao.delete(cardInfo);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过卡片ID挂失 (当前用户挂失自己的卡片)
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent cardLossById(CardLossParam param) {
|
|
|
+ Assert.hasText(param.getPassWord(), "密码不能为空");
|
|
|
+ Assert.hasText(param.getId(), "id不能为空");
|
|
|
+ String userId = getCurrentUserId();
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<Void> resultContent = userService.checkLoginPassword(userId, param.getPassWord());
|
|
|
+ if (resultContent.getState() != ResultState.Success) {
|
|
|
+ return ResultContent.buildFail("密码错误");
|
|
|
+ }
|
|
|
+ CardInfo cardInfo = cardInfoDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(cardInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ cardInfo.setCardState(CardState.Loss);
|
|
|
+ cardInfoDao.save(cardInfo);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过卡片的iccid挂失 (帮别人挂失)
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent cardLossByIccId(CardLossParam param) {
|
|
|
+ Assert.hasText(param.getPassWord(), "密码不能为空");
|
|
|
+ Assert.hasText(param.getIccid(), "iccid不能为空");
|
|
|
+ String userId = getCurrentUserId();
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<Void> resultContent = userService.checkLoginPassword(userId, param.getPassWord());
|
|
|
+ if (resultContent.getState() != ResultState.Success) {
|
|
|
+ return ResultContent.buildFail("密码错误");
|
|
|
+ }
|
|
|
+ CardInfo cardInfo = cardInfoDao.findTopByIccid(param.getIccid());
|
|
|
+ if (ObjectUtils.isEmpty(cardInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format("iccid不存在:%s", param.getIccid()));
|
|
|
+ }
|
|
|
+ cardInfo.setCardState(CardState.Loss);
|
|
|
+ cardInfoDao.save(cardInfo);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 卡片启用
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent cardEnableById(CardLossParam param) {
|
|
|
+ Assert.hasText(param.getPassWord(), "密码不能为空");
|
|
|
+ Assert.hasText(param.getId(), "id不能为空");
|
|
|
+ String userId = getCurrentUserId();
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<Void> resultContent = userService.checkLoginPassword(userId, param.getPassWord());
|
|
|
+ if (resultContent.getState() != ResultState.Success) {
|
|
|
+ return ResultContent.buildFail("密码错误");
|
|
|
+ }
|
|
|
+ CardInfo cardInfo = cardInfoDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(cardInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ cardInfo.setCardState(CardState.Enable);
|
|
|
+ cardInfoDao.save(cardInfo);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过ID查询卡片详情
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent<CardInfoModel> getCardDetail(String id) {
|
|
|
+ Assert.hasText(id, "id不能为空");
|
|
|
+ CardInfo cardInfo = cardInfoDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(cardInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ CardInfoModel model = toModel(cardInfo);
|
|
|
+ return ResultContent.buildSuccess(model);
|
|
|
+ }
|
|
|
+
|
|
|
public CardInfoModel toModel(CardInfo entity) {
|
|
|
CardInfoModel model = null;
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|