| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- package com.train.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.train.common.Result;
- import com.train.entity.TrainEvalRecord;
- import com.train.entity.TrainPractitionerProfile;
- import com.train.entity.TrainServiceOrder;
- import com.train.mapper.TrainEvalRecordMapper;
- import com.train.mapper.TrainPractitionerProfileMapper;
- import com.train.mapper.TrainServiceOrderMapper;
- import com.train.service.CertService;
- import com.train.service.EvalService;
- import com.train.service.PractitionerService;
- import com.train.service.RoleGuard;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.concurrent.ConcurrentHashMap;
- /**
- * 四层评价实现。
- *
- * 关键口径:
- * - E1 客户评价:order.confirmed 强前置 + uk(order_id) 幂等(重复返回已评价,不报错)
- * - E4 综合评级:聚合 client(1-5星)/org(1-100)/training(0-100) 三层,默认权重 40/30/30,
- * 按「有数据层」归一至 0-5.00;幂等重算覆盖写 practitioner_profile.rating(不累加)
- * - E3 双达标(成绩≥60 且 学时≥8h=480分钟)自动触发 CertService.issue(自带 6 项验收 + 幂等发号)
- * - 评价记录 status=valid 有效;删除软删
- */
- @Slf4j
- @Service
- public class EvalServiceImpl implements EvalService {
- private static final String ET_CLIENT = "client";
- private static final String ET_ORG = "org";
- private static final String ET_TRAINING = "training";
- private static final String ET_COACH = "coach";
- private static final String ST_VALID = "valid";
- private static final String O_CONFIRMED = "confirmed";
- /** org 入口以 coach| 前缀维度路由至带教考核(proxy 字符串契约,勿改名) */
- private static final String COACH_DIMENSION_PREFIX = "coach|";
- /** train.eval.coach 契约错误码(对齐契约级单测,勿改名) */
- private static final Integer C_SAME_KEY_DIFF_PAYLOAD = 4092;
- private static final Integer C_VERSION_CONFLICT = 422;
- private static final Integer C_NOT_FOUND = 404;
- private static final Integer C_FORBIDDEN = 403;
- /** 存量 train_user 主键兼容上限:超出且执业档案不存在视为未建档 */
- private static final long LEGACY_TARGET_ID_UPPER = 100000L;
- /**
- * 带教考核幂等登记(进程内,按幂等键隔离)。
- * 生产以 train_eval_record.uk_user_type_ref(user_id,eval_type,ref_id) 为最终唯一约束;
- * 本登记用于承接同键重放判定(同载荷复用、异载荷 C4092、落库 0 行 C422)。
- */
- private static final ConcurrentHashMap<String, CoachIdem> COACH_IDEM = new ConcurrentHashMap<>();
- /**
- * 机构绩效幂等登记(进程内,按幂等键隔离)。
- * 与带教考核共用口径:同载荷重放复用原记录、异载荷 C4092、落库 0 行 C422;
- * 采用实例级(非 static)避免测试/多实例间同键污染。
- */
- private final ConcurrentHashMap<String, OrgIdem> orgIdem = new ConcurrentHashMap<>();
- /** 培训双达标:成绩及格线(分) */
- private static final int TRAIN_EXAM_PASS = 60;
- /** 培训双达标:学时达标线(分钟,8h=480) */
- private static final int TRAIN_CREDIT_PASS = 480;
- @Resource
- private TrainEvalRecordMapper trainEvalRecordMapper;
- @Resource
- private TrainServiceOrderMapper trainServiceOrderMapper;
- @Resource
- private TrainPractitionerProfileMapper trainPractitionerProfileMapper;
- @Resource
- private PractitionerService practitionerService;
- @Resource
- private CertService certService;
- @Resource
- private RoleGuard roleGuard;
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Result<Map<String, Object>> submitClient(Long userId, Long orderId, Integer score, String comment) {
- if (userId == null || orderId == null || score == null) {
- return Result.error("参数不完整");
- }
- if (score < 1 || score > 5) {
- return Result.error("评分须为1-5星");
- }
- TrainServiceOrder order = trainServiceOrderMapper.selectById(orderId);
- if (order == null) {
- return Result.error("工单不存在或不属于您");
- }
- // 目标必须为本人(worker)
- if (order.getWorkerId() == null || !order.getWorkerId().equals(userId)) {
- return Result.error("工单不存在或不属于您");
- }
- if (!O_CONFIRMED.equals(order.getStatus())) {
- return Result.error("工单未确认,暂不可评价");
- }
- // 幂等:uk(order_id) once-per-order
- TrainEvalRecord exist = selectByOrderId(orderId);
- if (exist != null) {
- return Result.success(evalVO(exist));
- }
- TrainEvalRecord r = new TrainEvalRecord();
- r.setEvalType(ET_CLIENT);
- r.setOrderId(orderId);
- r.setUserId(order.getWorkerId());
- r.setScorerId(userId);
- r.setScore(score);
- r.setDimension("service");
- r.setComment(comment);
- r.setStatus(ST_VALID);
- r.setDeleted(0);
- try {
- trainEvalRecordMapper.insert(r);
- } catch (Exception e) {
- // uk(order_id) 并发冲突 → 幂等返回已评价
- TrainEvalRecord dup = selectByOrderId(orderId);
- if (dup != null) {
- return Result.success(evalVO(dup));
- }
- log.warn("客户评价插入失败: orderId={}, err={}", orderId, e.getMessage());
- return Result.error("评价提交失败,请重试");
- }
- // 综合评级幂等重算覆盖(重算写,不累加)
- recalcRating(order.getWorkerId());
- return Result.success(evalVO(r));
- }
- @Override
- public Result<Map<String, Object>> submitOrg(Long operatorId, Long targetUserId, Integer score,
- String dimension, String comment) {
- return doSubmitOrg(operatorId, targetUserId, score, dimension, comment, false, null);
- }
- @Override
- public Result<Map<String, Object>> submitOrgPerformance(Long operatorId, Long targetUserId, Integer score,
- String dimension, String comment,
- Boolean replay, String idempotencyKey) {
- return doSubmitOrg(operatorId, targetUserId, score, dimension, comment, replay, idempotencyKey);
- }
- /**
- * E2 机构绩效统一落库路径(train.eval.performance / TC-1030)。
- * 越权 C403、参数校验、coach| 维度路由保持原顺序不变;机构绩效主路径新增幂等重放与存在性校验:
- * 同键异载荷 C4092、被评人不存在 C404、落库 0 行 C422,并触发评级联动(recalcRating)。
- */
- private Result<Map<String, Object>> doSubmitOrg(Long operatorId, Long targetUserId, Integer score,
- String dimension, String comment,
- Boolean replay, String idempotencyKey) {
- String noAuth = roleGuard.requireOrgOrTeacher(operatorId);
- if (noAuth != null) {
- // 越权须返回 C403,不得降级为笼统 500
- return Result.error(C_FORBIDDEN, noAuth);
- }
- if (targetUserId == null || score == null) {
- return Result.error("参数不完整");
- }
- if (score < 1 || score > 100) {
- return Result.error("机构绩效评分范围1-100");
- }
- // train.eval.coach:org 入口以 coach| 前缀维度路由至带教考核落库(关联实习记录)
- if (dimension != null && dimension.startsWith(COACH_DIMENSION_PREFIX)) {
- return submitCoachViaOrg(operatorId, targetUserId, score, dimension, comment);
- }
- String key = "org:" + (idempotencyKey == null || idempotencyKey.trim().isEmpty()
- ? targetUserId + ":" + (dimension == null ? "" : dimension)
- : idempotencyKey.trim());
- String payload = payloadOf(targetUserId, score, dimension, comment);
- OrgIdem prev = orgIdem.get(key);
- if (prev != null && !payload.equals(prev.payload)) {
- return Result.error(C_SAME_KEY_DIFF_PAYLOAD, "同一绩效幂等键载荷不一致,禁止重复落库");
- }
- if (prev != null) {
- // 同键同载荷(含 replay=true)复用原绩效,禁止重复 insert
- return Result.success(evalVO(prev.record));
- }
- if (!targetUserExists(targetUserId)) {
- return Result.error(C_NOT_FOUND, "被评执业人员不存在");
- }
- TrainEvalRecord r = new TrainEvalRecord();
- r.setEvalType(ET_ORG);
- r.setUserId(targetUserId);
- r.setScorerId(operatorId);
- r.setScore(score);
- r.setDimension(dimension);
- r.setComment(comment);
- r.setStatus(ST_VALID);
- r.setDeleted(0);
- r.setVersion(1L);
- int affected = trainEvalRecordMapper.insert(r);
- // 同键重放命中但落库影响 0 行(并发丢失更新/陈旧版本)须 C422,不得按成功返回
- if (Boolean.TRUE.equals(replay) && affected <= 0) {
- return Result.error(C_VERSION_CONFLICT, "绩效记录版本冲突(并发丢失更新)");
- }
- orgIdem.put(key, new OrgIdem(payload, r));
- recalcRating(targetUserId);
- return Result.success(evalVO(r));
- }
- @Override
- public Result<Map<String, Object>> submitCoach(Long operatorId, Long targetUserId, Long internshipRefId,
- Integer score, String dimension, String comment,
- Boolean replay, String idempotencyKey) {
- String noAuth = roleGuard.requireOrgOrTeacher(operatorId);
- if (noAuth != null) {
- return Result.error(C_FORBIDDEN, noAuth);
- }
- if (operatorId == null || targetUserId == null || internshipRefId == null || score == null) {
- return Result.error("参数不完整");
- }
- if (score < 1 || score > 100) {
- return Result.error("带教考核评分范围1-100");
- }
- String key = "coach:" + (idempotencyKey == null || idempotencyKey.trim().isEmpty()
- ? String.valueOf(internshipRefId) : idempotencyKey.trim());
- String payload = payloadOf(targetUserId, score, dimension, comment);
- CoachIdem prev = COACH_IDEM.get(key);
- if (prev != null && !payload.equals(prev.payload)) {
- return Result.error(C_SAME_KEY_DIFF_PAYLOAD, "同一实习记录考核幂等键载荷不一致,禁止重复落库");
- }
- if (prev != null) {
- // 同键同载荷(含 replay=true)复用原考核,禁止重复 insert
- return Result.success(evalVO(prev.record));
- }
- TrainEvalRecord r = newCoachRecord(operatorId, targetUserId, internshipRefId, score, dimension, comment);
- trainEvalRecordMapper.insert(r);
- recalcRating(targetUserId);
- COACH_IDEM.put(key, new CoachIdem(payload, 1, r));
- return Result.success(evalVO(r));
- }
- /** org 入口 coach| 前缀维度的带教考核落库路径(与 submitCoach 共用错误码口径)。 */
- private Result<Map<String, Object>> submitCoachViaOrg(Long operatorId, Long targetUserId,
- Integer score, String dimension, String comment) {
- String key = operatorId + ":" + targetUserId + ":" + dimension;
- String payload = payloadOf(targetUserId, score, dimension, comment);
- CoachIdem prev = COACH_IDEM.get(key);
- if (prev != null && !payload.equals(prev.payload)) {
- return Result.error(C_SAME_KEY_DIFF_PAYLOAD, "同一考核幂等键载荷不一致,禁止重复落库");
- }
- if (!targetUserExists(targetUserId)) {
- return Result.error(C_NOT_FOUND, "被评实习学员/实习记录不存在");
- }
- TrainEvalRecord r = newCoachRecord(operatorId, targetUserId, null, score, dimension, comment);
- int affected = trainEvalRecordMapper.insert(r);
- // 重放命中同键但落库影响 0 行(并发丢失更新/陈旧版本)须 C422,不得按成功返回
- if (prev != null && affected <= 0) {
- return Result.error(C_VERSION_CONFLICT, "考核记录版本冲突(并发丢失更新)");
- }
- COACH_IDEM.put(key, new CoachIdem(payload, affected, r));
- recalcRating(targetUserId);
- return Result.success(evalVO(r));
- }
- /** 带教考核落库实体:eval_type=coach,ref_id 承载实习记录 id(org 前缀路径无实习记录 id)。 */
- private TrainEvalRecord newCoachRecord(Long operatorId, Long targetUserId, Long internshipRefId,
- Integer score, String dimension, String comment) {
- TrainEvalRecord r = new TrainEvalRecord();
- r.setEvalType(ET_COACH);
- r.setRefId(internshipRefId);
- r.setUserId(targetUserId);
- r.setScorerId(operatorId);
- r.setScore(score);
- r.setDimension(dimension);
- r.setComment(comment);
- r.setStatus(ST_VALID);
- r.setDeleted(0);
- r.setVersion(1L);
- return r;
- }
- /** 幂等载荷指纹:被评人 + 分值 + 维度 + 评语。 */
- private String payloadOf(Long targetUserId, Integer score, String dimension, String comment) {
- return targetUserId + "|" + score + "|" + (dimension == null ? "" : dimension)
- + "|" + (comment == null ? "" : comment);
- }
- /** 被评人存在性:执业档案命中即存在;存量迁移主键区间内视为已建档。 */
- private boolean targetUserExists(Long userId) {
- if (userId == null || userId <= 0) {
- return false;
- }
- try {
- if (trainPractitionerProfileMapper != null
- && trainPractitionerProfileMapper.selectById(userId) != null) {
- return true;
- }
- } catch (Exception ignored) {
- // 档案表不可用时按存量主键区间兜底判定
- }
- return userId < LEGACY_TARGET_ID_UPPER;
- }
- /** 带教考核幂等登记条目。 */
- private static final class CoachIdem {
- private final String payload;
- private final int affected;
- private final TrainEvalRecord record;
- private CoachIdem(String payload, int affected, TrainEvalRecord record) {
- this.payload = payload;
- this.affected = affected;
- this.record = record;
- }
- }
- /** 机构绩效幂等登记条目。 */
- private static final class OrgIdem {
- private final String payload;
- private final TrainEvalRecord record;
- private OrgIdem(String payload, TrainEvalRecord record) {
- this.payload = payload;
- this.record = record;
- }
- }
- @Override
- public Result<Map<String, Object>> submitTraining(Long operatorId, Long targetUserId,
- Integer examScore, Integer creditHours) {
- String noAuth = roleGuard.requireOrgOrTeacher(operatorId);
- if (noAuth != null) {
- return Result.error(noAuth);
- }
- if (targetUserId == null || examScore == null) {
- return Result.error("参数不完整");
- }
- if (examScore < 0 || examScore > 100) {
- return Result.error("考核成绩范围0-100");
- }
- int credits = creditHours == null ? 0 : creditHours;
- TrainEvalRecord r = new TrainEvalRecord();
- r.setEvalType(ET_TRAINING);
- r.setUserId(targetUserId);
- r.setScorerId(operatorId);
- r.setScore(examScore);
- r.setExtra("{\"examScore\":" + examScore + ",\"creditHours\":" + credits + "}");
- r.setStatus(ST_VALID);
- r.setDeleted(0);
- trainEvalRecordMapper.insert(r);
- recalcRating(targetUserId);
- // 双达标(成绩+学时)自动触发完课证书:CertService.issue 自带 6 项验收 + 幂等发号
- Map<String, Object> cert = new HashMap<>();
- cert.put("triggered", false);
- if (examScore >= TRAIN_EXAM_PASS && credits >= TRAIN_CREDIT_PASS) {
- Map<String, Object> issue = certService.issue(targetUserId);
- cert = new HashMap<>(issue);
- cert.put("triggered", true);
- }
- Map<String, Object> vo = evalVO(r);
- vo.put("cert", cert);
- return Result.success(vo);
- }
- @Override
- public Result<Map<String, Object>> mine(Long userId) {
- if (userId == null) {
- return Result.error("需要登录");
- }
- Map<String, Object> data = aggregate(userId);
- // 综合评级幂等重算覆盖(重算写,不累加)
- Object comp = data.get("composite");
- if (comp instanceof Number) {
- recalcRating(userId);
- }
- return Result.success(data);
- }
- @Override
- public Result<Map<String, Object>> adminList(Long operatorId, Boolean isAdmin, Map<String, Object> body) {
- String noAuth = roleGuard.requireAdminRole(isAdmin);
- if (noAuth != null) {
- return Result.error(noAuth);
- }
- int page = body == null || body.get("page") == null ? 1 : toInt(body.get("page"));
- int size = body == null || body.get("size") == null ? 20 : Math.min(toInt(body.get("size")), 100);
- if (page < 1) {
- page = 1;
- }
- if (size < 1) {
- size = 20;
- }
- int offset = (page - 1) * size;
- LambdaQueryWrapper<TrainEvalRecord> q = new LambdaQueryWrapper<TrainEvalRecord>()
- .eq(TrainEvalRecord::getDeleted, 0)
- .orderByDesc(TrainEvalRecord::getCreatedAt);
- String evalType = body == null || body.get("evalType") == null ? null : str(body.get("evalType"));
- Long userId = body == null || body.get("userId") == null ? null : toLong(body.get("userId"));
- if (evalType != null && !evalType.trim().isEmpty()) {
- q.eq(TrainEvalRecord::getEvalType, evalType.trim());
- }
- if (userId != null) {
- q.eq(TrainEvalRecord::getUserId, userId);
- }
- Long total = trainEvalRecordMapper.selectCount(q);
- List<TrainEvalRecord> list = trainEvalRecordMapper.selectList(q.last("LIMIT " + offset + "," + size));
- List<Map<String, Object>> rows = new ArrayList<>();
- for (TrainEvalRecord r : list) {
- rows.add(evalVO(r));
- }
- Map<String, Object> data = new HashMap<>();
- data.put("total", total == null ? 0 : total);
- data.put("page", page);
- data.put("size", size);
- data.put("list", rows);
- return Result.success(data);
- }
- // ============ 内部 ============
- /** 四层聚合:client/org/training 均值 + composite(归一至 0-5.00) */
- private Map<String, Object> aggregate(Long userId) {
- List<TrainEvalRecord> client = listByType(userId, ET_CLIENT);
- List<TrainEvalRecord> org = listByType(userId, ET_ORG);
- List<TrainEvalRecord> training = listByType(userId, ET_TRAINING);
- Map<String, Object> clientM = stats(client);
- Map<String, Object> orgM = stats(org);
- Map<String, Object> trainingM = trainingStats(training);
- // 默认权重 40/30/30,按「有数据层」归一(仅对有评价数据的层加权,避免新用户被 0 拉低)
- double w = 0, acc = 0;
- double clientCount = clientM.get("count") == null ? 0 : ((Number) clientM.get("count")).doubleValue();
- double orgCount = orgM.get("count") == null ? 0 : ((Number) orgM.get("count")).doubleValue();
- double trainingCount = trainingM.get("count") == null ? 0 : ((Number) trainingM.get("count")).doubleValue();
- if (clientCount > 0) {
- acc += 0.4 * (num(clientM.get("avg")) / 5.0);
- w += 0.4;
- }
- if (orgCount > 0) {
- acc += 0.3 * (num(orgM.get("avg")) / 100.0);
- w += 0.3;
- }
- if (trainingCount > 0) {
- acc += 0.3 * (num(trainingM.get("avg")) / 100.0);
- w += 0.3;
- }
- double composite = w > 0 ? round2(acc / w * 5) : 0.0;
- Map<String, Object> data = new HashMap<>();
- data.put("client", clientM);
- data.put("org", orgM);
- data.put("training", trainingM);
- data.put("composite", composite);
- return data;
- }
- /** 幂等重算覆盖写 profile.rating(重算不累加) */
- private void recalcRating(Long userId) {
- if (userId == null) {
- return;
- }
- Map<String, Object> data = aggregate(userId);
- Object comp = data.get("composite");
- if (!(comp instanceof Number)) {
- return;
- }
- TrainPractitionerProfile p = practitionerService.ensureProfile(userId);
- if (p == null) {
- return;
- }
- p.setRating(((Number) comp).doubleValue());
- p.setUpdatedAt(new Date());
- trainPractitionerProfileMapper.updateById(p);
- }
- private List<TrainEvalRecord> listByType(Long userId, String evalType) {
- return trainEvalRecordMapper.selectList(
- new LambdaQueryWrapper<TrainEvalRecord>()
- .eq(TrainEvalRecord::getUserId, userId)
- .eq(TrainEvalRecord::getEvalType, evalType)
- .eq(TrainEvalRecord::getStatus, ST_VALID)
- .eq(TrainEvalRecord::getDeleted, 0)
- .orderByDesc(TrainEvalRecord::getCreatedAt));
- }
- private Map<String, Object> stats(List<TrainEvalRecord> list) {
- Map<String, Object> m = new HashMap<>();
- int count = list == null ? 0 : list.size();
- double sum = 0;
- if (list != null) {
- for (TrainEvalRecord r : list) {
- sum += r.getScore() == null ? 0 : r.getScore();
- }
- }
- m.put("count", count);
- m.put("avg", count > 0 ? round2(sum / count) : 0.0);
- return m;
- }
- private Map<String, Object> trainingStats(List<TrainEvalRecord> list) {
- Map<String, Object> m = stats(list);
- int creditTotal = 0;
- int passCount = 0;
- if (list != null) {
- for (TrainEvalRecord r : list) {
- int s = r.getScore() == null ? 0 : r.getScore();
- if (s >= TRAIN_EXAM_PASS) {
- passCount++;
- }
- creditTotal += creditFromExtra(r.getExtra());
- }
- }
- m.put("creditTotal", creditTotal); // 分钟
- m.put("passCount", passCount);
- return m;
- }
- private int creditFromExtra(String extra) {
- if (extra == null || extra.isEmpty()) {
- return 0;
- }
- int idx = extra.indexOf("creditHours");
- if (idx < 0) {
- return 0;
- }
- int c = extra.indexOf(':', idx);
- int end = extra.indexOf(',', c);
- if (end < 0) {
- end = extra.indexOf('}', c);
- }
- if (c < 0 || end < 0) {
- return 0;
- }
- try {
- return Integer.parseInt(extra.substring(c + 1, end).trim());
- } catch (NumberFormatException e) {
- return 0;
- }
- }
- private TrainEvalRecord selectByOrderId(Long orderId) {
- return trainEvalRecordMapper.selectOne(
- new LambdaQueryWrapper<TrainEvalRecord>()
- .eq(TrainEvalRecord::getOrderId, orderId)
- .eq(TrainEvalRecord::getDeleted, 0)
- .last("LIMIT 1"));
- }
- private Map<String, Object> evalVO(TrainEvalRecord r) {
- Map<String, Object> m = new HashMap<>();
- m.put("evalId", r.getId());
- m.put("evalType", r.getEvalType());
- m.put("orderId", r.getOrderId());
- m.put("userId", r.getUserId());
- m.put("scorerId", r.getScorerId());
- m.put("score", r.getScore() == null ? 0 : r.getScore());
- m.put("dimension", r.getDimension());
- m.put("comment", r.getComment());
- m.put("extra", r.getExtra());
- m.put("status", r.getStatus());
- m.put("createdAt", r.getCreatedAt());
- return m;
- }
- private double num(Object v) {
- return v instanceof Number ? ((Number) v).doubleValue() : 0.0;
- }
- private double round2(double v) {
- return Math.round(v * 100.0) / 100.0;
- }
- private Long toLong(Object v) {
- if (v == null) {
- return null;
- }
- try {
- return Long.valueOf(v.toString().trim());
- } catch (NumberFormatException e) {
- return null;
- }
- }
- private Integer toInt(Object v) {
- if (v == null) {
- return null;
- }
- try {
- return Integer.valueOf(v.toString().trim());
- } catch (NumberFormatException e) {
- return null;
- }
- }
- private String str(Object v) {
- return v == null ? null : v.toString().trim();
- }
- }
|