diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplate.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplate.java index 2b79c782..96ae4c22 100644 --- a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplate.java +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplate.java @@ -37,6 +37,10 @@ public class AliyunTemplate { * 退款失败 */ public static final String REFUND_FAIL = "SMS_231445428"; + /** + * 工单派发通知 + */ + public static final String WORK_ORDER_CREATED = "SMS_232163808"; /** * 更新计费模型失败 diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplateKeyWord.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplateKeyWord.java index 4f83fb7b..e28e9382 100644 --- a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplateKeyWord.java +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplateKeyWord.java @@ -40,4 +40,8 @@ public class AliyunTemplateKeyWord { */ public static final String CHARGING_MODEL = "计费--尊敬的用户"; + /** + * 工单派送 + */ + public static final String WORK_ORDER_CREATED = "新的工单待处理"; } diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcSmsController.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcSmsController.java index 046876ad..f9963edd 100644 --- a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcSmsController.java +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcSmsController.java @@ -94,6 +94,9 @@ public class XhpcSmsController extends BaseController { }else if (content.contains(AliyunTemplateKeyWord.CHARGING_MODEL)) { signatureName = AliyunTemplate.SIGNATURE_NAME; templateId = AliyunTemplate.CHARGING_MODEL; + } else if(content.contains(AliyunTemplateKeyWord.WORK_ORDER_CREATED)){ + signatureName = AliyunTemplate.SIGNATURE_NAME; + templateId = AliyunTemplate.WORK_ORDER_CREATED; } xhpcSmsService.sendNotice(phone, signatureName, templateId, paramMap); diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/api/SmsService.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/api/SmsService.java new file mode 100644 index 00000000..ce03a677 --- /dev/null +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/api/SmsService.java @@ -0,0 +1,18 @@ +package com.xhpc.workorder.api; + +import com.xhpc.common.api.factory.SmsFallbackFactory; +import com.xhpc.common.core.constant.ServiceNameConstants; +import com.xhpc.common.core.domain.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.Map; + +@FeignClient(contextId = "smsService", value = ServiceNameConstants.XHPC_GENERAL, fallbackFactory = SmsFallbackFactory.class) +public interface SmsService { + + @PostMapping("/sms/send") + R sendNotice(@RequestBody Map paramMap); + +} \ No newline at end of file diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/controller/WorkOrderController.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/controller/WorkOrderController.java index 5c0bb761..698fc73b 100644 --- a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/controller/WorkOrderController.java +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/controller/WorkOrderController.java @@ -2,18 +2,58 @@ package com.xhpc.workorder.controller; import com.xhpc.common.core.web.controller.BaseController; +import com.xhpc.common.core.web.domain.AjaxResult; +import com.xhpc.common.core.web.page.TableDataInfo; +import com.xhpc.workorder.domain.XhpcWorkOrderDomain; import com.xhpc.workorder.service.WorkOrderService; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; @RestController -@RequestMapping("/workorder") +@RequestMapping("/workorder/order") public class WorkOrderController extends BaseController { @Resource WorkOrderService workOrderService; + @GetMapping("/getPage") + public TableDataInfo getOrderPage(Integer orderType, + String userName){ + startPage(); + Map params = new HashMap<>(); + params.put("orderType", orderType); + params.put("userName", userName); + + return getDataTable(workOrderService.getOrderPage(params)); + } + + + @PostMapping("/") + public AjaxResult insertNewOrder(@RequestBody XhpcWorkOrderDomain domain){ + return AjaxResult.success(workOrderService.insertOrder(domain)); + } + + + @GetMapping("/{orderId}") + public AjaxResult getOrderInfo(@PathVariable("orderId")Long orderId){ + return AjaxResult.success(workOrderService.selectOrderById(orderId)); + } + + + @PutMapping("/{orderId}") + public AjaxResult updateOrderInfo(@RequestBody XhpcWorkOrderDomain domain){ + return AjaxResult.success(workOrderService.updateOrder(domain)); + } + + + @DeleteMapping("/{orderId}") + public AjaxResult deleteOrder(@PathVariable("orderId")Long orderId) throws Exception { + return AjaxResult.success(workOrderService.deleteOrder(orderId)); + } + } diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/controller/WorkStationController.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/controller/WorkStationController.java new file mode 100644 index 00000000..b79dd022 --- /dev/null +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/controller/WorkStationController.java @@ -0,0 +1,86 @@ +package com.xhpc.workorder.controller; + + +import com.xhpc.common.core.utils.poi.ExcelUtil; +import com.xhpc.common.core.web.controller.BaseController; +import com.xhpc.common.core.web.domain.AjaxResult; +import com.xhpc.common.core.web.page.TableDataInfo; +import com.xhpc.common.log.annotation.Log; +import com.xhpc.common.log.enums.BusinessType; +import com.xhpc.workorder.domain.XhpcStationDeviceDomain; +import com.xhpc.workorder.service.WorkStationService; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/workorder/station") +public class WorkStationController extends BaseController { + + + @Resource + WorkStationService stationService; + + + @GetMapping("/getPage") + public TableDataInfo getPage(String stationName, + String terminalName){ + startPage(); + Map params = new HashMap<>(); + params.put("stationName", stationName); + params.put("terminalName", terminalName); + + return getDataTable(stationService.getStationDevice(params)); + } + + + @GetMapping("/getTree") + public TableDataInfo getTree(String stationName, + String terminalName){ + startPage(); + Map params = new HashMap<>(); + params.put("stationName", stationName); + params.put("terminalName", terminalName); + + return getDataTable(stationService.getStationDeviceTree(params)); + } + + + @Log(title = "导入设备", businessType = BusinessType.INSERT) + @PostMapping("/importData") + public AjaxResult importDevice(MultipartFile file, boolean updateSupport) throws Exception { + if(file == null){ + return AjaxResult.error("没有可导入的数据文件"); + } + ExcelUtil util = new ExcelUtil(XhpcStationDeviceDomain.class); + List deviceDomainList = util.importExcel(file.getInputStream()); + + String message = stationService.importDevice(deviceDomainList, updateSupport); + return AjaxResult.success(message); + } + + + @PostMapping("/") + public AjaxResult insertNewDevice(@RequestBody XhpcStationDeviceDomain domain) throws Exception{ + return AjaxResult.success(stationService.insertDevice(domain)); + } + + + @PutMapping("/{deviceId}") + public AjaxResult updateDeviceInfo(@RequestBody XhpcStationDeviceDomain domain, + @PathVariable("deviceId")Long deviceId){ + + domain.setDeviceId(deviceId); + return AjaxResult.success(stationService.updateDevice(domain)); + } + + + @DeleteMapping("/{deviceId}") + public AjaxResult deleteDeviceInfo(@PathVariable("deviceId") Long deviceId) throws Exception { + return AjaxResult.success(stationService.deleteDevice(deviceId)); + } +} diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/domain/XhpcStationDeviceDomain.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/domain/XhpcStationDeviceDomain.java index c16430dc..0eb098f7 100644 --- a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/domain/XhpcStationDeviceDomain.java +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/domain/XhpcStationDeviceDomain.java @@ -2,6 +2,8 @@ package com.xhpc.workorder.domain; import java.io.Serializable; import java.util.Date; + +import com.xhpc.common.core.annotation.Excel; import lombok.Data; /** @@ -13,36 +15,64 @@ public class XhpcStationDeviceDomain implements Serializable { /** * 设备ID */ - private Integer deviceId; + private Long deviceId; /** * 设备名称 */ + @Excel(name = "名称") private String deviceName; /** * 设备类型 */ + @Excel(name = "设备类型") private String deviceType; + /** + * 电流类型(直流,交流) + */ + @Excel(name = "电桩类型") + private String currentType; + /** * 所属场站 */ private Long stationId; + /** + * 场站名称 + */ + @Excel(name = "场站名称") + private String stationName; + + /** + * + */ + @Excel(name = "规格型号") + private String brandModel; + /** * 上级设备ID */ private Long parentDeviceId; + /** + * 上级设备编码 + */ + @Excel(name = "父级设备编码") + private String parentSerialNumber; + /** * 设备编码 */ + @Excel(name = "设备编码") private String serialNumber; /** * 设备状态(0-未启用,1-正常,2-异常,3-维修中,4-待检测) */ + @Excel(name = "状态") private Short status; /** diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/domain/XhpcWorkOrderDomain.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/domain/XhpcWorkOrderDomain.java index 3544a826..3263d63e 100644 --- a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/domain/XhpcWorkOrderDomain.java +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/domain/XhpcWorkOrderDomain.java @@ -2,6 +2,8 @@ package com.xhpc.workorder.domain; import java.io.Serializable; import java.util.Date; + +import com.xhpc.common.core.annotation.Excel; import lombok.Data; /** @@ -30,6 +32,11 @@ public class XhpcWorkOrderDomain implements Serializable { */ private String content; + /** + * 故障时间 + */ + private Date faultTime; + /** * 设备类型 */ @@ -95,5 +102,11 @@ public class XhpcWorkOrderDomain implements Serializable { */ private String updateBy; + + + private String userName; + + private String userPhone; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcStationDeviceMapper.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcStationDeviceMapper.java index f0047078..622abc4a 100644 --- a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcStationDeviceMapper.java +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcStationDeviceMapper.java @@ -1,17 +1,33 @@ package com.xhpc.workorder.mapper; import com.xhpc.workorder.domain.XhpcStationDeviceDomain; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + public interface XhpcStationDeviceMapper { - int deleteByPrimaryKey(Integer deviceId); + + List> selectStationGunDeviceListByParams(@Param("params") Map params); + + List> selectStationGunDeviceTreeByParams(@Param("params") Map params); + + + List> selectStationGunDeviceTreeByParent(@Param("parentDeviceId") String parentDeviceId); + + XhpcStationDeviceDomain selectStationGunDeviceBySerialNumber(@Param("serialNumber") String serialNumber); + + int deleteByPrimaryKey(Long deviceId); int insert(XhpcStationDeviceDomain record); int insertSelective(XhpcStationDeviceDomain record); - XhpcStationDeviceDomain selectByPrimaryKey(Integer deviceId); + XhpcStationDeviceDomain selectByPrimaryKey(Long deviceId); int updateByPrimaryKeySelective(XhpcStationDeviceDomain record); int updateByPrimaryKey(XhpcStationDeviceDomain record); + } \ No newline at end of file diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkOrderMapper.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkOrderMapper.java index cfd0ef81..c298dabd 100644 --- a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkOrderMapper.java +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkOrderMapper.java @@ -1,8 +1,21 @@ package com.xhpc.workorder.mapper; import com.xhpc.workorder.domain.XhpcWorkOrderDomain; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; public interface XhpcWorkOrderMapper { + + List> findOrderListByParams(@Param("params") Map params); + + XhpcWorkOrderDomain selectByTypeAndTitleAndDeviceSerialNumber(@Param("type")Integer type, + @Param("title")String title, + @Param("serialNumber")String serialNumber, + @Param("userId")Long userId, + @Param("status") Integer status); + int deleteByPrimaryKey(Long workOrderId); int insert(XhpcWorkOrderDomain record); diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkStationMapper.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkStationMapper.java index 1ff05de6..06aa31d4 100644 --- a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkStationMapper.java +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkStationMapper.java @@ -1,8 +1,12 @@ package com.xhpc.workorder.mapper; import com.xhpc.workorder.domain.XhpcWorkStationDomain; +import org.apache.ibatis.annotations.Param; public interface XhpcWorkStationMapper { + + XhpcWorkStationDomain selectByName(@Param("stationName") String stationName); + int deleteByPrimaryKey(Long workStationId); int insert(XhpcWorkStationDomain record); diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkUserMapper.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkUserMapper.java index b370ae29..b93b136b 100644 --- a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkUserMapper.java +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/mapper/XhpcWorkUserMapper.java @@ -1,8 +1,12 @@ package com.xhpc.workorder.mapper; import com.xhpc.workorder.domain.XhpcWorkUserDomain; +import org.apache.ibatis.annotations.Param; public interface XhpcWorkUserMapper { + + XhpcWorkUserDomain selectByUserNameAndPhone(@Param("userName")String userName, @Param("phone") String phone); + int deleteByPrimaryKey(Long workUserId); int insert(XhpcWorkUserDomain record); diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/WorkOrderService.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/WorkOrderService.java index 1c75a34e..f42946bc 100644 --- a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/WorkOrderService.java +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/WorkOrderService.java @@ -1,6 +1,20 @@ package com.xhpc.workorder.service; +import com.xhpc.workorder.domain.XhpcWorkOrderDomain; + +import java.util.List; +import java.util.Map; + public interface WorkOrderService { + List> getOrderPage(Map params); + + XhpcWorkOrderDomain selectOrderById(Long orderId); + + Boolean updateOrder(XhpcWorkOrderDomain domain); + + Boolean insertOrder(XhpcWorkOrderDomain domain); + + Boolean deleteOrder(Long orderId) throws Exception; } diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/WorkStationService.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/WorkStationService.java new file mode 100644 index 00000000..66a4ec51 --- /dev/null +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/WorkStationService.java @@ -0,0 +1,23 @@ +package com.xhpc.workorder.service; + +import com.xhpc.workorder.domain.XhpcStationDeviceDomain; + +import java.util.List; +import java.util.Map; + +public interface WorkStationService { + + + List> getStationDevice(Map params); + + + List> getStationDeviceTree(Map params); + + String importDevice(List deviceDomainList, Boolean updateSupport); + + Boolean insertDevice(XhpcStationDeviceDomain domain) throws Exception; + + Boolean updateDevice(XhpcStationDeviceDomain domain); + + Boolean deleteDevice(Long deviceId) throws Exception; +} diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/impl/WorkOrderServiceImpl.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/impl/WorkOrderServiceImpl.java index c425acc4..e3db9b47 100644 --- a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/impl/WorkOrderServiceImpl.java +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/impl/WorkOrderServiceImpl.java @@ -1,13 +1,96 @@ package com.xhpc.workorder.service.impl; +import cn.hutool.core.util.StrUtil; +import com.xhpc.common.api.SmsService; +import com.xhpc.workorder.domain.XhpcWorkOrderDomain; +import com.xhpc.workorder.domain.XhpcWorkOrderPushMessageDomain; +import com.xhpc.workorder.domain.XhpcWorkUserDomain; +import com.xhpc.workorder.mapper.XhpcWorkOrderMapper; +import com.xhpc.workorder.mapper.XhpcWorkOrderPushMessageMapper; +import com.xhpc.workorder.mapper.XhpcWorkUserMapper; import com.xhpc.workorder.service.WorkOrderService; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + -@Slf4j @Service public class WorkOrderServiceImpl implements WorkOrderService { + @Resource + XhpcWorkOrderMapper orderMapper; + + @Resource + XhpcWorkUserMapper userMapper; + + @Resource + XhpcWorkOrderPushMessageMapper messageMapper; + + @Resource + SmsService smsService; + + @Override + public List> getOrderPage(Map params){ + return orderMapper.findOrderListByParams(params); + } + + @Override + public XhpcWorkOrderDomain selectOrderById(Long orderId){ + return orderMapper.selectByPrimaryKey(orderId); + } + + @Override + public Boolean updateOrder(XhpcWorkOrderDomain domain){ + return orderMapper.updateByPrimaryKeySelective(domain) > 0; + } + + @Override + public Boolean insertOrder(XhpcWorkOrderDomain domain){ + + if(!StrUtil.hasBlank(domain.getUserName()) && !StrUtil.hasBlank(domain.getUserPhone())){ + XhpcWorkUserDomain userDomain = userMapper.selectByUserNameAndPhone(domain.getUserName(), domain.getUserPhone()); + if(userDomain == null){ + domain.setUserId(userDomain.getWorkUserId()); + domain.setDeptId(userDomain.getDeptId()); + } else { + // todo + } + } + orderMapper.insertSelective(domain); + + XhpcWorkOrderDomain resDomain = orderMapper.selectByTypeAndTitleAndDeviceSerialNumber(domain.getType().intValue(), + domain.getTitle(), + domain.getSerialNumber(), + domain.getUserId(), + domain.getStatus().intValue()); + + HashMap paramMap = new HashMap<>(); + paramMap.put("orderNo", resDomain.getWorkOrderId().toString()); + paramMap.put("phone", domain.getUserPhone()); + paramMap.put("content", "【小华充电】您好,您有新的工单(工单号:"+ resDomain.getWorkOrderId() +")待处理,请及时登陆后台查看并处理,谢谢。"); + smsService.sendNotice(paramMap); + + XhpcWorkOrderPushMessageDomain messageDomain = new XhpcWorkOrderPushMessageDomain(); + messageDomain.setContent(paramMap.get("content")); + messageDomain.setTarget(domain.getUserName()); + messageDomain.setType(Short.valueOf("1")); + messageDomain.setStatus(Short.valueOf("1")); + messageDomain.setFailMsg("发送成功"); + messageMapper.insertSelective(messageDomain); + return true; + } + + @Override + public Boolean deleteOrder(Long orderId) throws Exception { + XhpcWorkOrderDomain domain = orderMapper.selectByPrimaryKey(orderId); + if(domain == null){ + throw new Exception("工单不存在"); + } + orderMapper.deleteByPrimaryKey(orderId); + return true; + } } diff --git a/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/impl/WorkStationServiceImpl.java b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/impl/WorkStationServiceImpl.java new file mode 100644 index 00000000..a38a2dd9 --- /dev/null +++ b/xhpc-modules/xhpc-workorder/src/main/java/com/xhpc/workorder/service/impl/WorkStationServiceImpl.java @@ -0,0 +1,124 @@ +package com.xhpc.workorder.service.impl; + +import cn.hutool.core.util.StrUtil; +import com.xhpc.common.core.exception.CustomException; +import com.xhpc.workorder.domain.XhpcStationDeviceDomain; +import com.xhpc.workorder.domain.XhpcWorkStationDomain; +import com.xhpc.workorder.mapper.XhpcStationDeviceMapper; +import com.xhpc.workorder.mapper.XhpcWorkStationMapper; +import com.xhpc.workorder.service.WorkStationService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + + +@Service +public class WorkStationServiceImpl implements WorkStationService { + + @Resource + XhpcStationDeviceMapper deviceMapper; + + @Resource + XhpcWorkStationMapper stationMapper; + + @Override + public List> getStationDevice(Map params){ + return deviceMapper.selectStationGunDeviceListByParams(params); + } + + @Override + public List> getStationDeviceTree(Map params){ + + List> resultData = deviceMapper.selectStationGunDeviceTreeByParams(params); + for (Map resultMap: resultData){ + List> childData = deviceMapper.selectStationGunDeviceTreeByParent(resultMap.get("deviceId").toString()); + if(childData != null){ + resultMap.put("children", childData); + } + } + + return resultData; + } + + + @Override + public String importDevice(List deviceDomainList, Boolean updateSupport){ + + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + + for (XhpcStationDeviceDomain domain: deviceDomainList){ + if ("".equals(domain.getStationName())){ + failureNum ++; + failureMsg.append("
电站名称: ").append(domain.getStationName()).append(" ,设备编码: ").append(domain.getSerialNumber()).append(" 导入失败; 失败原因: 必填字段为空。"); + continue; + } + XhpcWorkStationDomain stationDomain = stationMapper.selectByName(domain.getStationName()); + if (stationDomain == null){ + failureNum ++; + failureMsg.append("
电站名称: ").append(domain.getStationName()).append(" ,设备编码: ").append(domain.getSerialNumber()).append(" 导入失败; 失败原因: 必填字段为空。"); + continue; + } else { + domain.setDeviceId(stationDomain.getWorkStationId()); + } + if(!StrUtil.hasBlank(domain.getParentSerialNumber())){ + XhpcStationDeviceDomain parentDomain = deviceMapper.selectStationGunDeviceBySerialNumber(domain.getParentSerialNumber()); + if(parentDomain != null){ + domain.setParentDeviceId(parentDomain.getDeviceId()); + } + } + + deviceMapper.insertSelective(domain); + } + + if (failureNum > 0) { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new CustomException(failureMsg.toString()); + } else { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } + + @Override + public Boolean insertDevice(XhpcStationDeviceDomain domain) throws Exception{ + + if ("".equals(domain.getStationName())){ + throw new Exception("所属场站不能为空"); + } + XhpcWorkStationDomain stationDomain = stationMapper.selectByName(domain.getStationName()); + if (stationDomain == null){ + throw new Exception("所属场站不存在"); + } else { + domain.setDeviceId(stationDomain.getWorkStationId()); + } + if(!StrUtil.hasBlank(domain.getParentSerialNumber())){ + XhpcStationDeviceDomain parentDomain = deviceMapper.selectStationGunDeviceBySerialNumber(domain.getParentSerialNumber()); + if(parentDomain != null){ + domain.setParentDeviceId(parentDomain.getDeviceId()); + } + } + deviceMapper.insertSelective(domain); + return true; + } + + @Override + public Boolean updateDevice(XhpcStationDeviceDomain domain){ + deviceMapper.updateByPrimaryKeySelective(domain); + return true; + } + + @Override + public Boolean deleteDevice(Long deviceId) throws Exception { + XhpcStationDeviceDomain deviceDomain = deviceMapper.selectByPrimaryKey(deviceId); + if(deviceDomain != null){ + throw new Exception("设备不存在"); + } + deviceMapper.deleteByPrimaryKey(deviceId); + return true; + } +} diff --git a/xhpc-modules/xhpc-workorder/src/main/resources/mapper/XhpcStationDeviceMapper.xml b/xhpc-modules/xhpc-workorder/src/main/resources/mapper/XhpcStationDeviceMapper.xml index dbf5fbc0..e5acbaa6 100644 --- a/xhpc-modules/xhpc-workorder/src/main/resources/mapper/XhpcStationDeviceMapper.xml +++ b/xhpc-modules/xhpc-workorder/src/main/resources/mapper/XhpcStationDeviceMapper.xml @@ -2,11 +2,13 @@ - + + + @@ -16,9 +18,84 @@ - device_id, device_name, device_type, station_id, parent_device_id, serial_number, + device_id, device_name, device_type, current_type, station_id, brand_model, parent_device_id, serial_number, `status`, del_flag, create_time, create_by, update_time, update_by + + + + + + + + + + + + + select + + from xhpc_work_order + where del_flag=0 + and type =#{type} + and title=#{title} + and serial_number=#{serialNumber} + and user_id=#{userId} + and status=#{status} + + + + + + select + + from xhpc_work_station + where name like concat('%', #{stationName}, '%') + + + select + + from xhpc_work_user + where user_name = #{userName} and phone=#{phone} + +