portal web service

DemandService.java 5.4KB

    package com.ekexiu.portal.service; import java.sql.Connection; import java.sql.SQLException; import java.util.List; import org.jfw.apt.annotation.Autowrie; import org.jfw.apt.annotation.DefaultValue; import org.jfw.apt.annotation.Nullable; import org.jfw.apt.web.annotation.Path; import org.jfw.apt.web.annotation.operate.Get; import org.jfw.apt.web.annotation.operate.Post; import org.jfw.apt.web.annotation.param.JdbcConn; import org.jfw.apt.web.annotation.param.RequestParam; import org.jfw.util.PageQueryResult; import org.jfw.util.StringUtil; import com.ekexiu.portal.dao.DemandDao; import com.ekexiu.portal.po.Demand; @Path("/demand") public class DemandService { public static final String MAX_CREATETIME = "9"; @Autowrie private DemandDao demandDao; public DemandDao getDemandDao() { return demandDao; } public void setDemandDao(DemandDao demandDao) { this.demandDao = demandDao; } /** * 发布需求 * @param con * @param demand * @throws SQLException */ @Post @Path public String insert(@JdbcConn(true) Connection con,@RequestParam(excludeFields={"id","state","createTime","modifyTime","shareId","pageViews","modifier"}) Demand demand)throws SQLException{ String demandId = StringUtil.buildUUID(); demand.setId(demandId); demand.setState("1"); if(demand.getCost()==null){ demand.setCost("0"); } if(demand.getDuration()==null){ demand.setDuration("0"); } demand.setModifier(demand.getCreator()); this.demandDao.insert(con, demand); return demandId; } /** * 修改需求 * @param con * @param demand * @throws SQLException */ @Post @Path("/modify") public boolean update(@JdbcConn(true) Connection con,@RequestParam(excludeFields={"state","createTime","modifyTime","title","descp","orgId","creator","pageViews","shareId"}) Demand demand)throws SQLException{ if(demand.getCost()==null){ demand.setCost("0"); } if(demand.getDuration()==null){ demand.setDuration("0"); } demand.setState("1"); return this.demandDao.update(con, demand)>0; } /** * 完成需求 * @param con * @param id 需求ID * @param uid 操作用户ID * @return * @throws SQLException */ @Post @Path("/over") public boolean over(@JdbcConn(true) Connection con,String id,String uid)throws SQLException{ return this.demandDao.over(con, id, uid)>0; } /** * 关闭需求 * @param con * @param id 需求ID * @param uid 需求ID * @return * @throws SQLException */ @Post @Path("/close") public boolean close(@JdbcConn(true) Connection con,String id,String uid)throws SQLException{ return this.demandDao.close(con, id, uid)>0; } /** * 延期需求 * @param con * @param id 需求ID * @param uid 操作用户ID * @param day 延期日期 YYYYMMD * @return * @throws SQLException */ @Post @Path("/defer") public boolean defer(@JdbcConn(true) Connection con,String id,String uid,String day)throws SQLException{ return this.demandDao.defer(con, id,uid,day)>0; } /** * 增加浏览量 * @param con * @param id 需求ID * @throws SQLException */ @Post @Path("/incPageViews") public void incPageViews(@JdbcConn(true) Connection con,String id)throws SQLException{ this.demandDao.incPageViews(con, id); } /** * 查询需求数量 * @param con * @param state 需求状态 * @param uid 发布者ID * @param oid 发布者发布时机构ID * @return * @throws SQLException */ @Get @Path("/qc") public int queryCount(@JdbcConn Connection con,@Nullable String[] state,@Nullable String uid,@Nullable String oid)throws SQLException{ return this.demandDao.cnt(con, state, uid,oid); } /** * 查询需求 * @param con * @param id 需求ID * @return * @throws SQLException */ @Get @Path("/qo") public Demand queryOne(@JdbcConn Connection con, String id)throws SQLException{ return this.demandDao.query(con, id); } /** * 根据分享ID 查询需求 * @param con * @param id 分享ID * @return * @throws SQLException */ @Get @Path("/byShareId") public Demand queryByShareId(@JdbcConn Connection con ,long id)throws SQLException{ return this.demandDao.query(con, id); } /** * 查询需求列表 * @param con * @param id 需求ID 数组 * @return * @throws SQLException */ @Get @Path("/qm") public List<Demand> queryOne(@JdbcConn Connection con, String[] id)throws SQLException{ return this.demandDao.query(con, id); } /** * 分页查询需求(按状态及发布时间排序) * @param con * @param state * @param uid * @param oid * @return * @throws SQLException */ @Get @Path("/pq") public PageQueryResult<Demand> query(@JdbcConn Connection con,@Nullable String[] state,@Nullable String uid,@Nullable String oid,@DefaultValue("1") int pageNo,@DefaultValue("5") int pageSize)throws SQLException{ return this.demandDao.pageQuery(con, state, uid, oid,pageSize,pageNo); } /** * 分页查询需求(按发布时间排序) * @param con * @param state * @param uid * @param oid * @return * @throws SQLException */ @Get @Path("/search") public PageQueryResult<Demand> query(@JdbcConn Connection con,@Nullable String key,@DefaultValue("1") int pageNo,@DefaultValue("5") int pageSize)throws SQLException{ return this.demandDao.pageQuery(con, key==null?key:("%"+key+"%"),pageSize,pageNo); } }