|
|
@@ -6,21 +6,20 @@ 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.github.microservice.net.ResultContent;
|
|
|
+import com.github.microservice.net.ResultMessage;
|
|
|
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.*;
|
|
|
-import com.github.microservice.net.ResultContent;
|
|
|
-import com.github.microservice.net.ResultMessage;
|
|
|
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.OrganizationUserDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
+import com.zhongshu.card.server.core.dao.school.CardInfoDao;
|
|
|
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;
|
|
|
@@ -35,7 +34,6 @@ 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;
|
|
|
@@ -54,6 +52,7 @@ import org.springframework.util.Assert;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -101,6 +100,9 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
@Autowired
|
|
|
private OrganizationUserServiceImpl organizationUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ CardInfoPoolService cardInfoPoolService;
|
|
|
+
|
|
|
/**
|
|
|
* 添加或修改卡片信息
|
|
|
*
|
|
|
@@ -183,6 +185,11 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
return bindCardFromPoolByOrgId(poolId, list.get(0).getId());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param poolId 卡池数据的id
|
|
|
+ * @param id OrganizationUser id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public ResultContent bindCardFromPoolByOrgId(String poolId, String id) {
|
|
|
@@ -685,72 +692,85 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
|
|
|
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;
|
|
|
+ int startRow = 2;
|
|
|
ImportParams params = new ImportParams();
|
|
|
params.setHeadRows(1);
|
|
|
params.setTitleRows(1);
|
|
|
- List<CardInfoPoolImportParam> list = ExcelImportUtil.importExcel(file.getInputStream(), CardInfoPoolImportParam.class, params);
|
|
|
+ List<CardInfoBindImportParam> list = ExcelImportUtil.importExcel(file.getInputStream(), CardInfoPoolImportParam.class, params);
|
|
|
model.setTotal(list.size());
|
|
|
|
|
|
+ HashMap<String, String> codeMap = new HashMap<>();
|
|
|
+ HashMap<String, OrganizationUser> phone2OrgId = new HashMap<>();
|
|
|
+
|
|
|
List<String> failDetails = new ArrayList<>();
|
|
|
- List<CardInfoPool> cardInfoPools = new ArrayList<>();
|
|
|
+ List<CardInfoPoolBind2OrgUserParam> cardInfoPools = new ArrayList<>();
|
|
|
if (ObjectUtils.isNotEmpty(list)) {
|
|
|
- for (CardInfoPoolImportParam param1 : list) {
|
|
|
+ for (CardInfoBindImportParam bindImportParam : list) {
|
|
|
+ startRow++;
|
|
|
+ CardInfoPoolBind2OrgUserParam bind2OrgUserParam = new CardInfoPoolBind2OrgUserParam();
|
|
|
// 验证数据合法性
|
|
|
- boolean b = true;
|
|
|
- if (b && StringUtils.isEmpty(param1.getCode())) {
|
|
|
- b = false;
|
|
|
+ String code = bindImportParam.getCode();
|
|
|
+ if (StringUtils.isEmpty(code)) {
|
|
|
failDetails.add(String.format("第%d行卡号不能为空", startRow));
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (b && StringUtils.isEmpty(param1.getCardType())) {
|
|
|
- b = false;
|
|
|
- failDetails.add(String.format("第%d行卡片类型不能为空", startRow));
|
|
|
+ String phone = bindImportParam.getPhone();
|
|
|
+ if (StringUtils.isEmpty(phone)) {
|
|
|
+ failDetails.add(String.format("第%d行手机号码不能为空", startRow));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (codeMap.containsKey(code)) {
|
|
|
+ failDetails.add(String.format("第%d行卡号已存在", startRow));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ CardInfo cardInfo = cardInfoDao.findTopByProjectOidAndCode(projectOid, code);
|
|
|
+ if (ObjectUtils.isNotEmpty(cardInfo)) {
|
|
|
+ failDetails.add(String.format("第%d行卡号%s已绑定", startRow, code));
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- if (b && StringUtils.isNotEmpty(param1.getCardType())) {
|
|
|
- CardType cardType = CommonUtil.getCardTypeByStr(param1.getCardType());
|
|
|
- if (cardType == null) {
|
|
|
- b = false;
|
|
|
- failDetails.add(String.format("第%d行卡片类型不正确", startRow));
|
|
|
- }
|
|
|
+ CardInfoPool cardInfoPool = cardInfoPoolService.getProjectCard(projectOid, code);
|
|
|
+ if (ObjectUtils.isEmpty(cardInfoPool)) {
|
|
|
+ failDetails.add(String.format("第%d行卡号 %s不存在或已使用", startRow, code));
|
|
|
+ continue;
|
|
|
}
|
|
|
+ bind2OrgUserParam.setPoolId(cardInfoPool.getId());
|
|
|
|
|
|
- if (b) {
|
|
|
- // 检查是否已存在 code
|
|
|
- boolean exit = cardInfoPoolDao.existsByCode(param1.getCode());
|
|
|
- if (exit) {
|
|
|
- b = false;
|
|
|
+
|
|
|
+ // 查询用户
|
|
|
+ UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
|
+ if (ObjectUtils.isEmpty(userAccount)) {
|
|
|
+ failDetails.add(String.format("第%d行用户%s不存在", startRow, phone));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ OrganizationUser organizationUser = null;
|
|
|
+ if (phone2OrgId.containsKey(phone)) {
|
|
|
+ organizationUser = phone2OrgId.get(phone);
|
|
|
+ } else {
|
|
|
+ List<OrganizationUser> organizationUsers = organizationUserService.getUserOrgList(userAccount.getUserId(), projectOid);
|
|
|
+ if (ObjectUtils.isNotEmpty(organizationUsers)) {
|
|
|
+ organizationUser = organizationUsers.get(0);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isEmpty(organizationUser)) {
|
|
|
+ failDetails.add(String.format("第%d行用户%s未加入当前项目", startRow, phone));
|
|
|
+ continue;
|
|
|
}
|
|
|
+ phone2OrgId.put(phone, organizationUser);
|
|
|
}
|
|
|
-
|
|
|
- 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);
|
|
|
+ codeMap.put(code, phone);
|
|
|
+ bind2OrgUserParam.setId(organizationUser.getId());
|
|
|
+ cardInfoPools.add(bind2OrgUserParam);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(cardInfoPools)) {
|
|
|
+ for (CardInfoPoolBind2OrgUserParam bind2OrgUserParam : cardInfoPools) {
|
|
|
+ bindCardFromPoolByOrgId(bind2OrgUserParam.getPoolId(), bind2OrgUserParam.getId());
|
|
|
}
|
|
|
- startRow++;
|
|
|
}
|
|
|
- cardInfoPoolDao.saveAll(cardInfoPools);
|
|
|
model.setSuccess(cardInfoPools.size());
|
|
|
model.setFailDetails(failDetails);
|
|
|
}
|