Browse Source

完成外部客户维护

dev_shibei_match
wxz 5 years ago
parent
commit
00d0973829
  1. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
  2. 22
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java
  3. 23
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalCustomerFormDTO.java
  4. 19
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java
  5. 2
      epmet-module/epmet-common-service/common-service-server/pom.xml
  6. 26
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java
  7. 45
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalCustomerController.java
  8. 4
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java
  9. 15
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalCustomerDao.java
  10. 1
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppAuthService.java
  11. 3
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java
  12. 9
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalCustomerService.java
  13. 8
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppAuthServiceImpl.java
  14. 37
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java
  15. 36
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalCustomerServiceImpl.java
  16. 11
      epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml
  17. 16
      epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalCustomerDao.xml

2
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java

@ -100,6 +100,8 @@ public enum EpmetErrorCode {
OPER_UPLOAD_FILE_OVER_SIZE(8707, "文件体积过大"),
OPER_UPLOAD_FILE_TYPE_ERROR(8708, "文件类型错误"),
OPER_EXTERNAL_APP_AUTH_ERROR(8709, "外部应用认证失败"),
OPER_EXTERNAL_CUSTOMER_NOT_EXISTS(8710, "该客户不存在"),
OPER_EXTERNAL_APP_EXISTS(8711, "应用已存在"),
// 党建声音 前端提示 88段
DRAFT_CONTENT_IS_NULL(8801, "至少需要添加一个段落"),

22
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java

@ -0,0 +1,22 @@
package com.epmet.dto.form;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
public class ExternalAppFormDTO {
public interface AddExternalApp {}
public interface UpdateExternalApp {}
@NotBlank(message = "缺少应用ID", groups = { UpdateExternalApp.class })
private String appId;
@NotBlank(message = "缺少应用名称", groups = { AddExternalApp.class, UpdateExternalApp.class })
private String appName;
@NotBlank(message = "缺少所属客户ID", groups = { AddExternalApp.class, UpdateExternalApp.class })
private String customerId;
}

23
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalCustomerFormDTO.java

@ -3,13 +3,28 @@ package com.epmet.dto.form;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
@Data
public class ExternalCustomerFormDTO {
@Min(0)
private Integer pageNo;
public interface ListExternalCustomerGroup {}
public interface AddExternalCustomerGroup {}
public interface UpdateExternalCustomerGroup {}
@Min(0)
private Integer pageSize;
@NotBlank(message = "缺少客户ID参数", groups = { UpdateExternalCustomerGroup.class })
private String customerId;
/**
* 客户名称
*/
@NotBlank(message = "请填写客户名称", groups = { AddExternalCustomerGroup.class, UpdateExternalCustomerGroup.class })
private String customerName;
@Min(value = 0, groups = { ListExternalCustomerGroup.class })
private Integer pageNo = 1;
@Min(value = 0, groups = { ListExternalCustomerGroup.class })
private Integer pageSize = 10;
}

19
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java

@ -0,0 +1,19 @@
package com.epmet.dto.result;
import lombok.Data;
@Data
public class ExternalAppResultDTO {
public String id;
/**
* APP名字
*/
private String appName;
/**
* 客户ID
*/
private String customerId;
}

2
epmet-module/epmet-common-service/common-service-server/pom.xml

@ -113,7 +113,7 @@
<spring.redis.port>6379</spring.redis.port>
<spring.redis.password>123456</spring.redis.password>
<!-- nacos -->
<nacos.register-enabled>true</nacos.register-enabled>
<nacos.register-enabled>false</nacos.register-enabled>
<nacos.server-addr>122.152.200.70:8848</nacos.server-addr>
<nacos.discovery.namespace>fcd6fc8f-ca3a-4b01-8026-2b05cdc5976b</nacos.discovery.namespace>
<nacos.config.namespace></nacos.config.namespace>

26
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java

@ -2,9 +2,13 @@ package com.epmet.controller;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.ExternalAppAuthFormDTO;
import com.epmet.dto.form.ExternalAppFormDTO;
import com.epmet.dto.result.ExternalAppAuthResultDTO;
import com.epmet.dto.result.ExternalAppResultDTO;
import com.epmet.service.ExternalAppAuthService;
import com.epmet.service.ExternalAppService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -14,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotBlank;
@RestController
@RequestMapping("/externalapp")
public class ExternalAppController {
@ -23,6 +29,9 @@ public class ExternalAppController {
@Autowired
private ExternalAppAuthService externalAppAuthService;
@Autowired
private ExternalAppService externalAppService;
/**
* 外部请求认证
* @param formDTO
@ -41,4 +50,21 @@ public class ExternalAppController {
return new Result<ExternalAppAuthResultDTO>().ok(auth);
}
/**
* 添加应用
* @param formDTO
* @return
*/
@PostMapping("/add")
public Result<ExternalAppResultDTO> add(@RequestBody ExternalAppFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO, ExternalAppFormDTO.AddExternalApp.class);
String appName = formDTO.getAppName();
String customerId = formDTO.getCustomerId();
ExternalAppResultDTO dto = externalAppService.add(appName, customerId);
return new Result<ExternalAppResultDTO>().ok(dto);
}
}

45
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalCustomerController.java

@ -1,13 +1,12 @@
package com.epmet.controller;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.ExternalAppAuthFormDTO;
import com.epmet.dto.form.ExternalCustomerFormDTO;
import com.epmet.dto.result.ExternalAppAuthResultDTO;
import com.epmet.service.ExternalAppAuthService;
import org.apache.commons.lang3.StringUtils;
import com.epmet.dto.result.ExternalCustomerResultDTO;
import com.epmet.entity.ExternalCustomerEntity;
import com.epmet.service.ExternalCustomerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -16,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
/**
* 外部客户管理
@ -28,20 +27,46 @@ public class ExternalCustomerController {
private static Logger logger = LoggerFactory.getLogger(ExternalCustomerController.class);
@Autowired
private ExternalAppAuthService externalAppAuthService;
private ExternalCustomerService externalCustomerService;
/**
* 外部客户管理
* @return
*/
@PostMapping("/list")
public Result<ExternalAppAuthResultDTO> list(@RequestBody ExternalCustomerFormDTO form) {
ValidatorUtils.validateEntity(form);
public Result<PageData<ExternalCustomerResultDTO>> list(@RequestBody ExternalCustomerFormDTO form) {
ValidatorUtils.validateEntity(form, ExternalCustomerFormDTO.ListExternalCustomerGroup.class);
Integer pageNo = form.getPageNo();
Integer pageSize = form.getPageSize();
PageData<ExternalCustomerResultDTO> page = externalCustomerService.listPage(pageNo, pageSize);
return new Result<PageData<ExternalCustomerResultDTO>>().ok(page);
}
/**
* 添加外部客户
* @param formDTO
* @return
*/
@PostMapping("add")
public Result<ExternalCustomerEntity> add(@RequestBody ExternalCustomerFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO, ExternalCustomerFormDTO.AddExternalCustomerGroup.class);
String customerName = formDTO.getCustomerName();
ExternalCustomerEntity result = externalCustomerService.add(customerName);
return new Result<ExternalCustomerEntity>().ok(result);
}
return null;
/**
* 更新客户信息
* @param formDTO
* @return
*/
@PostMapping("update")
public Result<ExternalCustomerEntity> update(@RequestBody ExternalCustomerFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO, ExternalCustomerFormDTO.UpdateExternalCustomerGroup.class);
String customerId = formDTO.getCustomerId();
String customerName = formDTO.getCustomerName();
ExternalCustomerEntity result = externalCustomerService.update(customerId, customerName);
return new Result<ExternalCustomerEntity>().ok(result);
}
}

4
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java

@ -20,6 +20,7 @@ package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.entity.ExternalAppEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 外部应用列表
@ -29,5 +30,6 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ExternalAppDao extends BaseDao<ExternalAppEntity> {
Integer countByAppNameAndCustomerId(@Param("appName") String appName, @Param("customerId") String customerId);
}

15
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalCustomerDao.java

@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.result.ExternalCustomerResultDTO;
import com.epmet.entity.ExternalCustomerEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -38,4 +39,18 @@ public interface ExternalCustomerDao extends BaseDao<ExternalCustomerEntity> {
* @return
*/
List<ExternalCustomerResultDTO> listBaseInfo();
/**
* 根据名称查询客户
* @param customerName
* @return
*/
ExternalCustomerResultDTO getByCustomerName(@Param("customerName") String customerName);
/**
* 根据客户名称计数
* @param customerName
* @return
*/
Integer countByCustomerName(@Param("customerName") String customerName);
}

1
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppAuthService.java

@ -1,6 +1,7 @@
package com.epmet.service;
import com.epmet.dto.result.ExternalAppAuthResultDTO;
import com.epmet.dto.result.ExternalAppResultDTO;
public interface ExternalAppAuthService {

3
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java

@ -17,6 +17,8 @@
package com.epmet.service;
import com.epmet.dto.result.ExternalAppResultDTO;
/**
* 外部应用列表
*
@ -24,4 +26,5 @@ package com.epmet.service;
* @since v1.0.0 2020-08-18
*/
public interface ExternalAppService {
ExternalAppResultDTO add(String appName, String customerId);
}

9
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalCustomerService.java

@ -1,11 +1,14 @@
package com.epmet.service;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.result.ExternalCustomerResultDTO;
import java.util.List;
import com.epmet.entity.ExternalCustomerEntity;
public interface ExternalCustomerService {
public List<ExternalCustomerResultDTO> list(Integer pageNo, Integer pageSize);
PageData<ExternalCustomerResultDTO> listPage(Integer pageNo, Integer pageSize);
ExternalCustomerEntity add(String customerName);
ExternalCustomerEntity update(String customerId, String customerName);
}

8
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppAuthServiceImpl.java

@ -1,10 +1,15 @@
package com.epmet.service.impl;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.dao.ExternalAppDao;
import com.epmet.dao.ExternalAppSecretDao;
import com.epmet.dto.result.ExternalAppAuthResultDTO;
import com.epmet.dto.result.ExternalAppResultDTO;
import com.epmet.entity.ExternalAppEntity;
import com.epmet.entity.ExternalAppSecretEntity;
import com.epmet.service.ExternalAppAuthService;
import com.epmet.utils.externalapp.ExtAppJwtTokenUtils;
@ -29,6 +34,9 @@ public class ExternalAppAuthServiceImpl implements ExternalAppAuthService {
@Autowired
private ExternalAppSecretDao externalAppSecretDao;
@Autowired
private ExternalAppDao externalAppDao;
private int diffMillins = 1000 * 60 * 5;
@Override

37
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java

@ -17,7 +17,14 @@
package com.epmet.service.impl;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.dao.ExternalAppDao;
import com.epmet.dao.ExternalCustomerDao;
import com.epmet.dto.result.ExternalAppResultDTO;
import com.epmet.entity.ExternalAppEntity;
import com.epmet.service.ExternalAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@ -29,5 +36,35 @@ import org.springframework.stereotype.Service;
@Service
public class ExternalAppServiceImpl implements ExternalAppService {
@Autowired
private ExternalAppDao externalAppDao;
@Autowired
private ExternalCustomerDao externalCustomerDao;
@Override
public ExternalAppResultDTO add(String appName, String customerId) {
Integer count = externalAppDao.countByAppNameAndCustomerId(appName, customerId);
if (count > 0) {
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getCode(),
EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getMsg());
}
if (externalCustomerDao.selectById(customerId) == null) {
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(),
EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getMsg());
}
ExternalAppEntity entity = new ExternalAppEntity();
entity.setAppName(appName);
entity.setCustomerId(customerId);
externalAppDao.insert(entity);
ExternalAppResultDTO dto = new ExternalAppResultDTO();
dto.setAppName(appName);
dto.setCustomerId(customerId);
dto.setId(entity.getId());
return dto;
}
}

36
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalCustomerServiceImpl.java

@ -1,7 +1,11 @@
package com.epmet.service.impl;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dao.ExternalCustomerDao;
import com.epmet.dto.result.ExternalCustomerResultDTO;
import com.epmet.entity.ExternalCustomerEntity;
import com.epmet.service.ExternalCustomerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@ -17,10 +21,36 @@ public class ExternalCustomerServiceImpl implements ExternalCustomerService {
private ExternalCustomerDao externalCustomerDao;
@Override
public List<ExternalCustomerResultDTO> list(Integer pageNo, Integer pageSize) {
public PageData<ExternalCustomerResultDTO> listPage(Integer pageNo, Integer pageSize) {
PageHelper.startPage(pageNo, pageSize);
List<ExternalCustomerResultDTO> customers = externalCustomerDao.listBaseInfo();
PageInfo<ExternalCustomerResultDTO> pageInfo = new PageInfo<>(customers);
return null;
long total = new PageInfo<>(customers).getTotal();
PageData<ExternalCustomerResultDTO> pageData = new PageData<>(customers, (int) total);
return pageData;
}
@Override
public ExternalCustomerEntity add(String customerName) {
Integer exitsCustomerCount = externalCustomerDao.countByCustomerName(customerName);
if (exitsCustomerCount > 0) {
throw new RenException(EpmetErrorCode.OPER_CUSTOMER_EXISTS.getCode(), "客户已存在");
}
ExternalCustomerEntity entity = new ExternalCustomerEntity();
entity.setCustomerName(customerName);
externalCustomerDao.insert(entity);
return entity;
}
@Override
public ExternalCustomerEntity update(String customerId, String customerName) {
ExternalCustomerEntity existsCustomer = externalCustomerDao.selectById(customerId);
if (existsCustomer == null) {
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(),
EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getMsg());
}
existsCustomer.setCustomerName(customerName);
externalCustomerDao.updateById(existsCustomer);
return existsCustomer;
}
}

11
epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml

@ -15,5 +15,16 @@
<result property="updatedTime" column="UPDATED_TIME"/>
</resultMap>
<!-- appName和客户ID查询-->
<select id="countByAppNameAndCustomerId" resultType="java.lang.Integer">
SELECT
count(0)
FROM
external_app
WHERE
APP_NAME = #{appName}
AND CUSTOMER_ID = #{customerId}
</select>
</mapper>

16
epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalCustomerDao.xml

@ -25,5 +25,21 @@
DEL_FLAG = 0
</select>
<select id="getByCustomerName" resultType="com.epmet.dto.result.ExternalCustomerResultDTO">
SELECT
ID, CUSTOMER_NAME
from
external_customer
WHERE CUSTOMER_NAME = #{customerName}
</select>
<select id="countByCustomerName" resultType="int">
SELECT
count(1)
from
external_customer
WHERE CUSTOMER_NAME = #{customerName}
</select>
</mapper>
Loading…
Cancel
Save