类型接口开发
This commit is contained in:
parent
237002d479
commit
10e324a89b
|
|
@ -11,6 +11,7 @@ import com.github.pagehelper.PageInfo;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
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.RestController;
|
||||
|
||||
|
|
@ -38,6 +39,36 @@ public class PaTypeController {
|
|||
return service.getTypeList(dto.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* X详情接口
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("addTypeData")
|
||||
@DecryptAndVerify(decryptedClass = PaTypeVo.class)
|
||||
public ServerResponse addTypeData(EncryptedReq<PaTypeVo> dto) {
|
||||
return service.addTypeData(dto.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* X详情接口
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("updateTypeData")
|
||||
@DecryptAndVerify(decryptedClass = PaTypeVo.class)
|
||||
public ServerResponse updateTypeData(EncryptedReq<PaTypeVo> dto) {
|
||||
return service.updateTypeData(dto.getData());
|
||||
}
|
||||
/**
|
||||
* X详情接口
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("deleteTypeData")
|
||||
@DecryptAndVerify(decryptedClass = PaTypeVo.class)
|
||||
public ServerResponse deleteTypeData(EncryptedReq<PaTypeVo> dto) {
|
||||
return service.deleteTypeData(dto.getData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class PaTypeVo {
|
|||
/**
|
||||
* 父id
|
||||
*/
|
||||
private int pId;
|
||||
private int parentId;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
|
|
@ -21,7 +21,7 @@ public class PaTypeVo {
|
|||
/**
|
||||
* 等级
|
||||
*/
|
||||
private String level;
|
||||
private int level;
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
|
|
@ -44,4 +44,10 @@ public class PaTypeVo {
|
|||
*/
|
||||
private String isActive;
|
||||
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remarks;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.bonus.gzgqj.business.bases.mapper;
|
||||
|
||||
import com.bonus.gzgqj.business.bases.entity.PaTypeVo;
|
||||
import io.lettuce.core.dynamic.annotation.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -18,4 +19,36 @@ public interface PaTypeMapper {
|
|||
* @return
|
||||
*/
|
||||
List<PaTypeVo> getTypeList(PaTypeVo data);
|
||||
|
||||
/**
|
||||
* 查询上级节点
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
PaTypeVo getTypeDetails(@Param("id") int id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
int addTypeData(PaTypeVo data);
|
||||
|
||||
int updateTypeData(PaTypeVo data);
|
||||
|
||||
List<String> getChildList(@Param("id")int id);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
int deleteTypeData(PaTypeVo data);
|
||||
|
||||
/**
|
||||
* 依据名称查询 数量
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
int getActByName(PaTypeVo data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,25 @@ public interface PaTypeService {
|
|||
* @return
|
||||
*/
|
||||
ServerResponse getTypeList(PaTypeVo data);
|
||||
|
||||
/**
|
||||
* 新增类型
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
ServerResponse addTypeData(PaTypeVo data);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
ServerResponse updateTypeData(PaTypeVo data);
|
||||
|
||||
/**
|
||||
* 删除 数据类型
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
ServerResponse deleteTypeData(PaTypeVo data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,10 +29,120 @@ public class PaTypeServiceImpl implements PaTypeService{
|
|||
public ServerResponse getTypeList(PaTypeVo data) {
|
||||
List<PaTypeVo> list=new ArrayList<>();
|
||||
try{
|
||||
list=mapper.getTypeList(data);
|
||||
PaTypeVo vo=new PaTypeVo();
|
||||
vo.setLevel(0);
|
||||
vo.setId(-1);
|
||||
vo.setParentId(-2);
|
||||
vo.setName("配件类型列表");
|
||||
list=mapper.getTypeList(data);
|
||||
list.add(vo);
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return ServerResponse.createSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据类型
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ServerResponse addTypeData(PaTypeVo data) {
|
||||
try{
|
||||
int pId=data.getParentId();
|
||||
if (pId==-1){
|
||||
data.setLevel(1);
|
||||
data.setParentId(0);
|
||||
}else{
|
||||
PaTypeVo vo=mapper.getTypeDetails(data.getParentId());
|
||||
if(vo==null || vo.getId()==0){
|
||||
return ServerResponse.createErroe("数据节点不存在");
|
||||
}else {
|
||||
int level=vo.getLevel();
|
||||
if(level>=3){
|
||||
return ServerResponse.createErroe("该节点不允许添加数据");
|
||||
}else{
|
||||
level=level+1;
|
||||
}
|
||||
data.setLevel(level);
|
||||
}
|
||||
int nums=mapper.getActByName(data);
|
||||
if(nums>0){
|
||||
return ServerResponse.createErroe("该节点名称已存在");
|
||||
}else{
|
||||
int num= mapper.addTypeData(data);
|
||||
if(num>0){
|
||||
return ServerResponse.createSuccess("添加成功");
|
||||
}else{
|
||||
return ServerResponse.createErroe("添加失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return ServerResponse.createErroe("添加失败,请联系管理员!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ServerResponse updateTypeData(PaTypeVo data) {
|
||||
try{
|
||||
int id=data.getId();
|
||||
if(id>0){
|
||||
int num=mapper.getActByName(data);
|
||||
if(num>0){
|
||||
return ServerResponse.createErroe("该节点名称已存在");
|
||||
}else{
|
||||
int nums=mapper.updateTypeData(data);
|
||||
if(nums>0){
|
||||
return ServerResponse.createSuccess("修改成功");
|
||||
}else{
|
||||
return ServerResponse.createErroe("修改失败");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return ServerResponse.createErroe("该数据不允许修改");
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return ServerResponse.createErroe("修改失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data 删除
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ServerResponse deleteTypeData(PaTypeVo data) {
|
||||
try{
|
||||
int id=data.getId();
|
||||
if(id>0){
|
||||
List<String> idList=mapper.getChildList(data.getId());
|
||||
if(idList!=null && !idList.isEmpty()){
|
||||
int num= mapper.deleteTypeData(data);
|
||||
if(num>0){
|
||||
return ServerResponse.createSuccess("删除成功");
|
||||
}else{
|
||||
return ServerResponse.createErroe("删除失败!");
|
||||
}
|
||||
}else {
|
||||
return ServerResponse.createErroe("请先删除子节点!");
|
||||
}
|
||||
}else{
|
||||
return ServerResponse.createErroe("请选择要删除的数据");
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return ServerResponse.createErroe("修改失败");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.bonus.gzgqj.business.bases.mapper.PaTypeMapper" >
|
||||
<!--新增类型-->
|
||||
<insert id="addTypeData">
|
||||
insert into pa_type(parent_id, name,remarks,is_active,level)VALUES(#{pId},#{name},#{remarks},1,#{level})
|
||||
</insert>
|
||||
<update id="updateTypeData">
|
||||
update pa_type set name=#{name},remarks=#{remarks} where id=#{id}
|
||||
</update>
|
||||
<update id="deleteTypeData">
|
||||
update pa_type set is_active=0 where id=#{id}
|
||||
</update>
|
||||
<select id="getTypeList" resultType="com.bonus.gzgqj.business.bases.entity.PaTypeVo">
|
||||
select id,parent_id parentId,name,num,
|
||||
price,unit,weight,is_consumables ,
|
||||
remarks,is_active ,level,warn_num
|
||||
FROM pa_type
|
||||
WHERE is_active=1
|
||||
</select>
|
||||
<select id="getTypeDetails" resultType="com.bonus.gzgqj.business.bases.entity.PaTypeVo">
|
||||
select id,parent_id pId,name,num,
|
||||
price,unit,weight,is_consumables ,
|
||||
remarks,is_active ,level,warn_num
|
||||
FROM pa_type
|
||||
WHERE is_active=1 and id=#{id}
|
||||
</select>
|
||||
<select id="getChildList" resultType="java.lang.String">
|
||||
select id
|
||||
FROM pa_type
|
||||
WHERE is_active=1 and parent_id=#{id}
|
||||
</select>
|
||||
|
||||
<select id="getActByName" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
FROM pa_type
|
||||
WHERE is_active=1 AND name=#{name}
|
||||
<if test="id!=0">
|
||||
and id!=#{id}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue