Browse Source

修改商品详情入库引起的故障

master
xyiege 3 years ago
parent
commit
4a9fe74652
  1. 8
      src/main/java/cn/chjyj/szwh/bean/GoodsDetail.java
  2. 176
      src/main/java/cn/chjyj/szwh/controller/QuartzController.java
  3. 2
      src/main/java/cn/chjyj/szwh/mapper/GoodsDetailMapper.java
  4. 2
      src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java
  5. 31
      src/main/java/cn/chjyj/szwh/utils/ApiGoodsUtils.java
  6. 2
      src/main/resources/application.properties
  7. 22
      src/main/resources/mapper/szwh/GoodsDetailMapper.xml
  8. 13
      src/test/java/cn/chjyj/szwh/ApiTest.java
  9. 7
      src/test/java/cn/chjyj/szwh/mapper/GoodsDetailMapperTest.java

8
src/main/java/cn/chjyj/szwh/bean/GoodsDetail.java

@ -44,7 +44,7 @@ public class GoodsDetail {
private Date createtime;//创建时间
private Date updatetime;//修改时间
private Integer isDeleted;//删除状态;0:未删除;1:已删除
private Boolean isJoin;
private Integer isJoin;
public Integer getId() {
return id;
@ -286,11 +286,11 @@ public class GoodsDetail {
this.isDeleted = isDeleted;
}
public Boolean getJoin() {
public Integer getIsJoin() {
return isJoin;
}
public void setJoin(Boolean join) {
isJoin = join;
public void setIsJoin(Integer isJoin) {
this.isJoin = isJoin;
}
}

176
src/main/java/cn/chjyj/szwh/controller/QuartzController.java

@ -1,176 +0,0 @@
package cn.chjyj.szwh.controller;
import cn.chjyj.szwh.dto.JobAndTriggerDto;
import cn.chjyj.szwh.service.QuartzService;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.Map;
import org.quartz.SchedulerException;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
/**
* @Author: CJ
* @Date: 2021-11-2 11:41
*/
@RestController
@RequestMapping(path = "/quartz")
public class QuartzController {
@Autowired
private QuartzService quartzService;
/**
* 新增定时任务
*
* @param jName 任务名称
* @param jGroup 任务组
* @param tName 触发器名称
* @param tGroup 触发器组
* @param cron cron表达式
* @return ResultMap
*/
@PostMapping(path = "/addjob")
@ResponseBody
public JSONObject addjob(String jName, String jGroup, String tName, String tGroup, String cron) {
JSONObject jsonObject = new JSONObject();
try {
quartzService.addjob(jName, jGroup, tName, tGroup, cron);
jsonObject.put("code",200);
jsonObject.put("msg","添加任务成功");
} catch (Exception e) {
e.printStackTrace();
jsonObject.put("code",400);
jsonObject.put("msg","添加任务失败");
}
return jsonObject;
}
/**
* 暂停任务
*
* @param jName 任务名称
* @param jGroup 任务组
* @return ResultMap
*/
@PostMapping(path = "/pausejob")
@ResponseBody
public JSONObject pausejob(String jName, String jGroup) {
JSONObject jsonObject = new JSONObject();
try {
quartzService.pausejob(jName, jGroup);
jsonObject.put("code",200);
jsonObject.put("msg","暂停任务成功");
} catch (SchedulerException e) {
e.printStackTrace();
jsonObject.put("code",200);
jsonObject.put("msg","暂停任务失败");
}
return jsonObject;
}
/**
* 恢复任务
*
* @param jName 任务名称
* @param jGroup 任务组
* @return ResultMap
*/
@PostMapping(path = "/resumejob")
@ResponseBody
public JSONObject resumejob(String jName, String jGroup) {
JSONObject jsonObject = new JSONObject();
try {
quartzService.resumejob(jName, jGroup);
jsonObject.put("code",200);
jsonObject.put("msg","恢复任务成功");
} catch (SchedulerException e) {
e.printStackTrace();
jsonObject.put("code",400);
jsonObject.put("msg","恢复任务失败");
}
return jsonObject;
}
/**
* 重启任务
*
* @param jName 任务名称
* @param jGroup 任务组
* @param cron cron表达式
* @return ResultMap
*/
@PostMapping(path = "/reschedulejob")
@ResponseBody
public JSONObject rescheduleJob(String jName, String jGroup, String cron) {
JSONObject jsonObject =new JSONObject();
try {
quartzService.rescheduleJob(jName, jGroup, cron);
jsonObject.put("code",200);
jsonObject.put("msg","重启任务成功");
} catch (SchedulerException e) {
e.printStackTrace();
jsonObject.put("code",400);
jsonObject.put("msg","重启任务失败");
}
return jsonObject;
}
/**
* 删除任务
*
* @param jName 任务名称
* @param jGroup 任务组
* @return ResultMap
*/
@PostMapping(path = "/deletejob")
@ResponseBody
public JSONObject deletejob(String jName, String jGroup) {
JSONObject jsonObject = new JSONObject();
try {
quartzService.deletejob(jName, jGroup);
jsonObject.put("code",200);
jsonObject.put("msg","删除任务成功");
} catch (SchedulerException e) {
e.printStackTrace();
jsonObject.put("code",400);
jsonObject.put("msg","删除任务失败");
}
return jsonObject;
}
/**
* 查询任务
*
* @param pageNum 页码
* @param pageSize 每页显示多少条数据
* @return Map
*/
@GetMapping(path = "/queryjob")
@ResponseBody
public JSONObject queryjob(Integer pageNum, Integer pageSize) {
JSONObject jsonObject = new JSONObject();
PageInfo<JobAndTriggerDto> pageInfo = quartzService.getJobAndTriggerDetails(pageNum, pageSize);
Map<String, Object> map = new HashMap<>();
if (pageInfo!=null) {
map.put("JobAndTrigger", pageInfo);
map.put("number", pageInfo.getTotal());
jsonObject.put("code",200);
jsonObject.put("msg","查询任务成功");
jsonObject.put("data",map);
}else{
jsonObject.put("code",400);
jsonObject.put("msg","查询任务成功失败,没有数据");
}
return jsonObject;
}
}

2
src/main/java/cn/chjyj/szwh/mapper/GoodsDetailMapper.java

@ -36,5 +36,5 @@ public interface GoodsDetailMapper {
* @param goodsDetail
* @return
*/
int add(GoodsDetail goodsDetail);
int addGoodsDetail(GoodsDetail goodsDetail);
}

2
src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java

@ -126,7 +126,7 @@ public class GoodsServiceImpl implements GoodsService {
// insertGoodsDetail
GoodsDetail goodsDetail = ApiGoodsUtils.jsonToGoodsDetail(nsdjson, sdjson);
// 返回商品详情
int gdid = goodsDetailMapper.add(goodsDetail);
int gdid = goodsDetailMapper.addGoodsDetail(goodsDetail);
//抽取target 字段中的json,转为jsonobject
JSONObject targetJson = nsdjson.getJSONObject("targetData");

31
src/main/java/cn/chjyj/szwh/utils/ApiGoodsUtils.java

@ -75,6 +75,7 @@ public class ApiGoodsUtils {
* @return
*/
public static GoodsDetail jsonToGoodsDetail(JSONObject json,JSONObject nodejson){
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 抽取出sourcedata
String sprice = json.getString("price");
//删除价格中的letter
@ -101,9 +102,13 @@ public class ApiGoodsUtils {
goodsDetail.setTransactionClass(istclass);
// 交易类型
String transactionType = json.getString("transactionType");
//标的商品的分类
String jclassification=" ";
if(istclass==1){
goodsDetail.setIdentifier(json.getString("identifier"));
goodsDetail.setIdentifiers(json.getString("identifiers"));
// 商品所有权
goodsDetail.setGoodsOwnership(0);
goodsDetail.setGoodsOwnershipStr(json.getString("rights"));
// 判断交易类型
int itranstype = "授权".equals(transactionType)?2:1;
@ -115,19 +120,41 @@ public class ApiGoodsUtils {
}
}else{
goodsDetail.setIdentifier(json.getString("identifier"));
goodsDetail.setClassification(json.getString("classification"));
jclassification =json.getString("classification");
//类型
int irate = "租赁".equalsIgnoreCase(transactionType)?3:4;
goodsDetail.setGoodsEntrust(irate);
goodsDetail.setStock(1);
}
goodsDetail.setClassification(jclassification);
// 商品资源标识码
String csourceIslicode =" ";
goodsDetail.setSourceIslicode(csourceIslicode);
goodsDetail.setSourceIslicodeName(" ");
goodsDetail.setSourceUrl(" ");
goodsDetail.setSourceStatus(0);
// 商品描述
goodsDetail.setContract(json.getString("description"));
String contract =StringUtils.isEmpty(json.getString("description"))?"[]":json.getString("description");
goodsDetail.setContract(contract);
//其他属性
String otherIdentifiers = StringUtils.isEmpty(json.getString("otherIdentifiers"))?"[]":json.getString("otherIdentifiers");
goodsDetail.setOtherIdentifiers(otherIdentifiers);
//商品保证金
goodsDetail.setEarnestMoney(new BigDecimal(0.00));
//
goodsDetail.setDataJson(nodejson.toJSONString());
goodsDetail.setSourceJson(json.toJSONString());
String sdate= json.getString("releaseTime");
try {
Date createTime = sdf.parse(sdate);
goodsDetail.setCreatetime(createTime);
goodsDetail.setUpdatetime(createTime);
}catch (Exception ex){
//do nothing
}
//其他状态
goodsDetail.setIsDeleted(0);
goodsDetail.setIsJoin(0);
//处理授权周期
String contractualPeriod =json.getString("contractualPeriod");
int iperiod = 0; //授权周期

2
src/main/resources/application.properties

@ -6,7 +6,7 @@ logging.path=./logs/
server.port=9090
# 服务请求上下文
#server.servlet.context-path=/chapi
mybatis.mapper-locations=classpath*:/mapper/**/*.xml
mybatis.mapper-locations=classpath*:/mapper/szwh/*.xml
#指定redis信息 (如 host, ip, password)
spring.redis.host=localhost

22
src/main/resources/mapper/szwh/GoodsDetailMapper.xml

@ -13,12 +13,11 @@
source_islicode_name as sourceIslicodeName,source_url as sourceUrl,source_status as sourceStatus,
data_json as dataJson,source_json as sourceJson,join_field as joinField,
sourcedata_islicode as sourcedataIslicode,createtime,updatetime,is_deleted as isDeleted,is_join as isJoin
</sql>
<sql id="tbName">goods_detail</sql>
<!--查询记录列表-->
<select id="getGoodsList" parameterType="java.lang.Integer" resultType="cn.chjyj.szwh.bean.Goods">
<select id="getGoodsList" parameterType="java.lang.Integer" resultType="cn.chjyj.szwh.bean.GoodsDetail">
WITH mm as (select * from
<include refid="tbName"/>
where id>#{startRs} limit #{pageSize}
@ -57,15 +56,8 @@
AND goods.goods_islicode=#{islicode}
</select>
<!--查询用户-->
<select id="getSingleUserByOpenid" parameterType="java.lang.String" resultType="cn.chjyj.szwh.bean.Goods">
select <include refid="column"/> from
<include refid="tbName"/>
where openid=#{openid};
</select>
<!--新增用户-->
<insert id="add" parameterType="cn.chjyj.szwh.bean.GoodsDetail" useGeneratedKeys="true" keyColumn="id">
<!--新增商品详情-->
<insert id="addGoodsDetail" parameterType="cn.chjyj.szwh.bean.GoodsDetail" useGeneratedKeys="true" keyColumn="id">
insert into <include refid="tbName"/>
(goods_name,goods_image,identifier,identifiers,stock,price,goods_ownership,
goods_ownership_str,goods_type,
@ -73,7 +65,7 @@
contractual_period ,earnest_money ,transaction_class,contract,
otherIdentifiers,classification,source_islicode,
source_islicode_name ,source_url ,source_status ,
data_json,source_json ,join_field ,
data_json,source_json,join_field,
sourcedata_islicode ,createtime,updatetime,is_deleted,is_join)
values (
#{goodsName},
@ -89,6 +81,7 @@
#{goodsIslicode},
#{goodsEntrust},
#{contractualPeriod},
#{earnestMoney},
#{transactionClass},
#{contract},
#{otherIdentifiers},
@ -101,7 +94,10 @@
#{sourceJson},
#{joinField},
#{sourcedataIslicode},
0,0
#{createtime},
#{updatetime},
#{isDeleted},
#{isJoin}
)
</insert>

13
src/test/java/cn/chjyj/szwh/ApiTest.java

@ -2,19 +2,28 @@ package cn.chjyj.szwh;
import cn.chjyj.szwh.bean.GoodsDetail;
import cn.chjyj.szwh.bean.GoodsSource;
import cn.chjyj.szwh.mapper.GoodsDetailMapper;
import cn.chjyj.szwh.utils.*;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.CacheAwareContextLoaderDelegate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
@SpringBootTest
@RunWith(SpringRunner.class)
public class ApiTest {
@Autowired
private GoodsDetailMapper goodsDetailMapper;
@Test
public void apigoods(){
// 返回来的结果
@ -123,6 +132,10 @@ public class ApiTest {
// 商品详情
GoodsDetail goodsDetail = ApiGoodsUtils.jsonToGoodsDetail(nsdjson, sdjson);
System.out.println(goodsDetail.getGoodsName());
int gdid = goodsDetailMapper.addGoodsDetail(goodsDetail);
System.out.println(gdid);
//商品信息
}

7
src/test/java/cn/chjyj/szwh/mapper/GoodsDetailMapperTest.java

@ -35,4 +35,11 @@ public class GoodsDetailMapperTest {
//
goodsDetailMapper.updateGoodsDetail(goodsDetail);
}
@Test
public void AddTest(){
GoodsDetail goodsDetail = new GoodsDetail();
goodsDetail.setGoodsImage("ss.tds");
goodsDetailMapper.addGoodsDetail(goodsDetail);
}
}
Loading…
Cancel
Save