package com.changhong.epc.parsing.service.mq;
|
|
import com.changhong.epc.bean.form.FormDataEntity;
|
import com.changhong.epc.constter.base.BaseConst;
|
import com.changhong.epc.constter.base.Context;
|
import com.changhong.epc.constter.system.DataSourceKey;
|
import com.changhong.epc.parsing.mapper.centen.AutoIDMapper;
|
import com.changhong.epc.parsing.service.util.IFromOperate;
|
import com.iemsoft.framework.cloud.core.thread.Keys;
|
import com.iemsoft.framework.cloud.core.thread.ThreadData;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.math.NumberUtils;
|
import org.springframework.data.redis.connection.Message;
|
import org.springframework.data.redis.connection.MessageListener;
|
import org.springframework.stereotype.Component;
|
import org.springframework.ui.ModelMap;
|
|
import javax.annotation.Resource;
|
import java.util.Map;
|
import java.util.Objects;
|
|
@Component
|
@Slf4j
|
public class AutoFormConsumer implements MessageListener, DataSourceKey {
|
|
@Resource
|
private IFromOperate fromOperate;
|
|
@Resource
|
private AutoIDMapper autoIDMapper;
|
|
@Override
|
public void onMessage(Message message, byte[] pattern) {
|
ThreadData.set(BaseConst.DATA_SOURCE, ADMIN_DATA_SOURCE);
|
Context.MQParam<Map<String, Object>> param = ObjectUtil.byteToObject(message.getBody(), Context.MQParam.class);
|
ThreadData.set(BaseConst.TENANT_ID, param.getTenantId());
|
ThreadData.set(BaseConst.COMPANY_ID, NumberUtils.createInteger(param.getCompanyId()));
|
ThreadData.set(BaseConst.OPEN_ID, param.getOpenId());
|
ThreadData.set(Keys.USER_ID, param.getOpenId());
|
FormDataEntity formDataEntity = new FormDataEntity();
|
formDataEntity.setFormId(Objects.toString(param.getData().get("formID")));
|
formDataEntity.setTenantId(param.getTenantId());
|
formDataEntity.setDataRowNum(NumberUtils.createInteger(Objects.toString(param.getData().get("id"))));
|
formDataEntity.setMap(
|
new ModelMap(
|
Objects.toString(param.getData().get("field"))
|
, getNumber(Objects.toString(param.getData().get("fieldKey"))
|
, NumberUtils.toInt(Objects.toString(param.getData().get("fieldSize")))
|
, formDataEntity.getDataRowNum()
|
)
|
)
|
);
|
log.debug("回写序列编号租户:{}, 公司:{}, 表单:{}, 主键:{}, 内容:{}"
|
, param.getTenantId(), param.getCompanyId(), formDataEntity.getFormId(), formDataEntity.getDataRowNum(), JSONTool.toJson(formDataEntity.getMap()));
|
fromOperate.updateFormData(formDataEntity);
|
}
|
|
private String getNumber(String fieldKey, Integer size, Integer dataRowNum) {
|
// Long val = redisTemplate.opsForValue().increment(fieldKey, 1);
|
Integer val = autoIDMapper.getAutoID(fieldKey);
|
return String.format("%s%0"+size+"d", fieldKey, val);
|
}
|
|
}
|