diff --git a/admin/src/main/java/com/hcy/admin/controller/plant/PlantController.java b/admin/src/main/java/com/hcy/admin/controller/plant/PlantController.java index ddf7765..c1e01d8 100644 --- a/admin/src/main/java/com/hcy/admin/controller/plant/PlantController.java +++ b/admin/src/main/java/com/hcy/admin/controller/plant/PlantController.java @@ -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(); + } } diff --git a/admin/src/main/java/com/hcy/admin/service/plant/IPlantService.java b/admin/src/main/java/com/hcy/admin/service/plant/IPlantService.java index 375f89f..62f0ddf 100644 --- a/admin/src/main/java/com/hcy/admin/service/plant/IPlantService.java +++ b/admin/src/main/java/com/hcy/admin/service/plant/IPlantService.java @@ -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 ids); + /** + * 工厂管理绑定用户 + * @param plantParam + */ + void boundUser(PlantParam plantParam); + + /** + * 工厂管理解除绑定 + * @param plantParam + */ + void plantUnbound(PlantParam plantParam); } diff --git a/admin/src/main/java/com/hcy/admin/service/plant/impl/PlantServiceImpl.java b/admin/src/main/java/com/hcy/admin/service/plant/impl/PlantServiceImpl.java index 776dcff..45cd20d 100644 --- a/admin/src/main/java/com/hcy/admin/service/plant/impl/PlantServiceImpl.java +++ b/admin/src/main/java/com/hcy/admin/service/plant/impl/PlantServiceImpl.java @@ -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 authAdminList = new ArrayList<>(); + for (String uid : userid) { + SystemAuthAdmin authAdmin = systemAuthAdminMapper.selectOne( + new QueryWrapper() + .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 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 authAdminList = new ArrayList<>(); + for (String uid : userid) { + SystemAuthAdmin authAdmin = systemAuthAdminMapper.selectOne( + new QueryWrapper() + .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 ids) { + List modelList = plantMapper.selectList( + new QueryWrapper() + .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() - .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 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() + .eq("id", plantParam.getId()) + .eq("is_delete", 0) + .last("limit 1")); + + Assert.notNull(model, "数据不存在!"); + + List 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); } diff --git a/admin/src/main/java/com/hcy/admin/service/system/impl/SystemAuthAdminServiceImpl.java b/admin/src/main/java/com/hcy/admin/service/system/impl/SystemAuthAdminServiceImpl.java index 8125651..88d772c 100644 --- a/admin/src/main/java/com/hcy/admin/service/system/impl/SystemAuthAdminServiceImpl.java +++ b/admin/src/main/java/com/hcy/admin/service/system/impl/SystemAuthAdminServiceImpl.java @@ -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 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() + .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 userQueryWrapper = new QueryWrapper<>(); + userQueryWrapper.notIn("id", userid); + List 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); } /** diff --git a/admin/src/main/java/com/hcy/admin/validate/plant/PlantParam.java b/admin/src/main/java/com/hcy/admin/validate/plant/PlantParam.java index 883a76c..d4fead1 100644 --- a/admin/src/main/java/com/hcy/admin/validate/plant/PlantParam.java +++ b/admin/src/main/java/com/hcy/admin/validate/plant/PlantParam.java @@ -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 userList; //待绑定的用户 + private List authAdminList; //待绑定的用户 + private List ids; //批量删除 } diff --git a/admin/src/main/java/com/hcy/admin/validate/sparePart/SparePartParam.java b/admin/src/main/java/com/hcy/admin/validate/sparePart/SparePartParam.java index ec1514a..99b730e 100644 --- a/admin/src/main/java/com/hcy/admin/validate/sparePart/SparePartParam.java +++ b/admin/src/main/java/com/hcy/admin/validate/sparePart/SparePartParam.java @@ -52,5 +52,5 @@ public class SparePartParam implements Serializable { private BigDecimal unitPrice; - private List ids; //备件id集合 + private List ids; //批量删除 } diff --git a/admin/src/main/java/com/hcy/admin/vo/plant/PlantDetailVo.java b/admin/src/main/java/com/hcy/admin/vo/plant/PlantDetailVo.java index e1decd4..737b3d5 100644 --- a/admin/src/main/java/com/hcy/admin/vo/plant/PlantDetailVo.java +++ b/admin/src/main/java/com/hcy/admin/vo/plant/PlantDetailVo.java @@ -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 userList; //待绑定的用户 + private String createTime; // 创建时间 + private String updateTime; // 更新时间 + private List authAdminList; //待绑定的用户 } diff --git a/admin/src/main/java/com/hcy/admin/vo/plant/PlantListVo.java b/admin/src/main/java/com/hcy/admin/vo/plant/PlantListVo.java index 4e1cefb..aea6a00 100644 --- a/admin/src/main/java/com/hcy/admin/vo/plant/PlantListVo.java +++ b/admin/src/main/java/com/hcy/admin/vo/plant/PlantListVo.java @@ -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 userList; //待绑定的用户 + private List authAdminList; //待绑定的用户 } diff --git a/common/src/main/java/com/hcy/common/entity/plant/Plant.java b/common/src/main/java/com/hcy/common/entity/plant/Plant.java index 9bbffb7..4627f4b 100644 --- a/common/src/main/java/com/hcy/common/entity/plant/Plant.java +++ b/common/src/main/java/com/hcy/common/entity/plant/Plant.java @@ -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; // 创建时间