Merge branch 'master' of gitee.com:darlk/ShengTangManage into xzj

This commit is contained in:
德仔
2021-02-04 21:16:35 +08:00
committed by Gitee
9 changed files with 410 additions and 354 deletions

View File

@ -1,5 +1,6 @@
package com.stdiet.custom.domain;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@ -11,6 +12,7 @@ import java.math.BigDecimal;
* @author wonder
* @date 2020-12-28
*/
@Data
public class SysDishesIngredient extends SysIngredient {
private Long ingredientId;
@ -21,68 +23,10 @@ public class SysDishesIngredient extends SysIngredient {
private BigDecimal cusWeight;
private Integer cusWei;
private BigDecimal weight;
private String remark;
@Override
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String getRemark() {
return remark;
}
public Long getIngredientId() {
return ingredientId;
}
public void setIngredientId(Long ingredientId) {
this.ingredientId = ingredientId;
}
public Long getDishesId() {
return dishesId;
}
public void setDishesId(Long dishesId) {
this.dishesId = dishesId;
}
public BigDecimal getWeight() {
return weight;
}
public void setWeight(BigDecimal weight) {
this.weight = weight;
}
public BigDecimal getCusWeight() {
return cusWeight;
}
public void setCusWeight(BigDecimal cusWeight) {
this.cusWeight = cusWeight;
}
public Long getCusUnit() {
return cusUnit;
}
public void setCusUnit(Long cusUnit) {
this.cusUnit = cusUnit;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("ingredientId", getIngredientId())
.append("dishesId", getDishesId())
.append("weight", getWeight())
.append("cusWeight", getCusWeight())
.append("cusUnit", getCusUnit())
.toString();
}
}

View File

@ -1,7 +1,6 @@
package com.stdiet.custom.utils;
import com.alibaba.fastjson.JSONObject;
import com.stdiet.common.core.redis.RedisCache;
import com.stdiet.common.utils.StringUtils;
import com.stdiet.common.utils.http.HttpUtils;
import com.stdiet.custom.domain.WxXmlData;
@ -9,28 +8,30 @@ import com.stdiet.custom.domain.wechat.WxAccessToken;
import com.stdiet.custom.domain.wechat.WxFileUploadResult;
import com.thoughtworks.xstream.XStream;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.File;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class WxTokenUtils {
public static final String KEY_ACCESS_TOKEN="wx:access_token";
public static final String KEY_ACCESS_TOKEN_WATHER="wx:access_token_watcher";
public static final String KEY_ACCESS_TOKEN = "wx:access_token";
public static final String KEY_ACCESS_TOKEN_WATHER = "wx:access_token_watcher";
// 与接口配置信息中的Token要一致
private static String token = "shengtangdiet";
// private static String appId = "wx4a9c1fc9dba53202";
// private static String appSecret = "fff029ade5d3575df755f4cf9e52f8da";
private static String appId = "wxaf10fe560ea043a0";
private static String appSecret = "afb47e477337df23b7562c3c1f965826";
// 胜唐体控
private static String appId = "wx4a9c1fc9dba53202";
private static String appSecret = "fff029ade5d3575df755f4cf9e52f8da";
// 胜唐体控李晓
// private static String appId = "wxaf10fe560ea043a0";
// private static String appSecret = "afb47e477337df23b7562c3c1f965826";
private static String tokenUrl = "https://api.weixin.qq.com/cgi-bin/token";
private static String uploadMaterialUrl = "https://api.weixin.qq.com/cgi-bin/material/add_material";
private static String uploadMaterialUrl = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN&type=image";
public static WxAccessToken fetchAccessToken() {
@ -48,18 +49,28 @@ public class WxTokenUtils {
}
}
public static WxFileUploadResult uploadImage(String filePath, String accessToken) {
try {
String url = uploadMaterialUrl + "?access_token" + accessToken + "&type=image";
HttpPostUtil post = new HttpPostUtil(url);
post.addParameter("media", new File(filePath));
String resultStr = post.send();
JSONObject obj = JSONObject.parseObject(resultStr);
WxFileUploadResult result = JSONObject.toJavaObject(obj, WxFileUploadResult.class);
return result;
} catch (Exception e) {
return null;
/**
* 模拟form表单的形式 ,上传文件 以输出流的形式把文件写入到url中然后用输入流来获取url的响应
*
* @return String url的响应信息返回值
* @throws IOException
*/
public static WxFileUploadResult uploadImage(String filePath, String fileName, String accessToken) throws Exception {
String[] cmds = {"curl", uploadMaterialUrl.replaceAll("ACCESS_TOKEN", accessToken), "-F"
, "media=@" + filePath + ";filename=" + fileName};//必须分开写,不能有空格
ProcessBuilder process = new ProcessBuilder(cmds);
Process p = process.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
JSONObject obj = JSONObject.parseObject(builder.toString());
return JSONObject.toJavaObject(obj, WxFileUploadResult.class);
}
/**

View File

@ -28,6 +28,7 @@
<result property="rec" column="rec" />
<result property="notRec" column="not_rec" />
<result property="cusWeight" column="cus_weight" />
<result property="cusWei" column="cus_wei" />
<result property="cusUnit" column="cus_unit" />
<result property="weight" column="weight" />
</resultMap>
@ -48,7 +49,7 @@
<sql id="selectSysIngreditentsByIdVo">
SELECT * FROM(
SELECT ingredient_id AS id, ingredient_weight AS weight, cus_weight, cus_unit, remark
SELECT ingredient_id AS id, ingredient_weight AS weight, cus_weight, cus_wei, cus_unit, remark
FROM sys_dishes_ingredient
WHERE dishes_id = #{id}
) dishes
@ -148,9 +149,9 @@
</delete>
<insert id="bashInsertDishesIngredent">
insert into sys_dishes_ingredient(dishes_id, ingredient_id, ingredient_weight, cus_unit, cus_weight, remark) values
insert into sys_dishes_ingredient(dishes_id, ingredient_id, ingredient_weight, cus_unit, cus_wei, remark) values
<foreach collection="list" separator="," item="item" index="index">
(#{item.dishesId}, #{item.ingredientId}, #{item.weight}, #{item.cusUnit}, #{item.cusWeight}, #{item.remark})
(#{item.dishesId}, #{item.ingredientId}, #{item.weight}, #{item.cusUnit}, #{item.cusWei}, #{item.remark})
</foreach>
</insert>