|
@@ -0,0 +1,223 @@
|
|
|
+package com.caimei.www.service.link.impl;
|
|
|
+
|
|
|
+import com.caimei.www.mapper.RepairDao;
|
|
|
+import com.caimei.www.pojo.JsonModel;
|
|
|
+import com.caimei.www.pojo.link.PageVo;
|
|
|
+import com.caimei.www.pojo.link.RepairLinkVo;
|
|
|
+import com.caimei.www.pojo.link.RepairUserVo;
|
|
|
+import com.caimei.www.pojo.link.RepairVo;
|
|
|
+import com.caimei.www.service.link.RepairService;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.util.StringUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : Charles
|
|
|
+ * @date : 2021/10/20
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class RepairServiceImpl implements RepairService {
|
|
|
+ @Resource
|
|
|
+ private RepairDao repairDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 维修列表
|
|
|
+ *
|
|
|
+ * @param repairVo 维修列表查询条件
|
|
|
+ * @param page 分页对象
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JsonModel findMaintenance(RepairVo repairVo, PageVo page) {
|
|
|
+ if (repairVo.getUserId() == null) {
|
|
|
+ return JsonModel.error("参数错误");
|
|
|
+ }
|
|
|
+ PageHelper.startPage(page.getPageNum(), page.getPageSize());
|
|
|
+ List<RepairVo> list = repairDao.findMaintenance(repairVo);
|
|
|
+ PageVo<RepairVo> pageVo = new PageVo<>(list);
|
|
|
+ return JsonModel.success(pageVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 申请维修
|
|
|
+ *
|
|
|
+ * @param repairVo 申请维修提交的数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JsonModel applyMaintenance(RepairVo repairVo) {
|
|
|
+ JsonModel JsonModel = paramsCheck(repairVo);
|
|
|
+ if (JsonModel.getCode() == -1) {
|
|
|
+ return JsonModel;
|
|
|
+ }
|
|
|
+ if (repairVo.getUserId() != null) {
|
|
|
+ RepairUserVo user = repairDao.getRepairUser(repairVo.getUserId());
|
|
|
+ repairVo.setUserId(user.getUserId());
|
|
|
+ repairVo.setUserName(user.getUserName());
|
|
|
+ if (user.getRegisterUserTypeId() == 1 || user.getRegisterUserTypeId() == 3) {
|
|
|
+ repairVo.setUserAccount(user.getAccount());
|
|
|
+ } else {
|
|
|
+ repairVo.setUserAccount(user.getMobile());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
|
|
+ //维修单号orderNo的生成规则 日期加上两位数字 2019080801
|
|
|
+ String orderNo = repairDao.findOrderNoInToday(date);
|
|
|
+ String no;
|
|
|
+ if (StringUtil.isEmpty(orderNo)) {
|
|
|
+ no = "01";
|
|
|
+ } else {
|
|
|
+ String substring = orderNo.substring(8);
|
|
|
+ int number = Integer.parseInt(substring);
|
|
|
+ number += 1;
|
|
|
+ if (number <= 9) {
|
|
|
+ no = "0" + number;
|
|
|
+ } else {
|
|
|
+ no = String.valueOf(number);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ repairVo.setOrderNo(date + no);
|
|
|
+ repairVo.setSubmitDate(new Date());
|
|
|
+ //维修状态1.已提交,2已对接(确认真实后)3已评价,4取消
|
|
|
+ repairVo.setStatus("1");
|
|
|
+ String instrumentImages = repairVo.getInstrumentImages();
|
|
|
+ if (StringUtil.isNotEmpty(instrumentImages)) {
|
|
|
+ String[] instrumentImageArr = instrumentImages.split(",");
|
|
|
+ if (instrumentImageArr.length > 5) {
|
|
|
+ return JsonModel.error("图片数量不能超过5张");
|
|
|
+ }
|
|
|
+ Class clazz = repairVo.getClass();
|
|
|
+ for (int i = 0; i < instrumentImageArr.length; i++) {
|
|
|
+ Method method = clazz.getDeclaredMethod("setInstrumentImage" + (i + 1),String.class);
|
|
|
+ method.invoke(repairVo, instrumentImageArr[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ repairDao.insertMaintenance(repairVo);
|
|
|
+ RepairLinkVo userLink = new RepairLinkVo();
|
|
|
+ userLink.setType("1");
|
|
|
+ userLink.setUserId(repairVo.getUserId());
|
|
|
+ userLink.setCmInstrumentMaintenanceId(repairVo.getId());
|
|
|
+ userLink.setLinkCode(UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
+ RepairLinkVo repairerLink = new RepairLinkVo();
|
|
|
+ repairerLink.setType("2");
|
|
|
+ repairerLink.setUserId(repairVo.getUserId());
|
|
|
+ repairerLink.setCmInstrumentMaintenanceId(repairVo.getId());
|
|
|
+ repairerLink.setLinkCode(UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
+ repairDao.insertMaintenanceLink(userLink);
|
|
|
+ repairDao.insertMaintenanceLink(repairerLink);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("try-catch:",e);
|
|
|
+ return JsonModel.error("数据异常");
|
|
|
+ }
|
|
|
+ return JsonModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 维修详情
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JsonModel findMaintenanceDetail(Integer id) {
|
|
|
+ if (id == null) {
|
|
|
+ return JsonModel.error("参数异常");
|
|
|
+ }
|
|
|
+ RepairVo repairVo = repairDao.findMaintenanceDetail(id);
|
|
|
+ if (repairVo == null) {
|
|
|
+ return JsonModel.error("参数异常");
|
|
|
+ }
|
|
|
+ Class clazz = repairVo.getClass();
|
|
|
+ List<String> instrumentImageList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
+ try {
|
|
|
+ Method getMethod = clazz.getDeclaredMethod("getInstrumentImage" + (i+1));
|
|
|
+ Object image = getMethod.invoke(repairVo);
|
|
|
+ if (image != null && StringUtil.isNotEmpty(image.toString())) {
|
|
|
+ instrumentImageList.add(image.toString()) ;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("try-catch:",e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String[] instrumentArr = instrumentImageList.toArray(new String[instrumentImageList.size()]);
|
|
|
+ if (instrumentArr.length == 0) {
|
|
|
+ repairVo.setInstrumentArr(null);
|
|
|
+ }else{
|
|
|
+ repairVo.setInstrumentArr(instrumentArr);
|
|
|
+ }
|
|
|
+ return JsonModel.success(repairVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 评价维修
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param solveStatus 是否解决问题:0未解决,1已解决
|
|
|
+ * @param serviceRating 服务评分,一颗心表示1,多颗数次之
|
|
|
+ * @param serviceEvaluate 服务评价
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JsonModel evaluationMaintenance(Integer id, String solveStatus, String serviceRating, String serviceEvaluate) {
|
|
|
+ if (id == null || StringUtil.isEmpty(solveStatus) || StringUtil.isEmpty(serviceEvaluate) || StringUtil.isEmpty(serviceRating)) {
|
|
|
+ return JsonModel.error("参数不全");
|
|
|
+ }
|
|
|
+ RepairVo repairVo = repairDao.findMaintenanceDetail(id);
|
|
|
+ if (repairVo == null){
|
|
|
+ return JsonModel.error("参数异常");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ repairVo.setServiceEvaluate(serviceEvaluate);
|
|
|
+ repairVo.setServiceRating(Long.valueOf(serviceRating));
|
|
|
+ repairVo.setSolveStatus(solveStatus);
|
|
|
+ repairVo.setStatus("3");
|
|
|
+ repairVo.setEvaluateDate(new Date());
|
|
|
+ repairDao.updateMaintenace(repairVo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ JsonModel.error("服务器内部异常");
|
|
|
+ }
|
|
|
+ return JsonModel.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证提交的维修信息
|
|
|
+ */
|
|
|
+ private JsonModel paramsCheck(RepairVo bean) {
|
|
|
+ if (StringUtil.isEmpty(bean.getProvinceName()) || StringUtil.isEmpty(bean.getCityName())
|
|
|
+ || StringUtil.isEmpty(bean.getTownName()) || StringUtil.isEmpty(bean.getUserAddress())) {
|
|
|
+ return JsonModel.error("地址信息不全");
|
|
|
+ }
|
|
|
+ if (StringUtil.isEmpty(bean.getUserContact())) {
|
|
|
+ return JsonModel.error("联系人信息不全");
|
|
|
+ }
|
|
|
+ if (bean.getUserMobile() == null) {
|
|
|
+ return JsonModel.error("联系电话信息不全");
|
|
|
+ }
|
|
|
+ if (StringUtil.isEmpty(bean.getInstrumentName())) {
|
|
|
+ return JsonModel.error("仪器名称信息不全");
|
|
|
+ }
|
|
|
+ if (StringUtil.isEmpty(bean.getProblemDescription())) {
|
|
|
+ return JsonModel.error("问题描述信息不全");
|
|
|
+ }
|
|
|
+ //同一手机号同一天内只能提交一次申请
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ //CmInstrumentMaintenance 的orderNo 生成规则就是 2019080802 日期加数字的规则,通过模糊查询查询出用户今日提交次数
|
|
|
+ int times = repairDao.checkMobileSubmitTime(bean.getUserMobile().toString(), sdf.format(new Date()));
|
|
|
+ if (times != 0) {
|
|
|
+ return JsonModel.error("抱歉,您今天已经提交过了");
|
|
|
+ }
|
|
|
+ return JsonModel.success();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|