You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
3.1 KiB
83 lines
3.1 KiB
package com.fr.plugin.idm.sso.action; |
|
|
|
import com.fr.json.JSONArray; |
|
import com.fr.json.JSONObject; |
|
import com.fr.plugin.db.PluginDBManager; |
|
import com.fr.plugin.idm.sso.BaseAction; |
|
import com.fr.plugin.idm.sso.IdmResponse; |
|
import com.fr.plugin.idm.sso.RecordDBAccessProvider; |
|
import com.fr.plugin.idm.sso.dao.UserDao; |
|
import com.fr.plugin.idm.sso.dao.UserOrgDao; |
|
import com.fr.plugin.idm.sso.entity.OrgEntity; |
|
import com.fr.plugin.idm.sso.entity.UserEntity; |
|
import com.fr.plugin.idm.sso.entity.UserOrgEntity; |
|
import com.fr.stable.db.action.DBAction; |
|
import com.fr.stable.db.dao.DAOContext; |
|
import com.fr.stable.db.session.DBSession; |
|
import com.fr.stable.query.QueryFactory; |
|
import com.fr.stable.query.restriction.RestrictionFactory; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
import javax.servlet.http.HttpServletResponse; |
|
import java.util.ArrayList; |
|
import java.util.List; |
|
import java.util.UUID; |
|
|
|
/** |
|
* @Author fr.open |
|
* @Date 2020/8/18 |
|
* @Description |
|
**/ |
|
public class UserAction extends BaseAction { |
|
|
|
@Override |
|
public IdmResponse handel(HttpServletRequest req, HttpServletResponse res) throws Exception { |
|
JSONObject object = getBody(req); |
|
JSONArray array = object.getJsonArray("userorgs"); |
|
List<UserOrgEntity> list = new ArrayList<>(); |
|
for (int i = 0; i < array.size();i++){ |
|
JSONObject jsonObject = array.getJSONObject(i); |
|
UserOrgEntity userOrgEntity = jsonObject.mapTo(UserOrgEntity.class); |
|
list.add(userOrgEntity); |
|
} |
|
object.remove("userorgs"); |
|
UserEntity user = this.getEntity(object,UserEntity.class); |
|
RecordDBAccessProvider.getDbAccessor().runDMLAction(new DBAction<OrgEntity>() { |
|
@Override |
|
public OrgEntity run(DAOContext daoContext) throws Exception { |
|
user.setId(UUID.randomUUID().toString()); |
|
UserDao userDao = daoContext.getDAO(UserDao.class); |
|
UserOrgDao userOrgDao = daoContext.getDAO(UserOrgDao.class); |
|
userDao.addOrUpdate(user); |
|
userOrgDao.remove(QueryFactory.create().addRestriction(RestrictionFactory.eq("uid",user.getUid()))); |
|
for (UserOrgEntity userOrgEntity:list) { |
|
userOrgEntity.setId(UUID.randomUUID().toString()); |
|
userOrgDao.add(userOrgEntity); |
|
} |
|
return null; |
|
} |
|
}); |
|
|
|
|
|
return IdmResponse.ok("0"); |
|
} |
|
|
|
public void batchSubmit(List<UserOrgEntity> addData) throws Exception {//list里面的就是DBAccessProvider接口里面定义的entity对象 |
|
DBSession session = PluginDBManager.getInstance().getDbContext().openSession(); |
|
try { |
|
session.beginTransaction();//开始事务 |
|
if (addData != null) { |
|
for (Object addO : addData) { |
|
//添加更新的数据 |
|
session.persist(addO); |
|
} |
|
} |
|
session.commitTransaction();//提交 |
|
// |
|
session.closeSession(); |
|
} catch (Exception e) { |
|
session.rollbackTransaction();//回滚 |
|
throw e; |
|
} |
|
} |
|
}
|
|
|