Commit 69f45679 by rongkailun

【新增】商品分类新增修改删除

parent 34c05225
package io.office.modules.manage.controller;
import java.util.Arrays;
import java.util.Map;
import io.office.modules.sys.controller.AbstractController;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.office.modules.manage.entity.PcategoryEntity;
import io.office.modules.manage.service.PcategoryService;
import io.office.common.utils.PageUtils;
import io.office.common.utils.R;
/**
* 商品分类
*
* @author rkl
* @email
* @date 2021-11-13 22:13:03
*/
@RestController
@RequestMapping("/pcategory")
@Slf4j
public class PcategoryController extends AbstractController {
@Autowired
private PcategoryService pcategoryService;
/**
* 列表
*/
@RequestMapping("/list")
// @RequiresPermissions("manage:pcategory:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = pcategoryService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 信息
*/
@RequestMapping("/info/{categoryid}")
// @RequiresPermissions("manage:pcategory:info")
public R info(@PathVariable("categoryid") Integer categoryid){
PcategoryEntity pcategory = pcategoryService.getById(categoryid);
return R.ok().put("pcategory", pcategory);
}
/**
* 保存
*/
@RequestMapping("/save")
// @RequiresPermissions("manage:pcategory:save")
public R save(@RequestBody PcategoryEntity pcategory){
try {
R r = this.pcategoryService.insertPcategory(pcategory, getUser());
return r;
} catch (Exception e) {
log.error("save error:", e);
return R.error(e.getMessage());
}
}
/**
* 修改
*/
@RequestMapping("/update")
// @RequiresPermissions("manage:pcategory:update")
public R update(@RequestBody PcategoryEntity pcategory){
try {
R r = this.pcategoryService.updatePcategory(pcategory, getUser());
return r;
} catch (Exception e) {
log.error("update error:", e);
return R.error(e.getMessage());
}
}
/**
* 删除
*/
@RequestMapping("/delete")
// @RequiresPermissions("manage:pcategory:delete")
public R delete(@RequestBody Integer[] categoryids){
pcategoryService.removeByIds(Arrays.asList(categoryids));
return R.ok();
}
}
package io.office.modules.manage.dao;
import io.office.modules.manage.entity.PcategoryEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* ${comments}
*
* @author rkl
* @email
* @date 2021-11-13 22:13:03
*/
@Mapper
public interface PcategoryDao extends BaseMapper<PcategoryEntity> {
}
package io.office.modules.manage.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* ${comments}
*
* @author rkl
* @email
* @date 2021-11-13 22:13:03
*/
@Data
@TableName("Pcategory")
public class PcategoryEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* $column.comments
*/
@TableId
private Integer categoryid;
/**
* $column.comments
*/
private String category;
/**
* $column.comments
*/
private Integer parentid;
/**
* $column.comments
*/
private Integer childnum;
/**
* $column.comments
*/
private Integer depth;
/**
* $column.comments
*/
private String ppath;
}
package io.office.modules.manage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import io.office.common.utils.PageUtils;
import io.office.common.utils.R;
import io.office.modules.manage.entity.PcategoryEntity;
import io.office.modules.sys.entity.SysUserEntity;
import java.util.Map;
/**
* 商品分类
* @author rkl
* @email
* @date 2021-11-13 22:13:03
*/
public interface PcategoryService extends IService<PcategoryEntity> {
PageUtils queryPage(Map<String, Object> params);
R insertPcategory(PcategoryEntity pcategory, SysUserEntity user);
R updatePcategory(PcategoryEntity pcategory, SysUserEntity user);
}
package io.office.modules.manage.service.impl;
import io.office.common.utils.R;
import io.office.modules.manage.entity.NewsEntity;
import io.office.modules.sys.entity.SysUserEntity;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.office.common.utils.PageUtils;
import io.office.common.utils.Query;
import io.office.modules.manage.dao.PcategoryDao;
import io.office.modules.manage.entity.PcategoryEntity;
import io.office.modules.manage.service.PcategoryService;
@Service("pcategoryService")
public class PcategoryServiceImpl extends ServiceImpl<PcategoryDao, PcategoryEntity> implements PcategoryService {
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<PcategoryEntity> page = this.page(
new Query<PcategoryEntity>().getPage(params),
new QueryWrapper<PcategoryEntity>()
);
return new PageUtils(page);
}
@Override
public R insertPcategory(PcategoryEntity pcategory, SysUserEntity user) {
int insert = baseMapper.insert(pcategory);
if (insert>0){
return R.ok("新增成功!");
}else{
return R.error("新增失败!");
}
}
@Override
public R updatePcategory(PcategoryEntity pcategory, SysUserEntity user) {
QueryWrapper<PcategoryEntity> newsEntityQueryWrapper = new QueryWrapper<>();
newsEntityQueryWrapper.eq("categoryid",pcategory.getCategoryid());
int update = baseMapper.update(pcategory, newsEntityQueryWrapper);
if (update>0){
return R.ok("修改成功!");
}else{
return R.error("修改失败!");
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment