|
|
@@ -1,13 +1,20 @@
|
|
|
package org.dromara.backstage.consumption.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import io.seata.common.util.CollectionUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.backstage.consumption.domain.XfConsumeDetail;
|
|
|
+import org.dromara.backstage.consumption.domain.bo.HandImportConsumeBo;
|
|
|
+import org.dromara.backstage.consumption.domain.bo.HandImportExcelConsumeBo;
|
|
|
import org.dromara.backstage.consumption.domain.bo.XfConsumeDetailBo;
|
|
|
import org.dromara.backstage.consumption.domain.vo.XfConsumeAnalyzeVo;
|
|
|
import org.dromara.backstage.consumption.domain.vo.XfConsumeDetailCKBKVo;
|
|
|
@@ -15,11 +22,13 @@ import org.dromara.backstage.consumption.domain.vo.XfConsumeDetailVo;
|
|
|
import org.dromara.backstage.consumption.mapper.XfConsumeDetailMapper;
|
|
|
import org.dromara.backstage.consumption.service.IXfConsumeDetailService;
|
|
|
import org.dromara.common.core.enums.ConsumeRecordTypeEnum;
|
|
|
+import org.dromara.common.core.enums.CreditTypeEnum;
|
|
|
import org.dromara.common.core.utils.DateUtils;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.YearMonth;
|
|
|
@@ -35,10 +44,15 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class XfConsumeDetailServiceImpl implements IXfConsumeDetailService {
|
|
|
|
|
|
private final XfConsumeDetailMapper baseMapper;
|
|
|
|
|
|
+ // http://172.16.137.72/prod-api/consume
|
|
|
+ @Value("${XF_CONSUME_URL:http://localhost:8080/consume}")
|
|
|
+ private String XF_CONSUME_URL;
|
|
|
+
|
|
|
/**
|
|
|
* 查询消费明细
|
|
|
*
|
|
|
@@ -292,4 +306,78 @@ public class XfConsumeDetailServiceImpl implements IXfConsumeDetailService {
|
|
|
beginDate, endDate));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导入消费明细数据
|
|
|
+ *
|
|
|
+ * (模拟消费机消费) http://172.16.137.72/prod-api/consume/v1/Consumes/ConsumeOriginal
|
|
|
+ * // http://172.16.137.72/prod-api/consume/v1/Consumes/Consume
|
|
|
+ *
|
|
|
+ * @param list 导入结果
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<HandImportConsumeBo> importConsumeDetailList(List<HandImportExcelConsumeBo> list) {
|
|
|
+ List<HandImportConsumeBo> rs = new ArrayList<>(list.size());
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ HandImportExcelConsumeBo handImportExcelConsumeBo = list.get(i);
|
|
|
+ HandImportConsumeBo bo = new HandImportConsumeBo();
|
|
|
+ rs.add(bo);
|
|
|
+ bo.setConsumeDate(handImportExcelConsumeBo.getConsumeDate());
|
|
|
+ bo.setConsumeValue(handImportExcelConsumeBo.getConsumeValue());
|
|
|
+ bo.setEmployeeStrID(handImportExcelConsumeBo.getEmployeeStrID());
|
|
|
+ bo.setTermID(handImportExcelConsumeBo.getTermID());
|
|
|
+
|
|
|
+ bo.setCreditType(CreditTypeEnum.HAND_CONSUME.code().toString());
|
|
|
+ bo.setStatusFlag("3");
|
|
|
+ bo.setPosRecordState("364");
|
|
|
+ bo.setTermRecordID(String.valueOf(i));
|
|
|
+
|
|
|
+ // 调用消费接口
|
|
|
+ // http://172.16.137.72/prod-api/consume/v1/Consumes/ConsumeOriginal
|
|
|
+ // 使用hutool工具包的http请求工具类 发送post请求
|
|
|
+ HttpRequest httpRequest = HttpRequest.post(XF_CONSUME_URL+"/v1/Consumes/ConsumeOriginal")
|
|
|
+ .body(JSONUtil.toJsonStr(bo));
|
|
|
+ log.info("请求ConsumeOriginal开始:{}",httpRequest.toString());
|
|
|
+ HttpResponse result = httpRequest.execute();
|
|
|
+ log.info("请求ConsumeOriginal返回:{}", result.toString());
|
|
|
+ String resBody = result.body();
|
|
|
+ if(StringUtils.isBlank(resBody)){
|
|
|
+ bo.setResult("失败");
|
|
|
+ bo.setReason("ConsumeOriginal请求失败,返回为空");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(resBody);
|
|
|
+ String employeeStrID = jsonObject.getStr("employeeStrID");
|
|
|
+ if(StringUtils.isBlank(employeeStrID)){
|
|
|
+ bo.setResult("失败");
|
|
|
+ bo.setReason(resBody);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ bo.setEmployeeName(jsonObject.getStr("employeeName"));
|
|
|
+
|
|
|
+ // http://172.16.137.72/prod-api/consume/v1/Consumes/Consume
|
|
|
+ HttpRequest httpRequestAgain = HttpRequest.post(XF_CONSUME_URL+"/v1/Consumes/Consume")
|
|
|
+ .body(resBody);
|
|
|
+ log.info("请求Consume开始:{}",httpRequestAgain.toString());
|
|
|
+ HttpResponse resultAgain = httpRequestAgain.execute();
|
|
|
+ log.info("请求Consume返回:{}", resultAgain.toString());
|
|
|
+ String resBodyAgain = resultAgain.body();
|
|
|
+ if(StringUtils.isBlank(resBodyAgain)){
|
|
|
+ bo.setResult("失败");
|
|
|
+ bo.setReason("Consume请求失败,返回为空");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject jsonObjectAgain = JSONUtil.parseObj(resBodyAgain);
|
|
|
+ String employeeStrIDAgain = jsonObjectAgain.getStr("employeeStrID");
|
|
|
+ if(StringUtils.isBlank(employeeStrIDAgain)){
|
|
|
+ bo.setResult("失败");
|
|
|
+ bo.setReason(resBody);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ bo.setResult("成功");
|
|
|
+
|
|
|
+ }
|
|
|
+ return rs;
|
|
|
+ }
|
|
|
+
|
|
|
}
|