Ejemplo n.º 1
0
  /**
   * 签到详情
   *
   * @return
   */
  @RequestMapping(value = "signDetailView", method = RequestMethod.GET)
  public ModelAndView signDetailView(HttpServletRequest request) {
    ModelAndView modelAndView = super.createModelAndViewWithSign("sign_detail", request);
    Map<String, Object> requestParams = getRequestParams(request);
    String id = StringUtil.getString(requestParams.get("id"));
    if (StringUtils.isEmpty(id)) {
      throw new BusinessEnergyException(
          SpringContextUtil.getI18n("1002002", new String[] {"id"}, null));
    }
    // 需要获取签到信息
    Sign sign = new Sign();
    sign.setId(id);
    List<Map<String, Object>> signListMap = signService.getSign(sign);
    if (!CollectionUtils.isEmpty(signListMap)) {
      modelAndView.addObject("signInfo", signListMap.get(0));
    } else {
      if (CollectionUtils.isEmpty(signListMap)) {
        throw new EnergyException(
            SpringContextUtil.getI18n("1002003", new String[] {"id", id}, null));
      }
    }
    // 判断如果已经过期需要提醒
    Date currentDate = new Date();
    String signType = (String) signListMap.get(0).get("signType");
    Date beginTime = (Date) signListMap.get(0).get("beginTime");

    SignUser signUser = new SignUser();
    signUser.setSignId(id);
    signUser.setUserId(SystemCacheUtil.getInstance().getCurrentUser().getUserid());
    List<Map<String, Object>> signUserList = signUserService.getSignUser(signUser);
    if (!CollectionUtils.isEmpty(signUserList)) {
      Map<String, Object> temp = null;
      for (int i = 0, size = signUserList.size(); i < size; i++) {
        temp = signUserList.get(i);
        // 签到信息
        if ("0".equals(temp.get("attendType"))) {
          modelAndView.addObject("sign_in", temp);
          List<Accessory> accessoryList =
              accessoryService.getAccessoryByEntityId(StringUtil.getString(temp.get("id")));
          if (!CollectionUtils.isEmpty(accessoryList)) {
            modelAndView.addObject("signInAccessoryInfor", accessoryList);
          }
        } else
        /** 签退信息 */
        {
          modelAndView.addObject("sign_out", temp);
          List<Accessory> accessoryList =
              accessoryService.getAccessoryByEntityId(StringUtil.getString(temp.get("id")));
          if (!CollectionUtils.isEmpty(accessoryList)) {
            modelAndView.addObject("signOutAccessoryInfor", accessoryList);
          }
        }
      }
    }
    if ("0".equals(signType) && signUserList.size() < 2) {
      // 判断如果不是当天的考勤不能正常进行
      if (!DateUtil.dateToString(currentDate, "yyyy-MM-dd")
          .equals(DateUtil.dateToString(beginTime, "yyyy-MM-dd"))) {
        throw new BusinessEnergyException(SpringContextUtil.getI18n("1002007"));
      }
    }
    Date curentDate = new Date();
    modelAndView.addObject(
        "date", DateUtil.dateToString(curentDate, "MM月dd日") + DateUtil.getDayOfWeek(curentDate));
    modelAndView.addObject("time", DateUtil.dateToString(curentDate, "HH:mm"));

    return modelAndView;
  }
Ejemplo n.º 2
0
  @Override
  public Object appraisalOperate(JSONObject jsonAppraisalInfo) {
    // 判断对象是否有参数
    if (!CollectionUtils.isEmpty(jsonAppraisalInfo)) {
      // 获取命令信息
      JSONObject jsonCommandInfo = jsonAppraisalInfo.getJSONObject("commandInfo");
      if (CollectionUtils.isEmpty(jsonCommandInfo)) {
        throw new EnergyException("命令信息不能为空!");
      }
      String commandType = jsonCommandInfo.getString("commandType");
      if (StringUtils.isEmpty(commandType)) {
        throw new EnergyException("命令类型不能为空!");
      }

      String id = jsonAppraisalInfo.getString("id");
      if (StringUtils.isEmpty(id)) {
        throw new EnergyException("参数id不能为空!");
      }
      int type = jsonCommandInfo.getIntValue("commandType");
      // 获取当前用户
      WeixinUser weixinUser = SystemCacheUtil.getInstance().getCurrentUser();
      Appraisal currentAppraisal = appraisalDao.getAppraisalById(id);
      if (null == currentAppraisal) {
        throw new EnergyException(
            SpringContextUtil.getI18n("1002003", new String[] {"id", id}, null));
      }
      // 实体账户id
      if (Status.已评价.value().equals(currentAppraisal.getStatus())) {
        throw new EnergyException("当前评价已处理!");
      }
      switch (type) {
          // 提交评价
        case 1:
          // 获取问题列表
          String eaId = jsonAppraisalInfo.getString("eaId");
          if (StringUtils.isEmpty(eaId)) {
            throw new EnergyException(
                SpringContextUtil.getI18n("1002002", new String[] {"eaId", eaId}, null));
          }
          EntityAccount entityAccount = entityAccountService.getEntityAccountById(eaId);
          if (null == entityAccount) {
            throw new EnergyException(
                SpringContextUtil.getI18n("1002003", new String[] {"eaId", eaId}, null));
          }

          Score score = new Score();
          score.setAppraisalId(id);
          score.setRaterId(weixinUser.getUserid());
          score.setUserId(entityAccount.getAccountId());
          List<Score> scoreList = scoreService.getScore(score);
          if (!CollectionUtils.isEmpty(scoreList)) {
            throw new EnergyException("您已评价,不能重复评价!");
          }
          scoreList = generateProblemScore(jsonAppraisalInfo, id, weixinUser, entityAccount);
          if (!CollectionUtils.isEmpty(scoreList)) {
            scoreService.addScore(scoreList.toArray(new Score[] {}));
          }

          // 实体账户id
          if (!Status.评价中.value().equals(currentAppraisal.getStatus())) {
            Appraisal appraisal = new Appraisal();
            appraisal.setId(id);
            appraisal.setStatus(Status.评价中.value());
            appraisalDao.updateAppraisal(appraisal);
          }
          // 这里对每一个人评价进行标记 主要记录当前第几个人操作
          int appraiseTimes = entityAccount.getAppraiseTimes() + 1;
          entityAccount = new EntityAccount();
          entityAccount.setId(eaId);
          entityAccount.setAppraiseTimes(appraiseTimes);
          entityAccountService.updateEntityAccount(entityAccount);

          entityAccount = new EntityAccount();
          entityAccount.setEntityId(id);
          entityAccount.setPersonType(PersonType.PJ.value());
          // 获取总评价人数
          int count = (int) entityAccountService.getEntityAccountCount(entityAccount);
          // 查询所有带评价人 当前是否都已被评价
          entityAccount = new EntityAccount();
          entityAccount.setEntityId(id);
          entityAccount.setPersonType(PersonType.BPJ.value());
          List<EntityAccount> entityAccountList =
              entityAccountService.getEntityAccount(entityAccount);
          if (!CollectionUtils.isEmpty(entityAccountList)) {
            for (EntityAccount ea : entityAccountList) {
              if (ea.getAppraiseTimes() != count) {
                return null;
              }
            }
            Appraisal appraisal = new Appraisal();
            appraisal.setId(id);
            appraisal.setStatus(Status.已评价.value());
            appraisalDao.updateAppraisal(appraisal);
          }

          break;
          // 取消评价
        case 2:

          // 如果当前已被评价那么 禁止操作
          if (Status.未评价.value().equals(currentAppraisal.getStatus())) {
            // 被评价人 评价人 问题
            entityAccountService.deleteByEntityId(id);
            problemTemplateService.deleteByAppraisalId(id);
            appraisalDao.deleteAppraisalById(id);
          } else {
            throw new EnergyException("当前评价进行中不能操作!");
          }
          break;
        default:
          throw new EnergyException("无效操作!");
      }
    } else {
      LOGGER.warn("评价操作信息为空!");
    }
    return null;
  }