1.保存代码

feature-order-fix
x_z 3 years ago
parent f7e8306ba7
commit 3e4cf0c316

@ -0,0 +1,31 @@
package com.glxp.api.admin.dao.info;
import com.glxp.api.admin.entity.info.PlatformEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface PlatformDao{
int batchSave(List<PlatformEntity> list);
List<PlatformEntity> list( Map<String, Object> map);
int count(Map<String, Object> map);
PlatformEntity get(String id);
/**
* 访
*
* @param name
* @param host
* @return
*/
List<PlatformEntity> selectByNameAndHost(@Param("name") String name, @Param("host") String host);
PlatformEntity selectById(@Param("platformId") String platformId);
}

@ -0,0 +1,39 @@
package com.glxp.api.admin.dao.inout;
import com.glxp.api.admin.entity.inout.UnitMaintainPlatformEntity;
import com.glxp.api.admin.req.inout.PlatformLinkRequest;
import com.glxp.api.admin.res.info.PlatformLinkResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface UnitMaintainPlatformDao{
/**
*
*
* @param page
* @param customerId
* @param key
* @return
*/
List<PlatformLinkResponse> getLinkPlatformList(@Param("customerId") String customerId, @Param("key") String key);
/**
* ID
*
* @param customerId
* @return
*/
List<UnitMaintainPlatformEntity> selectByCustomerId(@Param("customerId") Long customerId);
void updateById(UnitMaintainPlatformEntity maintainPlatform);
void insert(UnitMaintainPlatformEntity unitMaintainPlatformEntity);
List<UnitMaintainPlatformEntity> selectList(PlatformLinkRequest platformLinkRequest);
UnitMaintainPlatformEntity findLinkData(@Param("customerId") long customerId, @Param("action") String action, @Param("unitId") String unitId);
}

@ -0,0 +1,20 @@
package com.glxp.api.admin.entity.info;
import lombok.Data;
@Data
public class PlatformEntity {
private String id;
/**
*
*/
private String name;
/**
*
*/
private String host;
}

@ -0,0 +1,63 @@
package com.glxp.api.admin.entity.inout;
import lombok.Data;
/**
*
*/
@Data
public class UnitMaintainPlatformEntity {
private Integer id;
/**
* ID
*/
private String unitId;
/**
* ID
*/
private Long customerId;
/**
* ID
*/
private String platformId;
/**
*
*/
private String sourceAction;
/**
*
*/
private String targetAction;
/**
*
*/
private String invCode;
/**
*
*/
private String invSubCode;
/**
*
*/
private String appid;
/**
*
*/
private String secretKey;
/**
* ID
*/
private String apiKey;
}

@ -0,0 +1,27 @@
package com.glxp.api.admin.req.info;
import lombok.Data;
/**
*
*/
@Data
public class PlatformUserInfoRequest {
/**
*
*/
private String platformId;
/**
*
*/
private String username;
/**
*
*/
private String password;
}

@ -0,0 +1,41 @@
package com.glxp.api.admin.req.inout;
import com.glxp.api.admin.req.ListPageRequest;
import lombok.Data;
/**
*
*/
@Data
public class PlatformLinkRequest extends ListPageRequest {
private Integer id;
private String unitId;
private String corpName;
private String platformId;
private String platformUsername;
private String platformPassword;
private String appid;
private String apiKey;
private String secretKey;
private String sourceAction;
private String targetAction;
private String invCode;
private String invSubCode;
private String key;
private String customerId;
}

@ -0,0 +1,32 @@
package com.glxp.api.admin.res.info;
import lombok.Data;
/**
*
*/
@Data
public class PlatformLinkResponse {
//往来单位ID
private Integer id;
//往来单位编码
private String unitId;
//往来单位名称
private String corpName;
//往来单位类型
private Integer corpType;
//拼音码
private String pinyinCode;
//自助平台名称
private String platformName;
//自助平台ID
private String platformId;
//本地单据类型
private String sourceAction;
//目标单据类型
private String targetAction;
private String invCode;
private String invSubCode;
}

@ -0,0 +1,5 @@
package com.glxp.api.admin.service.info;
public interface PlatformService {
}

@ -0,0 +1,284 @@
package com.glxp.api.admin.service.info.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.glxp.api.admin.dao.info.PlatformDao;
import com.glxp.api.admin.dao.inout.UnitMaintainPlatformDao;
import com.glxp.api.admin.entity.info.PlatformEntity;
import com.glxp.api.admin.entity.inout.UnitMaintainPlatformEntity;
import com.glxp.api.admin.req.inout.PlatformLinkRequest;
import com.glxp.api.admin.res.info.PlatformLinkResponse;
import com.glxp.api.admin.service.info.PlatformService;
import com.glxp.api.admin.util.HttpClient;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class PlatformServiceImpl implements PlatformService {
@Resource
private PlatformDao platformDao;
@Resource
private UnitMaintainPlatformDao unitMaintainPlatformDao;
public int save(PlatformEntity platformEntity) {
if (StringUtils.isEmpty(platformEntity.getId())) {
platformEntity.setId(String.valueOf(IdUtil.getSnowflakeNextId()));
}
return platformDao.insert(platformEntity);
}
public int remove(String id) {
return platformDao.deleteById(id);
}
public BaseResponse update(PlatformEntity platformEntity) {
if (StrUtil.isBlank(platformEntity.getId())) {
if (!verifyPlatformExist(platformEntity)) {
save(platformEntity);
return ResultVOUtils.success("添加成功");
} else {
return ResultVOUtils.error(500, "已存在相同数据");
}
}
platformDao.updateById(platformEntity);
return ResultVOUtils.success("更新成功");
}
private boolean verifyPlatformExist(PlatformEntity platformEntity) {
//校验名称和地址是否重复
List<PlatformEntity> list = platformDao.selectByNameAndHost(platformEntity.getName(), platformEntity.getHost());
if (CollUtil.isEmpty(list)) {
return false;
}
return true;
}
public IPage<PlatformEntity> list(Map<String, Object> map) {
QueryWrapper<PlatformEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StrUtil.isNotBlank(String.valueOf(map.get("id"))) && !"null".equals(String.valueOf(map.get("id"))), "id", map.get("id"))
.like(StrUtil.isNotBlank(String.valueOf(map.get("name"))) && !"null".equals(String.valueOf(map.get("name"))), "name", map.get("name"))
.like(StrUtil.isNotBlank(String.valueOf(map.get("host"))) && !"null".equals(String.valueOf(map.get("host"))), "host", map.get("host"));
if (map.get("page") != null && map.get("limit") != null) {
Integer page = Integer.valueOf(map.get("page").toString());
Integer limit = Integer.valueOf(map.get("limit").toString());
IPage<PlatformEntity> pageParam = new Page<>(page, limit);
return platformDao.selectPage(pageParam, wrapper);
} else {
List<PlatformEntity> list = platformDao.selectList(wrapper);
IPage<PlatformEntity> pageResult = new Page<>();
pageResult.setTotal(list.size());
pageResult.setRecords(list);
return pageResult;
}
}
public int count(Map<String, Object> map) {
return platformDao.count(map);
}
public PlatformEntity get(String id) {
return platformDao.get(id);
}
/**
*
*
* @param platformLinkRequest
* @return
*/
public IPage<PlatformLinkResponse> getLinkPlatformList(PlatformLinkRequest platformLinkRequest) {
if (null == platformLinkRequest) {
return new Page<>();
}
IPage<PlatformLinkResponse> page = new Page<>(platformLinkRequest.getPage(), platformLinkRequest.getLimit());
return UnitMaintainPlatformEntityDao.getLinkPlatformList(page, platformLinkRequest.getCustomerId(), platformLinkRequest.getKey());
}
/**
*
*
* @param id
*/
public void unbindPlatform(String id) {
UnitMaintainPlatformEntityDao.deleteById(id);
}
/**
*
*
* @param platformId
* @return
*/
public BaseResponse getTargetActions(String platformId, String invSubCode) {
PlatformEntity platformEntity = platformDao.get(platformId);
if (null == platformEntity) {
return ResultVOUtils.success();
}
String host = platformEntity.getHost();
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("invSubCode", invSubCode);
String resp = HttpClient.mipsGet(host + "/apiwms/bussinessType/apimsFilter", paramMap);
if (StrUtil.isNotBlank(resp) && resp.contains("20000")) {
return JSON.parseObject(resp, BaseResponse.class);
} else {
log.error("获取自助平台单据类型异常");
return ResultVOUtils.error(500, "获取自助平台接口异常");
}
}
//获取自助平台一级仓库
public BaseResponse getTargetInv(String platformId) {
PlatformEntity platformEntity = platformDao.get(platformId);
if (null == platformEntity) {
return ResultVOUtils.success();
}
String host = platformEntity.getHost();
String url = host + "/spms/inv/warehouse/filterInv/forapims";
log.info("拉取自助平台仓库数据:" + url);
String resp = HttpUtil.get(url);
log.info("拉取结果:" + resp);
if (StrUtil.isNotBlank(resp) && resp.contains("20000")) {
try {
return JSON.parseObject(resp, BaseResponse.class);
} catch (Exception e) {
log.error("格式化自助平台仓库信息异常", e);
return ResultVOUtils.error(500, "调用自助平台接口异常");
}
} else {
log.error("获取自助平台仓库失败");
return ResultVOUtils.error(500, "调用自助平台接口异常");
}
}
//获取自助平台一级仓库所属分库
public BaseResponse getTargetSubInv(String platformId, String invCode) {
PlatformEntity platformEntity = platformDao.get(platformId);
if (null == platformEntity) {
return ResultVOUtils.success();
}
String host = platformEntity.getHost();
Map<String, String> paramMap = new HashMap<>();
paramMap.put("invCode", invCode);
String resp = HttpClient.mipsGet(host + "/spms/sub/inv/warehouse/getSubInvForapims", paramMap);
if (StrUtil.isNotBlank(resp) && resp.contains("20000")) {
return JSON.parseObject(resp, BaseResponse.class);
} else {
log.error("获取自助平台分库失败");
return ResultVOUtils.error(500, "获取自助平台接口异常");
}
}
/**
*
*
* @param host
* @return
*/
public BaseResponse testPlatformConnection(String host) {
String testUrl = host + "/apiwms/auth/device/connect";
String response = HttpUtil.get(testUrl);
if (StrUtil.isNotBlank(response)) {
try {
BaseResponse result = JSONUtil.toBean(response, BaseResponse.class);
if (result.getCode() == 20000) {
return ResultVOUtils.success();
}
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
} catch (Exception e) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
} else {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
}
/**
* ID
*
* @param platformId
* @return
*/
public PlatformEntity getPlatformById(String platformId) {
return platformDao.selectById(platformId);
}
/**
*
*
* @param UnitMaintainPlatformEntity
*/
public void saveUnitPlatform(UnitMaintainPlatformEntity UnitMaintainPlatformEntity) {
if (null != UnitMaintainPlatformEntity.getId()) {
unitMaintainPlatformDao.updateById(UnitMaintainPlatformEntity);
} else {
unitMaintainPlatformDao.insert(UnitMaintainPlatformEntity);
}
//更新当前客户关联数据的所有key
List<UnitMaintainPlatformEntity> list = unitMaintainPlatformDao.selectByCustomerId(UnitMaintainPlatformEntity.getCustomerId());
if (CollUtil.isNotEmpty(list)) {
for (UnitMaintainPlatformEntity maintainPlatform : list) {
maintainPlatform.setAppid(UnitMaintainPlatformEntity.getAppid());
maintainPlatform.setApiKey(UnitMaintainPlatformEntity.getApiKey());
maintainPlatform.setSecretKey(UnitMaintainPlatformEntity.getSecretKey());
unitMaintainPlatformDao.updateById(maintainPlatform);
}
}
}
/**
*
*
* @param platformLinkRequest
* @return
*/
public String verifyUnitMaintainPlatformEntity(PlatformLinkRequest platformLinkRequest) {
List<UnitMaintainPlatformEntity> list = unitMaintainPlatformDao.selectList(platformLinkRequest);
if (CollUtil.isEmpty(list)) {
return "success";
} else {
for (UnitMaintainPlatformEntity maintainPlatform : list) {
if (maintainPlatform.getId().equals(platformLinkRequest.getId())) {
return "success";
} else {
return "重复添加";
}
}
}
return "重复添加";
}
/**
*
*
* @param customerId
* @param action
* @param unitId
* @return
*/
public UnitMaintainPlatformEntity findLinkData(long customerId, String action, String unitId) {
return unitMaintainPlatformDao.findLinkData(customerId, action, unitId);
}
}

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.glxp.api.admin.dao.info.PlatformDao">
<insert id="batchSave" parameterType="java.util.List">
replace into auth_platform
(id, name, host)
values
<foreach item="item" index="index" collection="list"
separator=",">
(#{item.id}, #{item.name,jdbcType=VARCHAR}, #{item.host,jdbcType=VARCHAR})
</foreach>
</insert>
<select id="get" resultType="com.glxp.api.admin.entity.info.PlatformEntity">
select *
from auth_platform
where id = #{value}
</select>
<select id="list" resultType="com.glxp.api.admin.entity.info.PlatformEntity">
select *
from auth_platform
<where>
<if test="id != null and id != ''">
and id = #{id}
</if>
<if test="name != null and name != ''">
and instr(name, #{name})
</if>
<if test="host != null and host != ''">
and instr(host, #{host})
</if>
</where>
order by id desc
</select>
<select id="count" resultType="int">
select count(*)
from auth_platform
<where>
<if test="id != null and id != ''">
and id = #{id}
</if>
<if test="name != null and name != ''">
and instr(name, #{name})
</if>
<if test="host != null and host != ''">
and instr(host, #{host})
</if>
</where>
</select>
<select id="selectByNameAndHost" resultType="com.glxp.api.admin.entity.info.PlatformEntity">
select *
from auth_platform
where name = #{name}
and host = #{host}
</select>
<select id="selectById" resultType="com.glxp.api.admin.entity.info.PlatformEntity">
select * from auth_platform where id = #{platformId}
</select>
</mapper>

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.glxp.api.admin.dao.inout.UnitMaintainPlatformDao">
<select id="getLinkPlatformList" resultType="com.glxp.api.admin.res.info.PlatformLinkResponse">
select up.id,
up.unitId,
u.name corpName,
u.corpType,
u.spell,
ap.name platformName,
ap.id platformId,
up.sourceAction,
up.targetAction,
up.invCode,
up.invSubCode
from io_unit_maintain_platform up
left join basic_corp u on up.unitId = u.erpId
left join auth_platform ap on up.platformId = ap.id
where up.customerId = #{customerId}
<if test="key != null and key != ''">
AND (u.erpId like concat('%', #{key}, '%')
or u.name like concat('%', #{key}, '%')
or u.spell like concat('%', #{key}, '%')
)
</if>
</select>
<select id="selectByCustomerId" resultType="com.glxp.api.admin.entity.inout.UnitMaintainPlatformEntity">
select *
from io_unit_maintain_platform
where customerId = #{customerId}
</select>
<update id="updateById" parameterType="com.glxp.api.admin.entity.inout.UnitMaintainPlatformEntity">
update io_unit_maintain_platform
<trim prefix="set" suffixOverrides=",">
<if test="unitId != null and unitId != ''">
unitId = #{unitId},
</if>
<if test="customerId != null">
customerId = #{customerId},
</if>
<if test="platformId != null and platformId != ''">
platformId = #{platformId},
</if>
<if test="sourceAction != null and sourceAction != ''">
sourceAction = #{sourceAction},
</if>
<if test="targetAction != null and targetAction != ''">
targetAction = #{targetAction},
</if>
<if test="invCode != null and invCode != ''">
invCode = #{invCode},
</if>
<if test="invSubCode != null and invSubCode != ''">
invSubCode = #{invSubCode},
</if>
<if test="appid != null and appid != ''">
appid = #{appid},
</if>
<if test="apiKey != null and apiKey != ''">
apiKey = #{apiKey},
</if>
<if test="secretKey != null and secretKey != ''">
secretKey = #{secretKey}
</if>
</trim>
where id = #{id}
</update>
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id"
parameterType="com.glxp.api.admin.entity.inout.UnitMaintainPlatformEntity">
insert into io_unit_maintain_platform (unitId, customerId, platformId, sourceAction, targetAction, invCode,
invSubCode, appid, apiKey, secretKey)
VALUES (#{unitId}, #{customerId}, #{platformId}, #{sourceAction}, #{targetAction}, #{invCode}, #{invSubCode},
#{appid}, #{apiKey}, #{secretKey})
</insert>
<select id="selectList" resultType="com.glxp.api.admin.entity.inout.UnitMaintainPlatformEntity">
select * from io_unit_maintain_platform
<where>
<if test="unitId != null and unitId != ''">
AND unitId = #{unitId}
</if>
<if test="customerId != null and customerId != ''">
AND customerId = #{customerId}
</if>
<if test="platformId != null and platformId != ''">
AND platformId = #{platformId}
</if>
<if test="sourceAction != null and sourceAction != ''">
AND sourceAction = #{sourceAction}
</if>
<if test="targetAction != null and targetAction != ''">
AND targetAction = #{targetAction}
</if>
<if test="invSubCode != null and invSubCode != ''">
AND invCode = #{invCode}
</if>
<if test="invSubCode != null and invSubCode != ''">
AND invSubCode = #{invSubCode}
</if>
<if test="appid != null and appid != ''">
AND appid = #{appid}
</if>
<if test="apiKey != null and apiKey != ''">
AND apiKey = #{apiKey}
</if>
<if test="secretKey != null and secretKey != ''">
AND secretKey = #{secretKey}
</if>
</where>
</select>
<select id="findLinkData" resultType="com.glxp.api.admin.entity.inout.UnitMaintainPlatformEntity">
select * from io_unit_maintain_platform
<where>
<if test="unitId != null and unitId != ''">
AND unitId = #{unitId}
</if>
<if test="customerId != null">
AND customerId = #{customerId}
</if>
<if test="action != null and action != ''">
AND sourceAction = #{action}
</if>
</where>
</select>
</mapper>
Loading…
Cancel
Save