|
|
@@ -0,0 +1,517 @@
|
|
|
+package com.train.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.train.common.Result;
|
|
|
+import com.train.common.StateGuard;
|
|
|
+import com.train.entity.TrainOrgMember;
|
|
|
+import com.train.entity.TrainOrderDispatch;
|
|
|
+import com.train.entity.TrainPractitionerProfile;
|
|
|
+import com.train.entity.TrainServiceOrder;
|
|
|
+import com.train.entity.TrainUser;
|
|
|
+import com.train.mapper.TrainOrgMemberMapper;
|
|
|
+import com.train.mapper.TrainOrderDispatchMapper;
|
|
|
+import com.train.mapper.TrainPractitionerProfileMapper;
|
|
|
+import com.train.mapper.TrainServiceOrderMapper;
|
|
|
+import com.train.mapper.TrainUserMapper;
|
|
|
+import com.train.service.DispatchService;
|
|
|
+import com.train.service.PromotionService;
|
|
|
+import com.train.service.RoleGuard;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 派单域实现(M4)。
|
|
|
+ *
|
|
|
+ * 关键口径:
|
|
|
+ * - create:pending + org_id 归属;workerId 入参废弃/忽略;不落 dispatch(uk 需 worker,assign 时落)
|
|
|
+ * - assign:资质闸口 unlockCheck(workerId, serviceType) → CAS assignOrder → dispatch(source=org_created, status=assigned) 同事务
|
|
|
+ * - reassign:状态仍 pending 且占用人=oldWorker 才 CAS 换人;旧留痕置 cancelled、新留痕 reassigned 同事务
|
|
|
+ * - cancel:StateGuard.checkOrder(status→cancelled) + 留痕 cancelled 同事务
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class DispatchServiceImpl implements DispatchService {
|
|
|
+
|
|
|
+ private static final String O_PENDING = StateGuard.O_PENDING;
|
|
|
+ private static final String O_ACCEPTED = StateGuard.O_ACCEPTED;
|
|
|
+ private static final String O_CANCELLED = StateGuard.O_CANCELLED;
|
|
|
+ private static final String D_ASSIGNED = "assigned";
|
|
|
+ private static final String D_ACCEPTED = "accepted";
|
|
|
+ private static final String D_REASSIGNED = "reassigned";
|
|
|
+ private static final String D_CANCELLED = "cancelled";
|
|
|
+ private static final String SRC_ORG = "org_created";
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TrainServiceOrderMapper trainServiceOrderMapper;
|
|
|
+ @Resource
|
|
|
+ private TrainOrderDispatchMapper trainOrderDispatchMapper;
|
|
|
+ @Resource
|
|
|
+ private TrainOrgMemberMapper trainOrgMemberMapper;
|
|
|
+ @Resource
|
|
|
+ private TrainPractitionerProfileMapper trainPractitionerProfileMapper;
|
|
|
+ @Resource
|
|
|
+ private TrainUserMapper trainUserMapper;
|
|
|
+ @Resource
|
|
|
+ private RoleGuard roleGuard;
|
|
|
+ @Resource
|
|
|
+ private PromotionService promotionService;
|
|
|
+
|
|
|
+ // ==================== create ====================
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Result<Map<String, Object>> create(Long operatorId, Boolean isAdmin, Map<String, Object> body) {
|
|
|
+ if (body == null || body.get("orgId") == null) {
|
|
|
+ return Result.error("参数不完整:缺少 orgId");
|
|
|
+ }
|
|
|
+ Long orgId = toLong(body.get("orgId"));
|
|
|
+ // 权限:admin 放行;org 用户须为该机构 active 管理者(资源级)
|
|
|
+ String noAuth = Boolean.TRUE.equals(isAdmin) ? null : roleGuard.requireOrgManagerAt(operatorId, orgId);
|
|
|
+ if (noAuth != null) {
|
|
|
+ return Result.error(noAuth);
|
|
|
+ }
|
|
|
+ String familyName = str(body.get("familyName"));
|
|
|
+ if (!StringUtils.hasText(familyName)) {
|
|
|
+ return Result.error("客户称呼必填");
|
|
|
+ }
|
|
|
+ String serviceType = str(body.get("serviceType"));
|
|
|
+ if (!StringUtils.hasText(serviceType)) {
|
|
|
+ serviceType = "cleaning";
|
|
|
+ }
|
|
|
+ TrainServiceOrder o = new TrainServiceOrder();
|
|
|
+ o.setOrderNo(genOrderNo());
|
|
|
+ o.setOrgId(orgId);
|
|
|
+ o.setFamilyName(familyName);
|
|
|
+ o.setContactPhone(str(body.get("contactPhone")));
|
|
|
+ o.setAddress(str(body.get("address")));
|
|
|
+ o.setServiceType(serviceType);
|
|
|
+ o.setServiceItems(body.get("serviceItems") == null ? null : body.get("serviceItems").toString());
|
|
|
+ o.setOrderDate(parseDate(body.get("orderDate")));
|
|
|
+ o.setStartAt(parseDate(body.get("startAt")));
|
|
|
+ o.setEndAt(parseDate(body.get("endAt")));
|
|
|
+ o.setStatus(O_PENDING); // ★只建 pending,不置 accepted;指派统一走 assign
|
|
|
+ o.setAmount(intv(body.get("amount")));
|
|
|
+ o.setPlatformFee(intv(body.get("platformFee")));
|
|
|
+ o.setRemark(str(body.get("remark")));
|
|
|
+ int income = (o.getAmount() == null ? 0 : o.getAmount()) - (o.getPlatformFee() == null ? 0 : o.getPlatformFee());
|
|
|
+ o.setStaffIncome(income < 0 ? 0 : income);
|
|
|
+ o.setCreatedAt(new Date());
|
|
|
+ o.setUpdatedAt(new Date());
|
|
|
+ // workerId 入参废弃/忽略(终裁)
|
|
|
+ trainServiceOrderMapper.insert(o);
|
|
|
+ log.info("组织建单: orderId={}, orgId={}, operatorId={}", o.getId(), orgId, operatorId);
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("orderId", o.getId());
|
|
|
+ data.put("orderNo", o.getOrderNo());
|
|
|
+ data.put("status", o.getStatus());
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== assign / reassign ====================
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Result<Map<String, Object>> assign(Long operatorId, Boolean isAdmin, Map<String, Object> body) {
|
|
|
+ if (body == null || body.get("orderId") == null || body.get("workerId") == null) {
|
|
|
+ return Result.error("参数不完整");
|
|
|
+ }
|
|
|
+ Long orderId = toLong(body.get("orderId"));
|
|
|
+ Long workerId = toLong(body.get("workerId"));
|
|
|
+ String noAuth = roleGuard.requireOrderDispatcherAt(operatorId, isAdmin, orderId);
|
|
|
+ if (noAuth != null) {
|
|
|
+ return Result.error(noAuth);
|
|
|
+ }
|
|
|
+ TrainServiceOrder order = trainServiceOrderMapper.selectById(orderId);
|
|
|
+ if (order == null) {
|
|
|
+ return Result.error("工单不存在");
|
|
|
+ }
|
|
|
+ if (!O_PENDING.equals(order.getStatus())) {
|
|
|
+ return Result.error("仅待接单工单可指派");
|
|
|
+ }
|
|
|
+ // 资质闸口:PromotionService.unlockCheck 接线(profile.status=approved 且 auth_level 已认证)
|
|
|
+ Result<Map<String, Object>> gate = promotionService.unlockCheck(workerId, serviceTypeBody(body.get("serviceType")));
|
|
|
+ String gateMsg = gateData(gate, "allowed");
|
|
|
+ if (!"true".equals(gateMsg)) {
|
|
|
+ return Result.error("该服务人员资质不符,无法派单");
|
|
|
+ }
|
|
|
+ // CAS 抢占锁:pending 且 worker_id IS NULL
|
|
|
+ int n = trainServiceOrderMapper.assignOrder(orderId, workerId);
|
|
|
+ if (n != 1) {
|
|
|
+ return Result.error("该工单已被占用,请刷新后重试");
|
|
|
+ }
|
|
|
+ insertDispatch(orderId, workerId, SRC_ORG, operatorId, D_ASSIGNED,
|
|
|
+ order.getStaffIncome(), str(body.get("remark")));
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("orderId", orderId);
|
|
|
+ data.put("workerId", workerId);
|
|
|
+ data.put("status", O_ACCEPTED);
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Result<Map<String, Object>> reassign(Long operatorId, Boolean isAdmin, Map<String, Object> body) {
|
|
|
+ if (body == null || body.get("orderId") == null || body.get("oldWorkerId") == null
|
|
|
+ || body.get("newWorkerId") == null) {
|
|
|
+ return Result.error("参数不完整");
|
|
|
+ }
|
|
|
+ Long orderId = toLong(body.get("orderId"));
|
|
|
+ Long oldWorkerId = toLong(body.get("oldWorkerId"));
|
|
|
+ Long newWorkerId = toLong(body.get("newWorkerId"));
|
|
|
+ String noAuth = roleGuard.requireOrderDispatcherAt(operatorId, isAdmin, orderId);
|
|
|
+ if (noAuth != null) {
|
|
|
+ return Result.error(noAuth);
|
|
|
+ }
|
|
|
+ TrainServiceOrder order = trainServiceOrderMapper.selectById(orderId);
|
|
|
+ if (order == null) {
|
|
|
+ return Result.error("工单不存在");
|
|
|
+ }
|
|
|
+ if (!O_PENDING.equals(order.getStatus())) {
|
|
|
+ return Result.error("仅待接单工单可改派");
|
|
|
+ }
|
|
|
+ if (!oldWorkerId.equals(order.getWorkerId())) {
|
|
|
+ return Result.error("原服务人员与工单占用不一致,请刷新后重试");
|
|
|
+ }
|
|
|
+ Result<Map<String, Object>> gate = promotionService.unlockCheck(newWorkerId, serviceTypeBody(body.get("serviceType")));
|
|
|
+ String gateMsg = gateData(gate, "allowed");
|
|
|
+ if (!"true".equals(gateMsg)) {
|
|
|
+ return Result.error("该服务人员资质不符,无法派单");
|
|
|
+ }
|
|
|
+ // CAS 换人:仅当占用人=oldWorker 且仍 pending(防并发双改派)
|
|
|
+ int n = trainServiceOrderMapper.reassignOrder(orderId, oldWorkerId, newWorkerId);
|
|
|
+ if (n != 1) {
|
|
|
+ return Result.error("该工单状态已变化,请刷新后重试");
|
|
|
+ }
|
|
|
+ // 旧留痕置 cancelled,新留痕 reassigned(同事务)
|
|
|
+ cancelDispatch(orderId, oldWorkerId, operatorId, "改派换人");
|
|
|
+ insertDispatch(orderId, newWorkerId, SRC_ORG, operatorId, D_REASSIGNED,
|
|
|
+ order.getStaffIncome(), str(body.get("remark")));
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("orderId", orderId);
|
|
|
+ data.put("workerId", newWorkerId);
|
|
|
+ data.put("status", O_PENDING);
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== cancel ====================
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Result<Boolean> cancel(Long operatorId, Boolean isAdmin, Map<String, Object> body) {
|
|
|
+ if (body == null || body.get("orderId") == null) {
|
|
|
+ return Result.error("参数不完整");
|
|
|
+ }
|
|
|
+ Long orderId = toLong(body.get("orderId"));
|
|
|
+ String noAuth = roleGuard.requireOrderDispatcherAt(operatorId, isAdmin, orderId);
|
|
|
+ if (noAuth != null) {
|
|
|
+ return Result.error(noAuth);
|
|
|
+ }
|
|
|
+ TrainServiceOrder order = trainServiceOrderMapper.selectById(orderId);
|
|
|
+ if (order == null) {
|
|
|
+ return Result.error("工单不存在");
|
|
|
+ }
|
|
|
+ String err = StateGuard.checkOrder(order.getStatus(), O_CANCELLED);
|
|
|
+ if (err != null) {
|
|
|
+ return Result.error(err);
|
|
|
+ }
|
|
|
+ TrainServiceOrder upd = new TrainServiceOrder();
|
|
|
+ upd.setId(orderId);
|
|
|
+ upd.setStatus(O_CANCELLED);
|
|
|
+ upd.setUpdatedAt(new Date());
|
|
|
+ trainServiceOrderMapper.updateById(upd);
|
|
|
+ cancelDispatch(orderId, order.getWorkerId(), operatorId, str(body.get("remark")));
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== list ====================
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Map<String, Object>> list(Long operatorId, Boolean isAdmin, Map<String, Object> body) {
|
|
|
+ Long orgId = body == null || body.get("orgId") == null ? null : toLong(body.get("orgId"));
|
|
|
+ if (Boolean.TRUE.equals(isAdmin)) {
|
|
|
+ if (orgId == null) {
|
|
|
+ // admin 无 orgId → 全机构工单(org_id 非空)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (orgId == null) {
|
|
|
+ // org 用户必须显式指定机构
|
|
|
+ List<Long> myOrgs = myManagerOrgs(operatorId);
|
|
|
+ if (myOrgs == null || myOrgs.isEmpty()) {
|
|
|
+ return Result.error("无机构管理权限");
|
|
|
+ }
|
|
|
+ if (myOrgs.size() == 1) {
|
|
|
+ orgId = myOrgs.get(0);
|
|
|
+ } else {
|
|
|
+ return Result.error("请指定 orgId");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ String noAuth = roleGuard.requireOrgManagerAt(operatorId, orgId);
|
|
|
+ if (noAuth != null) {
|
|
|
+ return Result.error(noAuth);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int page = body == null || body.get("page") == null ? 1 : Math.max(toInt(body.get("page")), 1);
|
|
|
+ int size = body == null || body.get("size") == null ? 20 : Math.min(Math.max(toInt(body.get("size")), 1), 100);
|
|
|
+ int offset = (page - 1) * size;
|
|
|
+ LambdaQueryWrapper<TrainServiceOrder> q = new LambdaQueryWrapper<TrainServiceOrder>()
|
|
|
+ .orderByDesc(TrainServiceOrder::getId);
|
|
|
+ if (orgId != null) {
|
|
|
+ q.eq(TrainServiceOrder::getOrgId, orgId);
|
|
|
+ } else {
|
|
|
+ // admin 全量视角:仅看机构归属工单(自接单 org_id 为空不展示)
|
|
|
+ q.isNotNull(TrainServiceOrder::getOrgId);
|
|
|
+ }
|
|
|
+ String status = body == null ? null : str(body.get("status"));
|
|
|
+ if (StringUtils.hasText(status)) {
|
|
|
+ q.eq(TrainServiceOrder::getStatus, status.trim());
|
|
|
+ }
|
|
|
+ String keyword = body == null ? null : str(body.get("keyword"));
|
|
|
+ if (StringUtils.hasText(keyword)) {
|
|
|
+ String kw = keyword.trim();
|
|
|
+ q.and(w -> w.like(TrainServiceOrder::getFamilyName, kw)
|
|
|
+ .or().like(TrainServiceOrder::getOrderNo, kw)
|
|
|
+ .or().like(TrainServiceOrder::getContactPhone, kw));
|
|
|
+ }
|
|
|
+ Long total = trainServiceOrderMapper.selectCount(q);
|
|
|
+ List<TrainServiceOrder> list = trainServiceOrderMapper.selectList(q.last("LIMIT " + offset + "," + size));
|
|
|
+ List<Map<String, Object>> rows = new ArrayList<>();
|
|
|
+ for (TrainServiceOrder o : list) {
|
|
|
+ Map<String, Object> vo = orderVO(o);
|
|
|
+ vo.put("workerName", workerName(o.getWorkerId()));
|
|
|
+ rows.add(vo);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== workers ====================
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Map<String, Object>> workers(Long operatorId, Boolean isAdmin, Map<String, Object> body) {
|
|
|
+ if (body == null || body.get("orgId") == null) {
|
|
|
+ return Result.error("参数不完整:缺少 orgId");
|
|
|
+ }
|
|
|
+ Long orgId = toLong(body.get("orgId"));
|
|
|
+ String noAuth = Boolean.TRUE.equals(isAdmin) ? null : roleGuard.requireOrgManagerAt(operatorId, orgId);
|
|
|
+ if (noAuth != null) {
|
|
|
+ return Result.error(noAuth);
|
|
|
+ }
|
|
|
+ // 机构 active 成员(任意角色)→ 已 approved 档案(资质已生效)候选
|
|
|
+ List<TrainOrgMember> members = trainOrgMemberMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TrainOrgMember>()
|
|
|
+ .eq(TrainOrgMember::getOrgId, orgId)
|
|
|
+ .eq(TrainOrgMember::getStatus, "active")
|
|
|
+ .eq(TrainOrgMember::getDeleted, 0));
|
|
|
+ List<Map<String, Object>> rows = new ArrayList<>();
|
|
|
+ String keyword = body.get("keyword") == null ? null : str(body.get("keyword")).trim();
|
|
|
+ for (TrainOrgMember m : members) {
|
|
|
+ TrainPractitionerProfile p = trainPractitionerProfileMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<TrainPractitionerProfile>()
|
|
|
+ .eq(TrainPractitionerProfile::getUserId, m.getUserId())
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (p == null || p.getStatus() == null || !"approved".equals(p.getStatus())) {
|
|
|
+ continue; // 只有资质生效(档案 approved)者可派
|
|
|
+ }
|
|
|
+ TrainUser u = trainUserMapper.selectById(m.getUserId());
|
|
|
+ String name = u == null ? null : u.getName();
|
|
|
+ if (StringUtils.hasText(keyword) && name != null && !name.contains(keyword)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, Object> vo = new HashMap<>();
|
|
|
+ vo.put("userId", m.getUserId());
|
|
|
+ vo.put("name", name == null ? "" : name);
|
|
|
+ vo.put("authLevel", p.getAuthLevel());
|
|
|
+ vo.put("rating", p.getRating() == null ? 0 : Math.round(p.getRating() * 100));
|
|
|
+ rows.add(vo);
|
|
|
+ }
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("total", rows.size());
|
|
|
+ data.put("list", rows);
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 内部 ====================
|
|
|
+
|
|
|
+ private void insertDispatch(Long orderId, Long workerId, String source, Long operatorId,
|
|
|
+ String status, Integer fee, String remark) {
|
|
|
+ TrainOrderDispatch d = new TrainOrderDispatch();
|
|
|
+ d.setOrderId(orderId);
|
|
|
+ d.setWorkerId(workerId);
|
|
|
+ d.setSource(source);
|
|
|
+ d.setDispatchedBy(operatorId);
|
|
|
+ d.setDispatchedAt(new Date());
|
|
|
+ d.setStatus(status);
|
|
|
+ d.setFee(fee == null ? 0 : fee);
|
|
|
+ d.setRemark(remark);
|
|
|
+ d.setCreatedAt(new Date());
|
|
|
+ d.setUpdatedAt(new Date());
|
|
|
+ trainOrderDispatchMapper.insert(d);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void cancelDispatch(Long orderId, Long workerId, Long operatorId, String reason) {
|
|
|
+ if (workerId == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<TrainOrderDispatch> ds = trainOrderDispatchMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TrainOrderDispatch>()
|
|
|
+ .eq(TrainOrderDispatch::getOrderId, orderId)
|
|
|
+ .eq(TrainOrderDispatch::getWorkerId, workerId));
|
|
|
+ for (TrainOrderDispatch d : ds) {
|
|
|
+ if (D_ASSIGNED.equals(d.getStatus()) || D_REASSIGNED.equals(d.getStatus())
|
|
|
+ || D_ACCEPTED.equals(d.getStatus())) {
|
|
|
+ TrainOrderDispatch upd = new TrainOrderDispatch();
|
|
|
+ upd.setId(d.getId());
|
|
|
+ upd.setStatus(D_CANCELLED);
|
|
|
+ upd.setRemark(reason);
|
|
|
+ upd.setUpdatedAt(new Date());
|
|
|
+ trainOrderDispatchMapper.updateById(upd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Long> myManagerOrgs(Long userId) {
|
|
|
+ List<TrainOrgMember> ms = trainOrgMemberMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TrainOrgMember>()
|
|
|
+ .eq(TrainOrgMember::getUserId, userId)
|
|
|
+ .eq(TrainOrgMember::getStatus, "active")
|
|
|
+ .eq(TrainOrgMember::getDeleted, 0)
|
|
|
+ .in(TrainOrgMember::getRole, "org_admin", "dispatcher"));
|
|
|
+ Set<Long> set = new HashSet<>();
|
|
|
+ for (TrainOrgMember m : ms) {
|
|
|
+ set.add(m.getOrgId());
|
|
|
+ }
|
|
|
+ return new ArrayList<>(set);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> orderVO(TrainServiceOrder o) {
|
|
|
+ Map<String, Object> m = new HashMap<>();
|
|
|
+ m.put("id", o.getId());
|
|
|
+ m.put("orderNo", o.getOrderNo());
|
|
|
+ m.put("orgId", o.getOrgId());
|
|
|
+ m.put("workerId", o.getWorkerId());
|
|
|
+ m.put("familyName", o.getFamilyName());
|
|
|
+ m.put("contactPhone", o.getContactPhone());
|
|
|
+ m.put("address", o.getAddress());
|
|
|
+ m.put("serviceType", o.getServiceType());
|
|
|
+ m.put("orderDate", o.getOrderDate() == null ? null : fmt(o.getOrderDate()));
|
|
|
+ m.put("startAt", o.getStartAt() == null ? null : fmt(o.getStartAt()));
|
|
|
+ m.put("endAt", o.getEndAt() == null ? null : fmt(o.getEndAt()));
|
|
|
+ m.put("status", o.getStatus());
|
|
|
+ m.put("amount", o.getAmount() == null ? 0 : o.getAmount());
|
|
|
+ m.put("platformFee", o.getPlatformFee() == null ? 0 : o.getPlatformFee());
|
|
|
+ m.put("staffIncome", o.getStaffIncome() == null ? 0 : o.getStaffIncome());
|
|
|
+ m.put("clientConfirmCode", o.getClientConfirmCode());
|
|
|
+ m.put("remark", o.getRemark());
|
|
|
+ m.put("createdAt", o.getCreatedAt() == null ? null : fmtFull(o.getCreatedAt()));
|
|
|
+ return m;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String workerName(Long workerId) {
|
|
|
+ if (workerId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ TrainUser u = trainUserMapper.selectById(workerId);
|
|
|
+ return u == null ? null : u.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String genOrderNo() {
|
|
|
+ return "HG" + new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
|
|
|
+ + (int) (Math.random() * 90 + 10);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> serviceTypeBody(Object serviceType) {
|
|
|
+ Map<String, Object> m = new HashMap<>();
|
|
|
+ if (serviceType != null && StringUtils.hasText(serviceType.toString())) {
|
|
|
+ m.put("serviceType", serviceType.toString().trim());
|
|
|
+ }
|
|
|
+ return m;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String gateData(Result<Map<String, Object>> r, String key) {
|
|
|
+ if (r == null || r.getData() == null || r.getData().get(key) == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return r.getData().get(key).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String fmt(Date d) {
|
|
|
+ return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm").format(d);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String fmtFull(Date d) {
|
|
|
+ return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date parseDate(Object v) {
|
|
|
+ if (v == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String s = v.toString().trim();
|
|
|
+ if (s.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String norm = s;
|
|
|
+ if (s.matches("\\d{4}-\\d{2}-\\d{2}")) {
|
|
|
+ norm = s + " 00:00:00";
|
|
|
+ }
|
|
|
+ if (norm.length() == 16) {
|
|
|
+ norm = norm + ":00";
|
|
|
+ }
|
|
|
+ return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(norm);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String str(Object v) {
|
|
|
+ if (v == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String s = v.toString().trim();
|
|
|
+ return s.isEmpty() ? null : s;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 Integer intv(Object v) {
|
|
|
+ Integer i = toInt(v);
|
|
|
+ return i == null ? 0 : i;
|
|
|
+ }
|
|
|
+}
|