package com.changhong.epc.admin.service.mq; import com.changhong.epc.admin.mapper.centen.AutoIDMapper; 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.constter.system.run.EpcRestInterface; import com.iemsoft.framework.cloud.core.base.ResMsg; import com.iemsoft.framework.cloud.core.thread.Keys; import com.iemsoft.framework.cloud.core.thread.ThreadData; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import com.iemsoft.framework.cloud.ribbon.RestInterface; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.data.redis.connection.Message; import org.springframework.data.redis.connection.MessageListener; import org.springframework.ui.ModelMap; import javax.annotation.Resource; import java.util.Map; import java.util.Objects; import static com.changhong.epc.constter.form.utf.FormUrlConst.FORM_DATA_UPDATFORM; import static com.changhong.epc.constter.system.SystemClients.SERVER_FORM; //@Component public class AutoFormConsumer implements MessageListener, DataSourceKey { @Resource private AutoIDMapper autoIDMapper; @Override public void onMessage(Message message, byte[] pattern) { ThreadData.set(BaseConst.DATA_SOURCE, ADMIN_DATA_SOURCE); Context.MQParam> 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() ) ) ); getFromRest(FORM_DATA_UPDATFORM, formDataEntity); } public Object getFromRest(String fs, Object parm) { RestInterface restInterface = SpringUtil.getBean(SERVER_FORM.getBeanName(), RestInterface.class); Object data = restInterface.post(fs, parm, ResMsg.class, EpcRestInterface.getEpcHeads()).getData(); return data; } 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); } }