zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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<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()
                        )
                )
        );
        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);
    }
 
}