Skip to content

Commit

Permalink
finish part1
Browse files Browse the repository at this point in the history
  • Loading branch information
yerunjie committed Oct 22, 2017
1 parent cab6c5d commit b1a5d0c
Show file tree
Hide file tree
Showing 32 changed files with 480 additions and 270 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
target/
!.mvn/wrapper/maven-wrapper.jar
application-dev.yml
src/main/webapp/image
### STS ###
.apt_generated
.classpath
Expand All @@ -21,4 +22,5 @@ build/
nbbuild/
dist/
nbdist/
.nb-gradle/
.nb-gradle/
src/main/webapp/WEB-INF/
22 changes: 22 additions & 0 deletions src/main/java/com/yqbd/beans/CompanyInfoBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.yqbd.beans;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class CompanyInfoBean {
private Integer companyId;

private String companyName;

private String companyAccount;

private String password;

private String classification;

private String summary;

private String headPortraitAddress;
}
6 changes: 5 additions & 1 deletion src/main/java/com/yqbd/beans/TaskBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ public class TaskBean implements Serializable {
private Integer taskStatus;
private Long publishTime;
private Long completeTime;
private Long startTime;
private Integer maxPeopleNumber;
private Long deadline;

private String simpleDrawingAddress;
private Integer isGroup;
private List<TypeBean> typeBeans;
private String name;

private String primaryWork;
private String otherCompany;
private String primaryContact;
private String remark;
}
35 changes: 35 additions & 0 deletions src/main/java/com/yqbd/beans/UserInfoBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.yqbd.beans;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class UserInfoBean {
private Integer userId;

private String accountNumber;

private String password;

private String sex;

private String realName;

private String nickName;

private String headPortrait;

private Integer professionalLevel;

private Integer creditLevel;

private String telephone;

private String school;

private String occupation;

private String companyName;

}
20 changes: 18 additions & 2 deletions src/main/java/com/yqbd/controller/api/CompanyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@

import com.yqbd.beans.BaseBean;
import com.yqbd.beans.BaseJson;
import com.yqbd.beans.CompanyInfoBean;
import com.yqbd.controller.BaseController;
import com.yqbd.mapper.CompanyInfoMapper;
import com.yqbd.mapper.GroupInfoMapper;
import com.yqbd.model.CompanyInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.stream.Collectors;

/**
* Created by joy12 on 2017/7/22.
Expand All @@ -30,11 +34,11 @@ public class CompanyController extends BaseController {
@Autowired
private GroupInfoMapper groupInfoMapper;

@RequestMapping(value = "/getCompanyInfoByCompanyId", method = RequestMethod.POST)
@RequestMapping(value = "/getCompanyInfoByCompanyId")
public BaseJson getCompanyInfoByCompanyId(@RequestParam("companyId") int companyId) {
BaseJson baseJson = new BaseJson();
CompanyInfo companyInfo = companyInfoMapper.selectByPrimaryKey(companyId);
baseJson.setObj(companyInfo);
baseJson.setObj(parse(companyInfo));
return baseJson;
}

Expand Down Expand Up @@ -74,5 +78,17 @@ public BaseJson companyLogin(@RequestParam("companyAccount") String companyAccou
return baseJson;
}

@RequestMapping(value = "/getAllCompanies")
public BaseJson getAllCompanies() {
BaseJson baseJson = new BaseJson();
List<CompanyInfo> companyInfoList = companyInfoMapper.getAllCompanies();
baseJson.setObj(companyInfoList.stream().map(this::parse).collect(Collectors.toList()));
return baseJson;
}

private CompanyInfoBean parse(CompanyInfo companyInfo) {
CompanyInfoBean result = new CompanyInfoBean();
BeanUtils.copyProperties(companyInfo, result);
return result;
}
}
71 changes: 66 additions & 5 deletions src/main/java/com/yqbd/controller/api/TaskController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.yqbd.controller.api;


import com.google.common.collect.Lists;
import com.yqbd.beans.*;
import com.yqbd.constants.TaskStatus;
import com.yqbd.constants.UserTaskStatus;
import com.yqbd.controller.BaseController;
import com.yqbd.mapper.TaskMapper;
import com.yqbd.mapper.TaskTypeMapper;
import com.yqbd.mapper.TypeMapper;
import com.yqbd.mapper.UserTakeMapper;
import com.yqbd.mapper.*;
import com.yqbd.model.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -43,6 +41,9 @@ public class TaskController extends BaseController {
@Autowired
protected TaskTypeMapper taskTypeMapper;

@Autowired
protected UserCollectMapper userCollectMapper;

@RequestMapping(value = "/getAllTypes")
public BaseJson getAllTypes() {
BaseJson baseJson = new BaseJson();
Expand All @@ -55,7 +56,22 @@ public BaseJson getAllTypes() {
public BaseJson getAllTasks() {
BaseJson baseJson = new BaseJson();
List<Task> tasks = taskMapper.selectAllTasks();
baseJson.setObj(tasks);
baseJson.setObj(Lists.transform(tasks, this::parse));
return baseJson;
}

@RequestMapping(value = "/getCollectedTasks")
public BaseJson getCollectedTasks(@RequestParam("userId") int userId) {
BaseJson baseJson = new BaseJson();
List<Task> tasks = taskMapper.getCollectedTasks(userId);
baseJson.setObj(Lists.transform(tasks, this::parse));
return baseJson;
}

@RequestMapping(value = "/getCompanyTasks")
public BaseJson getCompanyTasks(@RequestParam("companyId") int companyId) {
BaseJson baseJson = new BaseJson();
baseJson.setObj(Lists.transform(taskMapper.getCompanyTasks(companyId), this::parse));
return baseJson;
}

Expand Down Expand Up @@ -288,4 +304,49 @@ public BaseJson userCancelTakeTask(@RequestParam("taskId") int taskId, @RequestP
return baseJson;
}

@RequestMapping(value = "/isCollected")
public BaseJson isCollected(@RequestParam("taskId") int taskId, @RequestParam("userId") int userId) {
BaseJson baseJson = new BaseJson();
UserCollectKey userTakeKey = new UserCollectKey();
userTakeKey.setUserId(userId);
userTakeKey.setTaskId(taskId);
UserCollectKey userTake = userCollectMapper.selectByPrimaryKey(userTakeKey);
BaseBean baseBean = new BaseBean(Objects.nonNull(userTake));
baseJson.setObj(baseBean);
return baseJson;
}

@RequestMapping(value = "/collect")
public BaseJson collect(@RequestParam("taskId") int taskId, @RequestParam("userId") int userId) {
BaseJson baseJson = new BaseJson();
UserCollectKey userCollectKey = new UserCollectKey();
userCollectKey.setUserId(userId);
userCollectKey.setTaskId(taskId);
UserCollectKey userTake = userCollectMapper.selectByPrimaryKey(userCollectKey);
if (Objects.nonNull(userTake)) {
userCollectMapper.deleteByPrimaryKey(userCollectKey);
} else {
userCollectMapper.insert(userCollectKey);
}
BaseBean baseBean = new BaseBean(Objects.isNull(userTake));
baseJson.setObj(baseBean);
return baseJson;
}

private TaskBean parse(Task task) {
TaskBean taskBean = new TaskBean();
BeanUtils.copyProperties(task, taskBean);
taskBean.setPublishTime(task.getPublishTime().getTime());
taskBean.setCompleteTime(task.getCompleteTime().getTime());
taskBean.setStartTime(task.getStartTime().getTime());
taskBean.setDeadline(task.getDeadline().getTime());
taskBean.setTypeBeans(Lists.transform(typeMapper.selectTypesByTaskId(taskBean.getTaskId()), this::parse));
return taskBean;
}

private TypeBean parse(Type type) {
TypeBean result = new TypeBean();
BeanUtils.copyProperties(type, result);
return result;
}
}
26 changes: 14 additions & 12 deletions src/main/java/com/yqbd/mapper/CompanyInfoMapper.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.yqbd.mapper;

import com.yqbd.model.CompanyInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.yqbd.model.CompanyInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CompanyInfoMapper {
@Delete({
Expand All @@ -17,18 +15,17 @@ public interface CompanyInfoMapper {
@Insert({
"insert into company_info (company_id, company_name, ",
"company_account, password, ",
"classification, summary)",
"classification, summary, head_portrait_address)",
"values (#{companyId,jdbcType=INTEGER}, #{companyName,jdbcType=VARCHAR}, ",
"#{companyAccount,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, ",
"#{classification,jdbcType=VARCHAR}, #{summary,jdbcType=VARCHAR})"
"#{classification,jdbcType=VARCHAR}, #{summary,jdbcType=VARCHAR}, #{headPortraitAddress,jdbcType=VARCHAR})"
})
int insert(CompanyInfo record);

int insertSelective(CompanyInfo record);

@Select({
"select",
"company_id, company_name, company_account, password, classification, summary",
"select *",
"from company_info",
"where company_id = #{companyId,jdbcType=INTEGER}"
})
Expand All @@ -43,14 +40,19 @@ public interface CompanyInfoMapper {
"company_account = #{companyAccount,jdbcType=VARCHAR},",
"password = #{password,jdbcType=VARCHAR},",
"classification = #{classification,jdbcType=VARCHAR},",
"summary = #{summary,jdbcType=VARCHAR}",
"summary = #{summary,jdbcType=VARCHAR},",
"head_portrait_address = #{headPortraitAddress,jdbcType=VARCHAR}",
"where company_id = #{companyId,jdbcType=INTEGER}"
})
int updateByPrimaryKey(CompanyInfo record);

@Select(
"SELECT * FROM company_info WHERE company_account=#{accountNumber,jdbcType=VARCHAR} "
"SELECT * FROM company_info WHERE company_account = #{accountNumber,jdbcType=VARCHAR} "
)
@ResultMap("BaseResultMap")
CompanyInfo selectByCompanyAccount(String accountNumber);

@Select("select * from company_info")
@ResultType(CompanyInfo.class)
List<CompanyInfo> getAllCompanies();
}
Loading

0 comments on commit b1a5d0c

Please sign in to comment.