parent
ad6568e0b4
commit
5f50bf0572
@ -0,0 +1,64 @@ |
|||||||
|
package cn.toesbieya.jxc.controller.sys; |
||||||
|
|
||||||
|
import cn.toesbieya.jxc.model.entity.SysStorehouse; |
||||||
|
import cn.toesbieya.jxc.model.vo.R; |
||||||
|
import cn.toesbieya.jxc.model.vo.UserVo; |
||||||
|
import cn.toesbieya.jxc.model.vo.search.StorehouseSearch; |
||||||
|
import cn.toesbieya.jxc.service.sys.SysStorehouseService; |
||||||
|
import cn.toesbieya.jxc.util.SessionUtil; |
||||||
|
import org.springframework.util.StringUtils; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
|
||||||
|
@RestController |
||||||
|
@RequestMapping("system/storehouse") |
||||||
|
public class StorehouseController { |
||||||
|
@Resource |
||||||
|
private SysStorehouseService service; |
||||||
|
|
||||||
|
@PostMapping("search") |
||||||
|
public R search(@RequestBody StorehouseSearch vo) { |
||||||
|
return R.success(service.search(vo)); |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping("add") |
||||||
|
public R add(@RequestBody SysStorehouse storehouse) { |
||||||
|
String errMsg = validateCreateParam(storehouse); |
||||||
|
if (errMsg != null) return R.fail("添加失败," + errMsg); |
||||||
|
|
||||||
|
//添加创建人、创建时间
|
||||||
|
UserVo user = SessionUtil.get(); |
||||||
|
storehouse.setCreatorId(user.getId()); |
||||||
|
storehouse.setCreateTime(System.currentTimeMillis()); |
||||||
|
|
||||||
|
return service.add(storehouse); |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping("update") |
||||||
|
public R update(@RequestBody SysStorehouse storehouse) { |
||||||
|
String errMsg = validateUpdateParam(storehouse); |
||||||
|
return errMsg == null ? service.update(storehouse) : R.fail("修改失败," + errMsg); |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping("del") |
||||||
|
public R del(@RequestBody SysStorehouse storehouse) { |
||||||
|
if (storehouse.getId() == null) return R.fail("删除失败,参数错误"); |
||||||
|
return service.del(storehouse); |
||||||
|
} |
||||||
|
|
||||||
|
private String validateCreateParam(SysStorehouse storehouse) { |
||||||
|
if (StringUtils.isEmpty(storehouse.getId())) return "仓库编号不能为空"; |
||||||
|
if (StringUtils.isEmpty(storehouse.getName())) return "仓库名称不能为空"; |
||||||
|
if (storehouse.getLevel() == null) return "仓库级别不能为空"; |
||||||
|
if (storehouse.getType() == null) return "仓库类型不能为空"; |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
private String validateUpdateParam(SysStorehouse storehouse) { |
||||||
|
if (storehouse.getId() == null) return "参数错误"; |
||||||
|
return validateCreateParam(storehouse); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
package cn.toesbieya.jxc.mapper; |
||||||
|
|
||||||
|
import cn.toesbieya.jxc.model.entity.SysStorehouse; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
|
||||||
|
public interface SysStorehouseMapper extends BaseMapper<SysStorehouse> { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,67 @@ |
|||||||
|
package cn.toesbieya.jxc.model.entity; |
||||||
|
|
||||||
|
import cn.toesbieya.jxc.enumeration.StorehouseLevelEnum; |
||||||
|
import cn.toesbieya.jxc.enumeration.StorehouseTypeEnum; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.persistence.Column; |
||||||
|
/** |
||||||
|
* |
||||||
|
* @author 强子烨 |
||||||
|
* @version 1.0 |
||||||
|
* @since 2022-02-28 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class SysStorehouse { |
||||||
|
|
||||||
|
/** |
||||||
|
* 仓库编码 |
||||||
|
*/ |
||||||
|
@Column |
||||||
|
private String id; |
||||||
|
/** |
||||||
|
* 名称 |
||||||
|
*/ |
||||||
|
@Column |
||||||
|
private String name; |
||||||
|
/** |
||||||
|
* 级别,1一级(默认)、2二级 |
||||||
|
*/ |
||||||
|
@Column |
||||||
|
private Integer level = StorehouseLevelEnum.ONE.getCode(); |
||||||
|
/** |
||||||
|
* 类型,1常温(默认),2冷藏 |
||||||
|
*/ |
||||||
|
@Column |
||||||
|
private Integer type = StorehouseTypeEnum.NPT.getCode(); |
||||||
|
/** |
||||||
|
* 状态,0停用,1启用 |
||||||
|
*/ |
||||||
|
@Column |
||||||
|
private boolean enable = false; |
||||||
|
|
||||||
|
/** |
||||||
|
* 备注 |
||||||
|
*/ |
||||||
|
private String remark; |
||||||
|
/** |
||||||
|
* 创建人id |
||||||
|
*/ |
||||||
|
@Column |
||||||
|
private Integer creatorId; |
||||||
|
/** |
||||||
|
* 创建时间 |
||||||
|
*/ |
||||||
|
@Column |
||||||
|
private Long createTime; |
||||||
|
/** |
||||||
|
* 修改人id |
||||||
|
*/ |
||||||
|
@Column |
||||||
|
private Integer updateId; |
||||||
|
/** |
||||||
|
* 修改时间 |
||||||
|
*/ |
||||||
|
@Column |
||||||
|
private Long updateTime; |
||||||
|
} |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
package cn.toesbieya.jxc.model.vo; |
||||||
|
|
||||||
|
import cn.toesbieya.jxc.model.entity.SysStorehouse; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
import lombok.ToString; |
||||||
|
import org.springframework.beans.BeanUtils; |
||||||
|
|
||||||
|
@Data |
||||||
|
@NoArgsConstructor |
||||||
|
@ToString(callSuper = true) |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class StorehouseVo extends SysStorehouse { |
||||||
|
|
||||||
|
public StorehouseVo(SysStorehouse parent){ |
||||||
|
BeanUtils.copyProperties(parent,this); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
package cn.toesbieya.jxc.model.vo.search; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import lombok.ToString; |
||||||
|
|
||||||
|
@Data |
||||||
|
@ToString(callSuper = true) |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class StorehouseSearch extends BaseSearch { |
||||||
|
|
||||||
|
private String id; |
||||||
|
private String name; |
||||||
|
private Integer level; |
||||||
|
private Integer type; |
||||||
|
private Boolean enable; |
||||||
|
private Long startTime; |
||||||
|
private Long endTime; |
||||||
|
} |
||||||
@ -0,0 +1,118 @@ |
|||||||
|
package cn.toesbieya.jxc.service.sys; |
||||||
|
|
||||||
|
import cn.toesbieya.jxc.annoation.UserAction; |
||||||
|
import cn.toesbieya.jxc.mapper.SysStorehouseMapper; |
||||||
|
import cn.toesbieya.jxc.model.entity.SysStorehouse; |
||||||
|
import cn.toesbieya.jxc.model.vo.R; |
||||||
|
import cn.toesbieya.jxc.model.vo.StorehouseVo; |
||||||
|
import cn.toesbieya.jxc.model.vo.result.PageResult; |
||||||
|
import cn.toesbieya.jxc.model.vo.search.StorehouseSearch; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||||
|
import com.github.pagehelper.PageHelper; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.util.StringUtils; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@Service |
||||||
|
public class SysStorehouseService { |
||||||
|
@Resource |
||||||
|
private SysStorehouseMapper storehouseMapper; |
||||||
|
|
||||||
|
public List<SysStorehouse> get() { |
||||||
|
return storehouseMapper.selectList( |
||||||
|
Wrappers.lambdaQuery(SysStorehouse.class) |
||||||
|
.eq(SysStorehouse::isEnable, true) |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
public PageResult<StorehouseVo> search(StorehouseSearch vo){ |
||||||
|
String id = vo.getId(); |
||||||
|
String name = vo.getName(); |
||||||
|
Integer level = vo.getLevel(); |
||||||
|
Integer type = vo.getType(); |
||||||
|
Boolean enable = vo.getEnable(); |
||||||
|
Long startTime = vo.getStartTime(); |
||||||
|
Long endTime = vo.getEndTime(); |
||||||
|
|
||||||
|
Wrapper<SysStorehouse> wrapper = |
||||||
|
Wrappers.lambdaQuery(SysStorehouse.class) |
||||||
|
.like(false, SysStorehouse::getId, id) |
||||||
|
.like(!StringUtils.isEmpty(name), SysStorehouse::getName, name) |
||||||
|
.eq(level != null, SysStorehouse::getLevel, level) |
||||||
|
.eq(type != null, SysStorehouse::getType, type) |
||||||
|
|
||||||
|
.eq(enable != null, SysStorehouse::isEnable, enable) |
||||||
|
.ge(startTime != null, SysStorehouse::getCreateTime, startTime) |
||||||
|
.le(endTime != null, SysStorehouse::getCreateTime, endTime) |
||||||
|
.orderByDesc(SysStorehouse::getCreateTime); |
||||||
|
|
||||||
|
PageHelper.startPage(vo.getPage(), vo.getPageSize()); |
||||||
|
|
||||||
|
List<SysStorehouse> storehouses = storehouseMapper.selectList(wrapper); |
||||||
|
|
||||||
|
PageResult<SysStorehouse> pageResult = new PageResult<>(storehouses); |
||||||
|
|
||||||
|
int storehouseNum = storehouses.size(); |
||||||
|
|
||||||
|
List<StorehouseVo> list = new ArrayList<>(storehouseNum); |
||||||
|
|
||||||
|
storehouses.forEach(storehouse -> list.add(new StorehouseVo(storehouse))); |
||||||
|
|
||||||
|
return new PageResult<>(pageResult.getTotal(), list); |
||||||
|
} |
||||||
|
|
||||||
|
@UserAction("'添加仓库:'+ #storehouse.name") |
||||||
|
public R add(SysStorehouse storehouse) { |
||||||
|
if (isNameExist(storehouse.getName(), null)) { |
||||||
|
return R.fail(String.format("添加失败,仓库【%s】已存在", storehouse.getName())); |
||||||
|
} |
||||||
|
int rows = storehouseMapper.insert(storehouse); |
||||||
|
return rows > 0 ? R.success("添加成功") : R.fail("添加失败"); |
||||||
|
} |
||||||
|
|
||||||
|
@UserAction("'修改仓库:'+ #storehouse.name") |
||||||
|
public R update(SysStorehouse storehouse) { |
||||||
|
String id = storehouse.getId(); |
||||||
|
String name = storehouse.getName(); |
||||||
|
|
||||||
|
if (isNameExist(name, id)) { |
||||||
|
return R.fail(String.format("修改失败,供应商【%s】已存在", name)); |
||||||
|
} |
||||||
|
|
||||||
|
storehouseMapper.update( |
||||||
|
null, |
||||||
|
Wrappers.lambdaUpdate(SysStorehouse.class) |
||||||
|
.set(SysStorehouse::getName, name) |
||||||
|
.set(SysStorehouse::getLevel, storehouse.getLevel()) |
||||||
|
.set(SysStorehouse::getType, storehouse.getType()) |
||||||
|
.set(SysStorehouse::isEnable, storehouse.isEnable()) |
||||||
|
//添加修改人 .set(SysStorehouse::getUpdateId, storehouse.getRegion())
|
||||||
|
//添加修改时间 .set(SysStorehouse::getUpdateTime, storehouse.isEnable())
|
||||||
|
.eq(SysStorehouse::getId, id) |
||||||
|
); |
||||||
|
return R.success("修改成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@UserAction("'删除仓库:'+ #storehouse.name") |
||||||
|
public R del(SysStorehouse storehouse) { |
||||||
|
int rows = storehouseMapper.delete( |
||||||
|
Wrappers.lambdaQuery(SysStorehouse.class) |
||||||
|
.eq(SysStorehouse::getId, storehouse.getId()) |
||||||
|
.eq(SysStorehouse::isEnable, false) |
||||||
|
); |
||||||
|
return rows > 0 ? R.success("删除成功") : R.fail("删除失败,请刷新重试"); |
||||||
|
} |
||||||
|
|
||||||
|
private boolean isNameExist(String name, String id) { |
||||||
|
Integer num = storehouseMapper.selectCount( |
||||||
|
Wrappers.lambdaQuery(SysStorehouse.class) |
||||||
|
.eq(SysStorehouse::getName, name) |
||||||
|
.ne(!StringUtils.isEmpty(id), SysStorehouse::getId, id) |
||||||
|
); |
||||||
|
return num != null && num > 0; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
import {PostApi} from "@/api/request" |
||||||
|
|
||||||
|
export const search = new PostApi(`/system/storehouse/search`) |
||||||
|
|
||||||
|
export const add = new PostApi(`/system/storehouse/add`) |
||||||
|
|
||||||
|
export const update = new PostApi(`/system/storehouse/update`) |
||||||
|
|
||||||
|
export const del = new PostApi(`/system/storehouse/del`) |
||||||
Loading…
Reference in new issue