同步班级代码到新生信息
This commit is contained in:
@@ -14,6 +14,7 @@ import com.srs.comprehensive.domain.Vo.CphSearch;
|
||||
import com.srs.comprehensive.domain.Vo.DataScreen;
|
||||
import com.srs.comprehensive.service.ISrsMajorsService;
|
||||
import com.srs.framework.web.domain.server.Sys;
|
||||
import com.srs.stureg.domain.GxsdxySjzx009Temp2024xsxx;
|
||||
import com.srs.stureg.domain.SrsStuReg;
|
||||
import com.srs.stureg.domain.SrsStuRegImport;
|
||||
import com.srs.stureg.service.ISrsStuRegService;
|
||||
@@ -56,6 +57,24 @@ public class SrsStuRegController extends BaseController
|
||||
@Autowired
|
||||
ISrsMajorsService srsMajorsService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('stureg:temp:index')")
|
||||
@ApiOperation("同步班级代码")
|
||||
@PostMapping("/syncClassCode")
|
||||
public AjaxResult syncClassCode(){
|
||||
return srsStuRegService.syncClassCode();
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('stureg:temp:index')")
|
||||
@ApiOperation("列出新生临时数据")
|
||||
@GetMapping("/listXsxxTemp")
|
||||
public TableDataInfo listXsxxTemp(GxsdxySjzx009Temp2024xsxx param){
|
||||
startPage();
|
||||
List<GxsdxySjzx009Temp2024xsxx> res = srsStuRegService.listXsxxTemp(param);
|
||||
return getDataTable(res);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("统计住宿")
|
||||
@GetMapping("/countRoomBed")
|
||||
public AjaxResult countRoomBed(){
|
||||
|
@@ -0,0 +1,49 @@
|
||||
package com.srs.stureg.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("gxsdxy_sjzx_009_temp_2024xsxx")
|
||||
public class GxsdxySjzx009Temp2024xsxx {
|
||||
|
||||
@TableField("临时学号_报到后给新的")
|
||||
public String 临时学号报到后给新的; // 临时学号_报到后给新的
|
||||
@TableField("姓名")
|
||||
public String 姓名; // 姓名
|
||||
@TableField("性别")
|
||||
public String 性别; // 性别
|
||||
@TableField("出生日期字符串")
|
||||
public String 出生日期字符串; // 出生日期字符串
|
||||
@TableField("民族代码")
|
||||
public String 民族代码; // 民族代码
|
||||
@TableField("民族名称")
|
||||
public String 民族名称; // 民族名称
|
||||
@TableField("政治面貌代码")
|
||||
public String 政治面貌代码; // 政治面貌代码
|
||||
@TableField("政治面貌名称")
|
||||
public String 政治面貌名称; // 政治面貌名称
|
||||
@TableField("教务系统_所属院系")
|
||||
public String 教务系统所属院系; // 教务系统_所属院系
|
||||
@TableField("教务系统_年度专业代码")
|
||||
public String 教务系统年度专业代码; // 教务系统_年度专业代码\
|
||||
@TableField("教务系统_专业名称")
|
||||
public String 教务系统专业名称; // 教务系统_专业名称
|
||||
@TableField("教务系统_班级编号")
|
||||
public String 教务系统班级编号; // 教务系统_班级编号
|
||||
@TableField("班级名称")
|
||||
public String 班级名称; // 班级名称
|
||||
@TableField("班级简称")
|
||||
public String 班级简称; // 班级简称
|
||||
@TableField("是否报到核验")
|
||||
public String 是否报到核验; // 是否报到核验
|
||||
@TableField("报到核验时间")
|
||||
public String 报到核验时间; // 报到核验时间
|
||||
@TableField("学号")
|
||||
public String 学号; // 学号
|
||||
}
|
@@ -197,10 +197,10 @@ public class SrsStuReg extends BaseEntity
|
||||
@TableField("disable_descript")
|
||||
private String disableDescript;
|
||||
@Excel(name = "是否吸烟")
|
||||
@TableField("isSmoke")
|
||||
@TableField("is_smoke")
|
||||
public String isSmoke;
|
||||
@Excel(name = "是否早睡")
|
||||
@TableField("isEarly")
|
||||
@TableField("is_early")
|
||||
public String isEarly;
|
||||
@Excel(name = "兴趣特长")
|
||||
@TableField("hobby")
|
||||
|
@@ -1,8 +1,11 @@
|
||||
package com.srs.stureg.mapper;
|
||||
|
||||
import com.srs.common.annotation.DataSource;
|
||||
import com.srs.common.enums.DataSourceType;
|
||||
import com.srs.comprehensive.domain.Vo.CphSearch;
|
||||
import com.srs.comprehensive.domain.Vo.DataScreen;
|
||||
import com.srs.framework.mybatisplusMapper.EasyBaseMapper;
|
||||
import com.srs.stureg.domain.GxsdxySjzx009Temp2024xsxx;
|
||||
import com.srs.stureg.domain.SrsStuReg;
|
||||
import com.srs.stureg.domain.VO.TeacherVo;
|
||||
import org.apache.ibatis.annotations.MapKey;
|
||||
@@ -22,6 +25,9 @@ import java.util.Map;
|
||||
@Mapper
|
||||
public interface SrsStuRegMapper extends EasyBaseMapper<SrsStuReg> {
|
||||
|
||||
@DataSource(DataSourceType.SLAVE)
|
||||
public List<GxsdxySjzx009Temp2024xsxx> listXsxxTemp(GxsdxySjzx009Temp2024xsxx param);
|
||||
|
||||
public List<Map<String,Object>> countRoomBed();
|
||||
|
||||
public List<Map<String,Object>> countStuXb();
|
||||
|
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.srs.common.core.domain.AjaxResult;
|
||||
import com.srs.comprehensive.domain.Vo.CphSearch;
|
||||
import com.srs.comprehensive.domain.Vo.DataScreen;
|
||||
import com.srs.stureg.domain.GxsdxySjzx009Temp2024xsxx;
|
||||
import com.srs.stureg.domain.SrsStuReg;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -24,6 +25,10 @@ import java.util.concurrent.Future;
|
||||
*/
|
||||
public interface ISrsStuRegService extends IService<SrsStuReg> {
|
||||
|
||||
public AjaxResult syncClassCode();
|
||||
|
||||
public List<GxsdxySjzx009Temp2024xsxx> listXsxxTemp(GxsdxySjzx009Temp2024xsxx param);
|
||||
|
||||
public List<Map<String,Object>> countRoomBed();
|
||||
|
||||
public List<Map<String,Object>> countStuXb();
|
||||
|
@@ -3,19 +3,20 @@ package com.srs.stureg.service.impl;
|
||||
import java.lang.management.LockInfo;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.srs.common.annotation.DataSource;
|
||||
import com.srs.common.core.domain.AjaxResult;
|
||||
import com.srs.common.core.domain.entity.SysDictData;
|
||||
import com.srs.common.core.domain.entity.SysUser;
|
||||
import com.srs.common.enums.DataSourceType;
|
||||
import com.srs.common.exception.ServiceException;
|
||||
import com.srs.common.utils.DateUtils;
|
||||
import com.srs.common.utils.SecurityUtils;
|
||||
@@ -45,7 +46,11 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.AsyncResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import static com.srs.common.utils.SecurityUtils.getUsername;
|
||||
@@ -97,6 +102,150 @@ public class SrsStuRegServiceImpl extends ServiceImpl<SrsStuRegMapper, SrsStuReg
|
||||
@Autowired
|
||||
private ISrsClassService srsClassService;
|
||||
|
||||
@Autowired
|
||||
public PlatformTransactionManager transactionManager;
|
||||
|
||||
@Override
|
||||
public AjaxResult syncClassCode() {
|
||||
// 初始化两个线程池,根据CPU核心数配置合理线程数
|
||||
ThreadPoolExecutor pool1 = new ThreadPoolExecutor(
|
||||
Runtime.getRuntime().availableProcessors() / 2,
|
||||
Runtime.getRuntime().availableProcessors(),
|
||||
60L, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(1000),
|
||||
new ThreadFactory() {
|
||||
private final AtomicInteger counter = new AtomicInteger(1);
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
return new Thread(r, "update-pool-1-" + counter.getAndIncrement());
|
||||
}
|
||||
},
|
||||
new ThreadPoolExecutor.CallerRunsPolicy() // 任务满时让提交线程执行,避免丢失
|
||||
);
|
||||
|
||||
ThreadPoolExecutor pool2 = new ThreadPoolExecutor(
|
||||
Runtime.getRuntime().availableProcessors() / 2,
|
||||
Runtime.getRuntime().availableProcessors(),
|
||||
60L, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(1000),
|
||||
new ThreadFactory() {
|
||||
private final AtomicInteger counter = new AtomicInteger(1);
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
return new Thread(r, "update-pool-2-" + counter.getAndIncrement());
|
||||
}
|
||||
},
|
||||
new ThreadPoolExecutor.CallerRunsPolicy()
|
||||
);
|
||||
|
||||
try {
|
||||
List<SrsStuReg> stuList = this.list();
|
||||
List<GxsdxySjzx009Temp2024xsxx> tempList = srsStuRegMapper.listXsxxTemp(new GxsdxySjzx009Temp2024xsxx());
|
||||
|
||||
tempList.forEach(x -> {
|
||||
x.临时学号报到后给新的 = x.临时学号报到后给新的.replace("LS", "");
|
||||
});
|
||||
|
||||
List<SrsStuReg> needUpdateList = new ArrayList<>();
|
||||
for (SrsStuReg srsStuReg : stuList) {
|
||||
GxsdxySjzx009Temp2024xsxx temp = tempList.stream()
|
||||
.filter(x -> x.临时学号报到后给新的.equals(srsStuReg.getKSH()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (temp != null) {
|
||||
SrsStuReg stu = new SrsStuReg();
|
||||
stu.setId(srsStuReg.getId());
|
||||
stu.setBJDM(temp.教务系统班级编号);
|
||||
needUpdateList.add(stu);
|
||||
}
|
||||
}
|
||||
|
||||
if (needUpdateList.isEmpty()) {
|
||||
return AjaxResult.success("没有需要更新的数据");
|
||||
}
|
||||
|
||||
// 将更新列表拆分为两部分,分配给两个线程池
|
||||
int mid = needUpdateList.size() / 2;
|
||||
List<SrsStuReg> part1 = needUpdateList.subList(0, mid);
|
||||
List<SrsStuReg> part2 = needUpdateList.subList(mid, needUpdateList.size());
|
||||
|
||||
// 用于等待所有线程完成
|
||||
CountDownLatch countDownLatch = new CountDownLatch(2);
|
||||
// 用于捕获线程中的异常
|
||||
AtomicReference<Exception> exceptionRef = new AtomicReference<>();
|
||||
|
||||
// 提交第一个任务到线程池1
|
||||
pool1.submit(() -> {
|
||||
try {
|
||||
if (!part1.isEmpty()) {
|
||||
boolean res = this.updateBatchById(part1);
|
||||
if (!res) {
|
||||
throw new Exception("线程池1批量更新失败");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
exceptionRef.set(e);
|
||||
} finally {
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
// 提交第二个任务到线程池2
|
||||
pool2.submit(() -> {
|
||||
try {
|
||||
if (!part2.isEmpty()) {
|
||||
boolean res = this.updateBatchById(part2);
|
||||
if (!res) {
|
||||
throw new Exception("线程池2批量更新失败");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
exceptionRef.set(e);
|
||||
} finally {
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
// 等待所有任务完成(最多等待30秒)
|
||||
boolean await = countDownLatch.await(30, TimeUnit.SECONDS);
|
||||
if (!await) {
|
||||
throw new Exception("批量更新超时");
|
||||
}
|
||||
|
||||
// 检查是否有异常
|
||||
if (exceptionRef.get() != null) {
|
||||
throw exceptionRef.get();
|
||||
}
|
||||
|
||||
return AjaxResult.success("同步班级代码成功,共更新" + needUpdateList.size() + "条数据");
|
||||
} catch (Exception ex) {
|
||||
return AjaxResult.error(ex.getMessage());
|
||||
} finally {
|
||||
// 关闭线程池
|
||||
pool1.shutdown();
|
||||
pool2.shutdown();
|
||||
try {
|
||||
// 等待线程池关闭(最多等5秒)
|
||||
if (!pool1.awaitTermination(5, TimeUnit.SECONDS)) {
|
||||
pool1.shutdownNow();
|
||||
}
|
||||
if (!pool2.awaitTermination(5, TimeUnit.SECONDS)) {
|
||||
pool2.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
pool1.shutdownNow();
|
||||
pool2.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DataSource(DataSourceType.SLAVE)
|
||||
public List<GxsdxySjzx009Temp2024xsxx> listXsxxTemp(GxsdxySjzx009Temp2024xsxx param){
|
||||
return srsStuRegMapper.listXsxxTemp(param);
|
||||
}
|
||||
|
||||
|
||||
public SrsStuRegServiceImpl(List<SysUser> userList) {
|
||||
this.userList = userList;
|
||||
|
@@ -998,4 +998,13 @@
|
||||
(#{item.XSXM}, #{item.KSH}, #{item.SFZH}, #{item.SJH},#{item.XB},#{item.ZZMM},#{item.MZ},#{item.XY},#{item.ZY},#{item.lastSchool},#{item.famNowAddr},#{item.sfzAddr},#{item.createTime},#{item.createBy},#{item.BJ},#{item.BJDM})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="listXsxxTemp" resultType="GxsdxySjzx009Temp2024xsxx" parameterType="GxsdxySjzx009Temp2024xsxx">
|
||||
select a.* from gxsdxy_sjzx_009_temp_2024xsxx as a
|
||||
<where>
|
||||
<if test="临时学号报到后给新的 != null and 临时学号报到后给新的 != ''">and a.临时学号_报到后给新的 like CONCAT('%',#{临时学号报到后给新的},'%')</if>
|
||||
<if test="教务系统班级编号 != null and 教务系统班级编号 != ''">and a.教务系统_班级编号 = #{教务系统班级编号}</if>
|
||||
</where>
|
||||
order by a.临时学号_报到后给新的 asc
|
||||
</select>
|
||||
</mapper>
|
||||
|
Reference in New Issue
Block a user