diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingPileController.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingPileController.java index f8879ae8..6e908c0c 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingPileController.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingPileController.java @@ -7,10 +7,13 @@ 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.domain.XhpcChargingPile; +import com.xhpc.common.log.annotation.Log; +import com.xhpc.common.log.enums.BusinessType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; @@ -34,10 +37,10 @@ public class XhpcChargingPileController extends BaseController { * @return */ @GetMapping("/list") - public TableDataInfo list(String name, Integer type, String serialNumber, Long chargingStationId) { + public TableDataInfo list(HttpServletRequest request,String name, Integer type, String serialNumber, Long chargingStationId) { startPage(); - List> list = xhpcChargingPileService.selectXhpcChargingPileList(name, type, serialNumber, chargingStationId); + List> list = xhpcChargingPileService.selectXhpcChargingPileList(request,name, type, serialNumber, chargingStationId); return getDataTable(list); } @@ -46,6 +49,7 @@ public class XhpcChargingPileController extends BaseController { * * @return */ + @Log(title = "场站-添加桩", businessType = BusinessType.INSERT) @PostMapping(value = "/addXhpcChargingPile") public AjaxResult addXhpcChargingPile(@RequestBody XhpcChargingPile xhpcChargingPile) { @@ -57,6 +61,7 @@ public class XhpcChargingPileController extends BaseController { * * @return */ + @Log(title = "场站-修改桩", businessType = BusinessType.UPDATE) @PostMapping(value = "/updateXhpcChargingPile") public AjaxResult updateXhpcChargingPile(@RequestBody XhpcChargingPile xhpcChargingPile) { @@ -80,6 +85,7 @@ public class XhpcChargingPileController extends BaseController { * * @return */ + @Log(title = "桩-停用", businessType = BusinessType.UPDATE) @PostMapping(value = "/updateStatus") public AjaxResult updateStatus(@RequestBody XhpcChargingPile xhpcChargingPile) { @@ -87,8 +93,9 @@ public class XhpcChargingPileController extends BaseController { } /** - * 删除电站 + * 桩-删除 */ + @Log(title = "桩-删除", businessType = BusinessType.DELETE) @DeleteMapping("/{chargingPileId}") public AjaxResult remove(@PathVariable Long chargingPileId) { @@ -98,6 +105,7 @@ public class XhpcChargingPileController extends BaseController { /** * 下载对应终端的图片 */ + @Log(title = "桩-下载对应终端的图片", businessType = BusinessType.EXPORT) @PostMapping(value = "/downloadsTerminalImgs") public AjaxResult downloadsTerminalImgs(@RequestBody List terminalIds){ List> xhpcImgs = xhpcChargingPileService.downloadsTerminalImgs(terminalIds); @@ -112,6 +120,7 @@ public class XhpcChargingPileController extends BaseController { * @return * @throws Exception */ + @Log(title = "桩-导入电桩", businessType = BusinessType.IMPORT) @PostMapping("/importData") public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { ExcelUtil util = new ExcelUtil(XhpcChargingPile.class); diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java index 6079c246..1a8739e5 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java @@ -21,7 +21,7 @@ public interface XhpcChargingPileMapper { * @param name 桩名称 * @return */ - List> selectXhpcChargingPileList(@Param("name") String name, @Param("type") Integer type, @Param("serialNumber") String serialNumber, @Param("chargingStationId") Long chargingStationId,@Param("operatorId")Long operatorId,@Param("number")Integer number); + List> selectXhpcChargingPileList(@Param("name") String name, @Param("type") Integer type, @Param("serialNumber") String serialNumber, @Param("chargingStationId") Long chargingStationId,@Param("operatorId")Long operatorId,@Param("number")Integer number,@Param("tenantId") String tenantId); /** * 终端 @@ -29,7 +29,7 @@ public interface XhpcChargingPileMapper { * @param xhpcChargingPile 终端 * @return 结果 */ - int addXhpcChargingPile(XhpcChargingPile xhpcChargingPile); + int insertXhpcChargingPile(XhpcChargingPile xhpcChargingPile); /** diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java index ab02d535..c3674273 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java @@ -59,7 +59,7 @@ public interface XhpcTerminalMapper { * @param xhpcTerminal 终端 * @return 结果 */ - int addXhpcTerminal(XhpcTerminal xhpcTerminal); + int insertXhpcTerminal(XhpcTerminal xhpcTerminal); /** * 终端详情 diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingPileService.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingPileService.java index 44386e4e..0515f0e5 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingPileService.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingPileService.java @@ -3,6 +3,7 @@ package com.xhpc.charging.station.service; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.domain.XhpcChargingPile; +import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; @@ -20,7 +21,7 @@ public interface IXhpcChargingPileService { * @param name 桩名称 * @return */ - List> selectXhpcChargingPileList(String name, Integer type, String serialNumber, Long chargingStationId); + List> selectXhpcChargingPileList(HttpServletRequest request, String name, Integer type, String serialNumber, Long chargingStationId); /** diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java index 0d10e68f..4b3f54e5 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java @@ -10,6 +10,7 @@ import com.xhpc.charging.station.mapper.XhpcTerminalMapper; import com.xhpc.charging.station.utils.img.QrImgUtils; import com.xhpc.common.api.PowerPileService; import com.xhpc.common.core.constant.HttpStatus; +import com.xhpc.common.core.domain.R; import com.xhpc.common.core.exception.CustomException; import com.xhpc.common.core.utils.SecurityUtils; import com.xhpc.common.core.utils.StringUtils; @@ -20,11 +21,15 @@ import com.xhpc.common.domain.XhpcTerminal; import com.xhpc.common.enums.ConnectorTypeEnum; import com.xhpc.common.enums.EquipmentTypeEnum; import com.xhpc.common.enums.PowerTypeEnum; +import com.xhpc.common.util.LogUserUtils; +import com.xhpc.system.api.model.LoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; +import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.*; @@ -51,7 +56,8 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService { private XhpcImgMapper xhpcImgMapper; @Autowired private IXhpcChargingStationService xhpcChargingStationService; - + @Autowired + private LogUserUtils logUserUtils; //字母集合 private static Map letterMap; static{ @@ -74,27 +80,28 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService { * @return */ @Override - public List> selectXhpcChargingPileList(String name, Integer type, String serialNumber, Long chargingStationId) { + public List> selectXhpcChargingPileList(HttpServletRequest request, String name, Integer type, String serialNumber, Long chargingStationId) { //获取登陆用户 - Long userId = SecurityUtils.getUserId(); //桩的统计、该时段金额 List> list =new ArrayList<>(); + LoginUser logUser = logUserUtils.getLogUser(request); + String tenantId = logUser.getTenantId(); if(userId !=1) { Map landUser = xhpcChargingStationService.getLandUser(userId); if(landUser !=null){ if(landUser.get("userType") !=null){ if("01".equals(landUser.get("userType").toString()) || "03".equals(landUser.get("userType").toString())){ Long operatorId = Long.valueOf(landUser.get("operatorId").toString()); - list= xhpcChargingPileMapper.selectXhpcChargingPileList(name, type, serialNumber, chargingStationId,operatorId,1); + list= xhpcChargingPileMapper.selectXhpcChargingPileList(name, type, serialNumber, chargingStationId,operatorId,1,tenantId); }else{ - list= xhpcChargingPileMapper.selectXhpcChargingPileList(name, type, serialNumber, chargingStationId,userId,2); + list= xhpcChargingPileMapper.selectXhpcChargingPileList(name, type, serialNumber, chargingStationId,userId,2,tenantId); } } } }else{ - list= xhpcChargingPileMapper.selectXhpcChargingPileList(name, type, serialNumber, chargingStationId,userId,0); + list= xhpcChargingPileMapper.selectXhpcChargingPileList(name, type, serialNumber, chargingStationId,userId,0,tenantId); } @@ -124,7 +131,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService { return AjaxResult.error("桩编号重复"); } //桩 - xhpcChargingPileMapper.addXhpcChargingPile(xhpcChargingPile); + xhpcChargingPileMapper.insertXhpcChargingPile(xhpcChargingPile); //终端 Long chargingPileId = xhpcChargingPile.getChargingPileId(); @@ -138,7 +145,12 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService { //插入redis 桩的编号 HashSet noSet = new HashSet<>(); noSet.add(serialNumber); - powerPileService.addPileWhitelist(chargingStationId,xhpcChargingPile.getCommunicationProtocolVersion(), noSet); + R r = powerPileService.addPileWhitelist(chargingStationId, xhpcChargingPile.getCommunicationProtocolVersion(), noSet); + if (r.getCode() != 200) { + //数据回滚-手动回滚 + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return AjaxResult.error("添加桩入缓存失败,请稍后在试"); + } return AjaxResult.success(); } @@ -159,7 +171,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService { xhpcTerminal.setRateModelId(rateModelId); xhpcTerminal.setNumber(number); xhpcTerminal.setConnectorType(conType); - xhpcTerminalMapper.addXhpcTerminal(xhpcTerminal); + xhpcTerminalMapper.insertXhpcTerminal(xhpcTerminal); //获取场站名称: String chargingStationName = xhpcChargingStationService.selectXhpcChargingStationById(xhpcTerminal.getChargingStationId()).getName(); @@ -201,7 +213,12 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService { //插入redis 桩的编号 HashSet noSet = new HashSet<>(); noSet.add(serialNumber); - powerPileService.addPileWhitelist(chargingStationId,xhpcChargingPile.getCommunicationProtocolVersion(), noSet); + R r = powerPileService.addPileWhitelist(chargingStationId, xhpcChargingPile.getCommunicationProtocolVersion(), noSet); + if (r.getCode() != 200) { + //数据回滚-手动回滚 + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return AjaxResult.error("添加桩入缓存失败,请稍后在试"); + } } xhpcChargingPileMapper.updaeXhpcChargingPile(xhpcChargingPile); return AjaxResult.success(); diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml index c3ad97eb..ea372367 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml @@ -104,10 +104,13 @@ and cp.charging_station_id in(select charging_station_id from xhpc_user_privilege where user_id=#{operatorId}) + + and cp.tenant_id=#{tenantId} + order by cp.create_time desc - insert into xhpc_charging_pile diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml index e05c63d1..09673fa4 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml @@ -138,7 +138,7 @@ where terminal_id = #{terminalId} - insert into xhpc_terminal