【admin】新增#工厂管理

dev
renfan 2024-08-12 21:10:57 +08:00
parent 0047457806
commit a4e765e8d1
9 changed files with 280 additions and 61 deletions

View File

@ -89,9 +89,36 @@ public class PlantController {
*/
@Log(title = "工厂管理删除")
@PostMapping("/del")
public Object del(@Validated(value = PlantParam.delete.class) @RequestBody PlantParam plantParam) {
iPlantService.del(Math.toIntExact(plantParam.getId()));
public Object del(@RequestBody PlantParam plantParam) {
iPlantService.del(plantParam.getIds());
return AjaxResult.success();
}
/**
*
*
* @author hcy
* @param plantParam
* @return Object
*/
@Log(title = "工厂管理绑定用户")
@PostMapping("/boundUser")
public Object boundUser(@RequestBody PlantParam plantParam) {
iPlantService.boundUser(plantParam);
return AjaxResult.success();
}
/**
*
*
* @author hcy
* @param plantParam
* @return Object
*/
@Log(title = "工厂管理解除绑定")
@PostMapping("/plantUnbound")
public Object plantUnbound(@RequestBody PlantParam plantParam) {
iPlantService.plantUnbound(plantParam);
return AjaxResult.success();
}
}

View File

@ -6,6 +6,7 @@ import com.hcy.admin.vo.plant.PlantListVo;
import com.hcy.admin.vo.plant.PlantDetailVo;
import com.hcy.common.core.PageResult;
import java.util.List;
import java.util.Map;
/**
@ -52,8 +53,19 @@ public interface IPlantService {
*
*
* @author hcy
* @param id ID
* @param ids ID
*/
void del(Integer id);
void del(List<Integer> ids);
/**
*
* @param plantParam
*/
void boundUser(PlantParam plantParam);
/**
*
* @param plantParam
*/
void plantUnbound(PlantParam plantParam);
}

View File

@ -5,13 +5,22 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.query.MPJQueryWrapper;
import com.hcy.admin.service.plant.IPlantService;
import com.hcy.admin.service.region.IDevRegionService;
import com.hcy.admin.validate.common.PageParam;
import com.hcy.admin.validate.plant.PlantParam;
import com.hcy.admin.vo.plant.PlantListVo;
import com.hcy.admin.vo.plant.PlantDetailVo;
import com.hcy.common.constant.GlobalConstant;
import com.hcy.common.core.PageResult;
import com.hcy.common.entity.SparePartAudit.SparePartAudit;
import com.hcy.common.entity.plant.Plant;
import com.hcy.common.entity.sparePart.SparePart;
import com.hcy.common.entity.system.SystemAuthAdmin;
import com.hcy.common.entity.user.User;
import com.hcy.common.entity.warehouse.Warehouse;
import com.hcy.common.mapper.plant.PlantMapper;
import com.hcy.common.mapper.system.SystemAuthAdminMapper;
import com.hcy.common.mapper.user.UserMapper;
import com.hcy.common.utils.ArrayUtil;
import com.hcy.common.utils.TimeUtil;
import com.hcy.common.utils.UrlUtil;
@ -32,6 +41,12 @@ public class PlantServiceImpl implements IPlantService {
@Resource
PlantMapper plantMapper;
@Resource
SystemAuthAdminMapper systemAuthAdminMapper;
@Resource
private IDevRegionService regionService;
/**
*
*
@ -60,6 +75,23 @@ public class PlantServiceImpl implements IPlantService {
PlantListVo vo = new PlantListVo();
BeanUtils.copyProperties(item, vo);
vo.setCreateTime(TimeUtil.timestampToDate(item.getCreateTime()));
if(item.getAuthAdminId() != null){
//字符串拆分获取用户id
String[] userid = item.getAuthAdminId().split(",");
List<SystemAuthAdmin> authAdminList = new ArrayList<>();
for (String uid : userid) {
SystemAuthAdmin authAdmin = systemAuthAdminMapper.selectOne(
new QueryWrapper<SystemAuthAdmin>()
.eq("id", uid)
.eq("is_delete", 0)
.last("limit 1"));
if(authAdmin != null){
authAdmin.setAvatar(UrlUtil.toAbsoluteUrl(authAdmin.getAvatar()));
authAdminList.add(authAdmin);
}
}
vo.setAuthAdminList(authAdminList);
}
list.add(vo);
}
@ -85,6 +117,29 @@ public class PlantServiceImpl implements IPlantService {
PlantDetailVo vo = new PlantDetailVo();
BeanUtils.copyProperties(model, vo);
vo.setCreateTime(TimeUtil.timestampToDate(model.getCreateTime()));
vo.setUpdateTime(TimeUtil.timestampToDate(model.getUpdateTime()));
Map<Long, String> regionMap = regionService.getRegionMap();
vo.setProvince(regionMap.get(model.getProvinceId()));
vo.setCity(regionMap.get(model.getCityId()));
vo.setDistrict(regionMap.get(model.getDistrictId()));
if(model.getAuthAdminId() != null){
//字符串拆分获取用户id
String[] userid = model.getAuthAdminId().split(",");
List<SystemAuthAdmin> authAdminList = new ArrayList<>();
for (String uid : userid) {
SystemAuthAdmin authAdmin = systemAuthAdminMapper.selectOne(
new QueryWrapper<SystemAuthAdmin>()
.eq("id", uid)
.eq("is_delete", 0)
.last("limit 1"));
authAdmin.setAvatar(UrlUtil.toAbsoluteUrl(authAdmin.getAvatar()));
authAdminList.add(authAdmin);
}
vo.setAuthAdminList(authAdminList);
}
return vo;
}
@ -97,16 +152,17 @@ public class PlantServiceImpl implements IPlantService {
@Override
public void add(PlantParam plantParam) {
Plant model = new Plant();
model.setUserId(plantParam.getUserId());
model.setName(plantParam.getName());
model.setNumberUsers(plantParam.getNumberUsers());
model.setSort(plantParam.getSort());
model.setRemark(plantParam.getRemark());
model.setLongitude(plantParam.getLongitude());
model.setDimensionality(plantParam.getDimensionality());
model.setRegion(plantParam.getRegion());
model.setLatitude(plantParam.getLatitude());
model.setProvinceId(plantParam.getProvinceId());
model.setCityId(plantParam.getCityId());
model.setDistrictId(plantParam.getDistrictId());
model.setDetailedAddress(plantParam.getDetailedAddress());
model.setCreateTime(System.currentTimeMillis() / 1000);
plantMapper.insert(model);
}
@ -127,15 +183,16 @@ public class PlantServiceImpl implements IPlantService {
Assert.notNull(model, "数据不存在!");
model.setId(plantParam.getId());
model.setUserId(plantParam.getUserId());
model.setName(plantParam.getName());
model.setNumberUsers(plantParam.getNumberUsers());
model.setSort(plantParam.getSort());
model.setRemark(plantParam.getRemark());
model.setLongitude(plantParam.getLongitude());
model.setDimensionality(plantParam.getDimensionality());
model.setRegion(plantParam.getRegion());
model.setLatitude(plantParam.getLatitude());
model.setProvinceId(plantParam.getProvinceId());
model.setCityId(plantParam.getCityId());
model.setDistrictId(plantParam.getDistrictId());
model.setDetailedAddress(plantParam.getDetailedAddress());
model.setUpdateTime(System.currentTimeMillis() / 1000);
plantMapper.updateById(model);
}
@ -144,20 +201,94 @@ public class PlantServiceImpl implements IPlantService {
*
*
* @author hcy
* @param id ID
* @param ids ID
*/
@Override
public void del(Integer id) {
public void del(List<Integer> ids) {
List<Plant> modelList = plantMapper.selectList(
new QueryWrapper<Plant>()
.in("id", ids));
Assert.notNull(modelList, "数据不存在!");
// GlobalConstant.NOT_DELETE 调用未删除常量
// GlobalConstant.DELETE 删除标识
for (Plant plant : modelList) {
plant.setIsDelete(GlobalConstant.DELETE);
plant.setDeleteTime(System.currentTimeMillis() / 1000);
plantMapper.updateById(plant);// 进行伪删除 根据id把is_delete修改成1
}
}
/**
*
*
* @param plantParam
*/
@Override
public void boundUser(PlantParam plantParam) {
Plant model = plantMapper.selectOne(
new QueryWrapper<Plant>()
.eq("id", id)
.eq("is_delete", 0)
.last("limit 1"));
.eq("id", plantParam.getId())
.eq("is_delete", 0)
.last("limit 1"));
Assert.notNull(model, "数据不存在!");
model.setIsDelete(1);
model.setDeleteTime(System.currentTimeMillis() / 1000);
List<SystemAuthAdmin> authAdminList = plantParam.getAuthAdminList();
if(authAdminList != null){
int userNumber = 0;
// 使用StringBuilder来拼接id值
StringBuilder sb = new StringBuilder();
for (SystemAuthAdmin authAdmin : authAdminList) {
sb.append(authAdmin.getId()).append(",");
userNumber = userNumber + 1;
}
model.setNumberUsers((long) userNumber);
sb.deleteCharAt(sb.length() - 1); // 删除最后一个逗号
model.setAuthAdminId(String.valueOf(sb));// 备件审核id
}else{
model.setNumberUsers(null);
model.setAuthAdminId(null);// 备件审核id
}
model.setUpdateTime(System.currentTimeMillis() / 1000);
plantMapper.updateById(model);
}
/**
*
*
* @param plantParam
*/
@Override
public void plantUnbound(PlantParam plantParam) {
Plant model = plantMapper.selectOne(
new QueryWrapper<Plant>()
.eq("id", plantParam.getId())
.eq("is_delete", 0)
.last("limit 1"));
Assert.notNull(model, "数据不存在!");
List<SystemAuthAdmin> authAdminList = plantParam.getAuthAdminList();
if(authAdminList != null){
int userNumber = 0;
// 使用StringBuilder来拼接id值
StringBuilder sb = new StringBuilder();
for (SystemAuthAdmin authAdmin : authAdminList) {
sb.append(authAdmin.getId()).append(",");
userNumber = userNumber + 1;
}
model.setNumberUsers((long) userNumber);
sb.deleteCharAt(sb.length() - 1); // 删除最后一个逗号
model.setAuthAdminId(String.valueOf(sb));// 备件审核id
}
model.setUpdateTime(System.currentTimeMillis() / 1000);
plantMapper.updateById(model);
}

View File

@ -15,14 +15,17 @@ import com.hcy.admin.service.system.ISystemAuthPermService;
import com.hcy.admin.service.system.ISystemAuthRoleService;
import com.hcy.admin.validate.common.PageParam;
import com.hcy.admin.validate.system.SystemAuthAdminParam;
import com.hcy.admin.vo.plant.PlantListVo;
import com.hcy.admin.vo.system.SystemAuthAdminVo;
import com.hcy.admin.vo.system.SystemAuthRoleVo;
import com.hcy.admin.vo.system.SystemAuthSelfVo;
import com.hcy.common.config.GlobalConfig;
import com.hcy.common.core.PageResult;
import com.hcy.common.entity.plant.Plant;
import com.hcy.common.entity.system.SystemAuthAdmin;
import com.hcy.common.entity.system.SystemAuthMenu;
import com.hcy.common.exception.OperateException;
import com.hcy.common.mapper.plant.PlantMapper;
import com.hcy.common.mapper.system.SystemAuthAdminMapper;
import com.hcy.common.mapper.system.SystemAuthMenuMapper;
import com.hcy.common.utils.*;
@ -51,6 +54,9 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
@Resource
ISystemAuthPermService iSystemAuthPermService;
@Resource
PlantMapper plantMapper;
/**
*
*
@ -96,23 +102,60 @@ public class SystemAuthAdminServiceImpl implements ISystemAuthAdminService {
new Page<>(page, limit),
SystemAuthAdminVo.class,
mpjQueryWrapper);
long total = 0;
List<SystemAuthAdminVo> list = new LinkedList<>();
for (SystemAuthAdminVo item : iPage.getRecords()) {
for (SystemAuthAdminVo vo : iPage.getRecords()) {
if (vo.getId() == 1) {
vo.setRole("系统管理员");
if (item.getId() == 1) {
item.setRole("系统管理员");
}
if (vo.getDept() == null) {
vo.setDept("");
if (item.getDept() == null) {
item.setDept("");
}
vo.setAvatar(UrlUtil.toAbsoluteUrl(vo.getAvatar()));
vo.setCreateTime(TimeUtil.timestampToDate(vo.getCreateTime()));
vo.setUpdateTime(TimeUtil.timestampToDate(vo.getUpdateTime()));
vo.setLastLoginTime(TimeUtil.timestampToDate(vo.getLastLoginTime()));
item.setAvatar(UrlUtil.toAbsoluteUrl(item.getAvatar()));
item.setCreateTime(TimeUtil.timestampToDate(item.getCreateTime()));
item.setUpdateTime(TimeUtil.timestampToDate(item.getUpdateTime()));
item.setLastLoginTime(TimeUtil.timestampToDate(item.getLastLoginTime()));
SystemAuthAdminVo vo = new SystemAuthAdminVo();
BeanUtils.copyProperties(item, vo);
//只查询没有被该工厂绑定的用户
if(params.get("plantId") != null && params.get("plantId") != ""){
Plant model = plantMapper.selectOne(
new QueryWrapper<Plant>()
.eq("id", params.get("plantId"))
.eq("is_delete", 0)
.last("limit 1"));
Assert.notNull(model, "数据不存在!");
if(model.getAuthAdminId() != null){
//字符串拆分获取用户id
String[] userid = model.getAuthAdminId().split(",");
// 查询没有被任何工厂绑定的用户
QueryWrapper<SystemAuthAdmin> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.notIn("id", userid);
List<SystemAuthAdmin> systemAuthAdmins = systemAuthAdminMapper.selectList(userQueryWrapper);
for (SystemAuthAdmin systemAuthAdmin : systemAuthAdmins) {
if(item.getId() == systemAuthAdmin.getId()){
list.add(vo);
total = total + 1;
}
}
}else{
list.add(vo);
total = total + 1;
}
}else {
list.add(vo);
total = total + 1;
}
}
return PageResult.iPageHandle(iPage);
return PageResult.iPageHandle(total, iPage.getCurrent(), iPage.getSize(), list);
}
/**

View File

@ -1,7 +1,7 @@
package com.hcy.admin.validate.plant;
import com.hcy.common.entity.SparePartAudit.SparePartAudit;
import com.hcy.common.entity.user.User;
import com.hcy.common.entity.system.SystemAuthAdmin;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
@ -27,43 +27,35 @@ public class PlantParam implements Serializable {
private Long id;
@NotNull(message = "userId参数缺失", groups = {create.class, update.class})
@DecimalMin(value = "0", message = "userId参数值不能少于0", groups = {create.class, update.class})
private Long userId;
private String authAdminId;
@NotNull(message = "name参数缺失", groups = {create.class, update.class})
@Length(max = 255, message = "name参数不能超出255个字符", groups = {create.class, update.class})
private String name;
@NotNull(message = "numberUsers参数缺失", groups = {create.class, update.class})
@DecimalMin(value = "0", message = "numberUsers参数值不能少于0", groups = {create.class, update.class})
private Long numberUsers;
@NotNull(message = "sort参数缺失", groups = {create.class, update.class})
@DecimalMin(value = "0", message = "sort参数值不能少于0", groups = {create.class, update.class})
private Long sort;
@NotNull(message = "remark参数缺失", groups = {create.class, update.class})
@Length(max = 255, message = "remark参数不能超出255个字符", groups = {create.class, update.class})
private String remark;
@NotNull(message = "longitude参数缺失", groups = {create.class, update.class})
@DecimalMin(value = "0", message = "longitude参数值不能少于0", groups = {create.class, update.class})
private Long longitude;
private String longitude;
@NotNull(message = "dimensionality参数缺失", groups = {create.class, update.class})
@DecimalMin(value = "0", message = "dimensionality参数值不能少于0", groups = {create.class, update.class})
private Long dimensionality;
@NotNull(message = "region参数缺失", groups = {create.class, update.class})
@Length(max = 255, message = "region参数不能超出255个字符", groups = {create.class, update.class})
private String region;
private String latitude; // 纬度
private Long provinceId; //省id
private Long cityId; //市id
private Long districtId; //区id
@NotNull(message = "detailedAddress参数缺失", groups = {create.class, update.class})
@Length(max = 255, message = "detailedAddress参数不能超出255个字符", groups = {create.class, update.class})
private String detailedAddress;
private String createTime;
private List<User> userList; //待绑定的用户
private List<SystemAuthAdmin> authAdminList; //待绑定的用户
private List<Integer> ids; //批量删除
}

View File

@ -52,5 +52,5 @@ public class SparePartParam implements Serializable {
private BigDecimal unitPrice;
private List<Integer> ids; //备件id集合
private List<Integer> ids; //批量删除
}

View File

@ -1,5 +1,6 @@
package com.hcy.admin.vo.plant;
import com.hcy.common.entity.system.SystemAuthAdmin;
import com.hcy.common.entity.user.User;
import lombok.Data;
@ -15,17 +16,22 @@ public class PlantDetailVo implements Serializable {
private static final long serialVersionUID = 1L;
private Long id; // 主键id
private Long userId; // 用户id
private String authAdminId; // 用户id
private String name; // 工厂名称
private Long numberUsers; // 管理员人数
private Long sort; // 排序
private String remark; // 备注
private Long longitude; // 经度
private Long dimensionality; // 维度
private String region; // 所属区域
private String longitude; // 经度
private String latitude; // 纬度
private Long provinceId; //省id
private Long cityId; //市id
private Long districtId; //区id
private String province; //省
private String city; //市
private String district; //区
private String detailedAddress; // 详细地址
private Long createTime; // 创建时间
private Long updateTime; // 更新时间
private List<User> userList; //待绑定的用户
private String createTime; // 创建时间
private String updateTime; // 更新时间
private List<SystemAuthAdmin> authAdminList; //待绑定的用户
}

View File

@ -1,5 +1,6 @@
package com.hcy.admin.vo.plant;
import com.hcy.common.entity.system.SystemAuthAdmin;
import com.hcy.common.entity.user.User;
import lombok.Data;
@ -15,12 +16,12 @@ public class PlantListVo implements Serializable {
private static final long serialVersionUID = 1L;
private Long id; // 主键id
private Long userId; // 用户id
private String authAdminId; // 用户id
private String name; // 工厂名称
private Long numberUsers; // 管理员人数
private Long sort; // 排序
private String remark; // 备注
private String createTime; // 创建时间
private List<User> userList; //待绑定的用户
private List<SystemAuthAdmin> authAdminList; //待绑定的用户
}

View File

@ -1,7 +1,10 @@
package com.hcy.common.entity.plant;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@ -16,14 +19,18 @@ public class Plant implements Serializable {
@TableId(value="id", type= IdType.AUTO)
private Long id; // 主键id
private Long userId; // 用户id
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String authAdminId; // 管理员id
private String name; // 工厂名称
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Long numberUsers; // 管理员人数
private Long sort; // 排序
private String remark; // 备注
private Long longitude; // 经度
private Long dimensionality; // 维度
private String region; // 所属区域
private String longitude; // 经度
private String latitude; // 纬度
private Long provinceId; //省id
private Long cityId; //市id
private Long districtId; //区id
private String detailedAddress; // 详细地址
private Integer isDelete; // 是否删除: [0=否, 1=是]
private Long createTime; // 创建时间