Browse Source

修复新增分类的bug

master
xyiege 4 years ago
parent
commit
bb7b3909e4
  1. 7
      src/main/java/cn/chjyj/szwh/mapper/ClassifyMapper.java
  2. 50
      src/main/java/cn/chjyj/szwh/service/impl/ClassifyServiceImpl.java
  3. 6
      src/main/resources/mapper/szwh/ClassifyMapper.xml

7
src/main/java/cn/chjyj/szwh/mapper/ClassifyMapper.java

@ -69,4 +69,11 @@ public interface ClassifyMapper {
* @return
*/
int addClassify(Classify classify);
/**
* 查询获取单类目
* @param tpname
* @return
*/
Classify getClassify(String tpname);
}

50
src/main/java/cn/chjyj/szwh/service/impl/ClassifyServiceImpl.java

@ -113,35 +113,43 @@ public class ClassifyServiceImpl implements ClassifyService {
@Override
public int addNewClass(String pullTopclass, String topClass, String sonClass,Integer userid,String uname) {
int ret=0;
Classify classify = new Classify();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date crt = sdf.parse(sdf.format(System.currentTimeMillis()));
classify.setCreatetime(crt);
// 该段代码由php 转来,完全搞不懂为啥要加这个判断
String newTopClass=topClass;
if(StringUtils.isNotEmpty(pullTopclass)){
newTopClass=pullTopclass;
}
int ret=0; //执行返回结果
Date nowdate = new Date();
//类目class
Classify classify = new Classify();
classify.setSonClass(sonClass);
classify.setUserId(userid);
classify.setCreatetime(nowdate);
classify.setIsDeleted(0);
classify.setStatus(0);
//保存操作记录
OperationLog oplog = new OperationLog();
oplog.setType("class");
String msg =sdf.format(nowdate)+"由"+uname+"创建";
oplog.setMessage(msg);
if(StringUtils.isNotBlank(pullTopclass)){
classify.setTopClass(pullTopclass);
classify.setSonClass(sonClass);
classify.setUserId(userid);
ret = classifyMapper.addClassify(classify);
//保存操作记录
OperationLog oplog = new OperationLog();
// ID 为返回的自编号
oplog.setLogid(classify.getId());
oplog.setType("class");
String msg ="由"+uname+"创建";
oplog.setMessage(msg);
operationLogMapper.addLog(oplog);
}catch (Exception ex){
log.error(ex);
}
// 查找类目
Classify clsfy= classifyMapper.getClassify(topClass);
if(clsfy!=null){
classify.setTopClass(topClass);
ret = classifyMapper.addClassify(classify);
oplog.setLogid(clsfy.getId());
operationLogMapper.addLog(oplog);
}else{
classify.setTopClass(topClass);
ret = classifyMapper.addClassify(classify);
oplog.setLogid(classify.getId());
operationLogMapper.addLog(oplog);
}
return ret;
}

6
src/main/resources/mapper/szwh/ClassifyMapper.xml

@ -45,6 +45,12 @@
where ${strwhere}
</select>
<select id="getClassify" resultType="cn.chjyj.szwh.bean.Classify">
select <include refid="column"/>
from <include refid="tbName"/>
where is_deleted=0 and top_class=#{tpname}
</select>
<!-- 查找顶级分类 -->
<select id="getTop" resultType="java.lang.String">
select distinct top_class

Loading…
Cancel
Save