前言
至今为止,我感觉自己各方面的能力都得到了相应的提示,无论是从技术还是团队沟通方面,所以我对自己还是相当满意的。本次冲刺我负责的主要任务有统计关卡以及上个冲刺遗留下来的定时任务。
一、查询同方向关卡延期个数
注意:有两个选择条件:一周内(week)和一个月内(month),所以我先得统计距当前时间前一周或一个月的所有时间,然后再根据这些时间去统计个数。
/**
* 根据一周内(week)或者一个月内(month)和用户名称查询同方向关卡延期个数
* @param condition
* @param username
* @return
*/
@RequestMapping("/selectCountPostponeByUsernameAndCondition")
@ResponseBody
public ResultInfo selectCountPostponeByCondition(@RequestParam(value = "condition")String condition,
@RequestParam(value = "username")String username){
ResultInfo info=customspassService.selectCountPostponeByCondition(condition,username);
return info;
}
/**
* 根据一周内(week)或者一个月内(month)和用户名称查询同方向关卡延期个数
* @param condition
* @param username
* @return
*/
@Override
public ResultInfo selectCountPostponeByCondition(String condition, String username) {
ResultInfo info=new ResultInfo();
info.setFlag(true);
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
try {
User user = new User();
user.setUsername(username);
//根据用户名称查询用户信息
User selectByCondition = userMapper.selectByCondition(user);
User us=new User();
us.setSubjectId(selectByCondition.getSubjectId());
us.setIssue(selectByCondition.getIssue());
//根据用户方向id查询所有的用户信息
List<User> userList=userMapper.selectUserList(us);
//查询一周内的日期
ArrayList<String> arrayList=new ArrayList<String>();
//存在延期日期对应的个数
LinkedHashMap<String,Integer> map=new LinkedHashMap<String, Integer>();
if ("week".equals(condition)){
arrayList = beforeDate(7);
}else if ("month".equals(condition)){
arrayList=beforeDate(30);
}
for (String s : arrayList) {
map.put(s,0);
}
for (User user1 : userList) {
//根据用户名称查询延期记录
List<Postpone> postponeList=postponeMapper.selectPostponeByUsername(user1.getUsername());
//判断是否存在延期
if (postponeList!=null){
//延期
for (Postpone postpone : postponeList) {
for (String date : arrayList) {
String deferDate = postpone.getDeferDate();
String dd=null;
try {
dd = format.format(format.parse(deferDate));
}catch (Exception e){
e.printStackTrace();
}
if (date.equals(dd)){
//将符合条件的存在到map集合中
map.put(date,map.get(date)+1);
}
}
}
}
}
//存储条件是一个月内的数据
LinkedHashMap<Integer,Integer> hp=new LinkedHashMap<Integer, Integer>();
int count=0;
Collection<Integer> values = map.values();
int sum1=0;
int sum2=0;
int sum3=0;
int sum4=0;
int sum5=0;
if ("month".equals(condition)){
//每一周作为一个周期
for (Integer value : values) {
//第一周
if (count/7==0){
sum1+=value;
hp.put(count/7+1,sum1);
}
//第二周
if (count/7==1){
sum2+=value;
hp.put(count/7+1,sum2);
}
//第三周
if (count/7==2){
sum3+=value;
hp.put(count/7+1,sum3);
}
//第四周
if (count/7==3){
sum4+=value;
hp.put(count/7+1,sum4);
}
//第五周
if (count/7==4){
sum5+=value;
hp.put(count/7+1,sum5);
}
count++;
}
}
if ("week".equals(condition)){
info.setData(map);
}else if ("month".equals(condition)){
info.setData(hp);
}
}catch (Exception e){
info.setFlag(false);
info.setErrorMsg("查询失败!");
e.printStackTrace();
}
return info;
}
二、查询同期同方向同阶段各关卡完成的人数
注意:如果一个冲刺下超过八条数据,那么我会查询最后一次完成或者进行,然后逆序输出8条数据形成map集合响应。
/**
* 根据用户名称和阶段名称查询同期同方向同阶段各关卡完成的人数
* @param username
* @return
*/
@RequestMapping("/selectCustomspassFinishByUsernameAndStageName")
@ResponseBody
public ResultInfo selectCustomspassFinishByUsernameAndStageName(@RequestParam(value = "username")String username,
@RequestParam(value = "stageName")String stageName){
ResultInfo info=customspassService.selectCustomspassFinishByUsernameAndStageName(username,stageName);
return info;
}
/**
* 根据用户名称和阶段名称查询同期同方向同阶段各关卡完成的人数
* @param username
* @param stageName
* @return
*/
@Override
public ResultInfo selectCustomspassFinishByUsernameAndStageName(String username, String stageName) {
ResultInfo info=new ResultInfo();
info.setFlag(true);
try {
//根据用户名称查询用户信息
User user=new User();
user.setUsername(username);
User selectByCondition = userMapper.selectByCondition(user);
//根据用户名称查询所有人集合
User us=new User();
us.setSubjectId(selectByCondition.getSubjectId());
us.setIssue(selectByCondition.getIssue());
List<User> userList = userMapper.selectUserList(us);
//根据阶段名称查询阶段
Stage selectStageByStageName = stageMapper.selectStageByStageName(stageName);
//根据阶段名称查询所有的关卡
List<Customspass> customspassList = customspassMapper.selectCustomspassAllByStageName(selectStageByStageName.getStageId());
//创建map集合,存储各阶段以及对应的个数
LinkedHashMap<String,Integer> map=new LinkedHashMap<String, Integer>();
//规定之多存储8条关卡 begin
int count=0;
int a=0;
for (Customspass customspass : customspassList) {
map.put(customspass.getName(),0);
}
for (User user1 : userList) {
//根据用户名称查询所有完成的关卡
List<StudyCustomspass> studyCustomspassList=customspassMapper.selectStudyCustomspassFinishByUsername(user1.getUsername());
for (Customspass customspass : customspassList) {
for (StudyCustomspass studyCustomspass : studyCustomspassList) {
//判断
if (customspass.getName().equals(studyCustomspass.getCustomspassName())){
map.put(customspass.getName(),map.get(customspass.getName())+1);
}
}
}
}
//规定之多存储8条关卡 end
LinkedHashMap<String,Integer> mp=new LinkedHashMap<String, Integer>();
if (map.size()>=7){
Set<String> strings = map.keySet();
//将set集合转为list集合
ArrayList<String> arrayList = new ArrayList<>(strings);
//查询正在进行的关卡
StudyCustomspass studyCustomspass = customspassMapper.selectOngoingCustomspass(username);
if (studyCustomspass==null){
//该用户没有进行中的关卡
//查询第一个未开始的关卡
studyCustomspass=customspassMapper.selectNotStartOne(username);
}
for (int i = arrayList.size()-1; i >=0 ; i--) {
if (studyCustomspass!=null) {
if (studyCustomspass.getCustomspassName().equals(arrayList.get(i))) {
a = i;
}
}
}
if (a<7){
a=7;
}
for (int i = a; i>=0 ; i--) {
if (count<8){
mp.put(arrayList.get(i),map.get(arrayList.get(i)));
count++;
}
}
Set<String> stringss = mp.keySet();
List<String> list=new ArrayList<String>(stringss);
//存储顺序的数据
LinkedHashMap<String,Integer> m=new LinkedHashMap<String, Integer>();
for (int i = list.size()-1; i >=0 ; i--) {
Integer value=mp.get(list.get(i));
m.put(list.get(i),value);
}
info.setData(m);
}else {
info.setData(map);
}
}catch (Exception e){
info.setFlag(false);
info.setErrorMsg("查询失败!");
e.printStackTrace();
}
return info;
}
定时任务
注意:只需要在application.xml中配置一下代码即可。在burnDownCron类中创建cron方法,cron表达式代表傍晚12点,所以意思就是在每一天的傍晚12点调用burnDownCron类中的cron方法。
<task:scheduled-tasks>
<task:scheduled ref="burnDownCron" method="cron" cron="0 0 0 * * ? "/>
</task:scheduled-tasks>
总结
经过前几个冲刺的努力,我在各个方面都得到了提升,有这一次的经验相信我会在后面做得越来越好,加油!