|
@@ -1,25 +1,130 @@
|
|
|
package com.hssx.pcbms.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.hssx.pcbms.constant.Constant;
|
|
|
+import com.hssx.pcbms.entity.Parameter;
|
|
|
import com.hssx.pcbms.entity.Score;
|
|
|
+import com.hssx.pcbms.entity.User;
|
|
|
+import com.hssx.pcbms.mapper.ParameterMapper;
|
|
|
import com.hssx.pcbms.mapper.ScoreMapper;
|
|
|
+import com.hssx.pcbms.mapper.UserMapper;
|
|
|
import com.hssx.pcbms.service.ScoreService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.hssx.pcbms.util.HttpRespMsg;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.xml.crypto.Data;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
|
|
|
/**
|
|
|
- * <p>
|
|
|
- * 服务实现类
|
|
|
- * </p>
|
|
|
- *
|
|
|
* @author 吴涛涛
|
|
|
* @since 2019-11-02
|
|
|
*/
|
|
|
@Service
|
|
|
public class ScoreServiceImpl extends ServiceImpl<ScoreMapper, Score> implements ScoreService {
|
|
|
+ @Resource
|
|
|
+ private ScoreMapper scoreMapper;
|
|
|
+ @Resource
|
|
|
+ private ParameterMapper parameterMapper;
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg add(Score score) {
|
|
|
- return null;
|
|
|
+ public HttpRespMsg add(Score score) throws ParseException {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+// SimpleDateFormat sdfymd = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ SimpleDateFormat sdfym = new SimpleDateFormat("yyyy-MM");
|
|
|
+ Parameter parameter = parameterMapper.selectOne(new QueryWrapper<Parameter>().eq("param_key", Constant.SCORING_DEADLINE_CODE));
|
|
|
+ if (parameter != null) {
|
|
|
+ User Rater = userMapper.selectById(score.getRaterId());
|
|
|
+ score.setRater(Rater.getName());
|
|
|
+ if(Rater != null){
|
|
|
+ msg.setError("当前打分人身份异常。");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ Score oldScore = scoreMapper.selectOne(new QueryWrapper<Score>().eq("scoring_year_month", score.getScoringYearMonth()));
|
|
|
+ if (score.getScoreId() != null) {
|
|
|
+ //修改打分
|
|
|
+ scoreMapper.updateById(score);
|
|
|
+ } else {
|
|
|
+ Date now = new Date();
|
|
|
+ now.setDate(Integer.parseInt(parameter.getParamValue()));
|
|
|
+ String thisMonth5 = sdfym.format(now);
|
|
|
+ now.setMonth(now.getMonth() - 1);
|
|
|
+ String lastMonth5 = sdfym.format(now);
|
|
|
+ now.setMonth(now.getMonth() + 2);
|
|
|
+ String nextMonth5 = sdfym.format(now);
|
|
|
+ Date nowDate = new Date();
|
|
|
+ String currentDateStr = sdfym.format(nowDate);
|
|
|
+ //打分日期
|
|
|
+ Date yearMonth = sdfym.parse(score.getScoringYearMonth());
|
|
|
+ if (currentDateStr.compareTo(lastMonth5) >= 0 && currentDateStr.compareTo(thisMonth5) <= 0) {
|
|
|
+ //上个月五号到本月五号之间(可评上月的分)
|
|
|
+ msg = addScore(yearMonth, nowDate, 0, score,oldScore);
|
|
|
+ } else if (currentDateStr.compareTo(thisMonth5) >= 0 && currentDateStr.compareTo(nextMonth5) <= 0) {
|
|
|
+ //本月五号到下月五号之间(可评本月的分)
|
|
|
+ msg = addScore(yearMonth, nowDate, 1, score,oldScore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ private HttpRespMsg addScore(Date yearMonth, Date nowDate, Integer type, Score score,Score oldScore) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ //评分上个月
|
|
|
+ if (type == 0) {
|
|
|
+ if (yearMonth.getMonth() == (nowDate.getMonth() - 1)) {
|
|
|
+ if (oldScore != null) {
|
|
|
+ msg.setError("本月已打分,请勿重复打分");
|
|
|
+ return msg;
|
|
|
+ } else {
|
|
|
+ scoreMapper.insert(score);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.setError("评分日期不和法,请切换日期后重试");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ } else if (type == 1) {
|
|
|
+ if (yearMonth.getMonth() == (nowDate.getMonth())) {
|
|
|
+ if (oldScore != null) {
|
|
|
+ msg.setError("本月已打分,请勿重复打分");
|
|
|
+ return msg;
|
|
|
+ } else {
|
|
|
+ scoreMapper.insert(score);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.setError("评分日期不和法,请切换日期后重试");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ System.out.println("2019-11-07".compareTo("2019-11-07"));
|
|
|
+ SimpleDateFormat sdfym = new SimpleDateFormat("yyyy-MM");
|
|
|
+ Date now = new Date();
|
|
|
+ now.setDate(Integer.parseInt("5"));
|
|
|
+ String thisMonth5 = sdfym.format(now);
|
|
|
+ now.setMonth(now.getMonth() - 1);
|
|
|
+ String lastMonth5 = sdfym.format(now);
|
|
|
+ now.setMonth(now.getMonth() + 2);
|
|
|
+ String nextMonth5 = sdfym.format(now);
|
|
|
+ System.out.println(thisMonth5 + " " + lastMonth5 + " " + nextMonth5);
|
|
|
+ Date nowDate = new Date();
|
|
|
+ String currentDateStr = "2019-11-06";
|
|
|
+ if (currentDateStr.compareTo(lastMonth5) > 0 && currentDateStr.compareTo(thisMonth5) < 0) {
|
|
|
+ System.out.println("上月五号到这月五号之间");
|
|
|
+
|
|
|
+ } else if (currentDateStr.compareTo(thisMonth5) > 0) {
|
|
|
+ System.out.println("超过本月五号了");
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|