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.
63 lines
2.3 KiB
63 lines
2.3 KiB
package com.fr.plugin.http; |
|
|
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
|
import com.fr.json.JSONObject; |
|
import com.fr.plugin.MyDecisionDBAccessProvider; |
|
import com.fr.plugin.dao.MyDao; |
|
import com.fr.plugin.entity.MyEntity; |
|
import com.fr.stable.db.accessor.DBAccessor; |
|
import com.fr.stable.query.QueryFactory; |
|
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.Date; |
|
import java.util.UUID; |
|
|
|
public class ModApi extends BaseHttpHandler { |
|
@Override |
|
public RequestMethod getMethod() { |
|
return null; |
|
} |
|
|
|
@Override |
|
public String getPath() { |
|
return "/mod"; |
|
} |
|
|
|
@Override |
|
public boolean isPublic() { |
|
return true; |
|
} |
|
|
|
@Override |
|
public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { |
|
DBAccessor dbAccessor = MyDecisionDBAccessProvider.getDbAccessor(); |
|
//通过这两个函数获取的参数可以避免中文乱码和空指针 |
|
String userName = WebUtils.getHTTPRequestParameter(httpServletRequest, "userName"); |
|
Integer source = WebUtils.getHTTPRequestIntParameter(httpServletRequest, "source"); |
|
//先查找要更新的用户 |
|
MyEntity entity = dbAccessor.runQueryAction(daoContext -> daoContext.getDAO(MyDao.class) |
|
.findOne(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))) |
|
); |
|
if (entity != null) { |
|
entity.setSource(source); |
|
dbAccessor.runDMLAction(daoContext -> { |
|
//执行更新操作 |
|
daoContext.getDAO(MyDao.class).update(entity); |
|
return null; |
|
}); |
|
JSONObject jsonObject = new JSONObject(); |
|
jsonObject.put("msg", "success"); |
|
jsonObject.put("code", 200); |
|
WebUtils.printAsJSON(httpServletResponse, jsonObject); |
|
} else { |
|
JSONObject jsonObject = new JSONObject(); |
|
jsonObject.put("msg", "user not find"); |
|
jsonObject.put("code", -1); |
|
WebUtils.printAsJSON(httpServletResponse, jsonObject); |
|
} |
|
} |
|
}
|
|
|