|
@@ -7,8 +7,8 @@ import com.rongwe.zhsw.system.domain.SwWaterUsageEntryDo;
|
|
import com.rongwei.commonservice.service.RedisService;
|
|
import com.rongwei.commonservice.service.RedisService;
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
import com.rongwei.rwcommon.base.BaseDo;
|
|
import com.rongwei.rwcommon.base.BaseDo;
|
|
-import com.rongwei.rwcommon.utils.Constants;
|
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
|
+import com.rongwei.zhsw.system.config.ContextHolder;
|
|
import com.rongwei.zhsw.system.utils.ZHSWCommonUtils;
|
|
import com.rongwei.zhsw.system.utils.ZHSWCommonUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -20,9 +20,7 @@ import org.springframework.transaction.TransactionDefinition;
|
|
import org.springframework.transaction.TransactionStatus;
|
|
import org.springframework.transaction.TransactionStatus;
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
-import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
@@ -69,21 +67,17 @@ public class BillGenerationServiceImpl {
|
|
* @param attributes
|
|
* @param attributes
|
|
*/
|
|
*/
|
|
@Async(value = "zhswThreadPool")
|
|
@Async(value = "zhswThreadPool")
|
|
- public void asyncGenerateBill(List<SwWaterUsageEntryDo> swWaterUsageEntryDoList, HttpServletRequest httpServletRequest, String dskey) {
|
|
|
|
|
|
+ public void asyncGenerateBill(List<SwWaterUsageEntryDo> swWaterUsageEntryDoList) {
|
|
if (swWaterUsageEntryDoList == null || swWaterUsageEntryDoList.isEmpty()) {
|
|
if (swWaterUsageEntryDoList == null || swWaterUsageEntryDoList.isEmpty()) {
|
|
log.error("暂无需要生成账单的信息");
|
|
log.error("暂无需要生成账单的信息");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- if(httpServletRequest==null){
|
|
|
|
- httpServletRequest =((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
|
- }
|
|
|
|
- log.info("httpServletRequest是否为空:{},所属库名:{}", httpServletRequest == null, dskey);
|
|
|
|
- httpServletRequest.setAttribute(Constants.SAAS_LOGIN_TOKEN, dskey);
|
|
|
|
generateBill(swWaterUsageEntryDoList);
|
|
generateBill(swWaterUsageEntryDoList);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
public void generateBill(List<SwWaterUsageEntryDo> swWaterUsageEntryDoList) {
|
|
public void generateBill(List<SwWaterUsageEntryDo> swWaterUsageEntryDoList) {
|
|
|
|
+ String dsKey = ContextHolder.getValue("dsKey");
|
|
|
|
+ log.info("上下文信息为:{},dsKey:{}", RequestContextHolder.getRequestAttributes(), dsKey);
|
|
log.debug("需要生成账单的抄表记录为:{}", swWaterUsageEntryDoList);
|
|
log.debug("需要生成账单的抄表记录为:{}", swWaterUsageEntryDoList);
|
|
// 对数据按照抄表日期排序
|
|
// 对数据按照抄表日期排序
|
|
List<SwWaterUsageEntryDo> collect = swWaterUsageEntryDoList.stream()
|
|
List<SwWaterUsageEntryDo> collect = swWaterUsageEntryDoList.stream()
|
|
@@ -173,7 +167,6 @@ public class BillGenerationServiceImpl {
|
|
userSaveList.add(swUserManagementDo);
|
|
userSaveList.add(swUserManagementDo);
|
|
saveUsageEntryList.add(usageEntryDo);
|
|
saveUsageEntryList.add(usageEntryDo);
|
|
}
|
|
}
|
|
- ;
|
|
|
|
dataSave(saveList, saveUsageEntryList, userSaveList);
|
|
dataSave(saveList, saveUsageEntryList, userSaveList);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -181,33 +174,33 @@ public class BillGenerationServiceImpl {
|
|
public void generateBill(String id) {
|
|
public void generateBill(String id) {
|
|
log.info("开始给抄表记录:{},生成账单信息", id);
|
|
log.info("开始给抄表记录:{},生成账单信息", id);
|
|
SwWaterUsageEntryDo swWaterUsageEntryDo = swWaterUsageEntryService.getById(id);
|
|
SwWaterUsageEntryDo swWaterUsageEntryDo = swWaterUsageEntryService.getById(id);
|
|
|
|
+ SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
|
|
|
|
+ ContextHolder.setValue("dskey", currentUser.getTenantDo().getDskey());
|
|
this.generateBill(Collections.singletonList(swWaterUsageEntryDo));
|
|
this.generateBill(Collections.singletonList(swWaterUsageEntryDo));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public void generateBill(List<String> ids, boolean a, HttpServletRequest httpServletRequest) {
|
|
|
|
|
|
+ public void generateBill(List<String> ids, boolean a) {
|
|
if (ids.isEmpty()) {
|
|
if (ids.isEmpty()) {
|
|
log.error("抄表记录ID为空");
|
|
log.error("抄表记录ID为空");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- String token = httpServletRequest.getHeader("token");
|
|
|
|
- log.info("token:{}", token);
|
|
|
|
- SysUserVo loginUser = redisService.getLoginUser(token);
|
|
|
|
- log.info("获取到的用户信息为:{}", loginUser);
|
|
|
|
- String dskey = loginUser.getTenantDo().getDskey();
|
|
|
|
- log.info("开始给抄表记录:{},生成账单信息", ids);
|
|
|
|
- this.asyncGenerateBill(swWaterUsageEntryService.getBaseMapper().selectBatchIds(ids), httpServletRequest, dskey);
|
|
|
|
|
|
+ SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
|
|
|
|
+ ContextHolder.setValue("dsKey", currentUser.getTenantDo().getDskey());
|
|
|
|
+ this.asyncGenerateBill(swWaterUsageEntryService.getBaseMapper().selectBatchIds(ids));
|
|
|
|
+ ContextHolder.clear();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public void generateBill(HttpServletRequest request) {
|
|
|
|
|
|
+ public void generateBill() {
|
|
List<SwWaterUsageEntryDo> list = swWaterUsageEntryService.list(new LambdaQueryWrapper<SwWaterUsageEntryDo>()
|
|
List<SwWaterUsageEntryDo> list = swWaterUsageEntryService.list(new LambdaQueryWrapper<SwWaterUsageEntryDo>()
|
|
.eq(SwWaterUsageEntryDo::getDeleted, "0")
|
|
.eq(SwWaterUsageEntryDo::getDeleted, "0")
|
|
.eq(SwWaterUsageEntryDo::getState, 0));
|
|
.eq(SwWaterUsageEntryDo::getState, 0));
|
|
log.info("开始给抄表记录:{},生成账单信息", list.stream().map(SwWaterUsageEntryDo::getId).collect(Collectors.toList()));
|
|
log.info("开始给抄表记录:{},生成账单信息", list.stream().map(SwWaterUsageEntryDo::getId).collect(Collectors.toList()));
|
|
SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
|
|
SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
|
|
- String dskey = currentUser.getTenantDo().getDskey();
|
|
|
|
- this.asyncGenerateBill(list, request, dskey);
|
|
|
|
|
|
+ ContextHolder.setValue("dskey", currentUser.getTenantDo().getDskey());
|
|
|
|
+ this.asyncGenerateBill(list);
|
|
|
|
+ ContextHolder.clear();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -243,6 +236,8 @@ public class BillGenerationServiceImpl {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
transactionManager.rollback(status);
|
|
transactionManager.rollback(status);
|
|
log.error("账单保存异常");
|
|
log.error("账单保存异常");
|
|
|
|
+ }finally {
|
|
|
|
+ ContextHolder.clear();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -255,7 +250,7 @@ public class BillGenerationServiceImpl {
|
|
*/
|
|
*/
|
|
public SwBillManagementUnpaidDo produceBill(SwUserManagementDo swUserManagementDo, SwWaterUsageEntryDo swWaterUsageEntryDo) {
|
|
public SwBillManagementUnpaidDo produceBill(SwUserManagementDo swUserManagementDo, SwWaterUsageEntryDo swWaterUsageEntryDo) {
|
|
// 上次抄表数
|
|
// 上次抄表数
|
|
- BigDecimal lastreading = swWaterUsageEntryDo.getLastreading()==null?BigDecimal.ZERO:swWaterUsageEntryDo.getLastreading();
|
|
|
|
|
|
+ BigDecimal lastreading = swWaterUsageEntryDo.getLastreading() == null ? BigDecimal.ZERO : swWaterUsageEntryDo.getLastreading();
|
|
// 本次抄表数
|
|
// 本次抄表数
|
|
BigDecimal thisreading = swWaterUsageEntryDo.getThisreading();
|
|
BigDecimal thisreading = swWaterUsageEntryDo.getThisreading();
|
|
|
|
|