Commit 020e2116 authored by 秦嘉's avatar 秦嘉

核酸模块代码优化

parent 89edc54f
...@@ -2,18 +2,19 @@ package com.ruoyi.system.mapper; ...@@ -2,18 +2,19 @@ package com.ruoyi.system.mapper;
import java.util.List; import java.util.List;
import com.ruoyi.system.domain.Hscj; import com.ruoyi.system.domain.Hscj;
import org.apache.ibatis.annotations.Param;
/** /**
* 核酸采集Mapper接口 * 核酸采集Mapper接口
* *
* @author ruoyi * @author ruoyi
* @date 2022-11-28 * @date 2022-11-28
*/ */
public interface HscjMapper public interface HscjMapper
{ {
/** /**
* 查询核酸采集 * 查询核酸采集
* *
* @param id 核酸采集主键 * @param id 核酸采集主键
* @return 核酸采集 * @return 核酸采集
*/ */
...@@ -21,7 +22,7 @@ public interface HscjMapper ...@@ -21,7 +22,7 @@ public interface HscjMapper
/** /**
* 查询核酸采集列表 * 查询核酸采集列表
* *
* @param hscj 核酸采集 * @param hscj 核酸采集
* @return 核酸采集集合 * @return 核酸采集集合
*/ */
...@@ -29,7 +30,7 @@ public interface HscjMapper ...@@ -29,7 +30,7 @@ public interface HscjMapper
/** /**
* 新增核酸采集 * 新增核酸采集
* *
* @param hscj 核酸采集 * @param hscj 核酸采集
* @return 结果 * @return 结果
*/ */
...@@ -37,7 +38,7 @@ public interface HscjMapper ...@@ -37,7 +38,7 @@ public interface HscjMapper
/** /**
* 修改核酸采集 * 修改核酸采集
* *
* @param hscj 核酸采集 * @param hscj 核酸采集
* @return 结果 * @return 结果
*/ */
...@@ -45,7 +46,7 @@ public interface HscjMapper ...@@ -45,7 +46,7 @@ public interface HscjMapper
/** /**
* 删除核酸采集 * 删除核酸采集
* *
* @param id 核酸采集主键 * @param id 核酸采集主键
* @return 结果 * @return 结果
*/ */
...@@ -53,11 +54,17 @@ public interface HscjMapper ...@@ -53,11 +54,17 @@ public interface HscjMapper
/** /**
* 批量删除核酸采集 * 批量删除核酸采集
* *
* @param ids 需要删除的数据主键集合 * @param ids 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */
public int deleteHscjByIds(Long[] ids); public int deleteHscjByIds(Long[] ids);
List<Hscj> checkCard(Hscj hscj); List<Hscj> checkCard(Hscj hscj);
List<Hscj> checkCardBatch(List<Hscj> hscjList);
void insertBatch(List<Hscj> insertList);
void updateBatch(List<Hscj> updateList);
} }
...@@ -65,7 +65,7 @@ public class HscjServiceImpl implements IHscjService { ...@@ -65,7 +65,7 @@ public class HscjServiceImpl implements IHscjService {
@Override @Override
public int insertHscj(Hscj hscj) { public int insertHscj(Hscj hscj) {
String createBy = DataUtils.getValue(hscj.getArea(), hscj.getStreet(), hscj.getCommittee()); String createBy = DataUtils.getValue(hscj.getArea(), hscj.getStreet(), hscj.getCommittee());
if(createBy.equals("null")) if (createBy.equals("null"))
throw new ServiceException("所选居住地、街道、社区不存在"); throw new ServiceException("所选居住地、街道、社区不存在");
if (CheckUtils.checkCard(hscj.getCardNo())) if (CheckUtils.checkCard(hscj.getCardNo()))
hscj.setCheckCard("正确"); hscj.setCheckCard("正确");
...@@ -88,7 +88,7 @@ public class HscjServiceImpl implements IHscjService { ...@@ -88,7 +88,7 @@ public class HscjServiceImpl implements IHscjService {
@Override @Override
public int updateHscj(Hscj hscj) { public int updateHscj(Hscj hscj) {
String createBy = DataUtils.getValue(hscj.getArea(), hscj.getStreet(), hscj.getCommittee()); String createBy = DataUtils.getValue(hscj.getArea(), hscj.getStreet(), hscj.getCommittee());
if(createBy.equals("null")) if (createBy.equals("null"))
throw new ServiceException("所选居住地、街道、社区不存在"); throw new ServiceException("所选居住地、街道、社区不存在");
List<Hscj> list = hscjMapper.checkCard(hscj); List<Hscj> list = hscjMapper.checkCard(hscj);
if (!list.isEmpty()) if (!list.isEmpty())
...@@ -127,7 +127,6 @@ public class HscjServiceImpl implements IHscjService { ...@@ -127,7 +127,6 @@ public class HscjServiceImpl implements IHscjService {
} }
List<Hscj> trueList = new ArrayList<>(); List<Hscj> trueList = new ArrayList<>();
List<Hscj> failureList = new ArrayList<>(); List<Hscj> failureList = new ArrayList<>();
for (Hscj hscj : list) { for (Hscj hscj : list) {
if (StringUtils.isEmpty(hscj.getProvince())) { if (StringUtils.isEmpty(hscj.getProvince())) {
hscj.setProvince("河北省"); hscj.setProvince("河北省");
...@@ -163,8 +162,8 @@ public class HscjServiceImpl implements IHscjService { ...@@ -163,8 +162,8 @@ public class HscjServiceImpl implements IHscjService {
// continue; // continue;
// } // }
List<Hscj> hsctList = list.stream().filter(l -> List<Hscj> hsctList = list.stream().filter(l ->
hscj.getCardNo().equals(l.getCardNo()) && l.getCjTime()!=null && hscj.getCardNo().equals(l.getCardNo()) && l.getCjTime() != null &&
DateUtils.dateTime(hscj.getCjTime()).equals(DateUtils.dateTime(l.getCjTime()))) DateUtils.dateTime(hscj.getCjTime()).equals(DateUtils.dateTime(l.getCjTime())))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (hsctList.size() > 1) { if (hsctList.size() > 1) {
failureList.add(hscj); failureList.add(hscj);
...@@ -240,83 +239,105 @@ public class HscjServiceImpl implements IHscjService { ...@@ -240,83 +239,105 @@ public class HscjServiceImpl implements IHscjService {
// continue; // continue;
// } // }
// } // }
String community = ""; //如果小区不为空,去数据字典匹配value
String committee = ""; if (StringUtils.isNotEmpty(hscj.getCommunity())) {
String street = "";
if (StringUtils.isNotEmpty(hscj.getCommunity())){ //如果小区不为空,去数据字典匹配value
List<SysDictData> communitys = DictUtils.getDictCache("community"); List<SysDictData> communitys = DictUtils.getDictCache("community");
List<String> values = communitys.stream().filter(l->hscj.getCommunity().equals(l.getDictLabel())) List<String> values = communitys.stream().filter(l -> hscj.getCommunity().equals(l.getDictLabel()))
.map(SysDictData::getDictValue).collect(Collectors.toList()); .map(SysDictData::getDictValue).collect(Collectors.toList());
if (!values.isEmpty()) if (!values.isEmpty())
community=values.get(0); hscj.setCommunity(values.get(0));
else { else {
failureList.add(hscj); failureList.add(hscj);
continue; continue;
} }
} }
if (StringUtils.isNotEmpty(hscj.getCommittee())){ //如果委员会不为空,去数据字典匹配value //如果委员会不为空,去数据字典匹配value
if (StringUtils.isNotEmpty(hscj.getCommittee())) {
List<SysDictData> communitys = DictUtils.getDictCache("committee"); List<SysDictData> communitys = DictUtils.getDictCache("committee");
List<String> values = communitys.stream().filter(l->hscj.getCommittee().equals(l.getDictLabel())) List<String> values = communitys.stream().filter(l -> hscj.getCommittee().equals(l.getDictLabel()))
.map(SysDictData::getDictValue).collect(Collectors.toList()); .map(SysDictData::getDictValue).collect(Collectors.toList());
if (!values.isEmpty()) if (!values.isEmpty())
committee=values.get(0); hscj.setCommittee(values.get(0));
else { else {
failureList.add(hscj); failureList.add(hscj);
continue; continue;
} }
} }
if (StringUtils.isNotEmpty(hscj.getStreet())){ //如果街道不为空,去数据字典匹配value //如果街道不为空,去数据字典匹配value
if (StringUtils.isNotEmpty(hscj.getStreet())) {
List<SysDictData> communitys = DictUtils.getDictCache("street_town"); List<SysDictData> communitys = DictUtils.getDictCache("street_town");
List<String> values = communitys.stream().filter(l->hscj.getStreet().equals(l.getDictLabel())) List<String> values = communitys.stream().filter(l -> hscj.getStreet().equals(l.getDictLabel()))
.map(SysDictData::getDictValue).collect(Collectors.toList()); .map(SysDictData::getDictValue).collect(Collectors.toList());
if (!values.isEmpty()) if (!values.isEmpty())
street=values.get(0); hscj.setStreet(values.get(0));
else { else {
failureList.add(hscj); failureList.add(hscj);
continue; continue;
} }
} }
if ((StringUtils.isNotEmpty(community)&&StringUtils.isEmpty(committee))|| if (StringUtils.isNotEmpty(hscj.getCommunity()) && StringUtils.isEmpty(hscj.getCommittee())) {
(StringUtils.isNotEmpty(committee)&&StringUtils.isEmpty(street))){
failureList.add(hscj); failureList.add(hscj);
continue; continue;
} }
Hscj hscjQuerry = new Hscj(); if (StringUtils.isNotEmpty(hscj.getCommittee()) && StringUtils.isEmpty(hscj.getStreet())) {
hscjQuerry.setCardNo(hscj.getCardNo()); failureList.add(hscj);
hscjQuerry.setCjTime(hscj.getCjTime()); continue;
List<Hscj> hscjs = hscjMapper.checkCard(hscjQuerry); }
if (!hscjs.isEmpty()) { if (CheckUtils.checkCard(hscj.getCardNo())) {
for (Hscj hscjUpdate:hscjs){ hscj.setCheckCard("正确");
hscj.setId(hscjUpdate.getId()); trueList.add(hscj);
hscj.setCommunity(community); } else {
hscj.setCommittee(committee); hscj.setCheckCard("不正确");
hscj.setStreet(street); failureList.add(hscj);
hscjMapper.updateHscj(hscj); continue;
}
}else {
if (CheckUtils.checkCard(hscj.getCardNo())) {
hscj.setCheckCard("正确");
hscj.setCommunity(community);
hscj.setCommittee(committee);
hscj.setStreet(street);
trueList.add(hscj);
} else {
hscj.setCheckCard("不正确");
failureList.add(hscj);
continue;
}
} }
} else { } else {
failureList.add(hscj); failureList.add(hscj);
} }
} }
if (!trueList.isEmpty()) { if (!trueList.isEmpty()) {
for (Hscj hscj : trueList) { // 因为数据量过大,所以将list拆分为每个数组100条的形式
String createBy = DataUtils.getValue(hscj.getArea(),hscj.getStreet(),hscj.getCommittee()); List<Hscj> hscjList = new ArrayList<>();
hscj.setCreateBy(createBy); int listSize = trueList.size();
hscj.setCreateTime(DateUtils.getNowDate()); int count = listSize / 100;
hscjMapper.insertHscj(hscj);
for (int i = 0; i < count; i++) {
hscjList = trueList.subList(i*100,(i+1)*100-1);
//1、从集合中获取到所有查询所需的条件,进行批量数据查询
List<Hscj> hscjs = hscjMapper.checkCardBatch(hscjList);
//2、循环数据进行判断是否是新增还是更新
List<Hscj> updateList = new ArrayList<>();
List<Hscj> insertList = new ArrayList<>();
if (!hscjs.isEmpty()) {
for (Hscj hscj : hscjs) {
updateList.addAll(hscjList.stream().filter(l -> hscj.getCardNo().equals(l.getCardNo())).collect(Collectors.toList()));
insertList.addAll(hscjList.stream().filter(l -> !(hscj.getCardNo().equals(l.getCardNo()))).collect(Collectors.toList()));
}
} else {
insertList.addAll(hscjList);
}
//3、将数据分别写入到更新数据集合和插入数据集合中
//4、判断新增集合和插入集合是否有数据,如果有数据则执行SQL语句
if (!insertList.isEmpty()) {
hscjMapper.insertBatch(insertList);
}
if (!updateList.isEmpty()) {
hscjMapper.updateBatch(updateList);
}
}
//判断是否还有剩余?如果有甚于数据,则,则将剩余数据取出,按照上面循环体中的代码逻辑执行即可
if (listSize % 100 != 0) {
hscjList = trueList.subList(count*100,listSize-1);
} }
// List<Hscj> hscjs = hscjMapper.checkCard(hscj);
// if (!hscjs.isEmpty()) {
// hscjMapper.updateHscj(hscj);
// continue;
// }
// String createBy = DataUtils.getValue(hscj.getArea(), hscj.getStreet(), hscj.getCommittee());
// hscj.setCreateBy(createBy);
// hscj.setCreateTime(DateUtils.getNowDate());
// hscjMapper.insertHscj(hscj);
} }
if (!failureList.isEmpty()) { if (!failureList.isEmpty()) {
ExcelUtil<Hscj> util = new ExcelUtil<Hscj>(Hscj.class); ExcelUtil<Hscj> util = new ExcelUtil<Hscj>(Hscj.class);
......
...@@ -121,6 +121,16 @@ ...@@ -121,6 +121,16 @@
and date_format(cj_time,'%y%m%d') = date_format(#{cjTime},'%y%m%d') and date_format(cj_time,'%y%m%d') = date_format(#{cjTime},'%y%m%d')
<if test="id != null">and id != #{id}</if> <if test="id != null">and id != #{id}</if>
</select> </select>
<select id="checkCardBatch" resultType="com.ruoyi.system.domain.Hscj">
SELECT id, card_no
FROM hscj
WHERE del_flag ='0'
AND card_no IN
<foreach collection="hscjList" item="item" index="index" open="(" separator="," close=")">
#{item.cardNo}
</foreach>
</select>
<insert id="insertHscj" parameterType="Hscj" useGeneratedKeys="true" keyProperty="id"> <insert id="insertHscj" parameterType="Hscj" useGeneratedKeys="true" keyProperty="id">
insert into hscj insert into hscj
...@@ -193,6 +203,7 @@ ...@@ -193,6 +203,7 @@
<if test="remark != null">#{remark},</if> <if test="remark != null">#{remark},</if>
</trim> </trim>
</insert> </insert>
<insert id="insertBatch"></insert>
<update id="updateHscj" parameterType="Hscj"> <update id="updateHscj" parameterType="Hscj">
update hscj update hscj
...@@ -231,6 +242,7 @@ ...@@ -231,6 +242,7 @@
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>
<update id="updateBatch"></update>
<delete id="deleteHscjById" parameterType="Long"> <delete id="deleteHscjById" parameterType="Long">
delete delete
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment