ソースを参照

--add demand.java

zzy.zhiyuan.foxmail 8 年 前
コミット
b42c0c1ddf

+ 101 - 0
src/main/java/com/ekexiu/portal/dao/DemandDao.java

@ -0,0 +1,101 @@
1
package com.ekexiu.portal.dao;
2

3
import java.sql.Connection;
4
import java.sql.PreparedStatement;
5
import java.sql.ResultSet;
6
import java.sql.SQLException;
7
import java.util.ArrayList;
8
import java.util.List;
9

10
import org.jfw.apt.annotation.Nullable;
11
import org.jfw.apt.orm.annotation.dao.DAO;
12
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
13
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
14
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
15
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
16

17
import com.ekexiu.portal.po.Demand;
18

19
@DAO
20
public abstract class DemandDao {
21
	@Insert
22
	public abstract int insert(Connection con,Demand demand)throws SQLException;
23
	
24
	@SelectOne
25
	@Nullable
26
	public abstract Demand queryOne(Connection con,String demandId)throws SQLException;
27
	
28
	@SelectList
29
	@OrderBy("ORDER BY CREATE_TIME DESC")
30
	public abstract List<Demand> queryByDemander(Connection con,String demander)throws SQLException;
31
	
32
	public List<Demand> queryByStatus(Connection con,String demandStatus,String demandAim,String subject,String industry,String createTime,long orderKey,int rows,int sortType) throws SQLException{
33
        StringBuilder sql = new StringBuilder();
34
        sql.append("SELECT DEMAND_ID,DEMANDER,DEMAND_AIM,DEMAND_TYPE,DEMAND_TITLE,DEMAND_CONTENT,DEMAND_STATUS,ORDER_KEY,CREATE_TIME FROM DEMAND ");
35
        boolean hasDemandAim = null != demandAim;
36
        boolean hasSubject = null !=subject;
37
        boolean hasIndustry = null != industry;
38
        sql.append(" WHERE DEMAND_STATUS = ? AND ORDER_KEY < ? AND CREATE_TIME < ? ");
39
        if(hasDemandAim){
40
        	sql.append(" AND DEMAND_AIM = ? ");
41
        }
42
        if(hasSubject){
43
        	sql.append(" AND DEMAND_ID IN (SELECT DEMAND_ID FROM DEMAND_SUB_OR_INDUS WHERE SUB_OR_INDUS LIKE ?) ");
44
        }
45
        if(hasIndustry){
46
        	sql.append(" AND DEMAND_ID IN (SELECT DEMAND_ID FROM DEMAND_SUB_OR_INDUS WHERE SUB_OR_INDUS LIKE ?) ");
47
        }
48
        sql.append(" ORDER BY CREATE_TIME ");
49
        if(sortType == 0){
50
        	sql.append(" DESC ");
51
        }
52
        sql.append(" ,ORDER_KEY ");
53
        if(sortType == 0){
54
        	sql.append(" DESC ");
55
        }
56
        sql.append(" LIMIT ").append(rows);
57
        int index = 1;
58
        PreparedStatement ps = con.prepareStatement(sql.toString());
59
        try{
60
        	ps.setString(index++, demandStatus);
61
            ps.setLong(index++,orderKey);
62
            ps.setString(index++,createTime);
63
            if(hasDemandAim){
64
            	ps.setString(index++,demandAim);
65
            }
66
            if(hasSubject){
67
            	ps.setString(index++,subject);
68
            }
69
            if(hasIndustry){
70
            	ps.setString(index++,industry);
71
            }
72
            ResultSet rs = ps.executeQuery();
73
            try{
74
                List<Demand> _result = new ArrayList<Demand>();
75
                while(rs.next()){
76
                    Demand demand =  new Demand();
77
                    demand.setDemandId(rs.getString(1));
78
                    demand.setDemander(rs.getString(2));
79
                    demand.setDemandAim(rs.getString(3));
80
                    demand.setDemandType(rs.getString(4));
81
                    demand.setDemandTitle(rs.getString(5));
82
                    String content = rs.getString(6);
83
                    if(rs.wasNull()){
84
                    	content = null;
85
                    }
86
                    demand.setDemandContent(content);
87
                    demand.setDemandStatus(rs.getString(7));
88
                    demand.setOrderKey(rs.getLong(8));
89
                    demand.setCreateTime(rs.getString(9));
90
                    _result.add(demand);
91
                }
92
                return _result;
93
            }finally{
94
                try{rs.close();}catch(Exception e1){}
95
            }
96
        }finally{
97
            try{ps.close();}catch(Exception e2){}
98
        }
99
    }
100
	
101
}

+ 16 - 0
src/main/java/com/ekexiu/portal/dao/DemandSubOrIndusDao.java

@ -0,0 +1,16 @@
1
package com.ekexiu.portal.dao;
2

3
import java.sql.Connection;
4
import java.sql.SQLException;
5

6
import org.jfw.apt.orm.annotation.dao.DAO;
7
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
8

9
import com.ekexiu.portal.po.DemandSubOrIndus;
10

11
@DAO
12
public abstract class DemandSubOrIndusDao {
13
	@Insert
14
	public abstract int insert(Connection con,DemandSubOrIndus demandSubOrIndus)throws SQLException;
15
	
16
}

+ 94 - 0
src/main/java/com/ekexiu/portal/po/Demand.java

@ -0,0 +1,94 @@
1
package com.ekexiu.portal.po;
2

3
import org.jfw.apt.orm.annotation.entry.Column;
4
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
5
import org.jfw.apt.orm.annotation.entry.Table;
6
import org.jfw.apt.orm.core.enums.DE;
7

8
import com.ekexiu.portal.basepo.CreateTimeSupported;
9
import com.ekexiu.portal.pojo.EditProfessor;
10

11
@Table
12
@PrimaryKey("demandId")
13
public class Demand implements CreateTimeSupported {
14
	private String demandId;
15
	private String demander;
16
	private String demandAim;
17
	private String demandType;
18
	private String demandTitle;
19
	private String demandContent;
20
	private String demandStatus;
21
	private String createTime;
22
	private long orderKey;
23
	private EditProfessor professor;
24
	
25
	public EditProfessor getProfessor() {
26
		return professor;
27
	}
28
	public void setProfessor(EditProfessor professor) {
29
		this.professor = professor;
30
	}
31
	@Column(DE.id_32)
32
	public String getDemandId() {
33
		return demandId;
34
	}
35
	public void setDemandId(String demandId) {
36
		this.demandId = demandId;
37
	}
38
	@Column(DE.id_32)
39
	public String getDemander() {
40
		return demander;
41
	}
42
	public void setDemander(String demander) {
43
		this.demander = demander;
44
	}
45
	@Column(DE.singleChar)
46
	public String getDemandAim() {
47
		return demandAim;
48
	}
49
	public void setDemandAim(String demandAim) {
50
		this.demandAim = demandAim;
51
	}
52
	@Column(DE.singleChar)
53
	public String getDemandType() {
54
		return demandType;
55
	}
56
	public void setDemandType(String demandType) {
57
		this.demandType = demandType;
58
	}
59
	@Column(DE.string_de)
60
	public String getDemandTitle() {
61
		return demandTitle;
62
	}
63
	public void setDemandTitle(String demandTitle) {
64
		this.demandTitle = demandTitle;
65
	}
66
	@Column(DE.Text_de)
67
	public String getDemandContent() {
68
		return demandContent;
69
	}
70
	public void setDemandContent(String demandContent) {
71
		this.demandContent = demandContent;
72
	}
73
	@Column(DE.singleChar)
74
	public String getDemandStatus() {
75
		return demandStatus;
76
	}
77
	public void setDemandStatus(String demandStatus) {
78
		this.demandStatus = demandStatus;
79
	}
80
	public String getCreateTime() {
81
		return createTime;
82
	}
83
	public void setCreateTime(String createTime) {
84
		this.createTime = createTime;
85
	}
86
	@Column(DE.long_de)
87
	public long getOrderKey() {
88
		return orderKey;
89
	}
90
	public void setOrderKey(long orderKey) {
91
		this.orderKey = orderKey;
92
	}
93
	
94
}

+ 43 - 0
src/main/java/com/ekexiu/portal/po/DemandSubOrIndus.java

@ -0,0 +1,43 @@
1
package com.ekexiu.portal.po;
2

3
import org.jfw.apt.orm.annotation.entry.Column;
4
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
5
import org.jfw.apt.orm.annotation.entry.Table;
6
import org.jfw.apt.orm.core.enums.DE;
7

8
@Table
9
@PrimaryKey("id")
10
public class DemandSubOrIndus{
11
	private String id;
12
	private int sort;
13
	private String subOrIndus;
14
	private String demandId;
15
	@Column(DE.id_32)
16
	public String getId() {
17
		return id;
18
	}
19
	public void setId(String id) {
20
		this.id = id;
21
	}
22
	@Column(DE.int_de)
23
	public int getSort() {
24
		return sort;
25
	}
26
	public void setSort(int sort) {
27
		this.sort = sort;
28
	}
29
	@Column(DE.string_de)
30
	public String getSubOrIndus() {
31
		return subOrIndus;
32
	}
33
	public void setSubOrIndus(String subOrIndus) {
34
		this.subOrIndus = subOrIndus;
35
	}
36
	@Column(DE.id_32)
37
	public String getDemandId() {
38
		return demandId;
39
	}
40
	public void setDemandId(String demandId) {
41
		this.demandId = demandId;
42
	}
43
}

+ 117 - 0
src/main/java/com/ekexiu/portal/service/DemandService.java

@ -0,0 +1,117 @@
1
package com.ekexiu.portal.service;
2

3
import java.sql.Connection;
4
import java.sql.SQLException;
5
import java.util.List;
6

7
import org.jfw.apt.annotation.Autowrie;
8
import org.jfw.apt.annotation.DefaultValue;
9
import org.jfw.apt.annotation.Nullable;
10
import org.jfw.apt.web.annotation.Path;
11
import org.jfw.apt.web.annotation.operate.Get;
12
import org.jfw.apt.web.annotation.operate.Post;
13
import org.jfw.apt.web.annotation.param.JdbcConn;
14
import org.jfw.util.StringUtil;
15

16
import com.ekexiu.portal.dao.DemandDao;
17
import com.ekexiu.portal.dao.DemandSubOrIndusDao;
18
import com.ekexiu.portal.dao.ProfessorDao;
19
import com.ekexiu.portal.po.Demand;
20
import com.ekexiu.portal.po.DemandSubOrIndus;
21
import com.ekexiu.portal.pojo.EditProfessor;
22

23
@Path("/demand")
24
public class DemandService {
25
	public static final String MAX_CREATETIME="9";
26
	
27
	@Autowrie
28
	private DemandDao demandDao;
29
	@Autowrie
30
	private DemandSubOrIndusDao demandSubOrIndusDao;
31
	@Autowrie
32
	private ProfessorDao professorDao;
33
	@Autowrie
34
	private ImageService imageService;
35
	public DemandDao getDemandDao() {
36
		return demandDao;
37
	}
38
	public void setDemandDao(DemandDao demandDao) {
39
		this.demandDao = demandDao;
40
	}
41
	public DemandSubOrIndusDao getDemandSubOrIndusDao() {
42
		return demandSubOrIndusDao;
43
	}
44
	public void setDemandSubOrIndusDao(DemandSubOrIndusDao demandSubOrIndusDao) {
45
		this.demandSubOrIndusDao = demandSubOrIndusDao;
46
	}
47
	public ProfessorDao getProfessorDao() {
48
		return professorDao;
49
	}
50
	public void setProfessorDao(ProfessorDao professorDao) {
51
		this.professorDao = professorDao;
52
	}
53
	public ImageService getImageService() {
54
		return imageService;
55
	}
56
	public void setImageService(ImageService imageService) {
57
		this.imageService = imageService;
58
	}
59
	
60
	@Post
61
	@Path
62
	public void insert(@JdbcConn(true) Connection con,Demand demand,@Nullable String[] args)throws SQLException{
63
		String demandId = StringUtil.buildUUID();
64
		demand.setDemandId(demandId);
65
		demand.setDemandStatus("1");
66
		demand.setOrderKey(System.nanoTime());
67
		this.demandDao.insert(con, demand);
68
		if(args != null){
69
			for (int i = 0; i < args.length; i++) {
70
				DemandSubOrIndus subOrIndus = new DemandSubOrIndus();
71
				subOrIndus.setId(StringUtil.buildUUID());
72
				subOrIndus.setSort(i+1);
73
				subOrIndus.setSubOrIndus(args[i]);
74
				subOrIndus.setDemandId(demandId);
75
				this.demandSubOrIndusDao.insert(con, subOrIndus);
76
			}
77
		}
78
	}
79
	
80
	@Get
81
	@Path("/queryOne")
82
	public Demand queryOne(@JdbcConn Connection con,String demandId)throws SQLException{
83
		Demand demand = this.demandDao.queryOne(con, demandId);
84
		EditProfessor professor = this.professorDao.queryBaseInfo(con, demand.getDemander());
85
		if(professor != null){
86
			professor.setHasHeadImage(this.imageService.hasProfessorImage(demand.getDemander()));
87
		}
88
		demand.setProfessor(professor);
89
		return demand;
90
	}
91
	
92
	@Get
93
	@Path("/byDemander")
94
	public List<Demand> queryByDemander(@JdbcConn Connection con,String demander)throws SQLException{
95
		List<Demand> demands = this.demandDao.queryByDemander(con, demander);
96
		return demands;
97
	}
98
	
99
	@Get
100
	@Path("/ql")
101
	public List<Demand> queryByStatus(@JdbcConn Connection con,@Nullable String demandAim,@Nullable String subject,
102
			@Nullable String industry,@DefaultValue("com.ekexiu.portal.service.DemandService.MAX_CREATETIME") String createTime,
103
			@DefaultValue("Long.MAX_VALUE") long orderKey,@DefaultValue("20") int rows,@DefaultValue("0") int sortType)throws SQLException{
104
		if(subject != null) subject = "%"+subject+"%";
105
		if(industry != null) industry = "%"+industry+"%";
106
		List<Demand> demands = this.demandDao.queryByStatus(con, "1", demandAim, subject, industry, createTime, orderKey, rows, sortType);
107
		for (Demand demand : demands) {
108
			EditProfessor professor = this.professorDao.queryBaseInfo(con, demand.getDemander());
109
			if(professor != null){
110
				professor.setHasHeadImage(this.imageService.hasProfessorImage(demand.getDemander()));
111
			}
112
			demand.setProfessor(professor);
113
		}
114
		return demands;
115
	}
116

117
}