package cn.com.goldenwater.dcproj.service.impl.meeting; import cn.com.goldenwater.dcproj.constValue.SmsCodeEnum; import cn.com.goldenwater.dcproj.dao.AttMeetingListDao; import cn.com.goldenwater.dcproj.dao.BisInspAllRlationPersDao; import cn.com.goldenwater.dcproj.dao.DdMessageDao; import cn.com.goldenwater.dcproj.model.AttMeetingList; import cn.com.goldenwater.dcproj.model.BisInspAllRlationPers; import cn.com.goldenwater.dcproj.model.DdMessage; import cn.com.goldenwater.dcproj.param.AttMeetingListParam; import cn.com.goldenwater.dcproj.param.BisInspAllRlationPersParam; import cn.com.goldenwater.dcproj.service.AttMeetingListService; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.utils.HttpClientUtils; import cn.com.goldenwater.id.util.UuidUtil; import com.github.pagehelper.PageHelper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.concurrent.TimeUnit; /** * @author lune * @date 2019-7-9 */ @Service @Transactional(rollbackFor = Exception.class) public class AttMeetingListServiceImpl extends AbstractCrudService implements AttMeetingListService { @Autowired private AttMeetingListDao attMeetingListDao; public AttMeetingListServiceImpl(AttMeetingListDao attMeetingListDao) { super(attMeetingListDao); this.attMeetingListDao = attMeetingListDao; } private static String apiKey = "1036432406699048960"; private static String apiSecrect = "bbSsX1wvmaKdca5x2+yBDgeFtl9hj4zJmnegunWuLuHLwLo+QjxOr3//P4BJNrVADa7tN4w0DX1KS/VSec5G0x+ucDeAcSt9tWgFGyoBVtblybh+vzLbwH4sJa92hQfu\n"; @Autowired private BisInspAllRlationPersDao bisInspAllRlationPersDao; @Autowired private RedisTemplate redisTemplate; @Override public String sendMessage(String persName, String phone) throws Exception { AttMeetingListParam attMeetingListParam = new AttMeetingListParam(); attMeetingListParam.setName(persName); List list = attMeetingListDao.findList(attMeetingListParam); if (null != list && list.size() > 0) { String oldCode = (String) redisTemplate.opsForValue().get(phone); if (StringUtils.isNotBlank(oldCode)) { return SmsCodeEnum.ERROR.getKey(); } String apiUrl = "http://10.1.198.101/gateway/api/sms/send"; Map params = new HashMap(); Random rand = new Random(); int num = rand.nextInt(900000) + 100000; String code = num + ""; params.put("apiKey", apiKey); params.put("apiSecrect", apiSecrect); params.put("templateParam", "{\"code\":\"" + code + "\"}"); params.put("signName", "金水云平台"); params.put("templeteCode", "SMS_177545278"); params.put("mobile", phone); String content = HttpClientUtils.simplePostInvoke(apiUrl+"/gateway/api/sms/send", params); redisTemplate.opsForValue().set(phone, code, 5L, TimeUnit.MINUTES); return SmsCodeEnum.SUCCESS.getKey(); } return SmsCodeEnum.NO_USER.getKey(); } @Override public AttMeetingList getAttmeetingList(String phone, String code, String meetingId) { String oldCode = (String) redisTemplate.opsForValue().get(phone); if (StringUtils.isNotBlank(code) && code.equals(oldCode)) { AttMeetingListParam attMeetingListParam = new AttMeetingListParam(); attMeetingListParam.setMeetingId(meetingId); attMeetingListParam.setMbleNum(phone); AttMeetingList attMeetingList = attMeetingListDao.getBy(attMeetingListParam); if (attMeetingList != null) { attMeetingList.setSignState("1"); attMeetingList.setUptm(new Date()); attMeetingList.setSignTm(new Date()); attMeetingListDao.update(attMeetingList); } else { BisInspAllRlationPersParam inspAllRlationPersParam = new BisInspAllRlationPersParam(); inspAllRlationPersParam.setMobilenumb(phone); BisInspAllRlationPers allRlationPers = bisInspAllRlationPersDao.getBy(inspAllRlationPersParam); attMeetingList = addAttMeetingList(allRlationPers, meetingId, "1"); } return attMeetingList; } return null; } @Override public AttMeetingList addAttMeetingList(BisInspAllRlationPers allRlationPers, String meetingId, String state) { AttMeetingList attMeetingList = new AttMeetingList(); attMeetingList.setId(UuidUtil.uuid()); attMeetingList.setIntm(new Date()); attMeetingList.setMbleNum(allRlationPers.getMobilenumb()); attMeetingList.setName(allRlationPers.getPersName()); attMeetingList.setSignTm(new Date()); attMeetingList.setSignState(state); attMeetingList.setSex(allRlationPers.getSex()); attMeetingList.setMeetingId(meetingId); attMeetingList.setUnit(allRlationPers.getOrgNm()); attMeetingList.setUptm(new Date()); attMeetingListDao.insert(attMeetingList); return attMeetingList; } @Override public boolean getAttmeeting(String persName, String phone, String code) { String oldCode = (String) redisTemplate.opsForValue().get(phone); if (StringUtils.isNotBlank(code) && code.equals(oldCode)) { return true; } return false; } }