package com.gkhy.exam.noncoalmine.service.impl;
|
|
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.TypeReference;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gkhy.exam.noncoalmine.entity.NcExaminees;
|
import com.gkhy.exam.noncoalmine.entity.NcStaff;
|
import com.gkhy.exam.noncoalmine.mapper.NcExamPlanMapper;
|
import com.gkhy.exam.noncoalmine.entity.NcExamPlan;
|
import com.gkhy.exam.noncoalmine.model.query.NcExamPlanQuery;
|
import com.gkhy.exam.noncoalmine.model.vo.ExamPlanExaminee;
|
import com.gkhy.exam.noncoalmine.model.vo.ExamPlanInfo;
|
import com.gkhy.exam.noncoalmine.model.vo.ReturnVO;
|
import com.gkhy.exam.noncoalmine.service.NcExamPlanService;
|
import com.gkhy.exam.noncoalmine.service.NcExamineesService;
|
import com.gkhy.exam.noncoalmine.service.NcStaffService;
|
import com.ruoyi.common.enums.HttpMethod;
|
import com.ruoyi.common.exception.ServiceException;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import java.io.UnsupportedEncodingException;
|
import java.net.URLEncoder;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
|
import static com.ruoyi.common.signature.SignatureUtils.getObject;
|
|
/**
|
* (NcExamPlan)表服务实现类
|
*
|
* @author makejava
|
* @since 2023-09-18 13:21:55
|
*/
|
@Service("ncExamPlanService")
|
public class NcExamPlanServiceImpl extends ServiceImpl<NcExamPlanMapper, NcExamPlan> implements NcExamPlanService {
|
@Autowired
|
private NcExamPlanMapper ncExamPlanMapper;
|
|
@Autowired
|
private NcStaffService ncStaffService;
|
@Autowired
|
private NcExamineesService ncExamineesService;
|
@Override
|
public List<NcExamPlan> selectNcExamPlanList(NcExamPlanQuery query) {
|
return ncExamPlanMapper.selectNcExamPlanList(query);
|
}
|
@Transactional
|
@Override
|
public void syncExamPlan() {
|
|
String startTime = "2018-05-25 00:00:00";
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String endTime = sdf.format(new Date());
|
try {
|
startTime = URLEncoder.encode(startTime, "UTF-8");
|
endTime = URLEncoder.encode(endTime, "UTF-8");
|
} catch (UnsupportedEncodingException e) {
|
throw new RuntimeException(e.getCause());
|
}
|
String getQueryParam = "startTime=" + startTime + "&endTime=" + endTime;
|
String json = getObject(getQueryParam,"/api/v1/exam/plan/enroll/download", HttpMethod.GET);
|
ReturnVO<List<ExamPlanInfo<ExamPlanExaminee>>> returnVo = JSONObject.parseObject(json, new TypeReference<ReturnVO<List<ExamPlanInfo<ExamPlanExaminee>>>>() {});
|
if(returnVo.getCode() == null || returnVo.getCode() != 200){
|
throw new ServiceException("拉取数据异常");
|
}
|
if(returnVo.getData() == null){
|
throw new ServiceException("无数据可更新");
|
}
|
List<ExamPlanInfo<ExamPlanExaminee>> data = returnVo.getData();
|
for (ExamPlanInfo examPlanInfo : data) {
|
NcExamPlan ncExamPlan = new NcExamPlan();
|
BeanUtils.copyProperties(examPlanInfo,ncExamPlan);
|
ncExamPlan.setDelFlag((byte)0);
|
ncExamPlan.setId(null);
|
ncExamPlan.setExamPlanId(examPlanInfo.getId());
|
//判断是否已同步
|
if(!this.isExsit(examPlanInfo.getId())){
|
//插入
|
ncExamPlanMapper.insert(ncExamPlan);
|
List<ExamPlanExaminee> examPlanExaminees = examPlanInfo.getExaminees();
|
if(!CollectionUtils.isEmpty(examPlanInfo.getExaminees())){
|
for (ExamPlanExaminee examPlanExaminee : examPlanExaminees) {
|
NcExaminees ncExaminees = new NcExaminees();
|
ncExaminees.setExamPlanId(examPlanInfo.getId());
|
ncExaminees.setDelFlag((byte)0);
|
ncExaminees.setCardNum(examPlanExaminee.getCardNum());
|
ncExaminees.setCardType(examPlanExaminee.getCardType());
|
ncExaminees.setName(examPlanExaminee.getName());
|
//判断人员是否存在
|
NcStaff ncStaff = ncStaffService.getByIdCard(examPlanExaminee.getCardNum());
|
if(ncStaff == null){
|
//插入staff表
|
ncStaff = new NcStaff();
|
ncStaff.setName(examPlanExaminee.getName());
|
ncStaff.setSex(examPlanExaminee.getSex());
|
ncStaff.setIdCardNum(examPlanExaminee.getCardNum());
|
ncStaff.setDelFlag((byte)0);
|
ncStaffService.save(ncStaff);
|
|
}
|
ncExaminees.setStaffId(ncStaff.getId());
|
ncExamineesService.save(ncExaminees);
|
}
|
|
}
|
}
|
}
|
}
|
public boolean isExsit(Long explanId){
|
NcExamPlan ncExamPlan = ncExamPlanMapper.selectOne(new LambdaQueryWrapper<NcExamPlan>()
|
.eq(NcExamPlan::getDelFlag, (byte) 0)
|
.eq(NcExamPlan::getExamPlanId, explanId));
|
if(ncExamPlan != null){
|
return true;
|
}
|
return false;
|
}
|
}
|