package com.sinosoft.lz.system.configer.service; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Iterator; import java.util.Set; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.ProduceMime; import org.apache.log4j.Logger; import com.formaction.Utils; import com.sinosoft.lz.system.configer.dao.PersonalconfDao; import com.sinosoft.lz.system.configer.vo.Configures; import com.sinosoft.lz.system.configer.vo.Personalconf; import com.sinosoft.lz.system.configer.vo.Personalconfs; @Path("/ConfigureService/") public class ConfigureServiceImp implements ConfigureService{ private Logger log = Logger.getLogger(this.getClass()); @GET @Path("/reloadConfigures") public String reloadConfigures() { // TODO Auto-generated method stub try { ConfigureImp conf = new ConfigureImp(); log.info("重新加载前===" + ConfigureImp.FountConfigureMap.size()); conf.getallConfigures(); log.info("重新加载后===" + ConfigureImp.BehindConfigureMap.size()); return "0"; } catch (Exception e) { return "1"; } } /** * 加载前台系统配置服务 */ @POST @ProduceMime("application/json") @Path("/getFountConfigures") public Configures getFountConfigures() { Configures configures = new Configures(); StringBuffer confs = new StringBuffer(); HashMap fountConfMap = ConfigureImp.FountConfigureMap; Set sKey = fountConfMap.keySet(); Iterator it = sKey.iterator(); String key = ""; String value = ""; confs.append("{"); while (it.hasNext()) { key = it.next(); value = fountConfMap.get(key); confs.append("\"" + key + "\""); confs.append(":"); confs.append("\"" + value + "\""); confs.append(","); } confs.setLength(confs.length() - 1); confs.append("}"); configures.setConfs(confs.toString()); return configures; } /** * 取得个人配置信息 * * @param uid * @return */ @POST @ProduceMime("application/json") @Path("/getPerInfos/{uid}") public Personalconfs getSysInfos(@PathParam("uid") String uid) { Personalconfs perCon = new Personalconfs(); PersonalconfDao pDao = new PersonalconfDao(); perCon = pDao.getPersonalconfs(uid); return perCon; } @POST @Path("/changPassword/") public String changPassword(String params) { try { params = java.net.URLDecoder.decode(params, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } String uid = Utils.getParameter("useid", params); String oPwd = Utils.getParameter("password", params); String nPwd = Utils.getParameter("userpassword", params); PersonalconfDao pconfdao = new PersonalconfDao(); return pconfdao.changePWD(uid, oPwd, nPwd); } @ProduceMime("application/json") @POST @Path("/addPersonalconf") public String addPersonalconf(String params) { params = decode(params); log.debug("fdfdfd:" + params); Personalconf pconf = new Personalconf(); String confkey = Utils.getParameter("confkey", params) == null ? "" : Utils.getParameter( "confkey", params); String location = Utils.getParameter("location", params) == null ? "" : Utils.getParameter( "location", params); String state = Utils.getParameter("state", params) == null ? "" : Utils.getParameter( "state", params); String id = Utils.getParameter("id", params) == null ? "" : Utils .getParameter("id", params); String uid = Utils.getParameter("uid", params) == null ? "" : Utils.getParameter("uid", params); String value = Utils.getParameter("value", params) == null ? "" : Utils.getParameter( "value", params); String description = Utils.getParameter("description", params) == null ? "" : Utils .getParameter("description", params);// 发件人id pconf.setConfkey(confkey); pconf.setDescription(description); pconf.setId(id); pconf.setLocation(location); pconf.setUidd(uid); pconf.setValue(value); pconf.setState(state); PersonalconfDao pconfdao = new PersonalconfDao(); pconfdao.addPersonalconf(pconf); return "ok"; } @GET @ProduceMime("application/json") @Path("/getPersonalconfs/{uid}") public Personalconfs getPersonalconfs(@PathParam("uid") String uid) { // TODO Auto-generated method stub PersonalconfDao pconfdao = new PersonalconfDao(); return pconfdao.getPersonalconfs(uid); } @ProduceMime("application/json") @POST @Path("/upDatePersonalconf") public String upDatePersonalconf(String params) { params = decode(params); Personalconf pconf = new Personalconf(); String confkey = Utils.getParameter("confkey", params) == null ? "" : Utils.getParameter( "confkey", params); String location = Utils.getParameter("location", params) == null ? "" : Utils.getParameter( "location", params); String state = Utils.getParameter("state", params) == null ? "" : Utils.getParameter( "state", params); String id = Utils.getParameter("id", params) == null ? "" : Utils .getParameter("id", params); String uid = Utils.getParameter("uid", params) == null ? "" : Utils.getParameter("uid", params); String value = Utils.getParameter("value", params) == null ? "" : Utils.getParameter( "value", params); String description = Utils.getParameter("description", params) == null ? "" : Utils .getParameter("description", params);// 发件人id pconf.setConfkey(confkey); pconf.setDescription(description); pconf.setId(id); pconf.setLocation(location); pconf.setUidd(uid); pconf.setValue(value); pconf.setState(state); PersonalconfDao pconfdao = new PersonalconfDao(); pconfdao.editPersonalconf(pconf); return "ok"; } // 编码解析 protected String decode(String params) { try { params = java.net.URLDecoder.decode(params, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); log.debug("编码解析 失败!"); } return params; } }