Commit 740d40d9 by lijingjing

发送ERP更改为单个发送

parent 2ac19b73
......@@ -33,7 +33,7 @@ import java.util.List;
import java.util.Map;
/**
* ${table.comment} 前端控制器
* 委托单样品所测检测项目 前端控制器
*
* @author wwd
* @since 2021-02-01
......@@ -734,8 +734,10 @@ public class EntrustSampleItemController extends ServiceController {
@ApiOperation(value = "模拟测试发送数据到ERP", notes = "模拟测试发送数据到ERP")
@PostMapping("/send_data")
@Login(action = Action.Skip)
public RestResult<Boolean> sendData(@RequestBody List<SampleItemVO> sampleItemVOList) {
return RestResult.failed("测试凯龙");
public RestResult<Boolean> sendData(@RequestBody SampleItemVO itemVO) {
logger.error(itemVO.getSample_code());
logger.error(itemVO.getBrand());
return RestResult.failed("测试中");
}
@ApiOperation(value = "根据检测项目ID退回原始记录", notes = "根据检测项目ID退回原始记录")
......
......@@ -4,11 +4,11 @@ import com.baomidou.mybatisplus.annotations.SqlParser;
import com.patzn.cloud.commons.mapper.BatchMapper;
import com.patzn.cloud.service.hmhj.entity.EntrustSampleItemIndex;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleItemIndexVO;
import com.patzn.cloud.service.hmhj.vo.SampleItemVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
import java.util.List;
import java.util.Map;
/**
* <p>
......@@ -16,22 +16,65 @@ import java.util.List;
* </p>
*
* @author wwd
* @since 2021-06-15
* @since 2021 -06-15
*/
public interface EntrustSampleItemIndexMapper extends BatchMapper<EntrustSampleItemIndex> {
/**
* List item by sample ids list.
*
* @param sampleIds the sample ids
* @return the list
*/
List<EntrustSampleItemIndex> listItemBySampleIds(@Param("sampleIds") List<Long> sampleIds);
/**
* List vo by exp ids list.
*
* @param expIdsList the exp ids list
* @return the list
*/
List<EntrustSampleItemIndexVO> listVOByExpIds(@Param("expIds") List<Long> expIdsList);
/**
* List by sample ids list.
*
* @param sampleIdList the sample id list
* @return the list
*/
List<EntrustSampleItemIndexVO> listBySampleIds(@Param("sampleIds") List<Long> sampleIdList);
/**
* Gets in report item index.
*
* @param sampleId the sample id
* @return the in report item index
*/
@SqlParser(filter = true)
List<EntrustSampleItemIndex> getInReportItemIndex(@Param("sampleId") Long sampleId);
/**
* Select index with item list.
*
* @param rowBounds the row bounds
* @param entrustSampleItemIndexVO the entrust sample item index vo
* @return the list
*/
List<EntrustSampleItemIndexVO> selectIndexWithItem(RowBounds rowBounds, @Param("vo") EntrustSampleItemIndexVO entrustSampleItemIndexVO);
List<SampleItemVO> selectSampleItemIndex(@Param("sampleIds") List<Long> sampleIds);
/**
* Select sample item index list.
*
* @param sampleIds the sample ids
* @return the list
*/
List<Map<String, Object>> selectSampleItemIndex(@Param("sampleIds") List<Long> sampleIds);
/**
* Physical delete by item ids integer.
*
* @param itemIds the item ids
* @return the integer
*/
Integer physicalDeleteByItemIds(@Param("itemIds") List<Long> itemIds);
}
......@@ -4,9 +4,9 @@ import com.baomidou.mybatisplus.plugins.Page;
import com.patzn.cloud.commons.service.IBaseService;
import com.patzn.cloud.service.hmhj.entity.EntrustSampleItemIndex;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleItemIndexVO;
import com.patzn.cloud.service.hmhj.vo.SampleItemVO;
import java.util.List;
import java.util.Map;
/**
* 服务类
......@@ -39,7 +39,7 @@ public interface IEntrustSampleItemIndexService extends IBaseService<EntrustSamp
Page<EntrustSampleItemIndexVO> pageIndexWithItem(Page<EntrustSampleItemIndexVO> page, EntrustSampleItemIndexVO entrustSampleItemIndexVO);
List<SampleItemVO> listSampleItemIndex(List<Long> sampleIds);
List<Map<String,Object>> listSampleItemIndex(List<Long> sampleIds);
boolean physicalDeleteByItemIds(List<Long> itemIds);
}
......@@ -10,7 +10,6 @@ import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import com.patzn.cloud.service.hmhj.entity.EntrustSampleItem;
import com.patzn.cloud.service.hmhj.entity.EntrustSampleItemIndex;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleItemIndexVO;
import com.patzn.cloud.service.hmhj.vo.SampleItemVO;
import com.patzn.cloud.service.lims.common.BeanUtils;
import com.patzn.cloud.service.lims.hmhj.mapper.EntrustSampleItemIndexMapper;
import com.patzn.cloud.service.lims.hmhj.service.IEntrustSampleItemIndexService;
......@@ -20,6 +19,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 服务实现类
......@@ -47,7 +47,7 @@ public class EntrustSampleItemIndexServiceImpl extends BaseServiceImpl<EntrustSa
}
@Override
public List<SampleItemVO> listSampleItemIndex(List<Long> sampleIds) {
public List<Map<String,Object>> listSampleItemIndex(List<Long> sampleIds) {
if (CollectionUtils.isEmpty(sampleIds)) {
return new ArrayList<>();
}
......
......@@ -33,7 +33,6 @@ import com.patzn.cloud.service.lims.base.enums.FlowTypeEnum;
import com.patzn.cloud.service.lims.base.vo.LmsUserRelGroupVO;
import com.patzn.cloud.service.lims.collection.entity.LmsOriginalRecordInfo;
import com.patzn.cloud.service.lims.common.CompareUtils;
import com.patzn.cloud.service.lims.common.RedisUtil;
import com.patzn.cloud.service.lims.common.StringHandleUtils;
import com.patzn.cloud.service.lims.common.service.IExportService;
import com.patzn.cloud.service.lims.hmhj.common.HSSFWorkbookUtil;
......@@ -1408,9 +1407,11 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
handleSampleBrand(ids, finalSampleBrandMap, true);
});
// 针对铝成品和原铝进行发送ERP数据处理
logger.error("{}开始执行发送ERP请求;", DateUtils.toYearMonthDayTime(new Date()));
sendTestDataToErp(Arrays.asList(ids));
executor1.execute(() -> {
// 针对铝成品和原铝进行发送ERP数据处理
logger.error("{}开始执行发送ERP请求:---->ERP---", DateUtils.toYearMonthDayTime(new Date()));
sendTestDataToErp(Arrays.asList(ids));
});
logger.error("======================质量判定结束========================");
return true;
......@@ -1436,80 +1437,35 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
return;
}
// 获取检测项目指标数据
List<SampleItemVO> dataList = entrustSampleItemIndexService.listSampleItemIndex(ids);
List<Map<String, Object>> dataList = entrustSampleItemIndexService.listSampleItemIndex(ids);
logger.error("====>ERP====:获取项目和指标数据:{}", JSONArray.toJSON(dataList));
String suffix = sampleName + ids.get(0) + dataList.size();
// 通信
String sampleConnectKey = "SAMPLE_CONNECT_COUNT_KEY" + suffix;
try {
logger.error("{}=====>===:将要发送ERP数据;", DateUtils.toYearMonthDayTime(new Date()));
doSendErpData(ids, dataList);
doSendErpData(dataList);
} catch (Exception e) {
logger.error(e.getMessage());
logger.error("{}:发送ERP请求失败,请稍后重试!", DateUtils.toYearMonthDayTime(new Date()));
try {
logger.error("{}====>ERP===:处理失败的数据", DateUtils.toYearMonthDayTime(new Date()));
dealFailureRequest(ids, dataList, sampleConnectKey);
} catch (Exception ex) {
logger.error("{}:重试后失败,发送结束。错误内容:", DateUtils.toYearMonthDayTime(new Date()), ex.getMessage());
}
}
}
private void doSendErpData(List<Long> ids, List<SampleItemVO> dataList) {
private void doSendErpData(List<Map<String, Object>> dataList) {
logger.error("{}====>ERP==== 开始发送中....");
String result = OkHttpUtils.sendByPostJson(HttpConst.ERP_URL, HttpConst.ERP_TOKEN, JacksonUtils.toJSONString(dataList));
logger.error("======>ERP====>result:" + result);
if (StringUtils.isNotBlank(result)) {
JSONObject jsonObject = JSON.parseObject(result);
logger.error("======<ERP>====" + jsonObject.toJSONString());
// 若成功 ,则更新标识
if (Objects.equals(jsonObject.getString("code"), "1") && Objects.equals(jsonObject.getBoolean("success"), true)) {
logger.error("{}:====>ERP===>Result===>data,更新本地库是否发送标识!");
entrustSampleService.update(new EntrustSample().setSendErp(1), Condition.create().in("ids", ids));
} else {
logger.error("{}:响应失败:{}", DateUtils.toYearMonthDayTime(new Date()), StringHandleUtils.parse(jsonObject.getString("msg")));
}
}
}
private void dealFailureRequest(List<Long> ids, List<SampleItemVO> dataList, String sampleFlagKey) throws InterruptedException {
Integer retryCount = 0;
//
logger.error("====>ERP===:开始处理失败的数据!");
String retryCountStr = RedisUtil.StringOps.get(sampleFlagKey);
String sampleFailureIdsKey = "SAMPLE_FAILURE_IDS_KEY";
logger.error("====>ERP====:获取重试次数:" + retryCountStr);
if (Objects.isNull(retryCountStr) || (retryCount = Integer.parseInt(retryCountStr)) < 4) {
logger.error("====>ERP===:满足重试机制限制数量!");
RedisUtil.StringOps.set(sampleFlagKey, retryCount + 1 + "");
Thread.sleep(10000);
executor1.execute(() -> {
logger.error("{} =====>==== 另开线程:再次执行发送操作!", DateUtils.toYearMonthDayTime(new Date()));
doSendErpData(ids, dataList);
});
logger.error("{}:处理之前发送失败的请求:{},嘀嘀嘀!", DateUtils.toYearMonthDayTime(new Date()), sampleFailureIdsKey);
// 对于那些已经失败的请求,重试
if (RedisUtil.KeyOps.hasKey(sampleFailureIdsKey)) {
List<String> idList = RedisUtil.ListOps.lWholeList(sampleFailureIdsKey);
logger.error("{}:处理之前发送失败的请求,获取IDS:{}", DateUtils.toYearMonthDayTime(new Date()), idList.toString());
RedisUtil.KeyOps.delete(sampleFailureIdsKey);
if (CollectionUtils.isNotEmpty(idList)) {
logger.error("失败的请求不为空,继续处理数据;");
List<Long> sampleIds = idList.stream().map(Long::parseLong).collect(Collectors.toList());
Thread.sleep(5000);
executor1.execute(() -> {
logger.error("{} =====>==== 另开线程:处理之前的数据进行发送操作!", DateUtils.toYearMonthDayTime(new Date()));
doSendErpData(ids, dataList);
});
dataList.forEach(t -> {
String result = OkHttpUtils.sendByPostJson(HttpConst.ERP_URL, HttpConst.ERP_TOKEN, JacksonUtils.toJSONString(t));
logger.error("======>ERP====>result:" + result);
if (StringUtils.isNotBlank(result)) {
JSONObject jsonObject = JSON.parseObject(result);
logger.error("======<ERP>====" + jsonObject.toJSONString());
// 若成功 ,则更新标识
if (Objects.equals(jsonObject.getString("code"), "1") && Objects.equals(jsonObject.getBoolean("success"), true)) {
logger.error("{}:====>ERP===>Result===>data,更新本地库是否发送标识!");
entrustSampleService.update(new EntrustSample().setSendErp(1), Condition.create().eq("code", t.get("sample_code")));
} else {
logger.error("{}:响应失败:{}", DateUtils.toYearMonthDayTime(new Date()), StringHandleUtils.parse(jsonObject.getString("msg")));
}
}
} else {
logger.error("{}:发送请求失败,系统自动记录失败样品ID:{}", DateUtils.toYearMonthDayTime(new Date()), StringUtils.join(ids, ","));
// 只对此失败的任务在下次判定时,连带重试一次
RedisUtil.ListOps.lLeftPushAll(sampleFailureIdsKey, ids.toArray(new String[ids.size()]));
}
});
}
@Override
......
......@@ -89,24 +89,24 @@
</if>
</select>
<select id="selectSampleItemIndex" resultType="com.patzn.cloud.service.hmhj.vo.SampleItemVO">
<select id="selectSampleItemIndex" resultType="java.util.Map">
SELECT
s.NAME "sample_name",
s.code "sample_code",
max(s.sample_grading) "brand",
max(i.test_time) "test_time",
to_char(max(i.test_time),'YYYY-MM-DD HH24:MI:SS') "test_time",
max(r.report_checker) "report_checker",
max(r.report_issuer) "report_issuer",
max(r.quality_inspector) "quality_inspector",
max(case when ii.name = '原铝Fe' then ii.test_value else null end) "fe",
max(case when ii.name = '原铝Si' then ii.test_value else null end) "si",
max(case when ii.name = '原铝Cu' then ii.test_value else null end) "cu",
max(case when ii.name = '原铝Ga' then ii.test_value else null end) "ga",
max(case when ii.name = '原铝Mg' then ii.test_value else null end) "mg",
max(case when ii.name = '原铝Zn' then ii.test_value else null end) "zn",
max(case when ii.name = '原铝Mn' then ii.test_value else null end) "mn",
max(case when ii.name = '原铝Ni' then ii.test_value else null end) "ni",
max(case when ii.name = '原铝V' then ii.test_value else null end) "v"
max(case when ii.name = '原铝Fe' then trim(ii.test_value) else null end) "fe",
max(case when ii.name = '原铝Si' then trim(ii.test_value) else null end) "si",
max(case when ii.name = '原铝Cu' then trim(ii.test_value) else null end) "cu",
max(case when ii.name = '原铝Ga' then trim(ii.test_value) else null end) "ga",
max(case when ii.name = '原铝Mg' then trim(ii.test_value) else null end) "mg",
max(case when ii.name = '原铝Zn' then trim(ii.test_value) else null end) "zn",
max(case when ii.name = '原铝Mn' then trim(ii.test_value) else null end) "mn",
max(case when ii.name = '原铝Ni' then trim(ii.test_value) else null end) "ni",
max(case when ii.name = '原铝V' then trim(ii.test_value) else null end) "v"
FROM
entrust_sample_item_index ii
JOIN entrust_sample_item i ON i.ID = ii.entrust_sample_item_id AND i.deleted = 0
......
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