购物车
parent
70cba32918
commit
e9143a08e8
|
|
@ -2,8 +2,10 @@ package com.wyh.admin.controller.setting;
|
|||
|
||||
import com.wyh.admin.aop.Log;
|
||||
import com.wyh.admin.service.ISettingProtocolService;
|
||||
import com.wyh.admin.validate.setting.SettingProtocolDetailValidate;
|
||||
import com.wyh.admin.validate.setting.SettingProtocolValidate;
|
||||
import com.wyh.admin.vo.setting.SettingProtocolDetailVo;
|
||||
import com.wyh.admin.vo.setting.SettingProtocolGetDetailVo;
|
||||
import com.wyh.common.core.AjaxResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
|
@ -35,4 +37,20 @@ public class SettingProtocolController {
|
|||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/getDetail")
|
||||
@ApiOperation(value="条约规则信息")
|
||||
public AjaxResult<SettingProtocolGetDetailVo> getDetail() {
|
||||
SettingProtocolGetDetailVo getDetailVo = iSettingProtocolService.getDetail();
|
||||
return AjaxResult.success(getDetailVo);
|
||||
}
|
||||
|
||||
@Log(title = "条约规则编辑")
|
||||
@PostMapping("/saveDeatil")
|
||||
@ApiOperation(value="条约规则编辑")
|
||||
public AjaxResult<Object> saveDeatil(@Validated @RequestBody SettingProtocolDetailValidate protocolDetailValidate) {
|
||||
iSettingProtocolService.saveDeatil(protocolDetailValidate);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.wyh.admin.service;
|
||||
|
||||
import com.wyh.admin.validate.setting.SettingProtocolDetailValidate;
|
||||
import com.wyh.admin.validate.setting.SettingProtocolValidate;
|
||||
import com.wyh.admin.vo.setting.SettingProtocolDetailVo;
|
||||
import com.wyh.admin.vo.setting.SettingProtocolGetDetailVo;
|
||||
|
||||
/**
|
||||
* 政策协议服务接口类
|
||||
|
|
@ -24,4 +26,7 @@ public interface ISettingProtocolService {
|
|||
*/
|
||||
void save(SettingProtocolValidate protocolValidate);
|
||||
|
||||
SettingProtocolGetDetailVo getDetail();
|
||||
|
||||
void saveDeatil(SettingProtocolDetailValidate protocolDetailValidate);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ package com.wyh.admin.service.impl;
|
|||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.wyh.admin.service.ISettingProtocolService;
|
||||
import com.wyh.admin.validate.setting.SettingProtocolDetailValidate;
|
||||
import com.wyh.admin.validate.setting.SettingProtocolValidate;
|
||||
import com.wyh.admin.vo.setting.SettingProtocolDetailVo;
|
||||
import com.wyh.admin.vo.setting.SettingProtocolGetDetailVo;
|
||||
import com.wyh.admin.vo.setting.SettingProtocolObjectVo;
|
||||
import com.wyh.common.util.ConfigUtils;
|
||||
import com.wyh.common.util.MapUtils;
|
||||
|
|
@ -56,4 +58,38 @@ public class SettingProtocolServiceImpl implements ISettingProtocolService {
|
|||
ConfigUtils.set("protocol","privacy", JSON.toJSONString(protocolValidate.getPrivacy()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SettingProtocolGetDetailVo getDetail() {
|
||||
String lease = ConfigUtils.get("protocol", "lease", "{\"name\":\"\",\"content\":\"\"}");
|
||||
String integrate = ConfigUtils.get("protocol", "integrate", "{\"name\":\"\",\"content\":\"\"}");
|
||||
String helpcenter = ConfigUtils.get("protocol", "helpcenter", "{\"name\":\"\",\"content\":\"\"}");
|
||||
Map<String, String> leaseMap = MapUtils.jsonToMap(lease);
|
||||
Map<String, String> integrateMap = MapUtils.jsonToMap(integrate);
|
||||
Map<String, String> helpcenterMap = MapUtils.jsonToMap(helpcenter);
|
||||
SettingProtocolObjectVo leaseObj = new SettingProtocolObjectVo();
|
||||
leaseObj.setName(leaseMap.getOrDefault("name", ""));
|
||||
leaseObj.setContent(leaseMap.getOrDefault("content", ""));
|
||||
|
||||
SettingProtocolObjectVo integrateObj = new SettingProtocolObjectVo();
|
||||
integrateObj.setName(integrateMap.getOrDefault("name", ""));
|
||||
integrateObj.setContent(integrateMap.getOrDefault("content", ""));
|
||||
|
||||
SettingProtocolObjectVo helpcenterObj = new SettingProtocolObjectVo();
|
||||
helpcenterObj.setName(helpcenterMap.getOrDefault("name", ""));
|
||||
helpcenterObj.setContent(helpcenterMap.getOrDefault("content", ""));
|
||||
|
||||
SettingProtocolGetDetailVo vo = new SettingProtocolGetDetailVo();
|
||||
vo.setLease(leaseObj);
|
||||
vo.setIntegrate(integrateObj);
|
||||
vo.setHelpcenter(helpcenterObj);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDeatil(SettingProtocolDetailValidate protocolDetailValidate) {
|
||||
ConfigUtils.set("protocol","lease", JSON.toJSONString(protocolDetailValidate.getLease()));
|
||||
ConfigUtils.set("protocol","integrate", JSON.toJSONString(protocolDetailValidate.getIntegrate()));
|
||||
ConfigUtils.set("protocol","helpcenter", JSON.toJSONString(protocolDetailValidate.getHelpcenter()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.wyh.admin.validate.setting;
|
||||
|
||||
import com.wyh.admin.vo.setting.SettingProtocolObjectVo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("政策协议设置参数")
|
||||
public class SettingProtocolDetailValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "租借条约")
|
||||
private SettingProtocolObjectVo lease;
|
||||
|
||||
@ApiModelProperty(value = "积分规则")
|
||||
private SettingProtocolObjectVo integrate;
|
||||
|
||||
@ApiModelProperty(value = "积分规则")
|
||||
private SettingProtocolObjectVo helpcenter;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.wyh.admin.vo.setting;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("条约规则详情Vo")
|
||||
public class SettingProtocolGetDetailVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "租借条约")
|
||||
private SettingProtocolObjectVo lease;
|
||||
|
||||
@ApiModelProperty(value = "积分规则")
|
||||
private SettingProtocolObjectVo integrate;
|
||||
|
||||
@ApiModelProperty(value = "帮助中心")
|
||||
private SettingProtocolObjectVo helpcenter;
|
||||
}
|
||||
|
|
@ -31,6 +31,14 @@
|
|||
|
||||
<!-- 依赖管理 -->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.mrzin</groupId>
|
||||
<artifactId>tool-wx</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.stuxuhai</groupId>
|
||||
<artifactId>jpinyin</artifactId>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.wyh.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@ApiModel("用户商品信息实体")
|
||||
public class UserGoods implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
@ApiModelProperty(value = "")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
private Integer userId;
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
private Integer goodsId;
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
private Integer num;
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
private Integer isCheck;
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
private BigDecimal price;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.wyh.common.mapper;
|
||||
|
||||
import com.wyh.common.core.basics.IBaseMapper;
|
||||
import com.wyh.common.entity.UserGoods;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 用户商品信息Mapper
|
||||
* @author wyh
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserGoodsMapper extends IBaseMapper<UserGoods> {
|
||||
}
|
||||
|
|
@ -0,0 +1,247 @@
|
|||
package com.wyh.common.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* HTTP/HTTPS 请求封装: GET / POST
|
||||
* 默认失败重试3次
|
||||
* @author admin
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpClientSslUtils {
|
||||
|
||||
/**
|
||||
* 默认的字符编码格式
|
||||
*/
|
||||
private static final String DEFAULT_CHAR_SET = "UTF-8";
|
||||
/**
|
||||
* 默认连接超时时间 (毫秒)
|
||||
*/
|
||||
private static final Integer DEFAULT_CONNECTION_TIME_OUT = 2000;
|
||||
/**
|
||||
* 默认socket超时时间 (毫秒)
|
||||
*/
|
||||
private static final Integer DEFAULT_SOCKET_TIME_OUT = 3000;
|
||||
|
||||
/** socketTimeOut上限 */
|
||||
private static final Integer SOCKET_TIME_OUT_UPPER_LIMIT = 10000;
|
||||
|
||||
/** socketTimeOut下限 */
|
||||
private static final Integer SOCKET_TIME_OUT_LOWER_LIMIT = 1000;
|
||||
|
||||
private static CloseableHttpClient getHttpClient() {
|
||||
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(DEFAULT_SOCKET_TIME_OUT)
|
||||
.setConnectTimeout(DEFAULT_CONNECTION_TIME_OUT).build();
|
||||
return HttpClients.custom().setDefaultRequestConfig(requestConfig)
|
||||
.setRetryHandler(new DefaultHttpRequestRetryHandler()).build();
|
||||
}
|
||||
|
||||
private static CloseableHttpClient getHttpClient(Integer socketTimeOut) {
|
||||
RequestConfig requestConfig =
|
||||
RequestConfig.custom().setSocketTimeout(socketTimeOut).setConnectTimeout(DEFAULT_CONNECTION_TIME_OUT)
|
||||
.build();
|
||||
return HttpClients.custom().setDefaultRequestConfig(requestConfig)
|
||||
.setRetryHandler(new DefaultHttpRequestRetryHandler()).build();
|
||||
}
|
||||
|
||||
public static String doPost(String url, String requestBody) throws Exception {
|
||||
return doPost(url, requestBody, ContentType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
public static String doPost(String url, String requestBody, Integer socketTimeOut) throws Exception {
|
||||
return doPost(url, requestBody, ContentType.APPLICATION_JSON, null, socketTimeOut);
|
||||
}
|
||||
|
||||
public static String doPost(String url, String requestBody, ContentType contentType) throws Exception {
|
||||
return doPost(url, requestBody, contentType, null);
|
||||
}
|
||||
|
||||
public static String doPost(String url, String requestBody, List<BasicHeader> headers) throws Exception {
|
||||
return doPost(url, requestBody, ContentType.APPLICATION_JSON, headers);
|
||||
}
|
||||
|
||||
public static String doPost(String url, String requestBody, ContentType contentType, List<BasicHeader> headers)
|
||||
throws Exception {
|
||||
return doPost(url, requestBody, contentType, headers, getHttpClient());
|
||||
}
|
||||
|
||||
public static String doPost(String url, String requestBody, ContentType contentType, List<BasicHeader> headers,
|
||||
Integer socketTimeOut) throws Exception {
|
||||
if (socketTimeOut < SOCKET_TIME_OUT_LOWER_LIMIT || socketTimeOut > SOCKET_TIME_OUT_UPPER_LIMIT) {
|
||||
log.error("socketTimeOut非法");
|
||||
throw new Exception();
|
||||
}
|
||||
return doPost(url, requestBody, contentType, headers, getHttpClient(socketTimeOut));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通用Post远程服务请求
|
||||
* @param url
|
||||
* 请求url地址
|
||||
* @param requestBody
|
||||
* 请求体body
|
||||
* @param contentType
|
||||
* 内容类型
|
||||
* @param headers
|
||||
* 请求头
|
||||
* @return String 业务自行解析
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String doPost(String url, String requestBody, ContentType contentType, List<BasicHeader> headers,
|
||||
CloseableHttpClient client) throws Exception {
|
||||
|
||||
// 构造http方法,设置请求和传输超时时间,重试3次
|
||||
CloseableHttpResponse response = null;
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
HttpPost post = new HttpPost(url);
|
||||
if (!CollectionUtils.isEmpty(headers)) {
|
||||
for (BasicHeader header : headers) {
|
||||
post.setHeader(header);
|
||||
}
|
||||
}
|
||||
StringEntity entity =
|
||||
new StringEntity(requestBody, ContentType.create(contentType.getMimeType(), DEFAULT_CHAR_SET));
|
||||
post.setEntity(entity);
|
||||
response = client.execute(post);
|
||||
if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
|
||||
log.error("业务请求返回失败:{}", EntityUtils.toString(response.getEntity()));
|
||||
throw new Exception();
|
||||
}
|
||||
String result = EntityUtils.toString(response.getEntity());
|
||||
return result;
|
||||
} finally {
|
||||
releaseResourceAndLog(url, requestBody, response, startTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂时用于智慧园区业务联调方式
|
||||
* @param url 业务请求url
|
||||
* @param param 业务参数
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String doPostWithUrlEncoded(String url,
|
||||
Map<String, String> param) throws Exception {
|
||||
// 创建Httpclient对象
|
||||
CloseableHttpClient httpClient = getHttpClient();
|
||||
CloseableHttpResponse response = null;
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
// 创建Http Post请求
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
// 创建参数列表
|
||||
if (param != null) {
|
||||
List<org.apache.http.NameValuePair> paramList = new ArrayList<>();
|
||||
for (String key : param.keySet()) {
|
||||
paramList.add(new BasicNameValuePair(key, param.get(key)));
|
||||
}
|
||||
// 模拟表单
|
||||
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList, DEFAULT_CHAR_SET);
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
// 执行http请求
|
||||
response = httpClient.execute(httpPost);
|
||||
if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
|
||||
log.error("业务请求返回失败:{}" , EntityUtils.toString(response.getEntity()));
|
||||
throw new Exception();
|
||||
}
|
||||
String resultString = EntityUtils.toString(response.getEntity(), DEFAULT_CHAR_SET);
|
||||
return resultString;
|
||||
} finally {
|
||||
releaseResourceAndLog(url, param == null ? null : param.toString(), response, startTime);
|
||||
}
|
||||
}
|
||||
|
||||
private static void releaseResourceAndLog(String url, String request, CloseableHttpResponse response, long startTime) {
|
||||
if (null != response) {
|
||||
try {
|
||||
response.close();
|
||||
recordInterfaceLog(startTime, url, request);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String doGet(String url) throws Exception {
|
||||
return doGet(url, ContentType.DEFAULT_TEXT);
|
||||
}
|
||||
|
||||
public static String doGet(String url, ContentType contentType) throws Exception {
|
||||
return doGet(url, contentType, null);
|
||||
}
|
||||
|
||||
public static String doGet(String url, List<BasicHeader> headers) throws Exception {
|
||||
return doGet(url, ContentType.DEFAULT_TEXT, headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用Get远程服务请求
|
||||
* @param url
|
||||
* 请求参数
|
||||
* @param contentType
|
||||
* 请求参数类型
|
||||
* @param headers
|
||||
* 请求头可以填充
|
||||
* @return String 业务自行解析数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String doGet(String url, ContentType contentType, List<BasicHeader> headers) throws Exception {
|
||||
CloseableHttpResponse response = null;
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
CloseableHttpClient client = getHttpClient();
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
if (!CollectionUtils.isEmpty(headers)) {
|
||||
for (BasicHeader header : headers) {
|
||||
httpGet.setHeader(header);
|
||||
}
|
||||
}
|
||||
if(contentType != null){
|
||||
httpGet.setHeader("Content-Type", contentType.getMimeType());
|
||||
}
|
||||
response = client.execute(httpGet);
|
||||
if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
|
||||
log.error("业务请求返回失败:{}", EntityUtils.toString(response.getEntity()));
|
||||
throw new Exception();
|
||||
}
|
||||
String result = EntityUtils.toString(response.getEntity());
|
||||
return result;
|
||||
} finally {
|
||||
releaseResourceAndLog(url, null, response, startTime);
|
||||
}
|
||||
}
|
||||
|
||||
private static void recordInterfaceLog(long startTime, String url, String request) {
|
||||
long endTime = System.currentTimeMillis();
|
||||
long timeCost = endTime - startTime;
|
||||
MDC.put("totalTime", String.valueOf(timeCost));
|
||||
MDC.put("url", url);
|
||||
MDC.put("logType", "third-platform-service");
|
||||
log.info("HttpClientSslUtils 远程请求:{} 参数:{} 耗时:{}ms", url, request, timeCost);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
package com.wyh.common.util;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
@Slf4j
|
||||
public class JsonUtil {
|
||||
|
||||
/**
|
||||
* 定义映射对象
|
||||
*/
|
||||
public static ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 日期格式化
|
||||
*/
|
||||
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
static {
|
||||
//对象的所有字段全部列入
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
//取消默认转换timestamps形式
|
||||
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
//忽略空Bean转json的错误
|
||||
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
//所有的日期格式都统一为以下的样式,即yyyy-MM-dd HH:mm:ss
|
||||
objectMapper.setDateFormat(new SimpleDateFormat(DATE_FORMAT));
|
||||
//忽略 在json字符串中存在,但是在java对象中不存在对应属性的情况。防止错误
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* string转JsonNode
|
||||
*
|
||||
* @param jsonString
|
||||
* @return com.fasterxml.jackson.databind.JsonNode
|
||||
*/
|
||||
public static JsonNode stringToJsonNode(String jsonString) throws JsonProcessingException {
|
||||
|
||||
return objectMapper.readTree(jsonString);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转json字符串
|
||||
*
|
||||
* @param obj
|
||||
* @param <T>
|
||||
*/
|
||||
public static <T> String objToString(T obj) {
|
||||
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return obj instanceof String ? (String) obj : objectMapper.writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.warn("Parse Object to String error : {}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转格式化的字符串字符串
|
||||
*
|
||||
* @param obj
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> String objToPrettyString(T obj) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return obj instanceof String ? (String) obj : objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.warn("Parse Object to String error : {}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* json字符串转对象
|
||||
*
|
||||
* @param jsonString
|
||||
* @param cls
|
||||
* @param <T>
|
||||
*/
|
||||
public static <T> T stringToObj(String jsonString, Class<T> cls) {
|
||||
if (StringUtils.isEmpty(jsonString) || cls == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return cls.equals(String.class) ? (T) jsonString : objectMapper.readValue(jsonString, cls);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.warn("Parse String to Object error : {}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.wyh.common.validator;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("用户商品信息创建参数")
|
||||
public class UserGoodsCreateValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull(message = "goodsId参数缺失")
|
||||
@ApiModelProperty(value = "商品id")
|
||||
private Integer goodsId;
|
||||
|
||||
@NotNull(message = "num参数缺失")
|
||||
@ApiModelProperty(value = "商品数量")
|
||||
private Integer num;
|
||||
|
||||
@NotNull(message = "isCheck参数缺失")
|
||||
@ApiModelProperty(value = "商品是否选中,0未选中,1选中")
|
||||
private Integer isCheck;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.wyh.common.vo;
|
||||
|
||||
import com.wyh.common.entity.goods.Goods;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CartVo {
|
||||
|
||||
private List<Goods> goodsList;
|
||||
private BigDecimal totalPrice;
|
||||
private BigDecimal checkTotalPrice;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.wyh.front.controller;
|
||||
|
||||
import com.wyh.common.core.AjaxResult;
|
||||
import com.wyh.common.validator.UserGoodsCreateValidate;
|
||||
import com.wyh.common.vo.CartVo;
|
||||
import com.wyh.front.service.CartService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("front/cart")
|
||||
@Api(tags = "购物车")
|
||||
public class CartController {
|
||||
|
||||
|
||||
@Resource
|
||||
CartService cartService;
|
||||
|
||||
|
||||
@PostMapping("addCart")
|
||||
@ApiOperation(value = "加入购物车")
|
||||
public AjaxResult<Object> addCart(@Validated @RequestBody List<UserGoodsCreateValidate> cartCreateValited) {
|
||||
cartService.addCart(cartCreateValited);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("getCart")
|
||||
@ApiOperation(value = "获取购物车")
|
||||
public AjaxResult<Object> getCart() {
|
||||
CartVo cart = cartService.getCart();
|
||||
return AjaxResult.success(cart);
|
||||
}
|
||||
}
|
||||
|
|
@ -59,13 +59,14 @@ public class IndexController {
|
|||
|
||||
@NotLogin
|
||||
@GetMapping("/policy")
|
||||
@ApiOperation(value="政策协议",notes="类型 service=服务协议,privacy=隐私协议" )
|
||||
@ApiParam(name="type",value="类型 service=服务协议,privacy=隐私协议")
|
||||
@ApiOperation(value="政策协议规则条约",notes="类型 service=服务协议,privacy=隐私协议, lease=租借条约,integrate=积分规则,helpcenter=帮助中心" )
|
||||
@ApiParam(name="type",value="类型 service=服务协议,privacy=隐私协议 , lease=租借条约,integrate=积分规则,helpcenter=帮助中心",required = true)
|
||||
public AjaxResult<Map<String, String>> policy(@RequestParam String type) {
|
||||
Map<String, String> map = iIndexService.policy(type);
|
||||
return AjaxResult.success(map);
|
||||
}
|
||||
|
||||
|
||||
@NotLogin
|
||||
@GetMapping("/hotSearch")
|
||||
// @ApiOperation(value="热门搜索")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package com.wyh.front.service;
|
||||
|
||||
import com.wyh.common.validator.UserGoodsCreateValidate;
|
||||
import com.wyh.common.vo.CartVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CartService {
|
||||
void addCart( List<UserGoodsCreateValidate> cartCreateValited);
|
||||
|
||||
CartVo getCart();
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package com.wyh.front.service;
|
||||
|
||||
import com.wyh.front.vo.user.UserCenterVo;
|
||||
import com.wyh.front.vo.user.UserInfoVo;
|
||||
import com.wyh.front.validate.users.NewUserUpdateValidate;
|
||||
import com.wyh.front.validate.users.UserBindWechatValidate;
|
||||
import com.wyh.front.validate.users.UserPhoneBindValidate;
|
||||
import com.wyh.front.validate.users.UserUpdateValidate;
|
||||
import com.wyh.front.vo.user.UserCenterVo;
|
||||
import com.wyh.front.vo.user.UserInfoVo;
|
||||
|
||||
/**
|
||||
* 用户服务接口类
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
package com.wyh.front.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.wyh.common.entity.UserGoods;
|
||||
import com.wyh.common.entity.goods.Goods;
|
||||
import com.wyh.common.mapper.UserGoodsMapper;
|
||||
import com.wyh.common.mapper.goods.GoodsMapper;
|
||||
import com.wyh.common.validator.UserGoodsCreateValidate;
|
||||
import com.wyh.common.vo.CartVo;
|
||||
import com.wyh.front.ZJFrontThreadLocal;
|
||||
import com.wyh.front.service.CartService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CartServiceImpl implements CartService {
|
||||
@Resource
|
||||
private UserGoodsMapper userGoodsMapper;
|
||||
|
||||
@Resource
|
||||
private GoodsMapper goodsMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public void addCart( List<UserGoodsCreateValidate> cartCreateValited) {
|
||||
Integer userId = ZJFrontThreadLocal.getUserId();
|
||||
for (UserGoodsCreateValidate userGoodsCreateValidate : cartCreateValited) {
|
||||
Integer goodsId = userGoodsCreateValidate.getGoodsId();
|
||||
Goods goods = goodsMapper.selectById(goodsId);
|
||||
Integer num = userGoodsCreateValidate.getNum();
|
||||
Integer isCheck = userGoodsCreateValidate.getIsCheck();
|
||||
UserGoods userGoods = new UserGoods();
|
||||
userGoods.setUserId(userId);
|
||||
userGoods.setGoodsId(goodsId);
|
||||
userGoods.setNum(num);
|
||||
userGoods.setIsCheck(isCheck);
|
||||
userGoods.setPrice(goods.getPrice().multiply(new BigDecimal(num)));
|
||||
userGoodsMapper.insert(userGoods);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CartVo getCart() {
|
||||
Integer userId = ZJFrontThreadLocal.getUserId();
|
||||
List<UserGoods> userGoodsList = userGoodsMapper.selectList(Wrappers.<UserGoods>lambdaQuery().eq(UserGoods::getUserId, userId));
|
||||
if (userGoodsList.isEmpty()) {
|
||||
return new CartVo();
|
||||
}
|
||||
List<Integer> ids
|
||||
= userGoodsList.stream().map(UserGoods::getGoodsId).collect(Collectors.toList());
|
||||
|
||||
List<Goods> goods = goodsMapper.selectList(Wrappers.<Goods>lambdaQuery().in(Goods::getId, ids));
|
||||
BigDecimal totalPrice = new BigDecimal(0);
|
||||
BigDecimal checkTotalPrice = new BigDecimal(0);
|
||||
for (UserGoods userGoods : userGoodsList) {
|
||||
Integer goodsId = userGoods.getGoodsId();
|
||||
for (Goods good : goods) {
|
||||
if (good.getId().equals(goodsId)) {
|
||||
BigDecimal price = good.getPrice().multiply(new BigDecimal(userGoods.getNum()));
|
||||
totalPrice = totalPrice.add(price);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<UserGoods> collect = userGoodsList.stream().filter(item -> item.getIsCheck().equals(1)).collect(Collectors.toList());
|
||||
for (UserGoods userGoods : collect) {
|
||||
Integer goodsId = userGoods.getGoodsId();
|
||||
for (Goods good : goods) {
|
||||
if (good.getId().equals(goodsId)) {
|
||||
BigDecimal price = good.getPrice().multiply(new BigDecimal(userGoods.getNum()));
|
||||
checkTotalPrice = checkTotalPrice.add(price);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CartVo cartVo = new CartVo();
|
||||
cartVo.setGoodsList(goods);
|
||||
cartVo.setTotalPrice(totalPrice);
|
||||
cartVo.setCheckTotalPrice(checkTotalPrice);
|
||||
return cartVo;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer num = 3;
|
||||
BigDecimal price = new BigDecimal(10.00);
|
||||
BigDecimal result = price.multiply(new BigDecimal(num));
|
||||
System.out.println("result = " + result);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -16,15 +16,15 @@ import com.wyh.common.mapper.user.UserAuthMapper;
|
|||
import com.wyh.common.mapper.user.UserMapper;
|
||||
import com.wyh.common.plugin.notice.NoticeCheck;
|
||||
import com.wyh.common.plugin.wechat.WxMnpDriver;
|
||||
import com.wyh.common.util.*;
|
||||
import com.wyh.front.ZJFrontThreadLocal;
|
||||
import com.wyh.front.service.IUserService;
|
||||
import com.wyh.front.vo.user.UserCenterVo;
|
||||
import com.wyh.front.vo.user.UserInfoVo;
|
||||
import com.wyh.common.util.*;
|
||||
import com.wyh.front.validate.users.NewUserUpdateValidate;
|
||||
import com.wyh.front.validate.users.UserBindWechatValidate;
|
||||
import com.wyh.front.validate.users.UserPhoneBindValidate;
|
||||
import com.wyh.front.validate.users.UserUpdateValidate;
|
||||
import com.wyh.front.vo.user.UserCenterVo;
|
||||
import com.wyh.front.vo.user.UserInfoVo;
|
||||
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.wyh.front.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AccessTokenVo {
|
||||
|
||||
private String access_token;
|
||||
private String expires_in;
|
||||
}
|
||||
|
|
@ -12,17 +12,17 @@ spring:
|
|||
username: root # 数据库账号
|
||||
password: ifpdge9z # 数据库密码
|
||||
# Redis配置
|
||||
redis:
|
||||
host: 101.133.172.2 # Redis服务地址
|
||||
port: 2007 # Redis端口
|
||||
password: 123456 # Redis密码
|
||||
database: 14 # 数据库索引
|
||||
|
||||
# redis:
|
||||
# host: 127.0.0.1 # Redis服务地址
|
||||
# port: 6379 # Redis端口
|
||||
# host: 101.133.172.2 # Redis服务地址
|
||||
# port: 2007 # Redis端口
|
||||
# password: 123456 # Redis密码
|
||||
# database: 11
|
||||
# database: 14 # 数据库索引
|
||||
|
||||
redis:
|
||||
host: 127.0.0.1 # Redis服务地址
|
||||
port: 6379 # Redis端口
|
||||
password: 123456 # Redis密码
|
||||
database: 11
|
||||
# Mybatis-plus配置 【是否开启SQL日志输出】
|
||||
#mybatis-plus:
|
||||
# configuration:
|
||||
|
|
|
|||
|
|
@ -60,6 +60,16 @@
|
|||
<!-- 依赖声明 -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.75</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.mrzin</groupId>
|
||||
<artifactId>tool-wx</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.stuxuhai</groupId>
|
||||
<artifactId>jpinyin</artifactId>
|
||||
|
|
|
|||
|
|
@ -25,3 +25,10 @@ export function getProtocol() {
|
|||
export function setProtocol(params: any) {
|
||||
return request.post({ url: '/setting/protocol/save', params })
|
||||
}
|
||||
// 获取政策协议
|
||||
export function getProtocolDetail() {
|
||||
return request.get({ url: '/setting/protocol/getDetail' })
|
||||
}
|
||||
export function saveDeatil(params: any) {
|
||||
return request.post({ url: '/setting/protocol/saveDeatil', params })
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
<template>
|
||||
<div class="xl:flex">
|
||||
<el-card class="!border-none flex-1 xl:mr-4 mb-4" shadow="never">
|
||||
<template #header>
|
||||
<span class="font-medium">租借条约</span>
|
||||
</template>
|
||||
<el-form :model="formData" label-width="80px">
|
||||
<el-form-item label="协议名称">
|
||||
<el-input v-model="formData.lease.name" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<editor class="mb-10" v-model="formData.lease.content" height="500"></editor>
|
||||
</el-card>
|
||||
<el-card class="!border-none flex-1 xl:mr-4 mb-4" shadow="never">
|
||||
<template #header>
|
||||
<span class="font-medium">积分规则</span>
|
||||
</template>
|
||||
<el-form :model="formData" label-width="80px">
|
||||
<el-form-item label="协议名称">
|
||||
<el-input v-model="formData.integrate.name" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<editor class="mb-10" v-model="formData.integrate.content" height="500"></editor>
|
||||
</el-card>
|
||||
|
||||
<el-card class="!border-none flex-1 xl:mr-4 mb-4" shadow="never">
|
||||
<template #header>
|
||||
<span class="font-medium">帮助中心</span>
|
||||
</template>
|
||||
<el-form :model="formData" label-width="80px">
|
||||
<el-form-item label="协议名称">
|
||||
<el-input v-model="formData.helpcenter.name" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<editor class="mb-10" v-model="formData.helpcenter.content" height="500"></editor>
|
||||
</el-card>
|
||||
</div>
|
||||
<footer-btns v-perms="['setting:protocol:save']">
|
||||
<el-button type="primary" @click="handelSave">保存</el-button>
|
||||
</footer-btns>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" naem="webProtocol">
|
||||
import { getProtocolDetail , saveDeatil } from '@/api/setting/website'
|
||||
import feedback from "@/utils/feedback";
|
||||
|
||||
const formData = ref({
|
||||
lease: {
|
||||
content: '',
|
||||
name: ''
|
||||
},
|
||||
integrate: {
|
||||
content: '',
|
||||
name: ''
|
||||
},
|
||||
helpcenter: {
|
||||
content: '',
|
||||
name: ''
|
||||
}
|
||||
})
|
||||
const getpro = async () => {
|
||||
formData.value = await getProtocolDetail()
|
||||
}
|
||||
const handelSave = async () => {
|
||||
await saveDeatil(formData.value)
|
||||
feedback.msgSuccess('操作成功')
|
||||
getProtocolDetail()
|
||||
}
|
||||
getpro()
|
||||
</script>
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
<material-picker size="300px" v-model="formData.goodsImg" />
|
||||
</el-form-item>
|
||||
<el-form-item label="产品列表图" prop="goodsListImg">
|
||||
<material-picker size="300px" v-model="formData.goodsListImg" />
|
||||
<material-picker size="300px" v-model="formData.goodsListImg" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort">
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<div class="xl:flex">
|
||||
<el-card class="!border-none flex-1 xl:mr-4 mb-4" shadow="never">
|
||||
<template #header>
|
||||
<span class="font-medium">服务协议</span>
|
||||
<span class="font-medium">用户协议</span>
|
||||
</template>
|
||||
<el-form :model="formData" label-width="80px">
|
||||
<el-form-item label="协议名称">
|
||||
|
|
|
|||
Loading…
Reference in New Issue