- 新增 DeltaGunCode 实体/Mapper/Service/Controller(分页列表、新增、更新、删除) - WebSecurityConfig 放行 /delta-gun-code/public/**,公开页免登录访问 - 附建表与菜单权限 SQL:sql/delta_gun_code.sql
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
package com.freedom.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.freedom.admin.base.BaseController;
|
||||
import com.freedom.admin.common.Result;
|
||||
import com.freedom.admin.entity.DeltaGunCode;
|
||||
import com.freedom.admin.service.DeltaGunCodeService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 控制层-三角洲改枪码表
|
||||
*
|
||||
* @author zhangjiaxun
|
||||
* @description 后台维护改枪码 + 公开复制接口(无需登录)
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("delta-gun-code")
|
||||
@Log4j2
|
||||
public class DeltaGunCodeController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private DeltaGunCodeService deltaGunCodeService;
|
||||
|
||||
/**
|
||||
* 后台管理-分页查询改枪码列表
|
||||
*/
|
||||
@RequestMapping("findPageList")
|
||||
public Result<DeltaGunCode> findPageList(long pageNum, long pageSize, DeltaGunCode deltaGunCode) {
|
||||
QueryWrapper<DeltaGunCode> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag", 0);
|
||||
queryWrapper.like(StringUtils.isNotBlank(deltaGunCode.getName()), "name", deltaGunCode.getName());
|
||||
queryWrapper.like(StringUtils.isNotBlank(deltaGunCode.getGunName()), "gun_name", deltaGunCode.getGunName());
|
||||
queryWrapper.like(StringUtils.isNotBlank(deltaGunCode.getCategory()), "category", deltaGunCode.getCategory());
|
||||
queryWrapper.eq(deltaGunCode.getStatus() != null, "status", deltaGunCode.getStatus());
|
||||
queryWrapper.orderByAsc("sort").orderByDesc("id");
|
||||
Page<DeltaGunCode> page = deltaGunCodeService.page(new Page<>(pageNum, pageSize), queryWrapper);
|
||||
return Result.ok().setData(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公开页面-查询所有启用的改枪码(无需登录)
|
||||
*/
|
||||
@RequestMapping("public/list")
|
||||
public Result<DeltaGunCode> publicList() {
|
||||
QueryWrapper<DeltaGunCode> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag", 0);
|
||||
queryWrapper.eq("status", 1);
|
||||
queryWrapper.orderByAsc("sort").orderByDesc("id");
|
||||
List<DeltaGunCode> list = deltaGunCodeService.list(queryWrapper);
|
||||
return Result.ok().setData(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公开页面-复制成功后增加复制次数(无需登录)
|
||||
*/
|
||||
@RequestMapping("public/addCopyCount")
|
||||
public Result addCopyCount(Long id) {
|
||||
if (id == null) {
|
||||
return Result.error().message("参数缺失");
|
||||
}
|
||||
UpdateWrapper<DeltaGunCode> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", id).eq("del_flag", 0)
|
||||
.setSql("copy_count = copy_count + 1");
|
||||
deltaGunCodeService.update(updateWrapper);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台管理-新增改枪码
|
||||
*/
|
||||
@RequestMapping("add")
|
||||
public Result add(DeltaGunCode deltaGunCode) {
|
||||
if (StringUtils.isBlank(deltaGunCode.getName())) {
|
||||
return Result.error().message("配装名称不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(deltaGunCode.getCode())) {
|
||||
return Result.error().message("改枪码不能为空");
|
||||
}
|
||||
try {
|
||||
if (deltaGunCode.getStatus() == null) {
|
||||
deltaGunCode.setStatus(1);
|
||||
}
|
||||
if (deltaGunCode.getSort() == null) {
|
||||
deltaGunCode.setSort(0);
|
||||
}
|
||||
deltaGunCode.setCopyCount(0);
|
||||
deltaGunCode.setCreateBy(getUsername());
|
||||
deltaGunCode.setCreateDate(new Date());
|
||||
boolean save = deltaGunCodeService.save(deltaGunCode);
|
||||
return Result.ok().setData(save);
|
||||
} catch (Exception e) {
|
||||
log.error("新增改枪码失败", e);
|
||||
return Result.error().message("新增失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台管理-更新改枪码
|
||||
*/
|
||||
@RequestMapping("update")
|
||||
public Result update(DeltaGunCode deltaGunCode) {
|
||||
if (deltaGunCode.getId() == null) {
|
||||
return Result.error().message("参数缺失");
|
||||
}
|
||||
if (StringUtils.isBlank(deltaGunCode.getName())) {
|
||||
return Result.error().message("配装名称不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(deltaGunCode.getCode())) {
|
||||
return Result.error().message("改枪码不能为空");
|
||||
}
|
||||
try {
|
||||
deltaGunCode.setUpdateBy(getUsername());
|
||||
deltaGunCode.setUpdateDate(new Date());
|
||||
boolean update = deltaGunCodeService.updateById(deltaGunCode);
|
||||
return Result.ok().setData(update);
|
||||
} catch (Exception e) {
|
||||
log.error("更新改枪码失败", e);
|
||||
return Result.error().message("更新失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台管理-删除改枪码(逻辑删除)
|
||||
*/
|
||||
@RequestMapping("remove")
|
||||
public Result remove(DeltaGunCode deltaGunCode) {
|
||||
try {
|
||||
boolean remove = deltaGunCodeService.removeById(deltaGunCode.getId());
|
||||
return Result.ok().setData(remove);
|
||||
} catch (Exception e) {
|
||||
log.error("删除改枪码失败", e);
|
||||
return Result.error().message("删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user