|
|
@@ -1,10 +1,32 @@
|
|
|
package com.kxs.system.biz.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.kxs.common.core.constant.SecurityConstants;
|
|
|
+import com.kxs.common.core.constant.enums.ErrorTypeEnum;
|
|
|
+import com.kxs.common.core.exception.GlobalCustomerException;
|
|
|
+import com.kxs.common.core.util.R;
|
|
|
+import com.kxs.common.core.util.RetOps;
|
|
|
+import com.kxs.system.api.model.KxsCampUser;
|
|
|
+import com.kxs.system.api.vo.admin.CampUserExcelVO;
|
|
|
+import com.kxs.system.biz.constant.enums.SysErrorTypeEnum;
|
|
|
import com.kxs.system.biz.mapper.KxsCampMapper;
|
|
|
import com.kxs.system.api.model.KxsCamp;
|
|
|
+import com.kxs.system.biz.mapper.KxsCampUserMapper;
|
|
|
import com.kxs.system.biz.service.KxsCampService;
|
|
|
+import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
|
+import com.kxs.user.api.model.KxsUser;
|
|
|
+import com.pig4cloud.plugin.excel.vo.ErrorMessage;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
+
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* 训练营(KxsCamp)表服务实现类
|
|
|
@@ -13,7 +35,100 @@ import org.springframework.stereotype.Service;
|
|
|
* @since 2024-04-08 15:44:02
|
|
|
*/
|
|
|
@Service("kxsCampService")
|
|
|
+@RequiredArgsConstructor
|
|
|
public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> implements KxsCampService {
|
|
|
|
|
|
+ private final RemoteKxsUserService remoteKxsUserService;
|
|
|
+
|
|
|
+ private final KxsCampUserMapper kxsCampUserMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R addData(KxsCamp param) {
|
|
|
+
|
|
|
+ R<KxsUser> kxsUserR = remoteKxsUserService.loadUserById(param.getCreateUserId(), SecurityConstants.FROM_IN);
|
|
|
+ KxsUser user = RetOps.of(kxsUserR)
|
|
|
+ .getData()
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(ErrorTypeEnum.USER_NOT_FOUND.getDescription()));
|
|
|
+
|
|
|
+ param.setCreateUsername(user.getUsername());
|
|
|
+ param.setCreateCode(user.getUserCode());
|
|
|
+
|
|
|
+ return R.ok(baseMapper.insert(param));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R updateData(KxsCamp param) {
|
|
|
+
|
|
|
+ if(param.getId() == null){
|
|
|
+ return R.failed(SysErrorTypeEnum.PARAM_ERROR.getDescription());
|
|
|
+ }
|
|
|
+ KxsCamp kxsCamp = baseMapper.selectById(param.getId());
|
|
|
+ if(kxsCamp == null){
|
|
|
+ return R.failed(SysErrorTypeEnum.NOT_DATA.getDescription());
|
|
|
+ }
|
|
|
+
|
|
|
+ R<KxsUser> kxsUserR = remoteKxsUserService.loadUserById(param.getCreateUserId(), SecurityConstants.FROM_IN);
|
|
|
+ KxsUser user = RetOps.of(kxsUserR)
|
|
|
+ .getData()
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(ErrorTypeEnum.USER_NOT_FOUND.getDescription()));
|
|
|
+
|
|
|
+ param.setCreateUsername(user.getUsername());
|
|
|
+ param.setCreateCode(user.getUserCode());
|
|
|
+
|
|
|
+ return R.ok(baseMapper.updateById(param));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R importUserData(List<CampUserExcelVO> campUserExcelVOList, BindingResult bindingResult) {
|
|
|
+
|
|
|
+ if (campUserExcelVOList.isEmpty()) {
|
|
|
+ return R.failed(SysErrorTypeEnum.IMPORT_EMPTY.getDescription());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 通用校验获取失败的数据
|
|
|
+ List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
|
|
|
+ // 执行数据插入操作
|
|
|
+ for (CampUserExcelVO excel : campUserExcelVOList) {
|
|
|
+ Set<String> errorMsg = new HashSet<>();
|
|
|
+ //查询用户
|
|
|
+ R<KxsUser> kxsUserR = remoteKxsUserService.loadUserByCode(excel.getUserCode(), SecurityConstants.FROM_IN);
|
|
|
+ KxsUser user = RetOps.of(kxsUserR)
|
|
|
+ .getData()
|
|
|
+ .orElse(null);
|
|
|
+ KxsCamp kxsCamp = baseMapper.selectById(excel.getCampId());
|
|
|
+ if(kxsCamp == null){
|
|
|
+ return R.failed(excel.getCampId() + "训练营编号不存在,请重新上传!");
|
|
|
+ }
|
|
|
+ if (user == null) {
|
|
|
+ errorMsg.add(excel.getUserCode() + "创客未找到!");
|
|
|
+ }
|
|
|
+ //判断创客是否加入
|
|
|
+ KxsCampUser kxsCampUser = kxsCampUserMapper.selectOne(Wrappers.<KxsCampUser>lambdaQuery()
|
|
|
+ .eq(KxsCampUser::getCampId, excel.getCampId())
|
|
|
+ .eq(KxsCampUser::getUserId, user.getId()));
|
|
|
+ if(kxsCampUser != null){
|
|
|
+ errorMsg.add(excel.getUserCode() + "已在训练营!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 数据合法情况
|
|
|
+ if (CollUtil.isEmpty(errorMsg)) {
|
|
|
+ KxsCampUser campUser = new KxsCampUser();
|
|
|
+ campUser.setCampId(excel.getCampId());
|
|
|
+ campUser.setUserId(user.getId());
|
|
|
+ campUser.setUsername(user.getUsername());
|
|
|
+ campUser.setUserCode(user.getUserCode());
|
|
|
+ kxsCampUserMapper.insert(campUser);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // 数据不合法
|
|
|
+ errorMessageList.add(new ErrorMessage(excel.getLineNum(), errorMsg));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(errorMessageList)) {
|
|
|
+ return R.failed(JSON.toJSONString(errorMessageList));
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
}
|
|
|
|