Authored by LUOXC

运费从配置文件读取

... ... @@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ConfigTypeMapper {
int deleteByPrimaryKey(Integer id);
int insert(ConfigType record);
... ... @@ -14,9 +15,7 @@ public interface ConfigTypeMapper {
ConfigType selectByCode(@Param("code") String code);
int updateByPrimaryKeySelective(ConfigType record);
int updateByPrimaryKey(ConfigType record);
int updateByCode(ConfigType record);
List<ConfigType> selectAllNormal();
}
\ No newline at end of file
... ...
... ... @@ -81,34 +81,16 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.resource.model.ConfigType">
<update id="updateByCode" parameterType="com.yohoufo.dal.resource.model.ConfigType">
update config_type
<set>
<if test="code != null">
code = #{code,jdbcType=VARCHAR},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="content != null">
content = #{content,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=TINYINT},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.resource.model.ConfigType">
update config_type
set code = #{code,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
content = #{content,jdbcType=VARCHAR},
status = #{status,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
where code = #{code,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.order.service.support;
import org.springframework.beans.factory.annotation.Value;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 运费
*
* @author LUOXC
* @date 2018/12/19 19:04
*/
@Component
public class DeliveryWayCostSupport {
/**
* 运费
*/
@Value("${buyer.delivery.way.cost.sf:15}")
private double delivery_way_cost_sf;
@Autowired
private UfoServiceCaller ufoServiceCaller;
public double getCostOfSf() {
double defaultValue = 15;
try {
ApiResponse resp = ufoServiceCaller.call(
"ufo.resource.getConfigTypeContent",
ApiResponse.class,
"buyer.delivery.way.cost.sf");
if (resp != null && resp.getCode() == 200 && resp.getData() != null) {
return NumberUtils.toDouble(String.valueOf(resp.getData()), defaultValue);
} else {
return defaultValue;
}
} catch (Exception e) {
return defaultValue;
}
public double getCostOfSf(){
return delivery_way_cost_sf;
}
}
... ...
... ... @@ -8,6 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
... ... @@ -35,4 +36,31 @@ public class ConfigTypeController {
logger.info("getConfigType success. result is ", data);
return new ApiResponse.ApiResponseBuilder().data(data).code(200).message("config type list data").build();
}
/**
* <p>获取配置信息</p>
*/
@ApiOperation(name = "ufo.resource.getConfigTypeContent", desc = "修改配置信息")
@RequestMapping(params = "method=ufo.resource.getConfigTypeContent")
@ResponseBody
@IgnoreSession
public ApiResponse getConfigTypeContent(@RequestParam(name = "code") String code) {
String content = configTypeService.getContentByCode(code);
return new ApiResponse.ApiResponseBuilder().data(content).code(200).build();
}
/**
* <p>修改配置信息</p>
*/
@ApiOperation(name = "ufo.resource.updateConfigTypeContent", desc = "修改配置信息")
@RequestMapping(params = "method=ufo.resource.updateConfigTypeContent")
@ResponseBody
@IgnoreSession
public ApiResponse updateConfigTypeContent(@RequestParam(name = "code") String code,
@RequestParam(name = "content") String content) {
int rows = configTypeService.updateContentByCode(code, content);
return new ApiResponse.ApiResponseBuilder().data(rows).code(200).build();
}
}
... ...
... ... @@ -6,11 +6,14 @@ public interface IConfigTypeService {
/**
* 获取所有状态正常的配置项
*
* @return
*/
Map<String,String> configTypeList();
Map<String, String> configTypeList();
String getContentByCode(String code);
int updateContentByCode(String code, String content);
}
... ...
... ... @@ -25,28 +25,29 @@ public class ConfigTypeServiceImpl implements IConfigTypeService {
@Autowired
private ConfigTypeMapper configTypeMapper;
private final String NormalConfigTypeList_CACHE_KEY= "NormalConfigTypeList";
private final String NormalConfigTypeList_CACHE_KEY = "NormalConfigTypeList";
@PostConstruct
private void init() {
localCache.init(NormalConfigTypeList_CACHE_KEY, 5, TimeUnit.MINUTES, (String s, Object o) -> {
LOGGER.info("NormalConfigTypeList init s = {}, o = {}", s, o);
List<ConfigType> expressCompanies = configTypeMapper.selectAllNormal();
return expressCompanies.stream().collect(Collectors.toMap(ConfigType::getCode,ConfigType::getContent));
return expressCompanies.stream().collect(Collectors.toMap(ConfigType::getCode, ConfigType::getContent));
});
}
/**
* 获取所有状态正常的配置项
*
* @return
*/
public Map<String,String> configTypeList(){
Map<String,String> map = (Map<String,String>) localCache.get(NormalConfigTypeList_CACHE_KEY);
if (map!=null&&map.size()>0) {
public Map<String, String> configTypeList() {
Map<String, String> map = (Map<String, String>) localCache.get(NormalConfigTypeList_CACHE_KEY);
if (map != null && map.size() > 0) {
return map;
}
List<ConfigType> expressCompanies = configTypeMapper.selectAllNormal();
return expressCompanies.stream().collect(Collectors.toMap(ConfigType::getCode,ConfigType::getContent));
return expressCompanies.stream().collect(Collectors.toMap(ConfigType::getCode, ConfigType::getContent));
}
@Override
... ... @@ -57,4 +58,12 @@ public class ConfigTypeServiceImpl implements IConfigTypeService {
.orElse(null);
}
@Override
public int updateContentByCode(String code, String content) {
ConfigType configType = new ConfigType();
configType.setCode(code);
configType.setContent(content);
return configTypeMapper.updateByCode(configType);
}
}
... ...