package com.qxueyou.scc.user.service.impl;
|
|
import java.io.File;
|
//import java.lang.reflect.InvocationTargetException;
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.apache.commons.beanutils.BeanUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
//import org.hibernate.exception.ConstraintViolationException;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
//import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.stereotype.Service;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.qxueyou.scc.admin.classes.model.ClsClass;
|
import com.qxueyou.scc.base.model.Constants;
|
import com.qxueyou.scc.base.model.FilePathConstants;
|
//import com.qxueyou.scc.base.model.ONSMsg;
|
import com.qxueyou.scc.base.model.Result;
|
//import com.qxueyou.scc.base.service.ICacheService;
|
import com.qxueyou.scc.base.service.IFileUploadService;
|
//import com.qxueyou.scc.base.service.IWeixinService;
|
import com.qxueyou.scc.base.service.impl.CommonAppService;
|
//import com.qxueyou.scc.base.service.impl.CommonONSProducer;
|
import com.qxueyou.scc.base.util.ClientUtils;
|
import com.qxueyou.scc.base.util.CollectionUtils;
|
import com.qxueyou.scc.base.util.NumRandomUtils;
|
import com.qxueyou.scc.base.util.RSAUtils;
|
import com.qxueyou.scc.base.util.TraceUtils;
|
import com.qxueyou.scc.base.util.UUIDUtils;
|
import com.qxueyou.scc.config.SccConfig;
|
//import com.qxueyou.scc.financial.service.ITransFlowService;
|
import com.qxueyou.scc.msg.model.MsgFriend;
|
import com.qxueyou.scc.msg.model.MsgGroup;
|
import com.qxueyou.scc.msg.model.MsgGroupUserRe;
|
import com.qxueyou.scc.msg.model.MsgUser;
|
//import com.qxueyou.scc.msg.service.IMessageSettingService;
|
//import com.qxueyou.scc.msg.service.IMsgVenderService;
|
import com.qxueyou.scc.notice.model.Notice;
|
import com.qxueyou.scc.org.model.OrgClassUserCustom;
|
import com.qxueyou.scc.org.model.OrgStudent;
|
import com.qxueyou.scc.school.model.SchRank;
|
//import com.qxueyou.scc.school.service.IScheduleService;
|
import com.qxueyou.scc.sms.model.SmsConfig;
|
import com.qxueyou.scc.sms.model.SmsContants;
|
//import com.qxueyou.scc.sms.service.ISMSService;
|
import com.qxueyou.scc.sms.utils.SmsUtils;
|
import com.qxueyou.scc.sys.model.ResponseResult;
|
import com.qxueyou.scc.sys.model.SysConfig;
|
import com.qxueyou.scc.sys.model.SysFileUploadTrace;
|
import com.qxueyou.scc.sys.model.SysLog;
|
import com.qxueyou.scc.sys.service.ISysLogService;
|
import com.qxueyou.scc.user.dao.RegistrationDAO;
|
import com.qxueyou.scc.user.model.ExportUserRegistration;
|
import com.qxueyou.scc.user.model.User;
|
import com.qxueyou.scc.user.model.UserExtend;
|
import com.qxueyou.scc.user.model.UserRegistration;
|
import com.qxueyou.scc.user.model.UserRegistrationCustom;
|
import com.qxueyou.scc.user.model.UserStudent;
|
import com.qxueyou.scc.user.service.IUserRegistrationService;
|
import com.qxueyou.scc.user.service.IUserService;
|
import com.qxueyou.scc.user.util.ExcelReader;
|
|
@Service
|
@EnableConfigurationProperties(SccConfig.class)
|
public class UserRegistrationService extends CommonAppService implements IUserRegistrationService {
|
|
private static final String SOURCE = "source";
|
|
private static final String ADD_REG_CLASS_IDS = "addRegClassIds";
|
|
private static final String IMG_PATH = "imgPath";
|
|
private static final String USER_NAME = "userName";
|
|
private static final String MOBILE_PHONE = "mobilePhone";
|
|
private static final String PASSWORD = "password";
|
|
private static final String USER_ID = "userId";
|
|
private static final String CLASS_ID = "classId";
|
|
private static final String REG_ID = "regId";
|
|
|
@Autowired
|
SccConfig sccConfig;
|
|
@Autowired
|
IUserService userService;
|
|
@Autowired
|
private ISysLogService sysLogService;
|
|
|
@Autowired
|
IFileUploadService fileUploadService;
|
|
private final Logger log = LogManager.getLogger("UserRegistrationService");
|
|
private RegistrationDAO registrationDAO;
|
|
public RegistrationDAO getRegistrationDAO() {
|
return registrationDAO;
|
}
|
|
/**
|
* ÒÀÀµ×¢Èë
|
*
|
* @param registrationDAO
|
*/
|
@Autowired(required = false)
|
public void setRegistrationDAO(@Qualifier("registrationDAO") RegistrationDAO registrationDAO) {
|
this.registrationDAO = registrationDAO;
|
}
|
|
|
|
/*
|
* (non-Javadoc)
|
*
|
* @see com.qxueyou.scc.user.service.IUserRegistrationService#addRegistration(javax.servlet.Registration)
|
*/
|
@Override
|
public Result insertRegistration(UserRegistration reg,String source) {
|
|
return insertRegistration(reg, true, source, null);
|
}
|
|
/**
|
* ÐÂÔö±¨Ãû
|
*
|
* @param reg
|
* @param companyName
|
* @return
|
*/
|
public Result insertRegistration(UserRegistration reg, String companyName, String source ) {
|
// ´´½¨Óû§
|
User user = getUser(reg, true, companyName, source);
|
// ¸üÐÂuser_name
|
user.setName(reg.getUserName());
|
|
// userService.saveUserTrace(user, false, null);
|
|
|
// ´´½¨×¢²áÐÅÏ¢
|
TraceUtils.setCreateTrace(reg);
|
reg.setDeleteFlag(false);
|
reg.setStatus(UserRegistration.STATUS_DEACTIVE);
|
reg.setUserId(user.getUserId());
|
reg.setUserName(user.getName());
|
reg.setRegistrationTime(new Date());
|
|
// ÉèÖÿÆÄ¿ÐÅÏ¢
|
ClsClass cls = read(ClsClass.class, reg.getClassId());
|
cls.setStudentCount(cls.getStudentCount()+1);
|
TraceUtils.setUpdateTrace(cls);
|
save(cls);
|
|
reg.setCollegeCourseId(cls.getCollegeCourseId());
|
|
return save(reg);
|
}
|
|
private User getUser(UserRegistration reg, boolean male, String companyName, String source ) {
|
|
// ¼ì²éÓû§±í´ËÓû§ÊÇ·ñ´æÔÚ
|
String hql = "from User where deleteFlag is false and mobilePhone = ? ";
|
|
List<User> lstUser = this.find(hql, CollectionUtils.newList(reg.getMobilePhone()), User.class);
|
|
if (!lstUser.isEmpty()) {
|
return lstUser.get(0);
|
}
|
|
User u = new User();
|
|
TraceUtils.setCreateTrace(u);
|
u.setDeleteFlag(false);
|
|
u.setAccount(this.doGetNewQxyAccount());
|
u.setImgPath(FilePathConstants.getUserDefaultImg());
|
u.setMobilePhone(reg.getMobilePhone());
|
u.setName(reg.getUserName());
|
u.setPassword(RSAUtils.encrypt(NumRandomUtils.randomSixNum()));
|
|
return u;
|
}
|
|
/*
|
* (non-Javadoc)
|
*
|
* @see com.qxueyou.scc.user.service.IUserRegistrationService#addRegistration(javax.servlet.Registration)
|
*/
|
@Override
|
public Result insertRegistration(UserRegistration reg, boolean male, String source, String signupInfo) {
|
|
// ´´½¨Óû§
|
User user = getUser(reg, male, null,source);
|
// ¸üÐÂuser_name
|
user.setName(reg.getUserName());
|
// userService.saveUserTrace(user, false, null);
|
|
// ´´½¨×¢²áÐÅÏ¢
|
TraceUtils.setCreateTrace(reg);
|
reg.setDeleteFlag(false);
|
reg.setStatus(UserRegistration.STATUS_DEACTIVE);
|
reg.setUserId(user.getUserId());
|
reg.setUserName(user.getName());
|
reg.setRegistrationTime(new Date());
|
// ¸üа༶³ÉÔ±
|
this.updateStudentCount(reg.getClassId(), 1, 1);
|
|
// ÉèÖÿÆÄ¿ÐÅÏ¢
|
ClsClass cls = read(ClsClass.class, reg.getClassId());
|
reg.setCollegeCourseId(cls.getCollegeCourseId());
|
|
save(reg);
|
|
//×Ô¶¨ÒåÐÅÏ¢
|
insertCustomInfo(reg.getRegistrationId(), user.getUserId(), cls.getClassId(), signupInfo);
|
// ±£´æÑ§Ô±µÄ²Ù×÷¼Ç¼
|
this.doInsertRegLog("ÐÂÔöѧԱ", reg.getRegistrationId(), reg.getMobilePhone() );
|
|
return new Result(true, reg.getRegistrationId());
|
}
|
|
public Result doInsertRegLog(String operator,String regId,String mobile ){
|
|
SysLog lg = new SysLog();
|
|
TraceUtils.setCreateActiveTrace(lg);
|
lg.setDeleteFlag(false);
|
lg.setContent(operator + ":" + regId );
|
lg.setDesp(mobile);
|
lg.setModule("USER-REGISTRATION");
|
lg.setType(SysLog.LOG_TYPE_BUSINESS);
|
|
|
if( null != ClientUtils.getUserInfo()){
|
lg.setUserId(ClientUtils.getUserId());
|
lg.setUserName(ClientUtils.getUserName());
|
}else{
|
lg.setUserId("admin");
|
lg.setUserName("admin");
|
}
|
|
save(lg);
|
|
return new Result(true);
|
|
}
|
|
/*
|
* (non-Javadoc)
|
*
|
* @see com.qxueyou.scc.user.service.IUserRegistrationService#deleteRegistrations(java.lang.String[])
|
*/
|
@Override
|
public Result deleteRegistrations(String[] regIds) {
|
|
String firstRegId = null ;
|
|
String arrId[] = new String[regIds.length];
|
StringBuffer strArrId = new StringBuffer(150);
|
int index = 0 ;
|
for (String regId : regIds) {
|
firstRegId = regId ;
|
Result result = deleteRegistration(regId);
|
|
arrId[index] = result.getMsg() ;
|
strArrId.append(arrId[index]).append('|');
|
index++;
|
|
}
|
|
|
UserRegistration ur = this.read(UserRegistration.class, firstRegId);
|
this.updateStudentCount(ur.getClassId(), regIds.length, 2);
|
|
bulkUpdateInLoop("update OrgStudent set deleteFlag = true where classId ='" + ur.getClassId() + "' and userId = ? ", arrId);
|
|
//ͬ²½»·ÐŲÙ×÷
|
Map<String,String> params = new HashMap<String,String>();
|
params.put("userIds", strArrId.toString());
|
params.put(CLASS_ID, ur.getClassId());
|
sendMsgActiveMsg(params,2);
|
|
return new Result(true);
|
|
}
|
/**
|
* ɾ³ý×¢²áÐÅÏ¢
|
*
|
* @param regId
|
* @return
|
*/
|
public Result deleteRegistration(String regId) {
|
|
UserRegistration reg = read(UserRegistration.class, regId);
|
|
reg.setDeleteFlag(true);
|
|
save(reg);
|
|
//¼Ç¼ѧԱ²Ù×÷¼Ç¼
|
this.doInsertRegLog("ɾ³ýѧԱ", reg.getRegistrationId(), reg.getMobilePhone() );
|
|
return new Result(true,reg.getUserId());
|
}
|
|
/*
|
* (non-Javadoc)
|
*
|
* @see com.qxueyou.scc.user.service.IUserRegistrationService#doActiveRegistrations(java.lang.String[])
|
*/
|
@SuppressWarnings("unchecked")
|
@Override
|
public Result doActiveRegistrations(String[] regIds,boolean smsFlag,Map<String,String> passwordMap) {
|
|
List<Map<String,String>> lst = new ArrayList<Map<String,String>>(regIds.length);
|
|
// Çå³ý»º´æ
|
clearCache();
|
|
for (String regId : regIds) {
|
Result objResult = doActiveRegistration(regId,smsFlag,passwordMap.get(regId));
|
if (!objResult.isSuccess()) {
|
return objResult;
|
}
|
|
if(null != objResult.getData("regActMap")){
|
lst.add((Map<String,String>)objResult.getData("regActMap"));
|
}
|
|
}
|
|
// ·ÅÔÚÊÂÎñ×îĩβ
|
for(Map<String,String> map : lst ){
|
sendMsgActiveMsg(map,1);
|
}
|
|
return new Result(true);
|
}
|
|
/**
|
* ¼¤»î×¢²áÓû§ÐÅÏ¢
|
*
|
* @param regId
|
* @return
|
*/
|
private Result doActiveRegistration(String regId,boolean smsFlag,String password) {
|
|
UserRegistration reg = read(UserRegistration.class, regId);
|
if(reg==null||reg.getStatus()==UserRegistration.STATUS_ACTIVE){
|
return new Result(true);
|
}
|
|
//ÅжÏÕ˺ŠÊÇ·ñ¿ÉÒÔ¼¤»î
|
Result objResult = doAccountSwitchCheck(reg);
|
if (!objResult.isSuccess()) {
|
return objResult;
|
}
|
|
reg.setStatus(UserRegistration.STATUS_ACTIVE);
|
if(null == reg.getActivationTime()){
|
reg.setActivationTime(new Date());
|
}
|
// Ìí¼Ó MsgUser
|
MsgUser msgUser = addMsgUser(reg);
|
|
// Ìí¼Ó Student
|
Result result = addStudent(reg);
|
|
// Ìí¼Óorg_student
|
addOrgStudent(reg, result.getData("studentId").toString());
|
|
// Ìí¼ÓºÃÓÑ: °à¼¶Í¨Öª£¬Ñ§Ð£Í¨Öª
|
addFridends(msgUser);
|
|
// ¼¤»îÇ©µ½±íµÄÊÇ·ñ°à¼¶³ÉԱ״̬
|
bulkUpdateInLoop("update SchSignStatistics set registeFlag = true where userId = ?", new Object[] { reg.getUserId() });
|
|
// Ìí¼Ó ÅÅÃû¼Ç¼
|
addRank(reg);
|
|
//·¢ËͶÌÐÅ
|
doSendRegActivityMsg(smsFlag,reg,password);
|
|
// ±£´æÑ§Ô±µÄ²Ù×÷¼Ç¼
|
doInsertRegLog("¼¤»îѧԱ", reg.getRegistrationId().concat(objResult.getMsg()), reg.getMobilePhone() );
|
|
// Òì²½´¦Àí¼¤»îѧԱËùÐèÒªµÄ²Ù×÷
|
result = new Result(true);
|
result.addData("regActMap", CollectionUtils.newStringMap(
|
USER_ID,msgUser.getUserId(),
|
PASSWORD,msgUser.getPassword(),
|
CLASS_ID,reg.getClassId(),
|
REG_ID,reg.getRegistrationId()
|
));
|
|
return result;
|
|
}
|
|
/**
|
* ¼¤»î·¢ËͶÌÐÅ
|
* @param smsFlag
|
* @param reg
|
*/
|
@SuppressWarnings("unused")
|
private void doSendRegActivityMsg(boolean smsFlag,UserRegistration reg,String password){
|
|
if(ClientUtils.getUserInfo()==null){
|
return;
|
}
|
|
if(smsFlag){
|
//×î½ü90ÌìÄÚÊÇ·ñµÇÈë¹ýϵͳ£¬Èç¹ûµÇÈë¹ýÔò²»·¢ËÍÃÜÂë
|
String isLoginHql = "select count(1) from UserOperate o where o.userId = ? and (to_days(sysdate()) - to_days(o.lastLoginTime)) <= 90";
|
int isLogin = this.findCount(isLoginHql, CollectionUtils.newList(reg.getUserId()));
|
String hql = " from SmsConfig where topOrgId = ? and module = ?";
|
SmsConfig config = findUnique(hql, CollectionUtils.newList(ClientUtils.getTopOrgId(),SmsConfig.REG_ACTIVITY_MODULE), SmsConfig.class);
|
String className = reg.getOrgClass().getName().replaceAll("¡¾", "[").replaceAll("¡¿", "]");
|
String userName = reg.getUserName().replaceAll("¡¾", "[").replaceAll("¡¿", "]");
|
}
|
}
|
|
/**
|
* ¼ì²âÊÇ·ñÄܼ¤»îѧԱ,²é¿´°à¼¶ÊÇ·ñ¸¶·Ñ·ÅÔÚµ¥¸ö¼¤»î·½·¨ÀïÃæ£¬·ÀÖ¹Íⲿ´«È벻ͬ°à¼¶
|
* @param reg
|
* @return
|
*/
|
private Result doAccountSwitchCheck(UserRegistration reg){
|
return null;
|
}
|
|
|
|
|
|
|
|
/**
|
* Ìí¼ÓÅÅÃû¼Ç¼
|
*
|
* @param reg
|
*/
|
private void addRank(UserRegistration reg) {
|
|
String hql = "from SchRank r where r.userId=? and r.rankType=?";
|
|
List<SchRank> rankLst = find(hql, CollectionUtils.newList(reg.getUserId(), SchRank.RANK_TYPE_SCORE), SchRank.class);
|
|
boolean rankCls = false;
|
boolean rankQXueyou = false;
|
|
for (SchRank rank : rankLst) {
|
if (SchRank.SCOPE_TYPE_QXUEYOU.equals(rank.getScopeType())) {
|
rankQXueyou = true;
|
}
|
if (reg.getClassId().equals(rank.getScopeId())) {
|
rankCls = true;
|
}
|
}
|
|
if (!rankCls) {
|
|
SchRank rankNew = newSchRank(reg);
|
rankNew.setScopeId(reg.getClassId());
|
rankNew.setScopeType(SchRank.SCOPE_TYPE_CLASS);
|
|
save(rankNew);
|
}
|
|
if (!rankQXueyou) {
|
|
SchRank rankNew = newSchRank(reg);
|
rankNew.setScopeId("null");
|
rankNew.setScopeType(SchRank.SCOPE_TYPE_QXUEYOU);
|
|
save(rankNew);
|
}
|
}
|
|
/**
|
* н¨ÅÅÃû¼Ç¼
|
*
|
* @param reg
|
* @return
|
*/
|
private SchRank newSchRank(UserRegistration reg) {
|
SchRank rankNew = new SchRank();
|
|
TraceUtils.setCreateTrace(rankNew);
|
rankNew.setDeleteFlag(false);
|
|
rankNew.setRankType(SchRank.RANK_TYPE_SCORE);
|
rankNew.setUserId(reg.getUserId());
|
rankNew.setValue(BigDecimal.valueOf(0l));
|
return rankNew;
|
}
|
|
/**
|
* ÐÂÔöȺ³ÉÔ±
|
*
|
* @param reg
|
*/
|
@SuppressWarnings({ "unused", "null" })
|
private void insertGroupMember(UserRegistration reg, MsgUser msgUser) {
|
|
MsgGroup group = read(MsgGroup.class, reg.getClassId());
|
if (group == null) {
|
|
group = insertNewGroup(reg,msgUser);
|
|
}else if(StringUtils.isBlank(group.getEasmobGroupId())){
|
|
// Result result = easeMobService.addGroup(group.getName(), group.getDescription(), 500000, msgUser.getUserId());
|
Result result = null;
|
|
String easemobGroupId = result.getMsg() ;
|
if(result.isSuccess() && StringUtils.isNotBlank(easemobGroupId)){
|
group.setEasmobGroupId(easemobGroupId);
|
TraceUtils.setUpdateTrace(group);
|
save(group);
|
}
|
}
|
|
int existNoticeClass = findCount("from MsgGroupUserRe where deleteFlag is false and userId = ? and groupId = ?", CollectionUtils.newList(reg.getUserId(), group.getGroupId()));
|
|
if (existNoticeClass == 0) {
|
MsgGroupUserRe member = new MsgGroupUserRe();
|
TraceUtils.setCreateTrace(member);
|
member.setUserId(msgUser.getUserId());
|
member.setGroupId(group.getGroupId());
|
member.setDeleteFlag(false);
|
save(member);
|
}
|
|
// ¼Ó»·ÐÅȺ
|
if( null != group && StringUtils.isNotBlank(group.getEasmobGroupId()) ){
|
// Ìí¼Ó»·ÐųÉÔ±
|
// Result result = easeMobService.addGroupMember(group.getEasmobGroupId() , msgUser.getUserId() );
|
}
|
|
}
|
|
/**
|
* ÐÂÔö Ⱥ+ »·ÐÅȺ
|
*
|
* @param reg
|
*/
|
@SuppressWarnings("null")
|
private MsgGroup insertNewGroup(UserRegistration reg, MsgUser msgUser) {
|
|
ClsClass orgClass = reg.getOrgClass();
|
|
//ÐÂÔö»·ÐÅȺ
|
// Result result = easeMobService.addGroup(orgClass.getName(), orgClass.getName() + "Ⱥ ½»Á÷", 500000, msgUser.getUserId());
|
Result result = null;
|
MsgGroup group = new MsgGroup();
|
|
TraceUtils.setCreateTrace(group);
|
group.setDeleteFlag(false);
|
|
group.setDescription(orgClass.getName() + "Ⱥ ½»Á÷");
|
group.setName(orgClass.getName());
|
group.setGroupId(reg.getClassId());
|
|
if(result.isSuccess()){
|
group.setEasmobGroupId(result.getMsg());
|
}
|
|
save(group);
|
|
return group;
|
}
|
|
/**
|
* Ìí¼ÓºÃÓÑÐÅÏ¢ + »·ÐźÃÓÑÐÅÏ¢
|
*
|
* @param reg
|
* @param msgUser
|
*/
|
private void addFridends(MsgUser msgUser) {
|
|
int existNoticeClass = findCount("from MsgFriend where deleteFlag is false and userIdTo = ? and userIdFrom = ?", CollectionUtils.newList(Notice.NOTICE_CLASS_MSG_USER_ID, msgUser.getUserId()));
|
|
int existNoticeOrg = findCount("from MsgFriend where deleteFlag is false and userIdTo = ? and userIdFrom = ?", CollectionUtils.newList(Notice.NOTICE_ORG_MSG_USER_ID, msgUser.getUserId()));
|
|
if (existNoticeClass == 0) {
|
MsgFriend friend = new MsgFriend();
|
TraceUtils.setCreateTrace(friend);
|
friend.setUserIdFrom(msgUser.getUserId());
|
friend.setUserIdTo(Notice.NOTICE_CLASS_MSG_USER_ID);
|
save(friend);
|
}
|
|
if (existNoticeOrg == 0) {
|
MsgFriend friend = new MsgFriend();
|
TraceUtils.setCreateTrace(friend);
|
friend.setUserIdFrom(msgUser.getUserId());
|
friend.setUserIdTo(Notice.NOTICE_ORG_MSG_USER_ID);
|
save(friend);
|
}
|
|
}
|
|
/**
|
* ×¢²áʱÔö¼ÓѧԱÐÅÏ¢
|
*
|
* @param reg
|
*/
|
private Result addStudent(UserRegistration reg) {
|
String hql = "from UserStudent u where u.deleteFlag is false and u.userId = ? ";
|
|
Result result = new Result(true);
|
|
List<UserStudent> studentsLst = find(hql, CollectionUtils.newList(reg.getUserId()), UserStudent.class);
|
|
if (studentsLst.isEmpty()) {
|
User user = reg.getUser();
|
UserStudent student = new UserStudent();
|
|
TraceUtils.setCreateTrace(student);
|
student.setDeleteFlag(false);
|
|
student.setClassId(reg.getClassId());
|
student.setUserId(user.getUserId());
|
save(student);
|
|
|
result.addData("studentId", student.getStudentId());
|
return result;
|
}
|
|
result.addData("studentId",studentsLst.get(0).getStudentId());
|
return result;
|
}
|
|
private void addOrgStudent(UserRegistration reg, String studentId) {
|
String hql = " from OrgStudent where userId=? and deleteFlag is false and classId=?";
|
|
OrgStudent student = findUnique(hql, CollectionUtils.newList(reg.getUserId(), reg.getClassId()), OrgStudent.class);
|
|
if (student == null) {
|
OrgStudent os = new OrgStudent();
|
TraceUtils.setCreateTrace(os);
|
|
os.setClassId(reg.getClassId());
|
os.setDeleteFlag(false);
|
os.setStudentId(studentId);
|
os.setUserId(reg.getUserId());
|
|
save(os);
|
}
|
}
|
|
/**
|
* ×¢²áʱÔö¼ÓÏûÏ¢Óû§
|
*
|
* @param reg
|
*/
|
private MsgUser addMsgUser(UserRegistration reg) {
|
|
MsgUser msgUser = read(MsgUser.class, reg.getUserId());
|
|
if (msgUser == null) {
|
User user = reg.getUser();
|
MsgUser u = new MsgUser();
|
|
TraceUtils.setCreateTrace(u);
|
u.setDeleteFlag(false);
|
|
u.setAccount(user.getAccount());
|
u.setAlias(user.getName());
|
u.setPassword(user.getPassword());
|
u.setPortrait(user.getImgPath());
|
u.setRealName(user.getName());
|
u.setUserId(user.getUserId());
|
// u.setSex(user.getSex());
|
insert(u);
|
|
return u;
|
}
|
|
return msgUser;
|
}
|
|
/*
|
* (non-Javadoc)
|
*
|
* @see com.qxueyou.scc.user.service.IUserRegistrationService#doDeActiveRegistrations(java.lang.String[])
|
*/
|
@Override
|
public Result doDeActiveRegistrations(String[] regIds) {
|
return changeStateBulk(regIds, UserRegistration.STATUS_DEACTIVE);
|
}
|
|
/**
|
* ͨ¹ý¼òµ¥Ñ»·, Ð޸ı¨Ãû״̬
|
*
|
* @param regIds
|
* ±¨ÃûÐÅÏ¢idÊý×é
|
* @param state
|
* ÒªÐ޸ĵÄ״̬
|
* @return
|
*/
|
private Result changeStateBulk(String[] regIds, short state) {
|
String hql = "update UserRegistration set status = " + state + " where registrationId=?";
|
Result obj = bulkUpdateInLoop(hql, regIds);
|
|
// ¸üÐÂÊÇ·ñ°à¼¶³ÉÔ±
|
String arrId[] = null ;
|
String classId = null ;
|
StringBuffer strArrId = new StringBuffer(150);
|
|
if (regIds != null) {
|
arrId = new String[regIds.length];
|
for (int i = 0; i < regIds.length; i++) {
|
UserRegistration ur = read(UserRegistration.class, regIds[i]);
|
if (null != ur) {
|
arrId[i] = ur.getUserId();
|
strArrId.append(arrId[i]).append('|') ;
|
classId = ur.getClassId();
|
|
// ±£´æÑ§Ô±µÄ²Ù×÷¼Ç¼
|
this.doInsertRegLog("¶³½áѧԱ", ur.getRegistrationId(), ur.getMobilePhone() );
|
|
}
|
}
|
}
|
|
if (arrId != null && StringUtils.isNotBlank(classId)) {
|
|
obj = bulkUpdateInLoop("update OrgStudent set deleteFlag = true where classId ='" + classId + "' and userId = ? ", arrId);
|
|
obj = bulkUpdateInLoop("update SchSignStatistics set registeFlag = false where userId = ?", arrId);
|
|
//ͬ²½»·ÐŲÙ×÷
|
Map<String,String> params = new HashMap<String,String>();
|
params.put("userIds", strArrId.toString());
|
params.put(CLASS_ID, classId);
|
sendMsgActiveMsg(params,2);
|
|
}
|
|
return obj;
|
}
|
|
/**
|
* @version 2.0 ͬ²½Éú³ÉÓû§ÒÔ¼°Óû§×¢²áÐÅÏ¢
|
* @param mobilePhone
|
* @param password
|
* @param salesCode
|
* @return
|
*//*
|
@SuppressWarnings("unused")
|
@Override
|
public ResponseResult doGenerateUserRegRecord(Map<String, Object> userMap,boolean flag) {
|
String mobilePhone = String.valueOf(userMap.get(MOBILE_PHONE));
|
String userName = String.valueOf(userMap.get(USER_NAME));
|
UserExtend userEx = (UserExtend) userMap.get("userEx");
|
String signupInfo = (String) userMap.get("signupInfo");
|
|
User user = null;
|
if(null != userMap.get("openId") && null != userMap.get("verifyCode") && !"".equals(userMap.get("verifyCode"))){ // ΢ÐŶ˱¨Ãû£¨Îª×Ô¼º±¨Ãûδ°ó¶¨×´Ì¬£©
|
UserReWeixin weixin = null;
|
// UserReWeixin weixin = weixinCommonService.queryUserReWxByOpenId(String.valueOf(userMap.get("openId")));
|
|
String hql = "from User where deleteFlag is false and mobilePhone = ?";
|
user = findUnique(hql, CollectionUtils.newList(mobilePhone), User.class);
|
|
if(null == user && null != weixin){ // ÑéÖ¤±¨ÃûµÄÊÖ»úºÅÊÇ·ñΪQѧÓÑÓû§£¨ÊÇ£ºÈ¡ÊÖ»úºÅÓû§£¬·ñ£ºÈ¥openId¹ØÁªµÄÓû§£©
|
|
user = read(User.class, weixin.getUserId());
|
if(user != null){
|
TraceUtils.setUpdateTrace(user);
|
user.setMobilePhone(mobilePhone);
|
user.setName(userName);
|
}
|
}
|
}
|
|
if(user == null){
|
user = generateUser(mobilePhone);
|
}
|
|
insertUser(user,userMap); // ²åÈëUser
|
// insertUserStringExtend(userMap,user); // ²åÈëuserStringextend
|
doUserExtend(user.getUserId(), userEx,false); // ²åÈë×Ô¶¨ÒåÓû§ÐÅÏ¢
|
|
// Èý¸öÌåÑé°à¼¶
|
// SysConfig sc = cacheService.get(ADD_REG_CLASS_IDS, SysConfig.class);
|
SysConfig sc = null;
|
if(null==sc){
|
String hql = " from SysConfig where configKey=?";
|
sc = findUnique(hql, CollectionUtils.newList(ADD_REG_CLASS_IDS), SysConfig.class);
|
//¼ÓÈ뻺´æ
|
// cacheService.set(ADD_REG_CLASS_IDS, 24*60*60, sc);
|
}
|
|
String scValue = userMap.get(CLASS_ID).toString();
|
|
if(null!=sc){
|
scValue = sc.getValue()+","+userMap.get(CLASS_ID);
|
}
|
|
String classIds []= scValue.split(",");
|
|
List<OrgClass> lstClass = new ArrayList<OrgClass>();
|
Map<String,String> classReg = new HashMap<String, String>();
|
//¼ÓÈë¶îÍâÈý¸ö°à¼¶
|
String regId = insertDefaultClass(classIds,userMap,lstClass,user,classReg);
|
|
//×Ô¶¨ÒåÐÅÏ¢
|
insertCustomInfo(regId, user.getUserId(), userMap.get(CLASS_ID).toString(), signupInfo);
|
// ·µ»ØÓû§id
|
ResponseResult result = new ResponseResult(true);
|
result.setUserId(user.getUserId());
|
result.setRegId(regId);
|
|
//Éú³É¶©µ¥
|
doGenerateOrder(flag,lstClass,userMap,user,classReg,result);
|
|
return result;
|
}*/
|
|
/**
|
* ±£´æ×Ô¶¨ÒåÐÅÏ¢
|
*
|
* @param regId ×¢²áid
|
* @param userId Óû§id
|
* @param classId °à¼¶id
|
* @param signupInfo ѧԱÌîдÐÅÏ¢
|
*/
|
private void insertCustomInfo(String regId, String userId, String classId, String signupInfo){
|
if(StringUtils.isEmpty(signupInfo) || "null".equals(signupInfo)){
|
return;
|
}
|
|
List<UserRegistrationCustom> customInfos = JSONArray.parseArray(signupInfo, UserRegistrationCustom.class);
|
List<UserRegistrationCustom> newCustomInfos = new ArrayList<UserRegistrationCustom>();
|
if(customInfos != null && !customInfos.isEmpty()){
|
for(UserRegistrationCustom customInfo: customInfos){
|
if(StringUtils.isEmpty(customInfo.getRegCustomId())){
|
customInfo.setClassId(classId);
|
customInfo.setUserId(userId);
|
customInfo.setRegistrationId(regId);
|
customInfo.setDeleteFlag(false);
|
TraceUtils.setCreateTrace(customInfo);
|
|
newCustomInfos.add(customInfo);
|
}else{
|
UserRegistrationCustom oldUserCustom = this.read(UserRegistrationCustom.class, customInfo.getRegCustomId());
|
oldUserCustom.setDeleteFlag(false);
|
oldUserCustom.setCustomValue(customInfo.getCustomValue());
|
TraceUtils.setUpdateTrace(oldUserCustom);
|
|
newCustomInfos.add(oldUserCustom);
|
}
|
}
|
|
this.saveOrUpdateAll(newCustomInfos);
|
}
|
}
|
|
/**
|
* ²åÈëuser
|
* @param user
|
* @param userMap
|
*/
|
private void insertUser(User user,Map<String, Object> userMap){
|
if (StringUtils.isBlank(user.getUserId())) {
|
TraceUtils.setCreateTrace(user);
|
|
if (null!=userMap.get(MOBILE_PHONE)) {
|
user.setMobilePhone(String.valueOf(userMap.get(MOBILE_PHONE)));
|
}
|
if (null!=userMap.get(PASSWORD)) {
|
user.setPassword(RSAUtils.encrypt(String.valueOf(userMap.get(PASSWORD))));
|
} else {
|
user.setPassword(RSAUtils.encrypt("hello"));
|
}
|
if (StringUtils.isBlank(user.getUserId()) && userMap.get(USER_NAME) != null) {
|
user.setName(String.valueOf(userMap.get(USER_NAME)));
|
}
|
if (StringUtils.isBlank(user.getUserId()) && userMap.get("name") != null) {
|
user.setName(String.valueOf(userMap.get("name")));
|
}
|
if (userMap.get("account") != null) {
|
user.setAccount(String.valueOf(userMap.get("account")));
|
} else if (StringUtils.isBlank(user.getAccount())) {
|
user.setAccount(this.doGetNewQxyAccount());
|
}
|
if (userMap.get(IMG_PATH) != null) {
|
user.setImgPath(String.valueOf(userMap.get(IMG_PATH)));
|
} else {
|
user.setImgPath(FilePathConstants.getUserDefaultImg());
|
}
|
|
user.setDeleteFlag(false);
|
|
|
}
|
}
|
|
|
|
|
|
/**
|
* @version Ñ¡¿Î±¨ÃûÉú³ÉÓû§
|
* @param mobilePhone
|
* @param password
|
* @param salesCode
|
* @return
|
*/
|
|
public ResponseResult doChooseClassReg(Map<String, Object> userMap,boolean flag) {
|
return null;
|
// return doGenerateUserRegRecord(userMap, flag);
|
}
|
|
/**
|
* Êý¾Ý¿âUSER±í£º ºǫ́Ïȵ¼ÈëÊÖ»úºÅÂ루´ËºÅÂë²»ÔÚuser±íÖУ©£¬²»¼¤»î»òÕßɾ³ý¸ÃÓû§£¬È»ºóappµÇ¼£¬»áÔì³ÉÁ½Ìõuser¼Ç¼ ²»Ö±½ÓÐÂÔö£¬Ôö¼ÓÅжÏ
|
*
|
* @param mobilePhone
|
* @return
|
*/
|
private User generateUser(String mobilePhone) {
|
|
if (StringUtils.isBlank(mobilePhone)) {
|
|
return new User();
|
}
|
|
String hql = "from User u where u.deleteFlag is false and u.mobilePhone = ? ";
|
User u = this.findUnique(hql, CollectionUtils.newList(mobilePhone), User.class);
|
|
return null == u ? new User() : u;
|
}
|
|
/**
|
* @version 2.0 ´Ë¹«¹²·½·¨£¬²¿·Öº¯Êýµ÷ÓÃǰûÓÐÅжÏuser_registrationÊÇ·ñÔÚ±íÖÐÓмǼ£¬eg£ºÑ¡¿Î±¨Ãû£»Ôö¼ÓÅжÏ
|
*
|
* @param mobilePhone
|
* @param classId
|
* @return
|
*/
|
private UserRegistration generateUserReg(String mobilePhone, String classId) {
|
if (StringUtils.isBlank(mobilePhone) || StringUtils.isBlank(classId)) {
|
return new UserRegistration();
|
}
|
|
String hql = "from UserRegistration r where r.deleteFlag is false and r.mobilePhone = ? and r.classId = ? ";
|
UserRegistration ur = this.findUnique(hql, CollectionUtils.newList(mobilePhone, classId), UserRegistration.class);
|
|
return null == ur ? new UserRegistration() : ur;
|
}
|
|
/**
|
* @version 2.0 ´Ë¹«¹²·½·¨£¬²¿·Öº¯Êýµ÷ÓÃǰûÓÐÅжÏuser_registrationÊÇ·ñÔÚ±íÖÐÓмǼ£¬eg£ºÑ¡¿Î±¨Ãû£»Ôö¼ÓÅжÏ
|
*
|
* @param mobilePhone
|
* @param classId
|
* @return
|
*/
|
private UserRegistration generateUserRegByUser(String userId, String classId) {
|
if (StringUtils.isBlank(userId) || StringUtils.isBlank(classId)) {
|
return new UserRegistration();
|
}
|
|
String hql = "from UserRegistration r where r.deleteFlag is false and r.userId = ? and r.classId = ? ";
|
UserRegistration ur = this.findUnique(hql, CollectionUtils.newList(userId, classId), UserRegistration.class);
|
|
return null == ur ? new UserRegistration() : ur;
|
}
|
|
@Override
|
public Result doRegClass(String classId, String courseId) {
|
// »ñÈ¡¿Í»§¶ËÐÅÏ¢
|
|
// Óû§×¢²á±íÐÂÔö¼Ç¼
|
UserRegistration regUser = new UserRegistration();
|
regUser.setClassId(classId);
|
regUser.setCollegeCourseId(courseId);
|
regUser.setUserId(ClientUtils.getUserId());
|
regUser.setUserName(ClientUtils.getUserName());
|
regUser.setMobilePhone(ClientUtils.getUserMobilePhone());
|
regUser.setStatus(UserRegistration.STATUS_DEACTIVE);
|
regUser.setSalesCode(Constants.USER_SALES_CODE);
|
regUser.setDeleteFlag(false);
|
regUser.setRegistrationTime(new Date());
|
TraceUtils.setCreateTrace(regUser);
|
save(regUser);
|
|
|
// ±¨ÃûÐÂÔö°à¼¶±¨ÃûÊý
|
ClsClass orgClass = read(ClsClass.class, classId);
|
orgClass.setStudentCount(orgClass.getStudentCount()+1);
|
TraceUtils.setUpdateTrace(orgClass);
|
save(orgClass);
|
|
return new Result(true);
|
}
|
|
/**
|
* ÓοÍÌá½»±¨Ãû
|
*/
|
@Override
|
public Result doVisitorRegClass(Map<String, Object> userMap) {
|
String name = userMap.get(USER_NAME)==null?String.valueOf(userMap.get("name")):String.valueOf(userMap.get(USER_NAME));
|
UserRegistration regUser = new UserRegistration();
|
regUser.setClassId(String.valueOf(userMap.get(CLASS_ID)));
|
regUser.setCollegeCourseId(String.valueOf(userMap.get("courseId")));
|
regUser.setUserId(String.valueOf(userMap.get(USER_ID)));
|
regUser.setUserName(name);
|
regUser.setMobilePhone(String.valueOf(userMap.get(MOBILE_PHONE)));
|
regUser.setStatus(UserRegistration.STATUS_DEACTIVE);
|
regUser.setSalesCode(String.valueOf(userMap.get("salesCode")));
|
regUser.setDeleteFlag(false);
|
TraceUtils.setCreateTrace(regUser);
|
regUser.setRegistrationTime(new Date());
|
save(regUser);
|
|
return new Result(true);
|
}
|
|
/**
|
* µ¼ÈëѧԱ±¨ÃûÐÅÏ¢//ÊÖ»úºÅÂë´æÔÚ£¬Ôò²»²åÈëuser±í,¸üÐÂuser±íµÄname×ֶΣ¬Ö±²åÈëUserRegistration
|
*
|
* @param file
|
* @param classId
|
* @return
|
*/
|
public Result doImportRegistration(String fullPath,String module , String classId) {
|
|
Result objResult = new Result(true);
|
// Ŀǰ¼ì²âÖØ¸´·½Ê½£º1.excelÖÐÓÐÖØ¸´£¬ÊǻᵼÖÂÖØ¸´²åÈë;2.Ò»´ÎÐÔ¼ì²âexcelÖеÄÊÖ»úºÅʱºòÔÙÊý¾Ý¿âÖÐuserÓмǼ£»3.ûÓмì²âÒ»¸öÓû§ÊÇ·ñÖØ¸´±¨ÃûÁËÒ»¸ö°à¼¶
|
// 2015-04-27 ÐÞ¸ÄÖØ¸´Ð£Ñé
|
// 1.excelÖÐÓÐÖØ¸´µÄÊÖ»úºÅ£¬Ö±²åÈëµÚÒ»Ìõ¼Ç¼
|
// 2.µ±Ç°°à¼¶ÒÑÓиÃÊÖ»úºÅ£¬²»²åÈë¼Ç¼
|
// 2015-06-08
|
// 1.ÐÞ¸Äͬ²½ÖÁmsg_user real_name ×Ö¶Î
|
|
// ÏÂÔØµ½Ó¦Ó÷þÎñÆ÷±¾µØ
|
String filePart[] = fullPath.split("\\.");
|
String fileType = filePart[filePart.length -1];
|
String uuid = UUIDUtils.generateUUID();
|
String filePath = UserRegistrationService.class.getClassLoader().getResource("../uploads").getPath().concat("userregistration/"+ uuid + "/" + uuid + "."+fileType);
|
File file = fileUploadService.doGetOssFile(fullPath, filePath, module,ClientUtils.getUserId());
|
|
if(null == file){
|
return new Result(false,"ÎĵµÎ´ÕÒµ½");
|
}
|
|
try {
|
// excelÖÐ×ܵı¨ÃûÐÅÏ¢Êý
|
List<UserRegistration> lstUserRegistration = new ArrayList<UserRegistration>();
|
List<UserRegistration> lstErrorUserRegistration = new ArrayList<UserRegistration>();
|
Map<String,UserExtend> mapUserExtend = new HashMap<String,UserExtend>();
|
|
parseFile(file, classId, lstUserRegistration, lstErrorUserRegistration,mapUserExtend);
|
if (lstUserRegistration != null && !lstUserRegistration.isEmpty()) {
|
|
// ²éѯÊÖ»úºÅÊÇ·ñ´æÔÚuser±í£¬²»´æÔڵϰÐèÒª²åÈëuser±í
|
List<User> lstExistsUser = getUserList(lstUserRegistration);
|
Map<String, User> mapEexistsUser = new HashMap<String, User>();
|
for (User user : lstExistsUser) {
|
mapEexistsUser.put(user.getAccount(), user);
|
}
|
|
// ×é×°userRegistration¼°user¶ÔÏó
|
List<UserRegistration> lstInsertUserRegistration = generateUserRegistration(lstUserRegistration, mapEexistsUser, mapUserExtend,null);
|
|
// ²åÈëËùÓÐ×¢²áÐÅÏ¢
|
saveOrUpdateAll(lstInsertUserRegistration);
|
|
//×Ô¶¨ÒåÐÅÏ¢²åÈë
|
// this.insertUserCustom(lstUserRegistration, mapUserExtend);
|
|
for(UserRegistration currUr : lstInsertUserRegistration){
|
this.doInsertRegLog("µ¼ÈëѧԱ", currUr.getRegistrationId(), currUr.getMobilePhone());
|
}
|
|
// ×é×°ËùÓеÄmsg_user ÐÅÏ¢
|
List<MsgUser> lstMu = getMsgUserAllList(lstInsertUserRegistration);
|
saveOrUpdateAll(lstMu);
|
|
// ¸üа༶³ÉÔ±
|
this.updateStudentCount(classId, lstInsertUserRegistration.size(), 1);
|
|
String msg = "³É¹¦µ¼Èë" + lstInsertUserRegistration.size() + "Ìõ¼Ç¼£¬×Ô¶¯ºöÂÔ" + lstErrorUserRegistration.size() + "Ìõ²»¹æ·¶¼Ç¼¡£";
|
objResult.setMsg(msg);
|
objResult.setData(lstErrorUserRegistration);
|
} else {
|
objResult = new Result(false, "Êý¾ÝÈ«²¿µ¼Èëʧ°Ü£¬¿ÉÄÜÊý¾ÝÖØ¸´µ¼Èë»òÊý¾Ý¸ñʽ´íÎó");
|
}
|
|
} catch (RuntimeException e) {
|
log.error(e, e);
|
objResult = new Result(false, "ϵͳÒì³££¬µ¼Èëʧ°Ü");
|
}
|
|
// ɾ³ýÏÂÔØµ½Ó¦Ó÷þÎñÆ÷µÄÎĵµ
|
fileUploadService.doDeleteTempOssFile(file.getParentFile(), module,ClientUtils.getUserId());
|
|
//¸üÐÂÉÏ´«ÎļþʹÓù켣
|
fileUploadService.updateUploadTrace(fullPath, module, SysFileUploadTrace.FILE_USE, classId);
|
return objResult;
|
}
|
|
/**
|
* ¸üа༶±¨ÃûÊýÁ¿
|
* @param classId
|
* @param updateCount
|
* @param updateType
|
* @return
|
*/
|
public Result updateStudentCount(String classId , int updateCount , int updateType){
|
|
if(1 == updateType){
|
|
bulkUpdateInLoop( "update ClsClass set studentCount = ( studentCount + " + updateCount + " ) where classId = ? ", new Object[] { classId });
|
|
}else{
|
|
bulkUpdateInLoop( "update ClsClass set studentCount = ( studentCount - " + updateCount+ " ) where classId = ? ", new Object[] { classId });
|
|
}
|
|
return new Result(true);
|
}
|
|
/**
|
* ¼ìÑéÊÖ»úºÅÊÇ·ñÔÚuser±íÖÐÒÑÓмǼ
|
*
|
* @param lstUserRegistration
|
* @return
|
*/
|
private List<User> getUserList(List<UserRegistration> lstUserRegistration) {
|
|
List<User> lstExistsUser = null;
|
if (lstUserRegistration != null && !lstUserRegistration.isEmpty()) {
|
List<Object> lstAllUser = new ArrayList<Object>();
|
for (UserRegistration ur : lstUserRegistration) {
|
lstAllUser.add(ur.getMobilePhone());
|
}
|
|
StringBuffer hql = new StringBuffer(150);
|
hql.append("from User where deleteFlag is false and account in ( ");
|
for (int i = 0; lstAllUser != null && i < lstAllUser.size(); i++) {
|
int size = lstAllUser.size() - 1;
|
if (i==size) {
|
hql.append(" ? ");
|
} else {
|
hql.append("? , ");
|
}
|
}
|
hql.append(" ) ");
|
lstExistsUser = this.find(hql.toString(), lstAllUser, User.class);
|
}
|
|
return lstExistsUser;
|
}
|
|
/**
|
* ×é×°userRegistration¼°²åÈëuser¶ÔÏó
|
*
|
* @param lstUserRegistration
|
* @param mapEexistsUser
|
* @return
|
*/
|
private List<UserRegistration> generateUserRegistration(List<UserRegistration> lstUserRegistration, Map<String, User> mapEexistsUser,Map<String,UserExtend> mapUserExtend,String source) {
|
List<UserRegistration> lstInsertUserRegistration = new ArrayList<UserRegistration>();
|
for (UserRegistration ur : lstUserRegistration) {
|
// user±íûÓÐÓÐÕâ¸öÊÖ»úºÅ¶ÔÓ¦µÄ¼Ç¼£¬ÐèÒª²åÈëuser£¬·ñÔòʹÓôÓÊý¾Ý¿â²éѯ³öÀ´µÄuser,²¢ÇÒ¸üÐÂname×Ö¶Î
|
if (!mapEexistsUser.containsKey(ur.getMobilePhone())) {
|
User user = getUser(ur, ur.getSex(), null, source);
|
// userService.saveUserTrace(user, false, null);
|
// lstInsertUser.add(newUser(ur,ur.getSex()));
|
// ´´½¨×¢²áÐÅÏ¢
|
TraceUtils.setCreateTrace(ur);
|
ur.setDeleteFlag(false);
|
ur.setStatus(UserRegistration.STATUS_DEACTIVE);
|
ur.setUserId(user.getUserId());
|
//ur.setUserName(user.getName());
|
|
// ÉèÖÿÆÄ¿ÐÅÏ¢
|
ClsClass cls = read(ClsClass.class, ur.getClassId());
|
// ur.setCourseId(cls.getCourseId());
|
ur.setCollegeCourseId(cls.getCollegeCourseId());
|
lstInsertUserRegistration.add(ur);
|
doUserExtend(user.getUserId(), mapUserExtend.get(ur.getMobilePhone()),false);
|
} else {
|
// ¸üÐÂname×Ö¶Î
|
User user = mapEexistsUser.get(ur.getMobilePhone());
|
user.setName(ur.getUserName());
|
// userService.saveUser(user);
|
|
// ´´½¨×¢²áÐÅÏ¢
|
TraceUtils.setCreateTrace(ur);
|
ur.setDeleteFlag(false);
|
ur.setStatus(UserRegistration.STATUS_DEACTIVE);
|
|
ur.setUserId(user.getUserId());
|
ur.setUserName(user.getName());
|
|
// ÉèÖÿÆÄ¿ÐÅÏ¢
|
ClsClass cls = read(ClsClass.class, ur.getClassId());
|
// ur.setCourseId(cls.getCourseId());
|
ur.setCollegeCourseId(cls.getCollegeCourseId());
|
lstInsertUserRegistration.add(ur);
|
doUserExtend(user.getUserId(), mapUserExtend.get(ur.getMobilePhone()),false);
|
}
|
|
}
|
return lstInsertUserRegistration;
|
}
|
|
/**
|
* ½âÎöExcelΪע²á¶ÔÏóµÄlist£¨Í¬Ê±Ð£ÑéÈ¥³ýÖØ¸´£©
|
*
|
* @param file
|
* ExcelÎļþ¾ø¶Ô·¾¶
|
* @return
|
* @throws RuntimeException
|
*/
|
private void parseFile(File file, String classId, List<UserRegistration> lstUserRegis,
|
List<UserRegistration> lstErrorUserRegistration,Map<String,UserExtend> mapUserExtend) throws RuntimeException {
|
|
ExcelReader excelReader = new ExcelReader(file);
|
|
// »ñÈ¡excelËùÓÐÐеÄÄÚÈÝ
|
List<String[]> allLineRegistration = excelReader.getAllData(0);
|
|
if (allLineRegistration != null && allLineRegistration.size() > 1) {
|
|
generateSingles(allLineRegistration, lstUserRegis, lstErrorUserRegistration, mapUserExtend, classId);
|
}
|
}
|
|
private void generateSingles(List<String[]> allLineRegistration, List<UserRegistration> lstUserRegis,
|
List<UserRegistration> lstErrorUserRegistration,Map<String,UserExtend> mapUserExtend, String classId){
|
|
// УÑéÊý¾Ý¿âÖУ¬¸Ã°à¼¶ÊÇ·ñÒÑ´æÔÚ¸ÃÊÖ»úºÅ
|
String hql = "select mobilePhone from UserRegistration where deleteFlag is false and classId = ? ";
|
// ´æÔÚµÄmobile
|
List<String> lstExistsMobile = this.find(hql, CollectionUtils.newList(classId), String.class);
|
|
// ÐèÒªµ¼ÈëµÄÊÖ»úºÅÂ룬ÓÃÓÚУÑéexcelÖÐÊÇ·ñÓÐÖØ¸´ÊÖ»úºÅ£¬ÓÐÖØ¸´µÄ£¬Ö»²åÈëµÚÒ»Ìõ¼Ç¼
|
List<String> lstInsertMobile = new ArrayList<String>();
|
|
Map<String,Integer> value = setCustomValue(allLineRegistration.get(0));
|
|
for (int i = 1; i < allLineRegistration.size(); i++) {
|
String[] singleLineRegistration = allLineRegistration.get(i);
|
// Èç¹ûÊǰ´ÕÕÄ£°åµ¼Èë
|
if (singleLineRegistration != null) {
|
|
String strMobile = value.get("ÊÖ»úºÅ") != null ? singleLineRegistration[value.get("ÊÖ»úºÅ")] : null;// ÊÖ»úºÅÂë·ûºÏ¹æÔò
|
UserRegistration tmpUserRegistration = tmpUserRegistration(value, singleLineRegistration, classId);
|
|
if (StringUtils.isNotBlank(strMobile) && SmsUtils.formatMobilePhone(strMobile)) {
|
// УÑéÊÖ»úºÅÊÇ·ñÔÚexcelÖÐÖØ¸´¡¢ÊÇ·ñÔÚÊý¾Ý¿âÖÐÖØ¸´
|
if (!lstInsertMobile.contains(strMobile) && checkMobileFromDB(lstExistsMobile, strMobile)) {
|
|
lstUserRegis.add(tmpUserRegistration);
|
UserExtend userExtend = tmpUserExtend(value, singleLineRegistration);
|
// userExtend.setUserCustom(this.getUserCustom(value, singleLineRegistration, strMobile));
|
mapUserExtend.put(strMobile, userExtend);
|
|
} else {
|
tmpUserRegistration.setStatus(UserRegistration.STATUS_DEACTIVE);
|
lstErrorUserRegistration.add(tmpUserRegistration);
|
log.info("µ¼È뱨ÃûÐÅÏ¢ÊÖ»úºÅÖØ¸´£º" + strMobile);
|
}
|
lstInsertMobile.add(strMobile);
|
}else{
|
tmpUserRegistration.setStatus(UserRegistration.STATUS_DEACTIVE);
|
lstErrorUserRegistration.add(tmpUserRegistration);
|
}
|
}
|
}
|
}
|
|
|
|
private UserRegistration tmpUserRegistration(Map<String,Integer> value,String[] singleLineRegistration,String classId){
|
|
boolean sex = value.get("ÐÔ±ð") != null && getSex(singleLineRegistration[value.get("ÐÔ±ð")]);
|
String strMobile = value.get("ÊÖ»úºÅ") != null ? singleLineRegistration[value.get("ÊÖ»úºÅ")] : null;// ÊÖ»úºÅÂë·ûºÏ¹æÔò
|
UserRegistration tmpUserRegistration = new UserRegistration();
|
tmpUserRegistration.setUserName(value.get("ÐÕÃû") != null ? singleLineRegistration[value.get("ÐÕÃû")] : null);
|
tmpUserRegistration.setSex(sex);// ÐÔ±ðuserÐèÒªÓÃ,
|
tmpUserRegistration.setSalesCode(value.get("±¨ÃûÂë") != null ? singleLineRegistration[value.get("±¨ÃûÂë")] : null);
|
tmpUserRegistration.setMobilePhone(strMobile.replaceAll(" ", ""));
|
tmpUserRegistration.setClassId(classId);
|
tmpUserRegistration.setRegistrationTime(new Date());
|
tmpUserRegistration.setOtherContactMethod(value.get(OrgClassUserCustom.OBJECT_NAME_ORDERPHONE) != null ? singleLineRegistration[value.get(OrgClassUserCustom.OBJECT_NAME_ORDERPHONE)] : null);
|
|
return tmpUserRegistration;
|
}
|
|
private UserExtend tmpUserExtend(Map<String,Integer> value,String[] singleLineRegistration){
|
|
UserExtend userExtend = new UserExtend();
|
if(value.get(OrgClassUserCustom.OBJECT_NAME_BIRTHDAY) != null){
|
userExtend.setBirthday(singleLineRegistration[value.get(OrgClassUserCustom.OBJECT_NAME_BIRTHDAY)]);
|
}
|
if(value.get(OrgClassUserCustom.OBJECT_NAME_COMPANY) != null){
|
userExtend.setCompany(singleLineRegistration[value.get(OrgClassUserCustom.OBJECT_NAME_COMPANY)]);
|
}
|
if(value.get(OrgClassUserCustom.OBJECT_NAME_IDNUMBER) != null){
|
userExtend.setIdNumber(singleLineRegistration[value.get(OrgClassUserCustom.OBJECT_NAME_IDNUMBER)]);
|
}
|
if(value.get(OrgClassUserCustom.OBJECT_NAME_MAILADDRESS) != null){
|
userExtend.setMailAddress(singleLineRegistration[value.get(OrgClassUserCustom.OBJECT_NAME_MAILADDRESS)]);
|
}
|
if(value.get(OrgClassUserCustom.OBJECT_NAME_QQ) != null){
|
userExtend.setQq(singleLineRegistration[value.get(OrgClassUserCustom.OBJECT_NAME_QQ)]);
|
}
|
if(value.get(OrgClassUserCustom.OBJECT_NAME_WEIXIN) != null){
|
userExtend.setWeixin(singleLineRegistration[value.get(OrgClassUserCustom.OBJECT_NAME_WEIXIN)]);
|
}
|
if(value.get(OrgClassUserCustom.OBJECT_NAME_ADDRESS) != null){
|
String[] address = singleLineRegistration[value.get(OrgClassUserCustom.OBJECT_NAME_ADDRESS)].split("-");
|
if(address.length > 2){
|
userExtend.setProvince(address[0]);
|
userExtend.setCity(address[1]);
|
userExtend.setRegion(address[2]);
|
}
|
}
|
userExtend.setMailFlag(value.get(OrgClassUserCustom.OBJECT_NAME_MAILADDRESS) != null ? true : false);
|
|
return userExtend;
|
}
|
|
/**
|
* ¸ñʽ»¯ - "£¨±ØÌ"
|
* @param singleHead
|
* @return
|
*/
|
private Map<String,Integer> setCustomValue(String[] singleHead){
|
|
Map<String,Integer> map = new HashMap<String,Integer>();
|
for (int i = 0; i < singleHead.length; i++) {
|
map.put(singleHead[i].replace("£¨±ØÌ", ""), i);
|
}
|
return map;
|
}
|
|
/**
|
* УÑéÊý¾Ý¿âÖУ¬¸ÃÊÖ»úºÅÊÇ·ñÒѾÔÚµ±Ç°°à¼¶ÖÐ
|
*
|
* @param lstExistsMobile
|
* @param strMobile
|
* @return
|
*/
|
private boolean checkMobileFromDB(List<String> lstExistsMobile, String strMobile) {
|
return !(lstExistsMobile != null && StringUtils.isNotBlank(strMobile) && lstExistsMobile.contains(strMobile));
|
}
|
|
/**
|
*
|
* @param strSex
|
* @return
|
*/
|
private boolean getSex(String strSex) {
|
return "ÄÐ".equals(strSex.trim()) ? true : false;
|
}
|
|
/**
|
* ѧԱע²áÁбí - °à¼¶
|
* @return
|
*/
|
@SuppressWarnings("unchecked")
|
public List<Map<String,Object>> queryClassRegistrationList(String classId) {
|
classId = StringUtils.isEmpty(classId)?ClientUtils.getClassId():classId;
|
String sql = "select r.user_id,r.registration_id,r.user_name,r.sales_code,r.registration_time,r.activation_time,"
|
+ "r.mobile_phone,r.status,case when o.operate_id is null then '0' else '1' end installFlag,"
|
+ "r.other_contact_method,e.id_number,e.user_photo,birthday,company,e.qq,e.weixin,e.province,e.city,e.region,e.mail_address "
|
+ "from user_registration r left join user_operate o on r.user_id = o.user_id left join user_extend e on e.user_id = r.user_id "
|
+ "where ifnull(o.delete_flag,0) = 0 and r.delete_flag = 0 and r.class_id = ? order by r.create_time desc";
|
|
List<Object[]> objLst = findBySql(sql, CollectionUtils.newList(classId));
|
|
//×Ô¶¨Òå×Ö¶Î
|
List<UserRegistrationCustom> lstCustom = this.find("from UserRegistrationCustom c where c.deleteFlag is false and c.classId = ?"
|
+ " and EXISTS (select 1 from OrgClassUserCustom t where t.deleteFlag is false and t.customId = c.customId)",
|
CollectionUtils.newList(classId), UserRegistrationCustom.class);
|
|
|
List<Map<String,Object>> resultMap = new ArrayList<Map<String,Object>>(objLst.size());
|
Map<String,Object> map = null;
|
for (Object[] obj : objLst) {
|
User user = read(User.class, String.valueOf(obj[0]));
|
if(user != null){
|
map = new HashMap<String,Object>();
|
map.put("userId", obj[0]);
|
// map.put("sex", user.getSex());
|
map.put("registrationId", obj[1]);
|
map.put("userName", obj[2]);
|
map.put("salesCode", obj[3]);
|
map.put("registrationTime", obj[4]);
|
map.put("activationTime", obj[5]);
|
map.put("mobilePhone", obj[6]);
|
map.put("status", obj[7]);
|
map.put("installFlag", obj[8]);
|
map.put("orderPhone", obj[9]);
|
|
map.put("idNumber", obj[10]);
|
map.put("userPhoto", obj[11]);
|
map.put("IMG_PATH", user.getImgPath());
|
map.put("birthday", obj[12]);
|
map.put("company", obj[13]);
|
map.put("QQ", obj[14]);
|
map.put("weixin", obj[15]);
|
|
String address = "";
|
if(StringUtils.isNotBlank(String.valueOf(obj[16])) && !"null".equals(String.valueOf(obj[16]))){
|
address = String.valueOf(obj[16]) + "-" + String.valueOf(obj[17]) + "-" + String.valueOf(obj[18]);
|
}
|
map.put("address", address);
|
map.put("mailAddress", obj[19]);
|
List<UserRegistrationCustom> userCustom = new ArrayList<UserRegistrationCustom>();
|
if(lstCustom != null && !lstCustom.isEmpty()){
|
for(UserRegistrationCustom objCustom : lstCustom){
|
if(objCustom.getRegistrationId().equals(obj[1])){
|
userCustom.add(objCustom);
|
}
|
}
|
}
|
map.put("userCustom", userCustom);
|
resultMap.add(map);
|
}
|
}
|
|
return resultMap;
|
}
|
|
/**
|
* »ú¹¹Ñ§Ô±Áбí
|
* @param orgId
|
* @return
|
*/
|
@SuppressWarnings("unchecked")
|
public List<Map<String,Object>> queryOrgRegistrationList(String orgId){
|
List<Map<String,Object>> classes = this.findListWithMapByHql("select s.classId as classId, s.name as name from ClsClass s where s.deleteFlag is false and s.orgId = :orgId",
|
CollectionUtils.newObjectMap("orgId", orgId));
|
String sql = "select r.user_id,r.registration_id,r.user_name,r.sales_code,r.registration_time,r.activation_time,"
|
+ "r.mobile_phone,r.status,case when o.operate_id is null then '0' else '1' end installFlag,"
|
+ "r.other_contact_method,e.id_number,e.user_photo,birthday,company,e.qq,e.weixin,e.province,e.city,e.region,e.mail_address,r.class_id,u.sex,u.img_path "
|
+ "from user_registration r left join user_operate o on r.user_id = o.user_id left join user_extend e on e.user_id = r.user_id left join user u on u.user_id = r.user_id "
|
+ "where ifnull(o.delete_flag,0) = 0 and r.delete_flag = 0 and r.class_id "
|
+ "in(select s.class_Id from org_class s where s.delete_Flag is false and s.org_Id = ?) order by r.class_id, r.create_time desc";
|
List<Object[]> objLst = this.findBySql(sql.toString(), CollectionUtils.newList(orgId));
|
|
//×Ô¶¨Òå×Ö¶Î
|
List<Map<String, Object>> lstCustom = this.findListWithMapByHql("select c.registrationId as registrationId, c.classId as classId,"
|
+ " c.customId as customId, t.objectName as customName, c.customValue as customValue, c.regCustomId as regCustomId "
|
+ " from UserRegistrationCustom c, OrgClassUserCustom t where c.deleteFlag is false and t.deleteFlag is false and t.customId = c.customId"
|
+ " and c.classId in(select s.classId from ClsClass s where s.deleteFlag is false and s.orgId = :orgId) ",
|
CollectionUtils.newObjectMap("orgId", orgId));
|
|
|
List<Map<String,Object>> resultMap = new ArrayList<Map<String,Object>>(objLst.size());
|
Map<String,Object> map = null;
|
for (Object[] obj : objLst) {
|
map = new HashMap<String,Object>();
|
map.put("userId", obj[0]);
|
map.put("sex", obj[21]);
|
map.put("registrationId", obj[1]);
|
map.put("userName", obj[2]);
|
map.put("salesCode", obj[3]);
|
map.put("registrationTime", obj[4]);
|
map.put("activationTime", obj[5]);
|
map.put("mobilePhone", obj[6]);
|
map.put("status", obj[7]);
|
map.put("installFlag", obj[8]);
|
for(Map<String,Object> name : classes){
|
if(name.get("classId").equals(obj[20])){
|
map.put("className", name.get("name"));
|
break;
|
}
|
}
|
|
List<Map<String,Object>> userCustom = new ArrayList<Map<String,Object>>();
|
if(lstCustom != null && !lstCustom.isEmpty()){
|
for(Map<String, Object> objCustom : lstCustom){
|
if(objCustom.get("registrationId").equals(obj[1]) && StringUtils.isNoneBlank((String)objCustom.get("customValue"))){
|
userCustom.add(objCustom);
|
continue;
|
}
|
}
|
}
|
map.put("userCustom", userCustom);
|
resultMap.add(map);
|
}
|
|
return resultMap;
|
}
|
|
|
/**
|
* ÐÂÔö±à¼×¢²áÐÅÏ¢(¼ì²âÖØ¸´) ¸Ä¶¯1£º¿ÉÒÔ±à¼ÐÞ¸Ä,ÐÞ¸Äʱ£¬ÊÖ»úºÅÂë²»ÄÜÐ޸ģ¨20150608£© ¸Ä¶¯2£º°à¼¶Àï¼ì²éÖØ¸´£¨20150608£© ¸Ä¶¯3£ºÐÞ¸Ämsg_user:real_name£¨20150608£©
|
*/
|
public Result updateRegistration(UserRegistration reg,UserExtend userEx,boolean male, String signupInfo) {
|
|
Result objResult = new Result(false);
|
objResult.setMsg("±£´æÊ§°Ü");
|
|
if (null != reg && StringUtils.isNotBlank(reg.getRegistrationId())) {
|
UserRegistration ug = read(UserRegistration.class, reg.getRegistrationId());
|
User user = read(User.class, ug.getUserId());
|
// ÊÖ»úºÅÂë²»¿ÉÐÞ¸Ä
|
if (null != user && null != ug && StringUtils.isNotBlank(reg.getUserName())) {
|
String strUserName = reg.getUserName();
|
user.setName(reg.getUserName());
|
// user.setSex(male);
|
// userService.saveUser(user);
|
|
ug.setUserName(strUserName);
|
ug.setOtherContactMethod(reg.getOtherContactMethod());
|
ug.setSalesCode(reg.getSalesCode());
|
save(ug);
|
|
// ÐÞ¸Ämsg_userµÄuser_name
|
List<MsgUser> lstMu = getMsgUserList(user.getUserId());
|
updateMsgUserList(lstMu, strUserName);
|
saveOrUpdateAll(lstMu);
|
objResult = new Result(true, ug.getRegistrationId());
|
// ѧԱ²Ù×÷¼Ç¼
|
this.doInsertRegLog("±à¼Ñ§Ô±", ug.getRegistrationId(), ug.getMobilePhone());
|
doUserExtend(user.getUserId(), userEx,true);
|
|
//×Ô¶¨ÒåÐÅÏ¢
|
insertCustomInfo(reg.getRegistrationId(), user.getUserId(), ug.getClassId(), signupInfo);
|
}
|
} else {
|
// (ÐèÒª¹ýÂ˵±Ç°°à¼¶ÊÇ·ñÓиÃѧԱ)
|
if (!checkMobileExists(reg.getMobilePhone())) {
|
// ´´½¨Óû§
|
User user = getUser(reg, male, null, null);
|
// ¸üÐÂuser_name,¸üÐÂÐÔ±ð
|
user.setName(reg.getUserName());
|
// user.setSex(male);
|
// userService.saveUserTrace(user, false, null);
|
// ´´½¨×¢²áÐÅÏ¢
|
TraceUtils.setCreateTrace(reg);
|
reg.setDeleteFlag(false);
|
reg.setStatus(UserRegistration.STATUS_DEACTIVE);
|
reg.setUserId(user.getUserId());
|
reg.setUserName(user.getName());
|
reg.setRegistrationId(null);
|
reg.setRegistrationTime(new Date());
|
// ¸üа༶³ÉÔ±
|
this.updateStudentCount(reg.getClassId(), 1, 1);
|
|
// ÉèÖÿÆÄ¿ÐÅÏ¢ reg.setCourseId(cls.getCourseId());
|
ClsClass cls = read(ClsClass.class, reg.getClassId());
|
reg.setCollegeCourseId(cls.getCollegeCourseId());
|
|
save(reg);
|
objResult = new Result(true, reg.getRegistrationId());
|
// ѧԱ²Ù×÷¼Ç¼
|
this.doInsertRegLog("ÐÂÔöѧԱ", reg.getRegistrationId(), reg.getMobilePhone());
|
doUserExtend(user.getUserId(), userEx, true);
|
|
//×Ô¶¨ÒåÐÅÏ¢
|
insertCustomInfo(reg.getRegistrationId(), user.getUserId(), reg.getClassId(), signupInfo);
|
} else {
|
objResult.setMsg("ÒѾ´æÔÚ¸ÃÓû§");
|
}
|
}
|
return objResult;
|
}
|
|
/**
|
* ²åÈë×Ô¶¨ÒåÓû§ÐÅÏ¢
|
* @param userId
|
* @param userEx
|
*/
|
private void doUserExtend(String userId,UserExtend userEx,Boolean editFlag){
|
if(StringUtils.isNotBlank(userId) && null != userEx){
|
String hql = "from UserExtend where deleteFlag is false and userId = ?";
|
UserExtend user = this.findUnique(hql, CollectionUtils.newList(userId), UserExtend.class);
|
if(null == user){
|
userEx.setUserId(userId);
|
userEx.setDeleteFlag(false);
|
TraceUtils.setCreateTrace(userEx);
|
save(userEx);
|
}else{
|
if(editFlag){
|
user.setProvince(userEx.getProvince());
|
user.setCity(userEx.getCity());
|
user.setRegion(userEx.getRegion());
|
user.setIdNumber(userEx.getIdNumber());
|
user.setUserPhoto(userEx.getUserPhoto());
|
user.setBirthday(userEx.getBirthday());
|
user.setCompany(userEx.getCompany());
|
user.setMailFlag(userEx.getMailFlag());
|
user.setMailAddress(userEx.getMailAddress());
|
user.setQq(userEx.getQq());
|
user.setWeixin(userEx.getWeixin());
|
user.setWeiboSina(userEx.getWeiboSina());
|
TraceUtils.setUpdateTrace(user);
|
save(user);
|
}else{
|
updateUserExtend(user, userEx);
|
}
|
}
|
}
|
}
|
|
/**
|
* ¸üÐÂUserExtend
|
* @param user
|
* @param userEx
|
*/
|
private void updateUserExtend(UserExtend user,UserExtend userEx){
|
|
String strN = "null";
|
if(StringUtils.isBlank(user.getProvince()) || strN.equals(user.getProvince())){
|
user.setProvince(userEx.getProvince());
|
user.setCity(userEx.getCity());
|
user.setRegion(userEx.getRegion());
|
}
|
|
if(StringUtils.isBlank(user.getIdNumber()) || strN.equals(user.getIdNumber())){
|
user.setIdNumber(userEx.getIdNumber());
|
}
|
if(StringUtils.isBlank(user.getUserPhoto()) || strN.equals(user.getUserPhoto())){
|
user.setUserPhoto(userEx.getUserPhoto());
|
}
|
if(StringUtils.isBlank(user.getBirthday()) || strN.equals(user.getBirthday())){
|
user.setBirthday(userEx.getBirthday());
|
}
|
updateUserExtendN(user, userEx, strN);
|
}
|
|
/**
|
* ¸üÐÂUserExtend
|
* @param user
|
* @param userEx
|
*/
|
private void updateUserExtendN(UserExtend user,UserExtend userEx,String strN){
|
|
if(StringUtils.isBlank(user.getCompany()) || strN.equals(user.getCompany())){
|
user.setCompany(userEx.getCompany());
|
}
|
if(StringUtils.isBlank(user.getMailAddress()) || strN.equals(user.getMailAddress())){
|
user.setMailAddress(userEx.getMailAddress());
|
}
|
if(StringUtils.isBlank(user.getQq()) || strN.equals(user.getQq())){
|
user.setQq(userEx.getQq());
|
}
|
if(StringUtils.isBlank(user.getWeixin()) || strN.equals(user.getWeixin())){
|
user.setWeixin(userEx.getWeixin());
|
}
|
if(StringUtils.isBlank(user.getWeiboSina()) || strN.equals(user.getWeiboSina())){
|
user.setWeiboSina(userEx.getWeiboSina());
|
}
|
|
TraceUtils.setUpdateTrace(user);
|
save(user);
|
}
|
|
/**
|
* µÃµ½MSG_USER
|
*
|
* @param userId
|
* @return
|
*/
|
private List<MsgUser> getMsgUserList(String userId) {
|
String hql = "from MsgUser where deleteFlag is false and userId = ? ";
|
// ´æÔÚµÄmobile
|
return this.find(hql, CollectionUtils.newList(userId), MsgUser.class);
|
}
|
|
/**
|
* ÐÞ¸ÄMsg¡ª¡ªuser
|
*
|
* @param lstMu
|
* @param strUserName
|
*/
|
private void updateMsgUserList(List<MsgUser> lstMu, String strUserName) {
|
for (MsgUser mu : lstMu) {
|
mu.setRealName(strUserName);
|
}
|
}
|
|
/**
|
* Åжϵ±Ç°°à¼¶ÊÇ·ñÓиÃÊÖ»úºÅÂ루Ӧ¸Ãǰ̨УÑé+ºǫ́Åжϣ©
|
*
|
* @param strMobilePhone
|
* @return
|
*/
|
private boolean checkMobileExists(String strMobilePhone) {
|
String hql = "from UserRegistration where deleteFlag is false and classId = ? and mobilePhone = ? ";
|
return this.findCount(hql, CollectionUtils.newList(ClientUtils.getClassId(), strMobilePhone)) > 0 ? true : false;
|
|
}
|
|
/**
|
* ×é×°µ¼ÈëÓйØËùÓеÄMSG_USER
|
*
|
* @param lstUg
|
* @return
|
*/
|
private List<MsgUser> getMsgUserAllList(List<UserRegistration> lstUg) {
|
if (lstUg != null && !lstUg.isEmpty()) {
|
StringBuffer hql = new StringBuffer(150);
|
hql.append("from MsgUser where deleteFlag is false and userId in ( ");
|
Map<String, String> objMap = new HashMap<String, String>();
|
List<Object> lstO = new ArrayList<Object>();
|
for (int i = 0; i < lstUg.size(); i++) {
|
UserRegistration ug = lstUg.get(i);
|
if (i == lstUg.size() - 1) {
|
hql.append(" ? ) ");
|
} else {
|
hql.append(" ? , ");
|
}
|
lstO.add(ug.getUserId());
|
objMap.put(ug.getUserId(), ug.getUserName());
|
}
|
// ´æÔÚµÄmobile
|
List<MsgUser> lstMu = this.find(hql.toString(), lstO, MsgUser.class);
|
for (MsgUser objMu : lstMu) {
|
objMu.setRealName(objMap.get(objMu.getUserId()));
|
}
|
return lstMu;
|
}
|
return null;
|
|
}
|
|
/**
|
* µÃµ½×¢²áÐÅÏ¢
|
*
|
* @return
|
*/
|
public List<ExportUserRegistration> queryExportRegList(boolean orgFlag) {
|
String strSQL = getExportSQL(orgFlag);
|
List<Object> args = null;
|
if (orgFlag) {
|
args = CollectionUtils.newList(ClientUtils.getOrgId());
|
} else {
|
args = CollectionUtils.newList(ClientUtils.getClassId());
|
}
|
return registrationDAO.queryExportRegList(strSQL, args);
|
}
|
|
/**
|
* µ¼³öSQL
|
*
|
* @param orgFlag
|
* @return
|
*/
|
private String getExportSQL(boolean orgFlag) {
|
String strSQL = null;
|
if(orgFlag){
|
strSQL = " SELECT UR.userName,UR.salesCode,UR.mobilePhone,UR.status,UR.installFlag,C.NAME AS className, UR.activationTime,UR.registrationTime FROM "
|
+ " ( SELECT R.USER_NAME AS userName,R.SALES_CODE AS salesCode,R.MOBILE_PHONE AS mobilePhone , R.CLASS_ID AS classId, R.ACTIVATION_TIME As activationTime,"
|
+ " CASE R.STATUS WHEN 0 THEN 'δ¿ªÊ¼' WHEN 1 THEN 'ÉÏ¿ÎÖÐ' ELSE '½áÊø' END AS status ,"
|
+ " CASE WHEN O.OPERATE_ID IS NULL THEN '·ñ' ELSE 'ÊÇ' END installFlag,R.REGISTRATION_TIME AS registrationTime "
|
+ " FROM USER_REGISTRATION R LEFT JOIN USER_OPERATE O ON R.USER_ID = O.USER_ID "
|
+ " WHERE IFNULL(O.DELETE_FLAG,0) = 0 AND R.DELETE_FLAG = 0 AND R.CLASS_ID IN "
|
+ " ( SELECT DISTINCT CLS.CLASS_ID FROM ORG_CLASS CLS,ORG_COLLEGE_COURSE COU WHERE COU.ORGANIZATION_ID = ? AND COU.COURSE_ID = CLS.COLLEGE_COURSE_ID "
|
+ " AND COU.DELETE_FLAG = 0 AND CLS.DELETE_FLAG = 0 ) "
|
+ " ) AS UR , ORG_CLASS C WHERE C.CLASS_ID = UR.classId ORDER BY UR.classId ASC ";
|
}else{
|
strSQL = " SELECT R.USER_NAME AS userName,R.SALES_CODE AS salesCode,R.MOBILE_PHONE AS mobilePhone,R.ACTIVATION_TIME As activationTime,R.REGISTRATION_TIME AS registrationTime, "
|
+ " CASE R.STATUS WHEN 0 THEN 'δ¿ªÊ¼' WHEN 1 THEN 'ÉÏ¿ÎÖÐ' ELSE '½áÊø' END AS status ,"
|
+ " CASE WHEN O.OPERATE_ID IS NULL THEN '·ñ' ELSE 'ÊÇ' END installFlag "
|
+ " FROM USER_REGISTRATION R LEFT JOIN USER_OPERATE O ON R.USER_ID = O.USER_ID "
|
+ " WHERE IFNULL(O.DELETE_FLAG,0) = 0 AND R.DELETE_FLAG = 0 AND R.CLASS_ID = ? ORDER BY R.CREATE_TIME DESC ";
|
}
|
return strSQL;
|
}
|
|
@Override
|
public boolean hasRegistration(String mobilePhone, String classId) {
|
|
String hql = "select count(1) from UserRegistration where deleteFlag is false and mobilePhone=? and classId=?";
|
|
int count = this.findUnique(hql, CollectionUtils.newList(mobilePhone, classId), int.class);
|
|
return count > 0;
|
}
|
|
/**
|
* ΢ÐżÓÈëÓοͻú¹¹ÌåÑé°à¼¶£¬²»ÐèÒªÏûºÄÕ˺Å
|
*
|
*/
|
public Result insertWXOrgVisitorClass(Map<String,Object> userMap){
|
// »ñÈ¡µ±Ç°¹«ÖںŻú¹¹±àÂë
|
String orgCode = (String) userMap.get("orgCode");
|
|
// 1¡¢²éѯ¸Ã»ú¹¹ÊÇ·ñÓÐÌåÑé°à¼¶ ÌåÑé°æ¼Û¸ñ±ØÐë=0
|
List<String> lstClass = this.find("select DISTINCT v.classId from OrgClassVisitor v,ClsClass c "
|
+ " where v.classId=c.classId and v.deleteFlag is false and c.deleteFlag is false"
|
+ " and c.disprice <=? and c.org.code=? ",
|
CollectionUtils.newList(BigDecimal.ZERO, orgCode), String.class);
|
|
if(lstClass.isEmpty()){// »ú¹¹ÎÞÌåÑé°à¼¶
|
|
// Éú³ÉÕ˺Å
|
User user = generateUser(String.valueOf(userMap.get(MOBILE_PHONE)));
|
Result result = new Result(false, "»ú¹¹ÎÞÌåÑé°æ");
|
//²åÈëuser
|
insertUser(user,userMap);
|
//²åÈëMsguser
|
insertMsgUser(user);
|
|
Map<String,Object> attrs = new HashMap<String,Object>(1);
|
attrs.put(USER_ID, user.getUserId());
|
result.setData(attrs);
|
return result;
|
}
|
|
// 2¡¢»ú¹¹ÓÐÌåÑé°à¼¶£¬Óû§¼ÓÈëÌåÑé°à¼¶
|
String[] classIds = new String[lstClass.size()];
|
for(int i=0; i<lstClass.size(); i++){
|
classIds[i] = lstClass.get(i);
|
}
|
|
return generateClassVisitor(userMap, classIds);
|
}
|
|
/**
|
* ¼ÓÈëQѧÓÑÓοͰ༶£¬²»ÐèÒªÏûºÄÕ˺Å
|
*/
|
public Result insertClassVisitor(Map<String,Object> userMap){
|
// Èý¸öÌåÑé°à¼¶
|
// SysConfig sc = cacheService.get(ADD_REG_CLASS_IDS, SysConfig.class);
|
SysConfig sc = null;
|
if (null == sc) {
|
String hql = " from SysConfig where configKey=?";
|
sc = findUnique(hql, CollectionUtils.newList(ADD_REG_CLASS_IDS), SysConfig.class);
|
// ¼ÓÈ뻺´æ
|
// cacheService.set(ADD_REG_CLASS_IDS, 24 * 60 * 60, sc);
|
}
|
|
String scValue = "";
|
if(null!=sc){
|
scValue = sc.getValue();
|
}
|
|
String classIds []= scValue.split(",");
|
|
return generateClassVisitor(userMap, classIds);
|
}
|
|
/**
|
* ¼ÓÈëÓοͰ༶£¬²»ÐèÒªÏûºÄÕ˺ŠÉú³ÉÕ˺Ų¢¼ÓÈëÌåÑé°à¼¶
|
*/
|
public Result generateClassVisitor(Map<String,Object> userMap,String[] classIds){
|
|
User user = generateUser(String.valueOf(userMap.get(MOBILE_PHONE)));
|
Result result = new Result(true);
|
//²åÈëuser
|
insertUser(user,userMap);
|
//²åÈëMsguser
|
insertMsgUser(user);
|
|
String regId = "";
|
for (String string : classIds) {
|
if(StringUtils.isBlank(string)){
|
continue;
|
}
|
ClsClass occ = read(ClsClass.class, string);
|
if(occ.getDisprice().compareTo(BigDecimal.ZERO) > 0){//Èç¹ûµ±Ç°°à¼¶µÄ¼Û¸ñ¸ßÓÚ0 ¼´Îª¸¶·Ñ°à ²»Ìí¼Ó½øÀ´
|
continue;
|
}
|
UserRegistration urg = generateUserRegByUser(String.valueOf(userMap.get("userId")), string);
|
|
if (null == urg.getRegistrationId()) {
|
urg.setClassId(string);
|
|
urg.setClassName(occ.getName());
|
urg.setCollegeCourseId(occ.getCollegeCourseId());
|
urg.setDeleteFlag(false);
|
if (userMap.get(MOBILE_PHONE) != null) {
|
urg.setMobilePhone(String.valueOf(userMap.get(MOBILE_PHONE)));
|
}
|
// urg.setSex(user.getSex());
|
urg.setStatus(UserRegistration.STATUS_ACTIVE);
|
urg.setUserId(user.getUserId());
|
urg.setUserName(user.getName());
|
urg.setRegistrationTime(new Date());
|
TraceUtils.setCreateTrace(urg);
|
insert(urg);
|
|
// ±¨ÃûÈËÊý¼Ó1
|
occ.setStudentCount(occ.getStudentCount()+1);
|
save(occ);
|
}
|
|
if(string.equals(Constants.VISITOR_CLASS_ID)){
|
regId = urg.getRegistrationId();
|
}
|
Map<String,String> param = new HashMap<String, String>();
|
param.put(USER_ID, user.getUserId());
|
param.put(PASSWORD, user.getPassword());
|
param.put(CLASS_ID, string);
|
param.put(REG_ID, urg.getRegistrationId());
|
|
sendMsgActiveMsg(param,1);
|
}
|
|
Map<String,Object> attrs = new HashMap<String,Object>(2);
|
attrs.put(USER_ID, user.getUserId());
|
|
result.setMsg(regId);
|
result.setData(attrs);
|
|
return result;
|
}
|
|
/**
|
* ÀÏÕË»§ ½ö½ö¼ÓÈë¸Ã»ú¹¹µÄÌåÑé°æ ²»Éú³ÉÕ˺Å
|
* @param userMap
|
* @return
|
*/
|
@Override
|
public Result insertOnlyWXOrgVisitorCls(Map<String,Object> userMap){
|
Result result = new Result(false);
|
String userId = (String) userMap.get("userId");
|
|
User user = this.read(User.class, userId);
|
|
// »ñÈ¡µ±Ç°¹«ÖںŻú¹¹±àÂë
|
String orgCode = (String) userMap.get("orgCode");
|
|
// 1¡¢²éѯ¸Ã»ú¹¹ÊÇ·ñÓÐÌåÑé°à¼¶ ÌåÑé°æ¼Û¸ñ±ØÐë=0
|
List<String> lstClass = this.find("select DISTINCT v.classId from OrgClassVisitor v,ClsClass c "
|
+ " where v.classId=c.classId and v.deleteFlag is false and c.deleteFlag is false"
|
+ " and c.disprice <=? and c.org.code=? ",
|
CollectionUtils.newList(BigDecimal.ZERO, orgCode), String.class);
|
|
if(lstClass.isEmpty()){// »ú¹¹ÎÞÌåÑé°à¼¶ ¼´¼ÓÈëQѧÓÑÌåÑé°à
|
return new Result(false,"»ú¹¹Îް༶");
|
}
|
|
// 2¡¢»ú¹¹ÓÐÌåÑé°à¼¶£¬Óû§¼ÓÈëÌåÑé°à¼¶
|
Map<String,String> param;
|
for (String classId : lstClass) {
|
if(StringUtils.isBlank(classId)){
|
continue;
|
}
|
|
UserRegistration urg = generateUserRegByUser(userId, classId);
|
|
if (null == urg.getRegistrationId()) {
|
urg.setClassId(classId);
|
|
ClsClass occ = read(ClsClass.class, classId);
|
urg.setClassName(occ.getName());
|
urg.setCollegeCourseId(occ.getCollegeCourseId());
|
urg.setDeleteFlag(false);
|
if (userMap.get(MOBILE_PHONE) != null) {
|
urg.setMobilePhone(String.valueOf(userMap.get(MOBILE_PHONE)));
|
}
|
// urg.setSex(user.getSex());
|
urg.setStatus(UserRegistration.STATUS_ACTIVE);
|
urg.setUserId(user.getUserId());
|
urg.setUserName(user.getName());
|
urg.setRegistrationTime(new Date());
|
TraceUtils.setCreateTrace(urg);
|
insert(urg);
|
|
// ±¨ÃûÈËÊý¼Ó1
|
occ.setStudentCount(occ.getStudentCount()+1);
|
save(occ);
|
}
|
|
param = new HashMap<String, String>(4);
|
param.put(USER_ID, user.getUserId());
|
param.put(PASSWORD, user.getPassword());
|
param.put(CLASS_ID, classId);
|
param.put(REG_ID, urg.getRegistrationId());
|
sendMsgActiveMsg(param,1);
|
}
|
|
Map<String, Object> attrs = new HashMap<String, Object>(1);
|
attrs.put("classId", lstClass.get(0));
|
result.setData(attrs);
|
result.setResult(true);
|
return result;
|
}
|
|
/**
|
* ²åÈëMsguser
|
* @param user
|
* @return
|
*/
|
private MsgUser insertMsgUser(User user){
|
MsgUser msgUser = this.read(MsgUser.class, user.getUserId());
|
if(null == msgUser){
|
msgUser = new MsgUser();
|
TraceUtils.setCreateTrace(msgUser);
|
msgUser.setDeleteFlag(false);
|
|
msgUser.setAccount(user.getAccount());
|
msgUser.setAlias(user.getName());
|
msgUser.setPassword(user.getPassword());
|
msgUser.setRealName(user.getName());
|
msgUser.setUserId(user.getUserId());
|
// msgUser.setSex(user.getSex());
|
|
msgUser.setPortrait(user.getImgPath());
|
|
insert(msgUser);
|
}
|
|
return msgUser;
|
}
|
|
/**
|
* ³õʼ»¯»·ÐÅÐÅÏ¢
|
* @param msgUser
|
* @param classId
|
* @return
|
*/
|
public Result insertEasemobInfo( MsgUser msgUser ,String classId ,String regId ){
|
|
// // 1. »·ÐÅÔö¼ÓÓû§
|
// easeMobService.addUser(msgUser);
|
//
|
// // 2. ºÃÓÑ£¬ÏµÍ³Í¨Öª£¬Ñ§Ð£Í¨Öª£¬°à¼¶Í¨Öª
|
// easeMobService.addFriend(msgUser.getUserId(), Notice.NOTICE_CLASS_MSG_USER_ID);
|
// easeMobService.addFriend(msgUser.getUserId(), Notice.NOTICE_ORG_MSG_USER_ID);
|
|
// 3. ¼ÓȺ
|
if(StringUtils.isBlank(regId)){
|
return new Result(true);
|
}
|
UserRegistration reg = read(UserRegistration.class,regId);
|
MsgGroup group = read(MsgGroup.class, classId );
|
if( null != group && StringUtils.isNotBlank(group.getEasmobGroupId()) ){
|
// easeMobService.addGroupMember(group.getEasmobGroupId() , msgUser.getUserId() );
|
}else{
|
|
if (group == null) {
|
|
group = insertNewGroup(reg,msgUser);
|
|
}else if(StringUtils.isBlank(group.getEasmobGroupId())){
|
|
// Result result = easeMobService.addGroup(group.getName(), group.getDescription(), 500000, msgUser.getUserId());
|
Result result = new Result();
|
|
String easemobGroupId = result.getMsg() ;
|
if(result.isSuccess() && StringUtils.isNotBlank(easemobGroupId)){
|
group.setEasmobGroupId(easemobGroupId);
|
TraceUtils.setUpdateTrace(group);
|
save(group);
|
}
|
}
|
|
// ½«¸Ã³ÉÔ±¼ÓÈëȺ
|
// easeMobService.addGroupMember(group.getEasmobGroupId() , msgUser.getUserId() );
|
|
}
|
int existNoticeClass = findCount("from MsgGroupUserRe where deleteFlag is false and userId = ? and groupId = ?", CollectionUtils.newList(reg.getUserId(), group.getGroupId()));
|
|
if (existNoticeClass == 0) {
|
MsgGroupUserRe member = new MsgGroupUserRe();
|
TraceUtils.setCreateTrace(member);
|
member.setUserId(msgUser.getUserId());
|
member.setGroupId(group.getGroupId());
|
member.setDeleteFlag(false);
|
save(member);
|
}
|
|
return new Result(true);
|
|
}
|
|
/**
|
* ¼ÓÈë»î¶¯·¢²¼Õ߰༶,²¢¼¤»î
|
*/
|
public Result insertClassUser(Map<String,Object> userMap){
|
Result result = new Result(true);
|
User user = generateUser(String.valueOf(userMap.get(MOBILE_PHONE)));
|
|
// ²åÈëuser
|
insertUser(user, userMap);
|
// ²åÈëMsguser
|
MsgUser msgUser = insertMsgUser(user);
|
|
String classId = (String) userMap.get(CLASS_ID);
|
|
UserRegistration urg = generateUserReg(String.valueOf(userMap.get(MOBILE_PHONE)), classId);
|
|
if (null == urg.getRegistrationId()) {
|
urg.setClassId(classId);
|
|
ClsClass occ = read(ClsClass.class, classId);
|
urg.setClassName(occ.getName());
|
urg.setCollegeCourseId(occ.getCollegeCourseId());
|
urg.setDeleteFlag(false);
|
if (userMap.get(MOBILE_PHONE) != null) {
|
urg.setMobilePhone(String.valueOf(userMap.get(MOBILE_PHONE)));
|
}
|
// urg.setSex(user.getSex());
|
urg.setStatus(UserRegistration.STATUS_ACTIVE);
|
urg.setUserId(user.getUserId());
|
urg.setUserName(user.getName());
|
urg.setRegistrationTime(new Date());
|
TraceUtils.setCreateTrace(urg);
|
insert(urg);
|
}
|
|
String regId = urg.getRegistrationId();
|
|
Map<String, String> param = new HashMap<String, String>();
|
param.put(USER_ID, msgUser.getUserId());
|
param.put(PASSWORD, msgUser.getPassword());
|
param.put(CLASS_ID, classId);
|
param.put(REG_ID, urg.getRegistrationId());
|
|
sendMsgActiveMsg(param, 1);
|
|
Map<String, Object> attrs = new HashMap<String, Object>(2);
|
attrs.put(USER_ID, user.getUserId());
|
/* attrs.put("regId", ur.getRegistrationId()); */
|
|
result.setMsg(regId);
|
result.setData(attrs);
|
|
return result;
|
|
}
|
|
/**
|
* IMEI¼ÓÈë°à¼¶(È«²¿Ãâ·Ñ¼¤»î£¬²»ÏûºÄÕ˺Å)
|
*/
|
public Result insertClassIMEI(Map<String,Object> userMap){
|
Result result = new Result(true);
|
User user = new User();
|
TraceUtils.setCreateTrace(user);
|
user.setDeleteFlag(false);
|
user.setImgPath(FilePathConstants.getUserDefaultImg());
|
user.setPassword(RSAUtils.encrypt("hello"));
|
// user.setImei(String.valueOf(userMap.get("imei")));
|
user.setAccount(doGetNewQxyAccount());
|
// if(null != userMap.get(SOURCE)){
|
// user.setSource(String.valueOf(userMap.get(SOURCE)));
|
// }
|
user.setName("ÓοÍ");
|
// userService.saveUserTrace(user, false, null);
|
|
MsgUser msgUser = read(MsgUser.class, user.getUserId());
|
if (msgUser == null) {
|
msgUser = new MsgUser();
|
TraceUtils.setCreateTrace(msgUser);
|
}
|
|
msgUser.setDeleteFlag(false);
|
|
msgUser.setAccount(user.getAccount());
|
msgUser.setAlias(user.getName());
|
msgUser.setPassword(user.getPassword());
|
msgUser.setRealName(user.getName());
|
msgUser.setUserId(user.getUserId());
|
// msgUser.setSex(user.getSex());
|
|
msgUser.setPortrait(user.getImgPath());
|
|
insert(msgUser);
|
|
// ¼ÓÈë¶îÍâÈý¸ö°à¼¶
|
// SysConfig sc = cacheService.get(ADD_REG_CLASS_IDS, SysConfig.class);
|
SysConfig sc = null;
|
if(null==sc){
|
String hql = " from SysConfig where configKey=?";
|
sc = findUnique(hql, CollectionUtils.newList(ADD_REG_CLASS_IDS), SysConfig.class);
|
//¼ÓÈ뻺´æ
|
// cacheService.set(ADD_REG_CLASS_IDS, 24*60*60, sc);
|
}
|
String scValue = "";
|
|
if(null!=sc){
|
scValue = sc.getValue();
|
}
|
//String scValue = sc.getValue();
|
|
String classIds []= scValue.split(",");
|
String regId="";
|
for (String string : classIds) {
|
UserRegistration urg = null != userMap.get(MOBILE_PHONE) ?
|
generateUserReg(String.valueOf(userMap.get(MOBILE_PHONE)), string) :
|
new UserRegistration() ;
|
|
if (null == urg.getRegistrationId()) {
|
urg.setClassId(string);
|
|
ClsClass occ = read(ClsClass.class, string);
|
if(null==occ){
|
continue;
|
}
|
urg.setClassName(occ.getName());
|
urg.setCollegeCourseId(occ.getCollegeCourseId());
|
urg.setDeleteFlag(false);
|
if (userMap.get(MOBILE_PHONE) != null) {
|
urg.setMobilePhone(String.valueOf(userMap.get(MOBILE_PHONE)));
|
}
|
// urg.setSex(user.getSex());
|
urg.setStatus(UserRegistration.STATUS_ACTIVE);
|
urg.setUserId(user.getUserId());
|
urg.setUserName(user.getName());
|
urg.setRegistrationTime(new Date());
|
TraceUtils.setCreateTrace(urg);
|
insert(urg);
|
}
|
|
if(string.equals(Constants.VISITOR_CLASS_ID)){
|
regId = urg.getRegistrationId();
|
}
|
//ÏûÏ¢´¦Àí³õʼ»¯»·ÐÅÐÅÏ¢
|
Map<String,String> param = new HashMap<String, String>();
|
param.put(USER_ID, msgUser.getUserId());
|
param.put(PASSWORD, msgUser.getPassword());
|
param.put(CLASS_ID, string);
|
param.put(REG_ID, urg.getRegistrationId());
|
|
sendMsgActiveMsg(param,1);
|
}
|
|
Map<String,Object> attrs = new HashMap<String,Object>(2);
|
attrs.put(USER_ID, user.getUserId());
|
/* attrs.put("regId", ur.getRegistrationId());*/
|
|
result.setMsg(regId);
|
result.setData(attrs);
|
|
return result;
|
|
}
|
/**
|
* @version 2.0 ×¢²á(ÐÂÔöÓû§¡¢Ñ§Ô±)
|
* @param role:½ÇÉ«£¨Ìí¼ÓÓû§µÄ½ÇÉ«,ûÓпÉÒÔ´«null£©, type:(²Ù×÷ÀàÐÍ£ººǫ́¡¢Î¢ÐÅ¡¢APP....) userMap£º²ÎÊý mode:¾ßÌå²Ù×÷(ûÓпÉÒÔ´«null)
|
*/
|
public Result executeRegist(String role, String type,String mode,Map<String, Object> userMap) {
|
//APP:
|
if (Constants.REG_TYPE_APP.equals(type)) {
|
if(Constants.REG_MODE_IMEI_JOIN.equals(mode)){
|
return insertClassIMEI(userMap);
|
}else{
|
// ÉêÇë×¢²á
|
Result result = new Result(true);
|
|
// ResponseResult response = doGenerateUserRegRecord(userMap, false); // ÒÑÌí¼Ó
|
|
ResponseResult response = null;
|
result.addData("response", response);
|
return result;
|
}
|
}
|
|
//ºǫ́£º
|
if (Constants.REG_TYPE_BACKSTAGE.equals(type)&&role == null) {
|
|
UserRegistration reg = (UserRegistration) userMap.get("reg");
|
UserExtend userEx = (UserExtend) userMap.get("userEx");
|
boolean male = (Boolean) userMap.get("male");
|
String signupInfo = (String) userMap.get("signupInfo");
|
// ÐÂÔö±¨ÃûÐÅÏ¢
|
if (Constants.REG_MODE_REGIST.equals(mode)) {
|
|
return insertRegistration(reg, male,generateSourceFromMap(userMap), signupInfo); // ÒÑÌí¼Ó
|
}
|
//¸üÐÂÓû§ÐÅÏ¢
|
if (Constants.REG_MODE_EDIT.equals(mode)) {
|
|
return updateRegistration(reg,userEx,male, signupInfo); // ÒÑÌí¼Ó
|
}
|
|
}
|
//ÍøÒ³¶Ë£¨Ñ¡¿Î±¨Ãû£©
|
if (Constants.REG_TYPE_WEB.equals(type)) {
|
doChooseClassReg(userMap,true); // ÒÑÌí¼Ó
|
|
}
|
//΢ÐÅ
|
if (Constants.REG_TYPE_WEIXIN.equals(type)) {
|
// return executeRegistWx(type, mode, userMap);
|
return null;
|
}
|
//sdk
|
if(Constants.REG_TYPE_SDK.equals(type)){
|
return insertClassUser(userMap);
|
}
|
|
// ÄÚÈÝ·ÖÏí£¨½²Òå¡¢ÊÓÆµ£©¡¢Ö±²¥»¥¶¯¡¢¿Î³Ì·ÖÏí
|
if(Constants.REG_TYPE_CONTENT_SHARE.equals(type)){
|
|
return insertUserToShare(userMap);
|
}
|
|
return null;
|
}
|
|
private String generateSourceFromMap(Map<String, Object> userMap){
|
|
return userMap.get(SOURCE) != null ? String.valueOf(userMap.get(SOURCE)) : null ;
|
|
}
|
|
|
/**
|
* ¹¦ÄÜ£ºÐÂÔöÓû§
|
* Ä£¿é£º ÄÚÈÝ·ÖÏí(½²Òå¡¢ÊÓÆµ)¡¢·ÖÏí¿Î³Ì¡¢Ö±²¥»¥¶¯
|
* À´Ô´£º·Ç΢ÐÅ
|
* ·µ»Ø£ºResult(attrs:Óû§ÐÅÏ¢)
|
*/
|
public Result insertUserToShare(Map<String,Object> userMap){
|
|
User user = insertUser(userMap);
|
|
return returnResult(user, userMap);
|
}
|
|
private Result returnResult(User user, Map<String,Object> userMap){
|
|
// »ñÈ¡msg_user,×¢²á»·ÐÅÓû§
|
MsgUser msgUser = doNewMsgUser(user,userMap);
|
|
// ·µ»Ø²ÎÊý
|
Map<String,Object> attrs = new HashMap<String,Object>(2);
|
attrs.put("userId", user.getUserId());
|
attrs.put("name", user.getName());
|
attrs.put("mobilePhone", user.getMobilePhone());
|
attrs.put("alias", msgUser.getAlias());
|
attrs.put("imgUrl", msgUser.getImgUrl());
|
|
Result result = new Result(true);
|
result.setData(attrs);
|
|
return result;
|
}
|
|
/**
|
* ¹¦ÄÜ£º»ñÈ¡ UserÂß¼´¦Àí
|
* Ä£¿é£º ÄÚÈÝ·ÖÏí(½²Òå¡¢ÊÓÆµ)¡¢·ÖÏí¿Î³Ì¡¢Ö±²¥»¥¶¯
|
* À´Ô´£º·Ç΢ÐÅ
|
* ·µ»Ø£ºuser
|
*/
|
public User insertUser(Map<String,Object> userMap){
|
|
User user = null;
|
|
String userId = String.valueOf(userMap.get("userId"));
|
|
if(StringUtils.isNotBlank(userId)){
|
|
String hql = "from User u where u.deleteFlag is false and u.userId = ? ";
|
user = this.findUnique(hql, CollectionUtils.newList(userId), User.class) ;
|
|
if(null == user){
|
user = saveAddUser( userMap, null, null );
|
}
|
}else{
|
|
user = saveAddUser( userMap, null, null);
|
}
|
|
return user;
|
}
|
|
/**
|
* ÐÂÔöÓû§
|
* @param userMap
|
* @param wxName
|
* @param wxImgUrl
|
* @return
|
*/
|
private User saveAddUser(Map<String,Object> userMap,String wxName,String wxImgUrl){
|
|
String accout = doGetNewQxyAccount();
|
User user = new User();
|
|
int loop = 0;
|
do {
|
|
try {
|
user.setName(StringUtils.isBlank(wxName) ? "ÓοÍ" + accout : wxName);
|
user.setAccount(accout);
|
user.setDeleteFlag(false);
|
user.setPassword(RSAUtils.encrypt(NumRandomUtils.randomSixNum()));
|
user.setImgPath(StringUtils.isBlank(wxImgUrl) ? FilePathConstants.getUserDefaultImg() : wxImgUrl);
|
|
TraceUtils.setCreateTrace(user);
|
break;
|
|
} catch (Exception e) {
|
loop++;
|
accout = doGetNewQxyAccount();
|
continue;
|
}
|
|
} while (loop < 100);
|
|
return user;
|
}
|
|
/**
|
* »ñÈ¡msg_user
|
* @param user
|
* @return
|
*/
|
public MsgUser doNewMsgUser(User user,Map<String,Object> userMap) {
|
|
String hql1 = "from MsgUser u where u.deleteFlag is false and u.userId = ? ";
|
MsgUser msgUser = this.findUnique(hql1, CollectionUtils.newList(user.getUserId()), MsgUser.class) ;
|
|
if(null == msgUser){
|
msgUser = new MsgUser();
|
msgUser.setCreateId(user.getUserId());
|
msgUser.setCreateTime(new Date(System.currentTimeMillis()));
|
msgUser.setCreator(user.getAccount());
|
msgUser.setUpdateId(user.getUserId());
|
msgUser.setUpdateTime(new Date(System.currentTimeMillis()));
|
msgUser.setUpdator(user.getAccount());
|
msgUser.setDeleteFlag(false);
|
msgUser.setAlias(user.getName());
|
msgUser.setAccount(user.getAccount());
|
msgUser.setPassword(user.getPassword());
|
msgUser.setPortrait(user.getImgPath());
|
msgUser.setRealName(user.getName());
|
msgUser.setUserId(user.getUserId());
|
insert(msgUser);
|
|
return msgUser;
|
}
|
|
// Èç¹ûAliasΪopenId¡¢¿Õ ÔòÐÞ¸ÄAliasÖµ
|
if(String.valueOf(userMap.get("openId")).equals(msgUser.getAlias())
|
|| StringUtils.isBlank(msgUser.getAlias())){
|
msgUser.setAlias(user.getName());
|
save(msgUser);
|
}
|
|
return msgUser;
|
}
|
|
|
/**
|
* ×¢²áÐÂÓû§ÐÅÏ¢×¼±¸ - ¼æÈÝ΢ÐŶËÐÂÔöÓû§
|
* @return
|
*/
|
public HashMap<String, Object> prepareUserInfoMap(String openId, String userId, String source,String wxSource) {
|
HashMap<String,Object> userMap = new HashMap<String,Object>(4);
|
|
userMap.put("openId", openId);
|
userMap.put("userId", userId);
|
|
if(StringUtils.isNotBlank(source)){
|
userMap.put(SOURCE, source);
|
}
|
|
if(StringUtils.isNotBlank(wxSource)){
|
userMap.put("wxSource", wxSource);
|
}
|
|
return userMap;
|
}
|
|
/**
|
* @version 2.0 ±¨Ãû
|
* @param role:½ÇÉ«£¨Ìí¼ÓÓû§µÄ½ÇÉ«£©, type:(²Ù×÷ÀàÐÍ£ººǫ́¡¢Î¢ÐÅ¡¢APP....) userMap£º²ÎÊý
|
*/
|
public Result executeSignup(String role, String type, String mode,Map<String, Object> userMap) {
|
if (Constants.REG_TYPE_APP.equals(type)) {
|
|
// ÓοÍÌá½»
|
if (Constants.REG_ROLE_VISITOR.equals(role)) {
|
|
doVisitorRegClass(userMap);
|
|
} else {
|
// Óû§Ìá½»
|
doRegClass(userMap.get(CLASS_ID).toString(), userMap.get("courseId").toString());
|
}
|
}
|
|
return null;
|
}
|
|
/**
|
* @version 2.0 ¼¤»î
|
* @param role:½ÇÉ«£¨Ìí¼ÓÓû§µÄ½ÇÉ«£©, type:(²Ù×÷ÀàÐÍ£ººǫ́¡¢Î¢ÐÅ¡¢APP....) userMap£º²ÎÊý
|
*/
|
public Result executeActivation(String role, String type,String mode, Map<String, Object> userMap,boolean smsFlag,Map<String,String> passwordMap) {
|
//APP£º
|
if (Constants.REG_TYPE_APP.equals(type)) {
|
doActiveRegistrations((String[]) userMap.get("regIds"),smsFlag,passwordMap);
|
}
|
if (Constants.REG_TYPE_BACKSTAGE.equals(type)) {
|
// ¼¤»î±¨ÃûÐÅÏ¢
|
if (Constants.REG_MODE_ACTIVATION.equals(mode)) {
|
return doActiveRegistrations((String[]) userMap.get("regIds"),smsFlag,passwordMap);
|
}
|
// ¶³½á±¨ÃûÐÅÏ¢
|
if (Constants.REG_MODE_FROZEN.equals(mode)) {
|
return doDeActiveRegistrations((String[]) userMap.get("regIds"));
|
}
|
}
|
return null;
|
}
|
|
/**
|
* »ñÈ¡QѧÓÑ×îеÄÕ˺źÅÂë
|
* @return
|
*/
|
@Override
|
public String doGetNewQxyAccount() {
|
return String.valueOf(this.findByComplexSql("select nextval('user_account')", null, Integer.class).get(0));
|
}
|
|
/**
|
* ¼¤»îѧԱ·¢ËÍÏûÏ¢
|
* @param map
|
* @return
|
*/
|
@SuppressWarnings("unused")
|
private Result sendMsgActiveMsg(Map<String,String> map,int iType) {
|
|
if(iType == 1 ){
|
// ¼¤»î£ºÑÓʱһ·ÖÖÓ·¢ËÍ
|
long deliverTime = System.currentTimeMillis() + 60 * 1000 ;
|
// ONSMsg msg = new ONSMsg(onsProducer.getTopic(),deliverTime);
|
//
|
// msg.put("msgType", "REG_ACTIVE");
|
// msg.put("iType", String.valueOf(iType));
|
// msg.put(USER_ID, map.get(USER_ID));
|
// msg.put(PASSWORD, map.get(PASSWORD));
|
// msg.put(CLASS_ID, map.get(CLASS_ID));
|
// msg.put(REG_ID, map.get("regId"));
|
//
|
// try {
|
// onsProducer.sendMsg(msg);
|
// return new Result(true);
|
// } catch (Exception e) {
|
// log.error("call userRegistrationMsgSendService fail.regId: " + map.get("regId"), e);
|
// }
|
}
|
|
// if(iType == 2){
|
//
|
// ONSMsg msg = new ONSMsg(onsProducer.getTopic());
|
//
|
// msg.put("msgType", "REG_ACTIVE");
|
// msg.put("iType", String.valueOf(iType));
|
// msg.put("userIds", map.get("userIds"));
|
// msg.put(CLASS_ID, map.get(CLASS_ID));
|
//
|
// try {
|
// onsProducer.sendMsg(msg);
|
// return new Result(true);
|
// } catch (Exception e) {
|
// log.error("call userRegistrationMsgSendService fail.regId: " + map.get("regId"), e);
|
// }
|
//
|
// }
|
|
return new Result(false);
|
}
|
|
/**
|
* Òì²½´¦ÀíѧԱ¼¤»îËùÐèÒªµÄ²Ù×÷
|
* @return
|
*/
|
public Result doOnsRegActive(String userId,String password,String classId,String regId){
|
String result = "ʱ¼äÏûºÄ£º";
|
long t1 = System.currentTimeMillis();
|
// 1.³õʼ»¯»·ÐÅÐÅÏ¢
|
doActiveInsertEasemobInfo(userId, classId, regId,password);
|
result = result.concat("1.³õʼ»¯»·ÐÅÐÅÏ¢:".concat(String.valueOf(System.currentTimeMillis()-t1)));
|
long t2 = System.currentTimeMillis();
|
// 2.³õʼ»¯Óû§Î¨Ò»±àÂë
|
doActiveUpdateUserUniqueCode(userId);
|
result = result.concat("-----2.³õʼ»¯Óû§Î¨Ò»±àÂë:".concat(String.valueOf(System.currentTimeMillis()-t2)));
|
long t3 = System.currentTimeMillis();
|
// 3.³õʼ»¯Óû§ÍÆËÍÏûÏ¢ÉèÖÃ
|
doActiveInitMessageSettrings(userId);
|
result = result.concat("-----3.³õʼ»¯Óû§ÍÆËÍÏûÏ¢ÉèÖÃ:".concat(String.valueOf(System.currentTimeMillis()-t3)));
|
long t4 = System.currentTimeMillis();
|
// 4.³õʼ»¯µ±Ç°°à¼¶ÒѾÓеĿαí¶ÔÓ¦µÄѧÉú¿Î±í
|
doActiveinsertStudentScheduleByRegActive(userId, classId);
|
result = result.concat("-----4.³õʼ»¯µ±Ç°°à¼¶ÒѾÓеĿαí¶ÔÓ¦µÄѧÉú¿Î±í:".concat(String.valueOf(System.currentTimeMillis()-t4)));
|
log.info(result);
|
return new Result(true);
|
|
}
|
|
/**
|
* Òì²½´¦ÀíѧԱ¼¤»îËùÐèÒªµÄ²Ù×÷
|
* @return
|
*/
|
public Result doOnsRegActive2(String userId,String password,String classId,String regId){
|
String result = "ʱ¼äÏûºÄ£º";
|
long t1 = System.currentTimeMillis();
|
// 1.³õʼ»¯»·ÐÅÐÅÏ¢
|
doActiveInsertEasemobInfo(userId, classId, regId,password);
|
result = result.concat("1.³õʼ»¯»·ÐÅÐÅÏ¢:".concat(String.valueOf(System.currentTimeMillis()-t1)));
|
long t2 = System.currentTimeMillis();
|
// 2.³õʼ»¯Óû§Î¨Ò»±àÂë
|
doActiveUpdateUserUniqueCode(userId);
|
result = result.concat("-----2.³õʼ»¯Óû§Î¨Ò»±àÂë:".concat(String.valueOf(System.currentTimeMillis()-t2)));
|
long t3 = System.currentTimeMillis();
|
// 3.³õʼ»¯Óû§ÍÆËÍÏûÏ¢ÉèÖÃ
|
doActiveInitMessageSettrings(userId);
|
result = result.concat("-----3.³õʼ»¯Óû§ÍÆËÍÏûÏ¢ÉèÖÃ:".concat(String.valueOf(System.currentTimeMillis()-t3)));
|
long t4 = System.currentTimeMillis();
|
// 4.³õʼ»¯µ±Ç°°à¼¶ÒѾÓеĿαí¶ÔÓ¦µÄѧÉú¿Î±í
|
doActiveinsertStudentScheduleByRegActive(userId, classId);
|
result = result.concat("-----4.³õʼ»¯µ±Ç°°à¼¶ÒѾÓеĿαí¶ÔÓ¦µÄѧÉú¿Î±í:".concat(String.valueOf(System.currentTimeMillis()-t4)));
|
return new Result(true, result);
|
|
}
|
|
|
/**
|
* ³õʼ»¯µ±Ç°°à¼¶ÒѾÓеĿαí¶ÔÓ¦µÄѧÉú¿Î±í
|
* @param userId
|
* @param classId
|
*/
|
@SuppressWarnings("null")
|
private void doActiveinsertStudentScheduleByRegActive(String userId,
|
String classId) {
|
try{
|
// Result result = scheduleService.insertStudentScheduleByRegActive(userId, classId);
|
Result result = null;
|
insertOnsLog(userId, "³õʼ»¯Óû§StudentSchedule³É¹¦;class_id£º".concat(classId) , "REG_INIT_STUDENT_SCHEDULE", "½á¹û£º".concat(result.getMsg()));
|
// sendSysNotice(new String[]{userId}, classId, true);
|
}catch( Exception e ){
|
log.error("³õʼ»¯µ±Ç°°à¼¶ÒѾÓеĿαí¶ÔÓ¦µÄѧÉú¿Î±íʧ°Ü£º "+userId , e );
|
insertOnsLog(userId, "³õʼ»¯Óû§StudentSchedule³É¹¦;class_id£º".concat(classId) , "REG_INIT_STUDENT_SCHEDULE", "" );
|
}
|
}
|
|
/**
|
* ³õʼ»¯Óû§ÍÆËÍÏûÏ¢ÉèÖÃ
|
* @param userId
|
*/
|
private void doActiveInitMessageSettrings(String userId) {
|
try{
|
// msgSettingService.doInitMessageSettrings(userId);
|
insertOnsLog(userId, "³õʼ»¯Óû§MessageSetting³É¹¦" , "REG_INIT_MESSAGE_SETTING", "" );
|
}catch(Exception e){
|
log.error("³õʼ»¯Óû§ÍÆËÍÉèÖÃʧ°Ü£º "+userId , e );
|
insertOnsLog(userId, "³õʼ»¯Óû§MessageSettingʧ°Ü" , "REG_INIT_MESSAGE_SETTING", "");
|
}
|
}
|
|
/**
|
* ³õʼ»¯Óû§Î¨Ò»±àÂë
|
* @param userId
|
*/
|
private void doActiveUpdateUserUniqueCode(String userId) {
|
try{
|
// userService.doUpdateUserUniqueCode(userId);
|
insertOnsLog(userId, "³õʼ»¯Óû§UniqueCode³É¹¦" , "REG_INIT_UNIQUE_CODE", "unique_code:");
|
}catch(Exception e){
|
log.error("³õʼ»¯Óû§codeʧ°Ü£º "+userId , e );
|
insertOnsLog(userId, "³õʼ»¯Óû§UniqueCodeʧ°Ü" , "REG_INIT_UNIQUE_CODE", "");
|
}
|
}
|
|
/**
|
* ³õʼ»¯»·ÐÅÐÅÏ¢
|
* @param userId
|
* @param classId
|
* @param regId
|
* @param password
|
*/
|
private void doActiveInsertEasemobInfo(String userId, String classId,
|
String regId, String password) {
|
try{
|
MsgUser user = new MsgUser();
|
user.setUserId(userId);
|
user.setPassword(password);
|
|
Result result = insertEasemobInfo(user, classId,regId);
|
insertOnsLog(userId, "³õʼ»¯Óû§Easemob䱨´í:result£º".concat(String.valueOf(result.isSuccess())).concat(";regId :").concat(regId) , "REG_INIT_EASEMOB_INFO", "classId: ".concat(classId));
|
}catch(Exception e){
|
log.error("³õʼ»¯Óû§Easemobʧ°Ü£º "+userId , e );
|
insertOnsLog(userId, "³õʼ»¯Óû§Easemobʧ°Ü;regId :".concat(regId) , "REG_INIT_EASEMOB_INFO", "classId: ".concat(classId));
|
}
|
}
|
|
/**
|
* ÏûÏ¢´¦Àíɾ³ý¡¢¶³½áѧԱºóÐø²Ù×÷
|
* @param userId
|
* @param password
|
* @param classId
|
* @param regId
|
* @return
|
*/
|
public Result doOnsRegDeActive(String userIds,String classId){
|
|
// 1.ɾ³ý»·ÐÅȺ³ÉÔ±
|
try{
|
MsgGroup group = read(MsgGroup.class, classId );
|
if( null == group ){
|
return new Result(true);
|
}
|
}catch(Exception e){
|
log.error("ɾ³ý»·ÐÅȺ³ÉԱʧ°Ü£º " + userIds + " groupId:" + classId , e );
|
}
|
|
return new Result(true);
|
|
}
|
|
/**
|
* ²åÈ뼤»îѧԱÒì²½²Ù×÷ ÒµÎñÈÕÖ¾
|
* @param userIds
|
* @param content
|
* @param module
|
* @param desp
|
* @return
|
*/
|
private Result insertOnsLog(String userId, String content ,String module, String desp ){
|
|
SysLog log = new SysLog() ;
|
|
TraceUtils.setCreateTrace(log);
|
log.setUserId(userId);
|
log.setContent(content);
|
log.setModule(module);
|
log.setDesp(desp);
|
log.setDeleteFlag(false);
|
log.setType(SysLog.LOG_TYPE_BUSINESS);
|
|
sysLogService.insertLog(log);
|
|
return new Result(true);
|
}
|
|
/**
|
* ¸øÑ§Ô±·¢ËͶÌÐÅ
|
*/
|
@Override
|
public Result doSendSmsToUser(String regIds) {
|
|
String[] strIds = regIds.split(",");
|
Result result = new Result(false);
|
|
for (int i = 0; i < strIds.length; i++) {
|
UserRegistration ur = read(UserRegistration.class, strIds[i]);
|
|
int sendCount = this.findCount("from Sms where templateId = ? and deleteFlag is false and mobilePhone = ? and state = ? and date(createTime) = date(sysdate())",
|
CollectionUtils.newList(SmsContants.SMS_REG_ACTIVE_ORG_TEMPLATE_ID, ur.getMobilePhone(), "000000"));
|
|
if(sendCount >=2){
|
return new Result(false, "·¢ËÍʧ°Ü£¬Ã¿¸öѧԱÿÌìÖ»ÄÜ·¢ËÍÁ½´ÎÃÜÂë¶ÌÐÅ");
|
}
|
|
if (null != ur && ur.getStatus() == UserRegistration.STATUS_ACTIVE) {
|
|
// result = smsService.doSendMsg(SmsContants.SMS_REG_ACTIVE_ORG_TEMPLATE_ID, ur.getMobilePhone(), false, ur.getUserName(), "¡°" + ur.getOrgClass().getName() + "¡±", RSAUtils.decrypt(ur.getUser().getPassword()));
|
}
|
}
|
|
return result;
|
}
|
|
/**
|
* °à¼¶ÐÞ¸Ä×Ô¶¨Òå×Ö¶Î
|
*
|
* @param data
|
* @param classId
|
* @return
|
*/
|
private List<OrgClassUserCustom> saveCustom(List<OrgClassUserCustom> customLst, String classId){
|
List<OrgClassUserCustom> newCustomLst = new ArrayList<OrgClassUserCustom>(customLst.size());
|
if(StringUtils.isNotBlank(classId)){//ÏÈɾ³ý°à¼¶µÄ
|
this.bulkUpdate("update OrgClassUserCustom set deleteFlag = 1 where classId = ?", new Object[]{classId});
|
}else{
|
this.bulkUpdate("update OrgClassUserCustom set deleteFlag = 1 where classId is null and orgId = ?", new Object[]{ClientUtils.getOrgId()});
|
}
|
int index = 0;
|
for (OrgClassUserCustom custom : customLst) {
|
if(custom != null){
|
OrgClassUserCustom newCustom = null;
|
if(StringUtils.isNotBlank(custom.getCustomId())){ // ÐÞ¸Ä
|
|
newCustom = read(OrgClassUserCustom.class, custom.getCustomId());
|
newCustom.setCheckedFlag(custom.getCheckedFlag());
|
newCustom.setRequiredFlag(custom.getRequiredFlag());
|
newCustom.setObjectName(custom.getObjectName());
|
newCustom.setSignupFillin(custom.isSignupFillin());
|
newCustom.setDeleteFlag(false);
|
newCustom.setObjectOption(custom.getObjectOption());
|
newCustom.setOrderNum(index);
|
TraceUtils.setUpdateTrace(newCustom);
|
}else{ // ÐÂÔö
|
|
newCustom = new OrgClassUserCustom();
|
newCustom.setCheckedFlag(custom.getCheckedFlag());
|
newCustom.setRequiredFlag(custom.getRequiredFlag());
|
newCustom.setSignupFillin(custom.isSignupFillin());
|
newCustom.setObjectName(custom.getObjectName());
|
newCustom.setObjectValue(custom.getObjectValue());
|
newCustom.setObjectType(custom.getObjectType());
|
newCustom.setObjectOption(custom.getObjectOption());
|
newCustom.setOrgId(ClientUtils.getOrgId());
|
newCustom.setClassId(classId);
|
newCustom.setDeleteFlag(false);
|
newCustom.setOrderNum(index);
|
TraceUtils.setCreateTrace(newCustom);
|
}
|
index ++;
|
newCustomLst.add(newCustom);
|
}
|
}
|
|
saveOrUpdateAll(newCustomLst);
|
|
return newCustomLst;
|
}
|
|
/**
|
* µÃµ½×¢²áÐÅÏ¢
|
*
|
* @return
|
*/
|
public Result doSaveCustom(String data, String classId) {
|
|
List<OrgClassUserCustom> customLst = JSONArray.parseArray(data, OrgClassUserCustom.class);
|
|
if(customLst.isEmpty()){
|
|
return new Result(false,"Ìá½»×Ô¶¨ÒåÐÅϢʧ°Ü");
|
}
|
List<OrgClassUserCustom> lstResult = new ArrayList<OrgClassUserCustom>();
|
//»ú¹¹
|
if(StringUtils.isEmpty(classId)){
|
lstResult = this.saveCustom(customLst, null);
|
}else{//°à¼¶
|
lstResult = this.saveCustom(customLst, classId);
|
}
|
|
return new Result(true, "", lstResult);
|
}
|
|
/**
|
* »ñÈ¡×Ô¶¨Òå×Ö¶ÎÐÅÏ¢
|
*
|
*/
|
public List<OrgClassUserCustom> doInitCustomLst(String classId, String pageType, boolean isApp){
|
|
//app¶Ë·ÃÎÊ
|
if(isApp){
|
return new ArrayList<OrgClassUserCustom>();
|
}
|
if(StringUtils.isBlank(classId)){//»ú¹¹²éѯ
|
//²éѯ»ú¹¹×Ô¶¨Òå×Ö¶Î
|
List<OrgClassUserCustom> orgCustomLst = find("from OrgClassUserCustom where deleteFlag is false and orgId = ? and classId is null order by orderNum asc",
|
CollectionUtils.newList(ClientUtils.getOrgId()), OrgClassUserCustom.class);
|
return orgCustomLst;
|
}else{ //°à¼¶²éѯ
|
List<OrgClassUserCustom> customLst = null;
|
if("all".equals(pageType)){
|
customLst = find("from OrgClassUserCustom where deleteFlag is false and classId = ? order by orderNum asc",
|
CollectionUtils.newList(classId), OrgClassUserCustom.class);
|
}else{
|
customLst = find("from OrgClassUserCustom where deleteFlag is false and classId = ? and signupFillin is true order by orderNum asc",
|
CollectionUtils.newList(classId), OrgClassUserCustom.class);
|
}
|
return customLst;
|
}
|
|
}
|
|
/**
|
* ѧԱת°à
|
*
|
* @return
|
*/
|
public Result doSaveTurn(List<String> regIds,String classId) {
|
|
// ҪתÈëµÄѧԱ
|
String hql = " from UserRegistration where deleteFlag is false and registrationId in (:regIds)";
|
List<UserRegistration> lstReg = findByComplexHql(hql, CollectionUtils.newObjectMap("regIds",regIds), UserRegistration.class);
|
|
String hql_r = " from UserRegistration where deleteFlag is false and classId = ?";
|
List<UserRegistration> lstRegLst = find(hql_r, CollectionUtils.newList(classId), UserRegistration.class);
|
List<String> lst = new ArrayList<String>(lstRegLst.size());
|
for (UserRegistration userR : lstRegLst) {
|
lst.add(userR.getMobilePhone());
|
}
|
|
int regCount = 0;
|
List<UserRegistration> userRegs = new ArrayList<UserRegistration>(lstReg.size());
|
for (UserRegistration userReg : lstReg) {
|
if(lst.contains(userReg.getMobilePhone())){
|
regCount++;
|
}else{
|
UserRegistration newUserReg = new UserRegistration();
|
try {
|
BeanUtils.copyProperties(newUserReg, userReg);
|
newUserReg.setClassId(classId);
|
newUserReg.setActivationTime(null);
|
newUserReg.setStatus(UserRegistration.STATUS_DEACTIVE);
|
newUserReg.setRegistrationId(null);
|
userRegs.add(newUserReg);
|
|
userReg.setDeleteFlag(true);
|
TraceUtils.setUpdateTrace(userReg);
|
save(userReg);
|
} catch (Exception e) {
|
log.error("¸´ÖÆUserRegistration³ö´í", e);
|
regCount++;
|
continue ;
|
}
|
}
|
}
|
if(!userRegs.isEmpty()){
|
saveOrUpdateAll(userRegs);
|
}
|
|
String msg = regCount > 0 ? "³É¹¦×ªÈë" + (lstReg.size() - regCount) + "Ìõ£¬ºöÂÔ" + regCount+ "Ìõ" : null;
|
return new Result(true,msg);
|
}
|
|
|
}
|