|
|
@@ -1,8 +1,12 @@
|
|
|
package com.zhongshu.card.server.core.service.projectAbout;
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
import com.github.microservice.auth.client.content.ResultState;
|
|
|
import com.github.microservice.auth.client.service.UserService;
|
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
+import com.github.microservice.core.util.bean.BeanUtil;
|
|
|
+import com.zhongshu.card.client.model.base.OidModel;
|
|
|
import com.zhongshu.card.client.model.org.OidAboutInfo;
|
|
|
import com.zhongshu.card.client.model.org.OrganizationUserModel;
|
|
|
import com.zhongshu.card.client.model.school.*;
|
|
|
@@ -12,33 +16,46 @@ import com.zhongshu.card.client.service.school.CardInfoService;
|
|
|
import com.zhongshu.card.client.type.CardCancelState;
|
|
|
import com.zhongshu.card.client.type.CardOperationType;
|
|
|
import com.zhongshu.card.client.type.school.CardState;
|
|
|
+import com.zhongshu.card.client.type.school.CardType;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationUserDao;
|
|
|
import com.zhongshu.card.server.core.dao.school.CardInfoDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
import com.zhongshu.card.server.core.dao.school.CardInfoPoolDao;
|
|
|
import com.zhongshu.card.server.core.dao.user.CardInfoLossRecordDao;
|
|
|
import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
+import com.zhongshu.card.server.core.domain.org.OrganizationUser;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
import com.zhongshu.card.server.core.domain.school.CardInfo;
|
|
|
import com.zhongshu.card.server.core.domain.school.CardInfoLossRecord;
|
|
|
import com.zhongshu.card.server.core.domain.school.CardInfoPool;
|
|
|
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.OrganizationUserServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.orgManager.OrganizationManagerServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
+import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
+import com.zhongshu.card.server.core.util.ExcelUtils;
|
|
|
+import com.zhongshu.card.server.core.util.excel.CommonExeclParam;
|
|
|
+import com.zhongshu.card.server.core.util.excel.CommonExeclTd;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
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.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -55,28 +72,34 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
private CardInfoDao cardInfoDao;
|
|
|
|
|
|
@Autowired
|
|
|
- OrganizationDao organizationDao;
|
|
|
+ private OrganizationDao organizationDao;
|
|
|
|
|
|
@Autowired
|
|
|
- UserCountDao userCountDao;
|
|
|
+ private UserCountDao userCountDao;
|
|
|
|
|
|
@Autowired
|
|
|
- UserService userService;
|
|
|
+ private UserService userService;
|
|
|
|
|
|
@Autowired
|
|
|
- CardInfoLossRecordDao cardInfoLossRecordDao;
|
|
|
+ private CardInfoLossRecordDao cardInfoLossRecordDao;
|
|
|
|
|
|
@Autowired
|
|
|
- CardInfoPoolDao cardInfoPoolDao;
|
|
|
+ private CardInfoPoolDao cardInfoPoolDao;
|
|
|
|
|
|
@Autowired
|
|
|
- OrganizationServiceImpl organizationService;
|
|
|
+ private OrganizationServiceImpl organizationService;
|
|
|
|
|
|
@Autowired
|
|
|
- UserAccountServiceImpl userAccountService;
|
|
|
+ private UserAccountServiceImpl userAccountService;
|
|
|
|
|
|
@Autowired
|
|
|
- OrganizationManagerServiceImpl organizationManagerService;
|
|
|
+ private OrganizationManagerServiceImpl organizationManagerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrganizationUserDao organizationUserDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrganizationUserServiceImpl organizationUserService;
|
|
|
|
|
|
/**
|
|
|
* 添加或修改卡片信息
|
|
|
@@ -141,8 +164,6 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
* @param poolId
|
|
|
* @return
|
|
|
*/
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
public ResultContent bindCardFromPool(String poolId, String userId) {
|
|
|
if (StringUtils.isEmpty(userId)) {
|
|
|
return ResultContent.buildFail("userId不能为空");
|
|
|
@@ -155,18 +176,50 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
if (ObjectUtils.isEmpty(cardInfoPool)) {
|
|
|
return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, poolId));
|
|
|
}
|
|
|
+ List<OrganizationUser> list = organizationUserService.getUserOrgList(cardInfoPool.getProjectOid(), userId);
|
|
|
+ if (ObjectUtils.isEmpty(list)) {
|
|
|
+ return ResultContent.buildFail("用户未加入结构,不能绑定卡片");
|
|
|
+ }
|
|
|
+ return bindCardFromPoolByOrgId(poolId, list.get(0).getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public ResultContent bindCardFromPoolByOrgId(String poolId, String id) {
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
+ return ResultContent.buildFail("id不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(poolId)) {
|
|
|
+ return ResultContent.buildFail("poolId不能为空");
|
|
|
+ }
|
|
|
+ // 卡池数据
|
|
|
+ CardInfoPool cardInfoPool = cardInfoPoolDao.findTopById(poolId);
|
|
|
+ if (ObjectUtils.isEmpty(cardInfoPool)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, poolId));
|
|
|
+ }
|
|
|
if (cardInfoPool.getIsUsed() != null && cardInfoPool.getIsUsed()) {
|
|
|
return ResultContent.buildFail(String.format("卡片已使用:%s", cardInfoPool.getCode()));
|
|
|
}
|
|
|
if (cardInfoPool.getCardCancelState() != null && cardInfoPool.getCardCancelState() != CardCancelState.Common) {
|
|
|
return ResultContent.buildFail(String.format("卡片:%s", cardInfoPool.getCardCancelState().getRemark()));
|
|
|
}
|
|
|
+
|
|
|
+ OrganizationUser organizationUser = organizationUserDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(organizationUser)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!cardInfoPool.getProjectOid().equals(organizationUser.getProjectOid())) {
|
|
|
+ return ResultContent.buildFail(String.format("卡片和用户不在同一个项目下,不能绑定"));
|
|
|
+ }
|
|
|
+
|
|
|
// 用户信息
|
|
|
- UserAccount account = userCountDao.findTopByUserId(userId);
|
|
|
+ UserAccount account = organizationUser.getUser();
|
|
|
if (ObjectUtils.isEmpty(account)) {
|
|
|
- return ResultContent.buildFail(String.format("", userId));
|
|
|
+ return ResultContent.buildFail("机构用户信息为空");
|
|
|
}
|
|
|
|
|
|
+ String userId = account.getUserId();
|
|
|
String code = cardInfoPool.getCode();
|
|
|
CardInfo cardInfo = cardInfoDao.findByCode(code);
|
|
|
if (ObjectUtils.isNotEmpty(cardInfo)) {
|
|
|
@@ -183,21 +236,22 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
cardInfo.setSchoolOid(cardInfoPool.getSchoolOid());
|
|
|
cardInfo.setAboutAuthType(cardInfoPool.getAboutAuthType());
|
|
|
cardInfo.setAboutOid(cardInfoPool.getAboutOid());
|
|
|
+ cardInfo.setOid(cardInfoPool.getOid());
|
|
|
+ cardInfo.setOrganization(organizationUser.getOrganization());
|
|
|
+ cardInfo.setOrganizationUser(organizationUser);
|
|
|
|
|
|
cardInfo.setCardState(CardState.Enable);
|
|
|
cardInfo.setUserAccount(account);
|
|
|
cardInfo.setUserId(userId);
|
|
|
cardInfo.setUserName(account.getName());
|
|
|
cardInfo.setPhone(account.getPhone());
|
|
|
- cardInfo.setOid(cardInfoPool.getOid());
|
|
|
cardInfoDao.save(cardInfo);
|
|
|
|
|
|
- // 标记卡池这张卡一使用
|
|
|
+ // 标记卡池这张卡已使用
|
|
|
cardInfoPool.setIsUsed(Boolean.TRUE);
|
|
|
cardInfoPool.setUseUserId(userId);
|
|
|
cardInfoPool.setUseTime(System.currentTimeMillis());
|
|
|
cardInfoPoolDao.save(cardInfoPool);
|
|
|
-
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
@@ -236,6 +290,25 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
return ResultContent.buildSuccess(getUserOrgAllCard(userId, oid));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询结构用户的卡片信息
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<List<CardInfoModel>> getOrgCardList(String id) {
|
|
|
+ List<CardInfoModel> models = new ArrayList<>();
|
|
|
+ OrganizationUser organizationUser = organizationUserDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(organizationUser)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ List<CardInfo> list = cardInfoDao.findByUserIdAndProjectOid(organizationUser.getUserId(), organizationUser.getProjectOid());
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
+ models = list.stream().map(this::toModel).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(models);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<CardInfoModel> getUserOrgAllCard(String userId, String oid) {
|
|
|
List<CardInfoModel> models = new ArrayList<>();
|
|
|
@@ -246,7 +319,7 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
list = cardInfoDao.findByUserId(userId);
|
|
|
}
|
|
|
if (ObjectUtils.isNotEmpty(list)) {
|
|
|
- models = list.stream().map(this::toModel).collect(Collectors.toList());
|
|
|
+ models = list.parallelStream().map(this::toModel).collect(Collectors.toList());
|
|
|
}
|
|
|
return models;
|
|
|
}
|
|
|
@@ -480,13 +553,10 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
|
|
|
//----------------------------园区卡片操作 start ------------------------
|
|
|
|
|
|
- public ResultContent<Page<CardInfoPoolModel>> page(CardInfoSearch param, Pageable pageable) {
|
|
|
- checkParamOid(param);
|
|
|
- initOidSearchParam(param);
|
|
|
- String oid = param.getOid();
|
|
|
- OidAboutInfo aboutInfo = organizationService.getOidAboutOrgInfo(oid);
|
|
|
- param.setProjectOid(aboutInfo.getProjectOid());
|
|
|
-
|
|
|
+ public ResultContent<Page<CardInfoModel>> page(CardInfoSearch param, Pageable pageable) {
|
|
|
+ if (StringUtils.isEmpty(param.getProjectOid())) {
|
|
|
+ return ResultContent.buildFail("projectOid不能为空");
|
|
|
+ }
|
|
|
Page<CardInfo> page = cardInfoDao.page(pageable, param);
|
|
|
return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toOrgModel));
|
|
|
}
|
|
|
@@ -604,9 +674,155 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
- //----------------------------园区卡片操作 end --------------------------
|
|
|
+ /**
|
|
|
+ * 导入 学校卡片excel
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<ImportResultModel> importCard(HttpServletRequest request, HttpServletResponse response, MultipartFile file, OidModel param) {
|
|
|
+ String oid = param.getOid();
|
|
|
+ Assert.hasText(oid, "oid不能为空");
|
|
|
|
|
|
+ OidAboutInfo oidAboutInfo = organizationManagerService.getOidAboutInfo(oid);
|
|
|
+ String projectOid = oidAboutInfo.getProjectOid();
|
|
|
+
|
|
|
+ ImportResultModel model = new ImportResultModel();
|
|
|
+ try {
|
|
|
+ int startRow = 3;
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
+ params.setHeadRows(1);
|
|
|
+ params.setTitleRows(1);
|
|
|
+ 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 && StringUtils.isNotEmpty(param1.getCardType())) {
|
|
|
+ CardType cardType = CommonUtil.getCardTypeByStr(param1.getCardType());
|
|
|
+ if (cardType == null) {
|
|
|
+ b = false;
|
|
|
+ failDetails.add(String.format("第%d行卡片类型不正确", startRow));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (b) {
|
|
|
+ // 检查是否已存在 code
|
|
|
+ boolean exit = cardInfoPoolDao.existsByCode(param1.getCode());
|
|
|
+ if (exit) {
|
|
|
+ b = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (b) {
|
|
|
+ // 验证通过
|
|
|
+ CardInfoPool pool = new CardInfoPool();
|
|
|
+ initEntity(pool);
|
|
|
+ param1.setCode(param1.getCode().trim());
|
|
|
+ BeanUtils.copyProperties(param1, pool, "cardType");
|
|
|
+ pool.setSchoolOid("");
|
|
|
+ pool.setProjectOid(projectOid);
|
|
|
+ pool.setOid(oid);
|
|
|
+ pool.setAboutOid(oidAboutInfo.getOid());
|
|
|
+ pool.setAboutAuthType(oidAboutInfo.getAuthType());
|
|
|
+
|
|
|
+ // 初始状态为 未使用
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出项目用户
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void exportProjectCard(HttpServletRequest request, HttpServletResponse response, CardInfoSearch param) {
|
|
|
+ Assert.hasText(param.getProjectOid(), "projectOid不能为空");
|
|
|
|
|
|
+ Organization organization = organizationDao.findTopByOid(param.getProjectOid());
|
|
|
+ Pageable pageable = PageRequest.of(0, Integer.MAX_VALUE);
|
|
|
+ Page<CardInfo> page = cardInfoDao.page(pageable, param);
|
|
|
+
|
|
|
+ List<Map<String, Object>> maps = new ArrayList<>();
|
|
|
+ if (page.getContent() != null) {
|
|
|
+ List<CardInfo> list = page.getContent();
|
|
|
+ maps = list.stream().map(it -> {
|
|
|
+ Map<String, Object> map = BeanUtil.bean2Map(it);
|
|
|
+ String cardStr = it.getCardType().getRemark();
|
|
|
+ map.put("cardStr", cardStr);
|
|
|
+
|
|
|
+ OrganizationUser orgUser = it.getOrganizationUser();
|
|
|
+ if (ObjectUtils.isEmpty(orgUser)) {
|
|
|
+ // 人员编号
|
|
|
+ List<OrganizationUser> tempList = organizationUserService.getUserOrgList(it.getUserId(), it.getProjectOid());
|
|
|
+ if (ObjectUtils.isNotEmpty(tempList)) {
|
|
|
+ orgUser = tempList.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ CommonExeclParam execlParam = new CommonExeclParam();
|
|
|
+ execlParam.setTitle(String.format("%s卡片数据", organization.getName()));
|
|
|
+ execlParam.setStartRow(2);
|
|
|
+ execlParam.setDatas(maps);
|
|
|
+
|
|
|
+ List<CommonExeclTd> tds = new ArrayList<>();
|
|
|
+ tds.add(CommonExeclTd.build("卡片ID", "code"));
|
|
|
+ tds.add(CommonExeclTd.build("卡片类型", "cardStr"));
|
|
|
+ tds.add(CommonExeclTd.build("人员编号", "useStr"));
|
|
|
+ tds.add(CommonExeclTd.build("姓名", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("性别", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("机构", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("部门", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("人员类型", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("手机号", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("作废状态", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("挂失状态", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("创建人员", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("创建时间", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("更新人员", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("更新时间", "cancelStr"));
|
|
|
+
|
|
|
+ execlParam.setTds(tds);
|
|
|
+ ExcelUtils.commonExecuteExcel(request, response, execlParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ //----------------------------园区卡片操作 end --------------------------
|
|
|
+
|
|
|
+ // 简单的信息
|
|
|
public CardInfoModel toModel(CardInfo entity) {
|
|
|
CardInfoModel model = null;
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
@@ -621,9 +837,14 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
model = new CardInfoModel();
|
|
|
BeanUtils.copyProperties(entity, model);
|
|
|
+
|
|
|
// 机构用户信息
|
|
|
- OrganizationUserModel organizationUser = userAccountService.getOrgUserDetail(entity.getOid(), entity.getUserId(), true);
|
|
|
- model.setOrganizationUser(organizationUser);
|
|
|
+ List<OrganizationUser> list = organizationUserService.getUserOrgList(entity.getUserId(), entity.getProjectOid());
|
|
|
+ OrganizationUserModel orgUserInfo = null;
|
|
|
+ if (ObjectUtils.isEmpty(list)) {
|
|
|
+ orgUserInfo = userAccountService.toOrgUserModel(list.get(0));
|
|
|
+ }
|
|
|
+ model.setOrganizationUser(orgUserInfo);
|
|
|
}
|
|
|
return model;
|
|
|
}
|