| | |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.tyyun.TyyZosUtil; |
| | | import com.doumee.dao.business.CasesMapper; |
| | | import com.doumee.dao.business.CategoryMapper; |
| | | import com.doumee.dao.business.MemberMapper; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.dto.CasesImport; |
| | | import com.doumee.dao.business.dto.MemberImport; |
| | | import com.doumee.dao.business.model.Cases; |
| | | import com.doumee.dao.business.model.Category; |
| | | import com.doumee.dao.business.model.ImportRecord; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.ImportRecordMapper; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.ImportRecordService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import com.sun.xml.internal.messaging.saaj.util.ByteInputStream; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.math.BigDecimal; |
| | |
| | | private MemberMapper memberMapper; |
| | | @Autowired |
| | | private CasesMapper casesMapper; |
| | | @Autowired |
| | | private MultifileMapper multifileMapper; |
| | | @Resource |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | @Resource |
| | |
| | | MPJLambdaWrapper<ImportRecord> queryWrapper = new MPJLambdaWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | queryWrapper.selectAll(ImportRecord.class ) |
| | | .selectAs(SystemUser::getRealname,ImportRecord::getUpdateUserName) |
| | | .select( "(select count(c.id) from cases c where c.import_id= t.id)",ImportRecord::getIngNum) |
| | | .selectAs(SystemUser::getRealname,ImportRecord::getUpdateUserName) |
| | | .leftJoin(SystemUser.class,SystemUser::getId,ImportRecord::getUpdateUser); |
| | | queryWrapper.eq(pageWrap.getModel().getId() != null,ImportRecord::getId, pageWrap.getModel().getId()); |
| | | queryWrapper.eq(pageWrap.getModel().getDeleted() != null,ImportRecord::getDeleted, pageWrap.getModel().getDeleted()); |
| | |
| | | Map<String, XSSFPictureData> pics = ie.getExcelPictures(); |
| | | if(type == 1) { |
| | | List<CasesImport> importList = (ie.getDataList(CasesImport.class,null)); |
| | | if(importList==null || importList.size()==0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"导入文件案例信息内容为空!"); |
| | | } |
| | | model.setCaseList(isvalidImpartCasesParam(loginUserInfo,importList)); |
| | | model.setTotalNum(model.getCaseList().size()); |
| | | }else{ |
| | | List<MemberImport> importList = (ie.getDataList(MemberImport.class,null)); |
| | | model.setMemberList(isvalidImpartMemberParam(loginUserInfo,categoryList,pics,importList)); |
| | | model.setMemberList(isvalidImpartMemberParam(loginUserInfo,categoryList,importList)); |
| | | model.setTotalNum(model.getMemberList().size()); |
| | | } |
| | | importRecordMapper.insert(model); |
| | |
| | | // redisTemplate.delete(Constants.RedisKeys.IMPORTING_RECORD); |
| | | } |
| | | } |
| | | private List<Member> isvalidImpartMemberParam(LoginUserInfo user, List<Category> categoryList ,Map<String, XSSFPictureData> pics, List<MemberImport> memberList) { |
| | | private List<Member> isvalidImpartMemberParam(LoginUserInfo user, List<Category> categoryList , List<MemberImport> memberList) { |
| | | if(memberList ==null || memberList.size()==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,未读取到有效数据"); |
| | | } |
| | | if(pics ==null || pics.size()==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,未读取到任何职业照图片数据"); |
| | | } |
| | | List<Member> insertMember = new ArrayList<>(); |
| | | List<Member> allList = memberMapper.selectList(new QueryWrapper<Member>().lambda() |
| | |
| | | int index = 1; |
| | | for(MemberImport param :memberList){ |
| | | index ++; |
| | | if(StringUtils.isBlank(param.getImgurl()) |
| | | ||StringUtils.isBlank(param.getFee()) |
| | | ||StringUtils.isBlank(param.getName()) |
| | | ||StringUtils.isBlank(param.getInfo()) |
| | | ||StringUtils.isBlank(param.getJobYear()) |
| | | ||StringUtils.isBlank(param.getPosition()) |
| | | ||StringUtils.isBlank(param.getFieldNames()) |
| | | ||StringUtils.isBlank(param.getSex()) |
| | | ||StringUtils.isBlank(param.getCode()) |
| | | ||StringUtils.isBlank(param.getZqNames()) |
| | | ||StringUtils.isBlank(param.getLevelName()) |
| | | ||StringUtils.isBlank(param.getServeNum()) |
| | | ||StringUtils.isBlank(param.getTypeNames())){ |
| | | if(( param.getImgurl() == null |
| | | ||param.getImgurl().getData() == null |
| | | ||param.getImgurl().getData().length == 0) |
| | | &&StringUtils.isBlank(param.getFee()) |
| | | &&StringUtils.isBlank(param.getName()) |
| | | &&StringUtils.isBlank(param.getInfo()) |
| | | &&StringUtils.isBlank(param.getJobYear()) |
| | | &&StringUtils.isBlank(param.getPosition()) |
| | | &&StringUtils.isBlank(param.getFieldNames()) |
| | | &&StringUtils.isBlank(param.getSex()) |
| | | &&StringUtils.isBlank(param.getCode()) |
| | | &&StringUtils.isBlank(param.getZqNames()) |
| | | &&StringUtils.isBlank(param.getLevelName()) |
| | | &&StringUtils.isBlank(param.getServeNum()) |
| | | &&StringUtils.isBlank(param.getTypeNames())){ |
| | | continue; |
| | | } |
| | | Member member = new Member(); |
| | |
| | | if(StringUtils.isBlank(param.getFee())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据, 费用标准信息不能为空"); |
| | | } |
| | | if(pics!=null && StringUtils.isNotBlank(param.getImgurl())){ |
| | | /* if(pics!=null && StringUtils.isNotBlank(param.getImgurl())){ |
| | | log.info("===================="+param.getImgurl()); |
| | | int start = param.getImgurl().indexOf("(\"")+2; |
| | | int end = param.getImgurl().indexOf("\","); |
| | |
| | | member.setImgurlData(data.getData()); |
| | | } |
| | | } |
| | | } |
| | | }*/ |
| | | if(param.getImgurl() ==null ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行【"+param.getName()+"】数据, 未读取到任何职业照图片数据"); |
| | | } |
| | | member.setImgurlData(param.getImgurl().getData()); |
| | | if(member.getImgurlData() ==null || member.getImgurlData().length==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行【"+param.getName()+"】数据, 未读取到任何职业照图片数据"); |
| | | } |
| | |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,未读取到有效数据"); |
| | | } |
| | | return insertMember; |
| | | |
| | | } |
| | | private List<Cases> isvalidImpartCasesParam(LoginUserInfo user, List<CasesImport> casesImportList) { |
| | | if(casesImportList ==null || casesImportList.size()==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,未读取到有效数据"); |
| | | } |
| | | List<Cases> insertList = new ArrayList<>(); |
| | | List<Member> allList = memberMapper.selectList(new QueryWrapper<Member>().lambda() |
| | | .eq(Member::getDeleted,Constants.ZERO)); |
| | | allList=allList==null?new ArrayList<>():allList; |
| | | if(allList == null || allList.size()==0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起, 读取老师数据异常,请先维护老师数据信息!"); |
| | | } |
| | | Date date = new Date(); |
| | | int index = 1; |
| | | for(CasesImport param :casesImportList){ |
| | | index ++; |
| | | if( StringUtils.isBlank(param.getName()) |
| | | &&StringUtils.isBlank(param.getMemberCode()) |
| | | &&StringUtils.isBlank(param.getStartDate()) |
| | | &&StringUtils.isBlank(param.getEndDate()) |
| | | &&StringUtils.isBlank(param.getDetail())){ |
| | | continue; |
| | | } |
| | | Cases cases = new Cases(); |
| | | cases.setStartDate(DateUtil.fromStringToDate("yyyy-MM-dd",param.getStartDate())); |
| | | cases.setEndDate(DateUtil.fromStringToDate("yyyy-MM-dd",param.getEndDate())); |
| | | if(StringUtils.isBlank(param.getName())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据, 案例主题不能为空"); |
| | | } |
| | | Member member =null; |
| | | for(Member m : allList){ |
| | | if(StringUtils.equals(param.getMemberCode(),m.getCode())){ |
| | | member = m; |
| | | } |
| | | } |
| | | if(member == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据, 老师工号【"+param.getMemberCode()+"】信息不存在,请确认不要重复录入"); |
| | | |
| | | } |
| | | if(StringUtils.isBlank(param.getDetail())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据, 案例说明不能为空"); |
| | | } |
| | | if(param.getImageList() == null){ |
| | | param.setImageList(new ArrayList<>()); |
| | | } |
| | | param.getImageList().addAll(param.getImageList1()!=null?param.getImageList1():new ArrayList<>()); |
| | | param.getImageList().addAll(param.getImageList2()!=null?param.getImageList2():new ArrayList<>()); |
| | | param.getImageList().addAll(param.getImageList3()!=null?param.getImageList3():new ArrayList<>()); |
| | | param.getImageList().addAll(param.getImageList4()!=null?param.getImageList4():new ArrayList<>()); |
| | | param.getImageList().addAll(param.getImageList5()!=null?param.getImageList5():new ArrayList<>()); |
| | | /* if(param.getImageList() == null |
| | | ||param.getImageList().size() == 0 ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据, 案例图信息不能为空"); |
| | | }*/ |
| | | if(cases.getStartDate()==null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据, 开始日期读取失败"); |
| | | } |
| | | if(cases.getEndDate()==null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据, 结束日期读取失败"); |
| | | } |
| | | cases.setImgdataList(new ArrayList<>()); |
| | | for(XSSFPictureData d : param.getImageList()){ |
| | | cases.getImgdataList().add(d.getData()); |
| | | } |
| | | cases.setCreateTime(date); |
| | | cases.setUpdateTime(date); |
| | | cases.setCreateUser(user.getId()); |
| | | cases.setUpdateUser(user.getId()); |
| | | cases.setAddType(Constants.ONE); |
| | | cases.setDeleted(Constants.ZERO); |
| | | cases.setStatus(Constants.ZERO); |
| | | cases.setName(param.getName()); |
| | | cases.setDetail(param.getDetail()); |
| | | cases.setMemberId(member.getId()); |
| | | |
| | | insertList.add(cases); |
| | | } |
| | | if(insertList ==null || insertList.size()==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,未读取到有效数据"); |
| | | } |
| | | return insertList; |
| | | |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 异步执行文件任务 |
| | | */ |
| | | @Override |
| | | public void clearImporTask(){ |
| | | try { |
| | | List<ImportRecord> records = importRecordMapper.selectList(new QueryWrapper<ImportRecord>() |
| | | .select("id,total_num,(select count(c.id) from cases c where c.import_id= import_record.id) as doneNum") |
| | | .lambda() |
| | | .eq(ImportRecord::getDeleted,Constants.ZERO) |
| | | .ne(ImportRecord::getStatus,Constants.TWO) |
| | | ); |
| | | for(ImportRecord importRecord : records){ |
| | | importRecord.setErrorNum(Constants.formatIntegerNum(importRecord.getTotalNum()- Constants.formatIntegerNum(importRecord.getDoneNum()))); |
| | | importRecord.setStatus(Constants.TWO); |
| | | importRecord.setUpdateTime(new Date()); |
| | | importRecord.setRemark("任务执行中断,强制设置任务状态"); |
| | | importRecordMapper.updateById(importRecord); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | redisTemplate.delete(Constants.RedisKeys.IMPORTING_RECORD); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理案例导入任务 |
| | | * @param importRecord |
| | | */ |
| | | |
| | | private int dealCaseImportBiz(ImportRecord importRecord) { |
| | | int success=0; |
| | | String msg =""; |
| | | String msg = ""; |
| | | String nowDate =DateUtil.getNowShortDate(); |
| | | try { |
| | | for(Cases param:importRecord.getCaseList()){ |
| | | |
| | | String bucket =systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.BUCKETNAME).getCode(); |
| | | String folder =systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.CASES_FILES).getCode(); |
| | | TyyZosUtil obs = new TyyZosUtil(systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.ENDPOINT).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.ACCESS_ID).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.ACCESS_KEY).getCode()); |
| | | for(Cases param: importRecord.getCaseList()){ |
| | | int ts =0; |
| | | try { |
| | | param.setImportId(importRecord.getId()); |
| | | param.setAddType(Constants.ONE); |
| | | ts = dealCasesInsert(obs,param,folder,nowDate,bucket); |
| | | }catch (Exception e){ |
| | | log.error("处理人员信息发生异常{}",e.getMessage()); |
| | | ts =0; |
| | | } |
| | | success += ts; |
| | | } |
| | | obs.shutDown(); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | importRecord.setDoneNum(success); |
| | | importRecord.setErrorNum(importRecord.getTotalNum() - success); |
| | | importRecord.setDetail(msg); |
| | | redisTemplate.delete(Constants.RedisKeys.IMPORTING_RECORD); |
| | | return success; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | private int dealCasesInsert( TyyZosUtil obs,Cases param,String folder,String nowDate,String bucketName) { |
| | | int success = casesMapper.insert(param); |
| | | if(param.getImgdataList()!=null && param.getImgdataList().size()>0){ |
| | | List<Multifile> multifileList = new ArrayList<>(); |
| | | for(byte[] d : param.getImgdataList()){ |
| | | String fileName = UUID.randomUUID() + ".png"; |
| | | String tempFileName = nowDate + "/" + fileName; |
| | | String key = folder + tempFileName;// 文件名 |
| | | if (obs.uploadInputstreamObjectNoShutdown(new ByteArrayInputStream(d ) ,bucketName, key)) { |
| | | Multifile s = new Multifile(); |
| | | s.setIsdeleted(Constants.ZERO); |
| | | s.setCreator(param.getCreateUser()); |
| | | s.setCreateDate(param.getCreateTime()); |
| | | s.setObjId(param.getId()); |
| | | s.setType(Constants.ZERO); |
| | | s.setFileurl(tempFileName); |
| | | s.setObjType(Constants.ONE); |
| | | multifileList.add(s); |
| | | param.setImgurl(tempFileName);//证件照地址 |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"图集上传失败!"); |
| | | } |
| | | } |
| | | multifileMapper.insert(multifileList); |
| | | } |
| | | return success; |
| | | } |
| | | |
| | | private int dealMemberInsert( TyyZosUtil obs,Member param,String folder,String nowDate,String bucketName) { |
| | | int success =0; |
| | | try { |