|
@@ -0,0 +1,116 @@
|
|
|
+package com.slibra.web.controller.listener;
|
|
|
+
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.slibra.business.domain.TImportFail;
|
|
|
+import com.slibra.business.domain.TUserInfo;
|
|
|
+import com.slibra.business.mapper.TImportFailMapper;
|
|
|
+import com.slibra.business.mapper.TUserInfoMapper;
|
|
|
+import com.slibra.business.res.UpdateUserExcelInfo;
|
|
|
+import com.slibra.business.res.UserFeeExcelInfo;
|
|
|
+import com.slibra.common.utils.DateUtils;
|
|
|
+import com.slibra.common.utils.StringUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.ibatis.session.SqlSession;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class UpdateUserFeeListener extends AnalysisEventListener<UserFeeExcelInfo> {
|
|
|
+
|
|
|
+ SqlSession sqlSession;
|
|
|
+ TUserInfoMapper tUserInfoMapper;
|
|
|
+ TImportFailMapper tImportFailMapper;
|
|
|
+
|
|
|
+ //成功数量
|
|
|
+ private int successNum = 0;
|
|
|
+
|
|
|
+ //失败数量
|
|
|
+ private int failNum = 0;
|
|
|
+
|
|
|
+ //失败数据列表
|
|
|
+ private List<UserFeeExcelInfo> failList = new ArrayList<>();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void invoke(UserFeeExcelInfo userExcelInfo, AnalysisContext context) {
|
|
|
+ //查询 如果2个有一个为空的,就标记为错误
|
|
|
+ String userNo = userExcelInfo.getUserNo();
|
|
|
+ BigDecimal waterFees = userExcelInfo.getWaterFees();
|
|
|
+ if(StringUtils.isBlank(userNo) || Objects.isNull(waterFees)){
|
|
|
+ log.info("存在为空的数据,无法更新");
|
|
|
+ failNum ++;
|
|
|
+ failList.add(userExcelInfo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //都存在
|
|
|
+ //通过编号查询用户数据,如果存在就更新并记录成功数量,不存在标记错误。
|
|
|
+ //2025年01月22日14:25:34 还是用这种,然后改成非批量,否则拿不到错误记录
|
|
|
+ List<TUserInfo> tUserInfos = this.tUserInfoMapper.selectTUserInfoList(TUserInfo.builder().userNo(userNo).build());
|
|
|
+ if(CollectionUtils.isEmpty(tUserInfos)){
|
|
|
+ log.info("通过用户编号未查询到用户明细");
|
|
|
+ failNum ++;
|
|
|
+ failList.add(userExcelInfo);
|
|
|
+ }else {
|
|
|
+ TUserInfo tUserInfo = tUserInfos.get(0);
|
|
|
+ TUserInfo updateBean = new TUserInfo();
|
|
|
+ updateBean.setId(tUserInfo.getId());
|
|
|
+ updateBean.setWaterFees(waterFees);
|
|
|
+ updateBean.setMeterAmount(userExcelInfo.getMeterAmount());
|
|
|
+ updateBean.setStatisticsTime(userExcelInfo.getStatisticsTime());
|
|
|
+ updateBean.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ updateBean.setUpdateBy("system");
|
|
|
+ this.tUserInfoMapper.updateTUserInfo(updateBean);
|
|
|
+ successNum++;
|
|
|
+ }
|
|
|
+ //2025年01月15日16:22:17 逻辑调整 直接通过name更新,如果返回调试是1,则代表成功;
|
|
|
+ /*int size = this.tUserInfoMapper.updateUserPhoneByNo(phone, userNo);
|
|
|
+ if(size != 0){//成功
|
|
|
+ successNum++;
|
|
|
+ }else{
|
|
|
+ log.info("通过用户编号未查询到用户明细,更新失败");
|
|
|
+ failNum ++;
|
|
|
+ failList.add(userExcelInfo);
|
|
|
+ }*/
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
+ // 所有数据读取完毕后的处理逻辑
|
|
|
+ log.info("所有数据读取完毕");
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+
|
|
|
+ //记录失败数据情况
|
|
|
+ TImportFail tImportFail = new TImportFail();
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("time", DateUtils.getTime());
|
|
|
+ map.put("failNum", failNum);
|
|
|
+ map.put("successNum", successNum);
|
|
|
+ map.put("failList", failList);
|
|
|
+ tImportFail.setType(1);
|
|
|
+ tImportFail.setContent(JSON.toJSONString(map));
|
|
|
+ tImportFail.setCreateTime(nowDate);
|
|
|
+ tImportFail.setCreateBy("system");
|
|
|
+ this.tImportFailMapper.insertTImportFail(tImportFail);
|
|
|
+ sqlSession.commit();
|
|
|
+ sqlSession.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ public UpdateUserFeeListener() {
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public UpdateUserFeeListener(SqlSession sqlSession, TUserInfoMapper tUserInfoMapper, TImportFailMapper tImportFailMapper) {
|
|
|
+ this.sqlSession = sqlSession;
|
|
|
+ this.tUserInfoMapper = tUserInfoMapper;
|
|
|
+ this.tImportFailMapper = tImportFailMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|