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.
105 lines
3.8 KiB
105 lines
3.8 KiB
2 years ago
|
package com.fr.plugin.web.hander;
|
||
|
|
||
|
import com.fr.decision.fun.impl.BaseHttpHandler;
|
||
|
import com.fr.json.JSONArray;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.plugin.dao.MyGroupDao;
|
||
|
import com.fr.plugin.entitys.YtGroupEntity;
|
||
|
import com.fr.plugin.yt.MyCoreDBAccess;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
import com.fr.stable.db.action.DBAction;
|
||
|
import com.fr.stable.db.dao.DAOContext;
|
||
|
import com.fr.stable.query.QueryFactory;
|
||
|
import com.fr.stable.query.condition.QueryCondition;
|
||
|
import com.fr.stable.query.restriction.RestrictionFactory;
|
||
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
|
||
|
import com.fr.web.utils.WebUtils;
|
||
|
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
import java.util.UUID;
|
||
|
|
||
|
public class UpdateGroupHandler extends BaseHttpHandler {
|
||
|
@Override
|
||
|
public RequestMethod getMethod() {
|
||
|
return RequestMethod.POST;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getPath() {
|
||
|
return "/yt/groupUpdate";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isPublic() {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception {
|
||
|
JSONArray resp = new JSONArray();
|
||
|
String groupId = WebUtils.getHTTPRequestParameter(request, "groupId");
|
||
|
String groupName = WebUtils.getHTTPRequestParameter(request, "groupName");
|
||
|
JSONObject respJson = JSONObject.create();
|
||
|
List<YtGroupEntity> ytGroupEntities = checkExist(groupId);
|
||
|
if (ytGroupEntities.isEmpty()) {
|
||
|
respJson.put("msg", "群组不存在");
|
||
|
respJson.put("errorCode", 1);
|
||
|
WebUtils.flushSuccessMessageAutoClose(request, httpServletResponse, respJson);
|
||
|
return;
|
||
|
}
|
||
|
if (StringUtils.isBlank(groupId)) {
|
||
|
respJson.put("msg", "group id 为空");
|
||
|
respJson.put("errorCode", 1);
|
||
|
WebUtils.flushSuccessMessageAutoClose(request, httpServletResponse, respJson);
|
||
|
return;
|
||
|
}
|
||
|
if (StringUtils.isBlank(groupName)) {
|
||
|
respJson.put("msg", "group name 为空");
|
||
|
respJson.put("errorCode", 1);
|
||
|
WebUtils.flushSuccessMessageAutoClose(request, httpServletResponse, respJson);
|
||
|
return;
|
||
|
}
|
||
|
YtGroupEntity entity = ytGroupEntities.get(0);
|
||
|
entity.setGroupId(groupId);
|
||
|
entity.setName(groupName);
|
||
|
entity.setId(UUID.randomUUID().toString());
|
||
|
saveGroup(entity);
|
||
|
respJson.put("errorCode", 0);
|
||
|
WebUtils.flushSuccessMessageAutoClose(request, httpServletResponse, respJson);
|
||
|
}
|
||
|
|
||
|
private void saveGroup(YtGroupEntity entity) {
|
||
|
try {
|
||
|
MyCoreDBAccess.getAccessor().runDMLAction(new DBAction<Object>() {
|
||
|
@Override
|
||
|
public Object run(DAOContext daoContext) throws Exception {
|
||
|
daoContext.getDAO(MyGroupDao.class).update(entity);
|
||
|
return null;
|
||
|
}
|
||
|
});
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private List<YtGroupEntity> checkExist(String id) {
|
||
|
List<YtGroupEntity> entityList = null;
|
||
|
try {
|
||
|
entityList = MyCoreDBAccess.getAccessor().runQueryAction(new DBAction<List<YtGroupEntity>>() {
|
||
|
public List<YtGroupEntity> run(DAOContext content) throws Exception {
|
||
|
QueryCondition queryCondition = QueryFactory.create();
|
||
|
queryCondition.addRestriction(RestrictionFactory.and(RestrictionFactory.like("groupId", id)));
|
||
|
return content.getDAO(MyGroupDao.class).find(queryCondition);
|
||
|
}
|
||
|
});
|
||
|
return entityList;
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
return new ArrayList<>();
|
||
|
}
|
||
|
}
|