|
@@ -1,16 +1,25 @@
|
|
|
package com.zhongshu.card.server.core.service.school;
|
|
package com.zhongshu.card.server.core.service.school;
|
|
|
|
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
|
|
|
|
+import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
|
|
+import com.github.microservice.auth.security.type.AuthType;
|
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
|
|
+import com.zhongshu.card.client.model.org.OidAboutInfo;
|
|
|
import com.zhongshu.card.client.model.org.ProjectOrgModel;
|
|
import com.zhongshu.card.client.model.org.ProjectOrgModel;
|
|
|
import com.zhongshu.card.client.model.school.*;
|
|
import com.zhongshu.card.client.model.school.*;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
import com.zhongshu.card.client.ret.ResultMessage;
|
|
import com.zhongshu.card.client.ret.ResultMessage;
|
|
|
|
|
+import com.zhongshu.card.client.utils.type.school.CardType;
|
|
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
import com.zhongshu.card.server.core.dao.school.CardInfoPoolDao;
|
|
import com.zhongshu.card.server.core.dao.school.CardInfoPoolDao;
|
|
|
|
|
+import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
import com.zhongshu.card.server.core.domain.school.CardInfoPool;
|
|
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.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
|
|
import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
|
|
+import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -18,6 +27,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author TRX
|
|
* @author TRX
|
|
@@ -33,6 +47,9 @@ public class CardInfoPoolService extends SuperService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
OrganizationServiceImpl organizationService;
|
|
OrganizationServiceImpl organizationService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ OrganizationDao organizationDao;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 保存卡片信息
|
|
* 保存卡片信息
|
|
|
*
|
|
*
|
|
@@ -44,14 +61,14 @@ public class CardInfoPoolService extends SuperService {
|
|
|
CardInfoPool entity = null;
|
|
CardInfoPool entity = null;
|
|
|
// 这是学校的oid
|
|
// 这是学校的oid
|
|
|
String oid = param.getOid();
|
|
String oid = param.getOid();
|
|
|
- ResultContent<ProjectOrgModel> projectContent = organizationService.getSchoolProjectDetail(oid);
|
|
|
|
|
- // 查询出项目的oid
|
|
|
|
|
- String projectOid = "";
|
|
|
|
|
- if (projectContent.isSuccess()) {
|
|
|
|
|
- projectOid = projectContent.getContent().getOid();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ OidAboutInfo oidAboutInfo = organizationService.getOidAboutProjectInfo(oid);
|
|
|
|
|
+
|
|
|
|
|
+ String projectOid = oidAboutInfo.getProjectOid();
|
|
|
|
|
+ String schoolOid = oidAboutInfo.getSchoolOid();
|
|
|
|
|
+
|
|
|
// 学校唯一
|
|
// 学校唯一
|
|
|
- CardInfoPool temp = cardInfoPoolDao.findTopByCodeAndOid(param.getCode(), oid);
|
|
|
|
|
|
|
+ CardInfoPool temp = cardInfoPoolDao.findTopByCodeAndProjectOid(param.getCode(), projectOid);
|
|
|
if (StringUtils.isNotEmpty(param.getId())) {
|
|
if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
entity = cardInfoPoolDao.findTopById(param.getId());
|
|
entity = cardInfoPoolDao.findTopById(param.getId());
|
|
|
if (ObjectUtils.isEmpty(entity)) {
|
|
if (ObjectUtils.isEmpty(entity)) {
|
|
@@ -68,6 +85,7 @@ public class CardInfoPoolService extends SuperService {
|
|
|
}
|
|
}
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
entity.setProjectOid(projectOid);
|
|
entity.setProjectOid(projectOid);
|
|
|
|
|
+ entity.setSchoolOid(schoolOid);
|
|
|
if (entity.getIsUsed() == null) {
|
|
if (entity.getIsUsed() == null) {
|
|
|
entity.setIsUsed(Boolean.FALSE);
|
|
entity.setIsUsed(Boolean.FALSE);
|
|
|
}
|
|
}
|
|
@@ -133,6 +151,79 @@ public class CardInfoPoolService extends SuperService {
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导入 学校卡片excel
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param request
|
|
|
|
|
+ * @param response
|
|
|
|
|
+ * @param file
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultContent<ImportUserModel> importCardPool(HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response, MultipartFile file) {
|
|
|
|
|
+ String oid = getCurrentOid();
|
|
|
|
|
+ Assert.hasText(oid, "oid不能为空");
|
|
|
|
|
+
|
|
|
|
|
+ OidAboutInfo oidAboutInfo = organizationService.getOidAboutProjectInfo(oid);
|
|
|
|
|
+
|
|
|
|
|
+ String projectOid = oidAboutInfo.getProjectOid();
|
|
|
|
|
+ String schoolOid = oidAboutInfo.getSchoolOid();
|
|
|
|
|
+
|
|
|
|
|
+ ImportUserModel model = new ImportUserModel();
|
|
|
|
|
+ try {
|
|
|
|
|
+ int startRow = 2;
|
|
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
|
|
+ List<CardInfoPoolImportParam> list = ExcelImportUtil.importExcel(file.getInputStream(),
|
|
|
|
|
+ CardInfoPoolImportParam.class, params);
|
|
|
|
|
+ model.setTotal(list.size());
|
|
|
|
|
+
|
|
|
|
|
+ List<String> failDetails = new ArrayList<>();
|
|
|
|
|
+ List<CardInfoPool> cardInfoPools = new ArrayList<>();
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
|
|
+ for (CardInfoPoolImportParam param1 : list) {
|
|
|
|
|
+ // 验证数据合法性
|
|
|
|
|
+ boolean b = true;
|
|
|
|
|
+ if (b && StringUtils.isEmpty(param1.getCode())) {
|
|
|
|
|
+ b = false;
|
|
|
|
|
+ failDetails.add(String.format("第%d行卡号不能为空", startRow));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (b && StringUtils.isEmpty(param1.getCardType())) {
|
|
|
|
|
+ b = false;
|
|
|
|
|
+ failDetails.add(String.format("第%d行卡片类型不能为空", startRow));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (b) {
|
|
|
|
|
+ // 检查是否已存在 code
|
|
|
|
|
+ boolean exit = cardInfoPoolDao.existsByCodeAndProjectOid(param1.getCode(), projectOid);
|
|
|
|
|
+ if (exit) {
|
|
|
|
|
+ b = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (b) {
|
|
|
|
|
+ // 验证通过
|
|
|
|
|
+ CardInfoPool pool = new CardInfoPool();
|
|
|
|
|
+ initEntity(pool);
|
|
|
|
|
+ BeanUtils.copyProperties(param1, pool, "cardType");
|
|
|
|
|
+ pool.setSchoolOid(schoolOid);
|
|
|
|
|
+ pool.setProjectOid(projectOid);
|
|
|
|
|
+ pool.setIsUsed(Boolean.FALSE);
|
|
|
|
|
+ CardType cardType = CommonUtil.getCardTypeByStr(param1.getCardType());
|
|
|
|
|
+ pool.setCardType(cardType);
|
|
|
|
|
+ cardInfoPools.add(pool);
|
|
|
|
|
+ }
|
|
|
|
|
+ startRow++;
|
|
|
|
|
+ }
|
|
|
|
|
+ cardInfoPoolDao.saveAll(cardInfoPools);
|
|
|
|
|
+ model.setSuccess(cardInfoPools.size());
|
|
|
|
|
+ model.setFailDetails(failDetails);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return ResultContent.buildFail(String.format("导入出错:%s", e.getMessage()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultContent.buildSuccess(model);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public CardInfoPoolModel toModel(CardInfoPool entity) {
|
|
public CardInfoPoolModel toModel(CardInfoPool entity) {
|
|
|
CardInfoPoolModel model = null;
|
|
CardInfoPoolModel model = null;
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|