提交 3a44b55a authored 作者: zjm's avatar zjm

fix(单位模块): 修改了单位以及展示区域的对应,以及维护相关的缓存

上级 4e68c77a
......@@ -3,9 +3,11 @@ package com.tykj.dev.device.confirmcheck.entity.cache;
import com.tykj.dev.config.cache.ConfigCache;
import com.tykj.dev.config.repository.SystemConfigDao;
import com.tykj.dev.device.user.cache.AreaCache;
import com.tykj.dev.device.user.cache.AreaExhibitionCache;
import com.tykj.dev.device.user.cache.UnitsCache;
import com.tykj.dev.device.user.cache.UserCache;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.dao.AreaExhibitionDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -33,6 +35,9 @@ public class CacheBeanConfig {
@Autowired
private SystemConfigDao systemConfigDao;
@Autowired
AreaExhibitionDao areaExhibitionDao;
@Bean
public AreaCache initAreaCache() {
return new AreaCache(areaRepo.findAll());
......@@ -43,6 +48,10 @@ public class CacheBeanConfig {
return new UserCache(userDao.findAll());
}
@Bean
public AreaExhibitionCache initAreaExhibitionCache() {
return new AreaExhibitionCache(areaExhibitionDao.findAll());
}
@Bean
public UnitsCache initUnitCache() {
return new UnitsCache(unitsDao.findAll());
......
spring.application.name=device-dev
spring.datasource.url=jdbc:mysql://192.168.100.249:3306/device?serverTimezone=Asia/Shanghai&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false
spring.datasource.url=jdbc:mysql://192.168.100.249:3306/device_master?serverTimezone=Asia/Shanghai&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
......
package com.tykj.dev.device.user.base.req;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author zjm
* @version 1.0.0
* @ClassName UnitStoreLocationVo.java
* @Description TODO
* @createTime 2021年11月08日 13:47:00
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel(value = "根据单位名称查询用户的接口", description = "根据单位名称查询用户的接口")
public class UnitStoreLocationVo {
@ApiModelProperty(value = "单位ID", name = "unitId", example = "12321L")
private Integer unitId;
@ApiModelProperty(value = "类型名称", name = "typeName", example = "12321L")
private String typeName;
}
package com.tykj.dev.device.user.base.req;
import com.tykj.dev.device.user.base.ret.AreaVo;
import com.tykj.dev.device.user.base.ret.LeftNavigation;
import com.tykj.dev.device.user.base.ret.UnitsTrainVo;
import com.tykj.dev.device.user.base.ret.UnitsVo;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.misc.base.BeanHelper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.modelmapper.ModelMapper;
import javax.persistence.*;
import java.util.UUID;
/**
* @author zjm
* @version 1.0.0
* @ClassName Units.java
* @Description 单位对象
* @createTime 2020年07月28日 09:23:00
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel(value = "单位添加对象", description = "单位添加对象")
public class UnitsAddVo {
/**
* 单位名称
*/
@ApiModelProperty(value = "单位名称", name = "unitName", example = "12321L")
private String name;
/**
* 单位描述
*/
@ApiModelProperty(value = "单位描述", name = "unitDesc", example = "12321L")
private String unitDesc;
/**
* 等级
*/
@ApiModelProperty(value = "等级", name = "level", example = "12321L")
private Integer level;
/**
* 1.在系统单位
* 2.省直属单位 areaid 0
* 3.省上级单位 areaid 0
*/
private Integer type=1;
/**
* 排序
*/
@ApiModelProperty(value = "排序", name = "showOrder", example = "12321L")
private Integer showOrder;
@ApiModelProperty(value = "装备配用范围的指定")
private Integer packingMatchingRange;
@ApiModelProperty(value = "是否代管")
private Integer escrow;
@ApiModelProperty(value = "展示区域id")
private Integer exhibitionId;
@ApiModelProperty(value = "上级单位ID")
private Integer parentUnitId;
public Units toUnits(){
ModelMapper mapper = BeanHelper.getUserMapper();
return mapper.map(this, Units.class);
}
}
package com.tykj.dev.device.user.cache;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.AreaExhibition;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
......@@ -21,6 +23,7 @@ public class AreaCache {
private Map<Integer, Area> idMap;
public AreaCache(List<Area> areaList) {
nameMap = areaList.stream().collect(Collectors.toMap(Area::getName, Function.identity()));
idMap = areaList.stream().collect(Collectors.toMap(Area::getId, Function.identity()));
......@@ -38,6 +41,11 @@ public class AreaCache {
public Area findById(Integer id) {
return idMap.get(id) == null ? new Area(0, "省直属", 9999, "9999", 0, "") : idMap.get(id);
}
public List<Area> findAll(){
return new ArrayList<>(idMap.values());
}
public AreaCache refresh(List<Area> areaList) {
nameMap = areaList.stream().collect(Collectors.toMap(Area::getName, Function.identity()));
......
package com.tykj.dev.device.user.cache;
import com.tykj.dev.device.user.subject.entity.AreaExhibition;
import com.tykj.dev.device.user.subject.entity.Units;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author zjm
* @version 1.0.0
* @ClassName AreaExhibitionCache.java
* @Description TODO
* @createTime 2021年11月09日 14:36:00
*/
@Data
public class AreaExhibitionCache {
private Map<Integer, AreaExhibition> idMap;
private List<AreaExhibition> areaExhibitions;
public AreaExhibitionCache(List<AreaExhibition> areaExhibitionList){
this.idMap = areaExhibitionList.stream().collect(Collectors.toMap(AreaExhibition::getId, Function.identity()));
this.areaExhibitions=areaExhibitionList;
}
public Map<Integer, AreaExhibition> getIdMap() {
return idMap;
}
public AreaExhibition findById(Integer id) {
return idMap.get(id);
}
public List<AreaExhibition> findAll(){
return new ArrayList<>(idMap.values());
}
/**
* 根据区域id查询下级以及
*/
public List<AreaExhibition> findByFatherId(Integer fatherId){
return new ArrayList<>(idMap.values()).stream().filter(areaExhibition -> fatherId.equals(areaExhibition.getFatherId())).collect(Collectors.toList());
}
public AreaExhibitionCache refresh(List<AreaExhibition> areaExhibitionList){
this.idMap = areaExhibitionList.stream().collect(Collectors.toMap(AreaExhibition::getId, Function.identity()));
this.areaExhibitions=areaExhibitionList;
return this;
}
}
......@@ -14,6 +14,9 @@ public class UnitsCache {
private Map<Integer, Units> idMap;
public UnitsCache(List<Units> unitsList){
this.idMap = unitsList.stream().collect(Collectors.toMap(Units::getUnitId, Function.identity()));
}
......@@ -30,6 +33,11 @@ public class UnitsCache {
return new ArrayList<>(idMap.values());
}
public List<Units> findAllByAreaExhibitionId(Integer areaExhibitionId){
return new ArrayList<>(idMap.values()).stream().filter(units -> units.getExhibitionId().equals(areaExhibitionId)).collect(Collectors.toList());
}
public UnitsCache refresh(List<Units> unitsList){
this.idMap = unitsList.stream().collect(Collectors.toMap(Units::getUnitId, Function.identity()));
return this;
......
......@@ -81,4 +81,12 @@ public class AreaController {
return ResponseEntity.ok(areaService.findIdQuerySubordinateIds(size));
}
@GetMapping("/findAll")
@ApiOperation(value = "查询所有区域列表", notes = "查询所有区域列表")
public ResponseEntity selectFindAll(){
return ResponseEntity.ok(areaService.findAllArea());
}
}
package com.tykj.dev.device.user.subject.controller;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.user.subject.entity.AreaExhibition;
import com.tykj.dev.device.user.subject.service.AreaExhibitionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* @author zjm
* @version 1.0.0
* @ClassName AreaExhibitionController.java
* @Description TODO
* @createTime 2021年11月09日 11:29:00
*/
@RestController
@AutoDocument
@Api(tags = "区域展示模块", description = "提供区域展示模块接口")
@RequestMapping("/areaExhibition")
public class AreaExhibitionController {
@Autowired
AreaExhibitionService areaExhibitionService;
@GetMapping("/finaAll")
@ApiOperation(value = "查询所有区域列表", notes = "查询所有区域列表")
public ResponseEntity selectFindAll() {
return ResponseEntity.ok(areaExhibitionService.finaAllAreaExhibition());
}
@PostMapping("/save")
@ApiOperation(value = "保存区域展示对象", notes = "保存区域展示对象")
public ResponseEntity saveExhibition(@RequestBody AreaExhibition areaExhibition) {
return ResponseEntity.ok(areaExhibitionService.save(areaExhibition));
}
}
\ No newline at end of file
package com.tykj.dev.device.user.subject.controller;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.user.base.req.UnitStoreLocationVo;
import com.tykj.dev.device.user.subject.entity.UnitStoreLocation;
import com.tykj.dev.device.user.subject.service.UnitStoreLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* @author zjm
* @version 1.0.0
* @ClassName UnitStoreLocationController.java
* @Description TODO
* @createTime 2021年11月08日 13:23:00
*/
@RestController
@AutoDocument
@Api(tags = "各单位存放位置", description = "提供用户相关的接口")
@RequestMapping("/unitStoreLocation")
@Slf4j
public class UnitStoreLocationController {
@Autowired
UnitStoreLocationService unitStoreLocationService;
@PostMapping(value = "/unitIdAndTypeName")
@ApiOperation(value = "根据单位ID以及字段名称查询单位存储列表", notes = "返回单位对象")
public ResponseEntity unitIdAndTypeName(@RequestBody UnitStoreLocationVo unitStoreLocationVo) {
return ResponseEntity.ok(unitStoreLocationService.findAllByUnitIdAndTypeName(unitStoreLocationVo));
}
@PostMapping(value = "/save")
@ApiOperation(value = "添加库房位置对象", notes = "添加库房位置对象")
public ResponseEntity unitIdAndTypeName(@RequestBody UnitStoreLocation unitStoreLocation) {
return ResponseEntity.ok(unitStoreLocationService.save(unitStoreLocation));
}
}
......@@ -2,6 +2,7 @@ package com.tykj.dev.device.user.subject.controller;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.user.base.req.UnitNameVo;
import com.tykj.dev.device.user.base.req.UnitsAddVo;
import com.tykj.dev.device.user.subject.entity.SecurityUser;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.service.UnitsService;
......@@ -25,7 +26,7 @@ import springfox.documentation.annotations.ApiIgnore;
*/
@RestController
@AutoDocument
@Api(tags = "用户模块", description = "提供用户相关的接口")
@Api(tags = "单位模块", description = "提供用户相关的接口")
@RequestMapping("/units")
@Slf4j
public class UnitsController {
......@@ -62,13 +63,13 @@ public class UnitsController {
@GetMapping(value = "/areaDevice")
@ApiOperation(value = "查询装备库区域单位列表", notes = "查询装备库区域单位列表")
public ResponseEntity selectOrganizationUnits1(@ApiIgnore @AuthenticationPrincipal SecurityUser securityUser) {
return ResponseEntity.ok(unitsService.findLeftNavigation1(securityUser));
return ResponseEntity.ok(unitsService.findLeftNavigation(securityUser));
}
@GetMapping(value = "/areaDirectlyUnder")
@ApiOperation(value = "查询直属代管单位列表", notes = "查询直属代管单位列表")
public ResponseEntity selectOrganizationUnits2(@ApiIgnore @AuthenticationPrincipal SecurityUser securityUser) {
return ResponseEntity.ok(unitsService.findLeftNavigation2(securityUser));
return ResponseEntity.ok(unitsService.findLeftNavigation(securityUser));
}
@GetMapping(value = "/findAll/GreaterThanEqual/{level}")
......@@ -134,8 +135,6 @@ public class UnitsController {
return ResponseEntity.ok(unitsService.findbyName(unitNameVo.getUnitName()));
}
@GetMapping("/countries/units")
@ApiOperation(value = "省入库发件单位下拉接口", notes = "省入库发件单位下拉接口")
public ResponseEntity findSuperiorUnitsList(){
......@@ -154,5 +153,31 @@ public class UnitsController {
return ResponseEntity.ok(DeviceModelSort.mapUnitSort);
}
/**
* 单位管理查询单位查询接口
*/
@GetMapping("/findAll/unitManagement")
@ApiOperation(value = "[单位管理]单位管理查询单位查询接口", notes = "单位管理查询单位查询接口")
public ResponseEntity unitManagement(){
return ResponseEntity.ok(unitsService.unitManagement());
}
/**
* 单位管理查询单位查询接口
*/
@PostMapping("/saveUnits")
@ApiOperation(value = "[单位管理]单位管理添加单位接口", notes = "单位管理添加单位接口")
public ResponseEntity unitManagement(@RequestBody UnitsAddVo unitsAddVo){
return ResponseEntity.ok(unitsService.saveUnits(unitsAddVo));
}
/**
* 查询添加单位中所有单位的下拉列表
*/
@GetMapping("/belongsUnits")
@ApiOperation(value = "[单位管理]查询添加单位中所属单位的下拉列表", notes = "查询添加单位中所属单位的下拉列表")
public ResponseEntity belongsUnits(){
return ResponseEntity.ok(unitsService.belongsUnits());
}
}
package com.tykj.dev.device.user.subject.dao;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.AreaExhibition;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author zjm
* @version 1.0.0
* @ClassName AreaExhibitionDao.java
* @Description TODO
* @createTime 2021年11月09日 09:33:00
*/
public interface AreaExhibitionDao extends JpaRepository<AreaExhibition, Integer>, JpaSpecificationExecutor<AreaExhibition> {
}
package com.tykj.dev.device.user.subject.dao;
import com.tykj.dev.device.user.subject.entity.UnitStoreLocation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
public interface UnitStoreLocationDao extends JpaRepository<UnitStoreLocation, Integer>, JpaSpecificationExecutor<UnitStoreLocation> {
List<UnitStoreLocation> findAllByUnitIdAndTypeName(Integer unitId,String typeName);
}
......@@ -39,7 +39,7 @@ public class Area {
private String name;
/**
* 等级 等级 0国家级 1省级 2市级 3县级 4.直属单位
* 等级 等级 0.国家级 1.省级 2.市级 3.县级 4.直属
*/
private Integer type;
......
package com.tykj.dev.device.user.subject.entity;
import com.tykj.dev.device.user.base.ret.LeftNavigation;
import com.tykj.dev.misc.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Transient;
import java.util.UUID;
/**
* @author zjm
* @version 1.0.0
* @ClassName AreaExhibition.java
* @Description TODO
* @createTime 2021年11月09日 09:12:00
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
@ApiModel(value = "地区提供展示对象", description = "地区提供展示信息")
public class AreaExhibition extends BaseEntity {
/**
* 区域名称
*/
private String areaName;
/**
* 区域描述
*/
@Column(name = "des",columnDefinition = "TEXT")
private String des;
/**
* 排序
*/
private String orders;
/**
* 父类id
*/
private Integer fatherId;
/**
* 父类名称
*/
@Transient
private String fatherName;
public LeftNavigation toLeftNavigation(){
return new LeftNavigation(this.getId(),areaName,null, UUID.randomUUID().toString(),1,Double.valueOf(orders).intValue(),null);
}
}
package com.tykj.dev.device.user.subject.entity;
import com.tykj.dev.misc.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
/**
* @author zjm
* @version 1.0.0
* @ClassName UnitStoreLocation.java
* @Description 存放位置信息
* @createTime 2021年11月08日 12:46:00
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
@ApiModel(value = "单位对象", description = "单位详细信息")
@Where(clause = "id_del = 0")
@SQLDelete(sql = "update user set id_del = 1 where id = ?")
public class UnitStoreLocation extends BaseEntity {
private Integer unitId;
private String storeName;
private String typeName;
@Column(name = "des",columnDefinition = "TEXT")
private String des;
}
......@@ -88,7 +88,7 @@ public class Units {
@ApiModelProperty(value = "排序", name = "showOrder", example = "12321L")
private Integer showOrder;
@ApiModelProperty(value = "区域名称", name = "areaName", example = "12321L")
@ApiModelProperty(value = "区域展示名称", name = "areaName", example = "12321L")
@Transient
private String areaName;
......@@ -98,12 +98,15 @@ public class Units {
@ApiModelProperty(value = "是否代管")
private Integer escrow;
@ApiModelProperty(value = "展示区域id")
private Integer exhibitionId;
/**
* 区域对象
*/
@Transient
private Area area;
public static Units toDb() {
return new Units(
null,
......@@ -117,6 +120,7 @@ public class Units {
null,
null,
null,
null,
null
);
}
......
package com.tykj.dev.device.user.subject.service;
import com.tykj.dev.device.user.subject.entity.AreaExhibition;
import java.util.List;
public interface AreaExhibitionService extends PublicService<AreaExhibition>{
/**
* 区域使用
* @return 区域对象集合
*/
List<AreaExhibition> finaAllAreaExhibition();
/**
* 根据id查询区域展示对象
*/
AreaExhibition findById(Integer areaExhibitionId);
}
......@@ -36,5 +36,10 @@ public interface AreaService extends PublicService<Area> {
Area findByIdTosuperiorArea(Integer areaId);
/**
* 区域管理使用
*/
List<Area> findAllArea();
}
package com.tykj.dev.device.user.subject.service;
import com.tykj.dev.device.user.base.req.UnitStoreLocationVo;
import com.tykj.dev.device.user.subject.entity.UnitStoreLocation;
import java.util.List;
import java.util.Map;
/**
* @author zjm
* @version 1.0.0
* @ClassName UnitStoreLocationService.java
* @Description TODO
* @createTime 2021年11月08日 12:57:00
*/
public interface UnitStoreLocationService extends PublicService<UnitStoreLocation>{
List<UnitStoreLocation> findAllByUnitIdAndTypeName(UnitStoreLocationVo unitStoreLocationVo);
Map<Integer,String> findByUnitIdToDeviceMap(Integer unitId);
}
package com.tykj.dev.device.user.subject.service;
import com.tykj.dev.device.user.base.req.UnitNameVo;
import com.tykj.dev.device.user.base.req.UnitsAddVo;
import com.tykj.dev.device.user.base.ret.*;
import com.tykj.dev.device.user.subject.entity.SecurityUser;
import com.tykj.dev.device.user.subject.entity.Units;
......@@ -143,8 +144,8 @@ public interface UnitsService extends PublicService<Units> {
*/
List<Units> findAllByIdIn(List<Integer> ids);
List<Units> finAllDirectlUnderUnits();
List<Units> finAllDirectlUnderUnits();
/**
* 左边侧面导航栏接口
......@@ -187,4 +188,23 @@ public interface UnitsService extends PublicService<Units> {
* @return 所有的单位id
*/
List<Integer> findByAreaId2(Integer areaId);
/**
* 单位管理使用 查询单位的接口
*/
List<Units> unitManagement();
/**
* 新增单位接口
*/
List<Units> saveUnits(UnitsAddVo unitsAddVo);
/**
* 添加单位所有单位列表
*/
List<Units> belongsUnits();
}
package com.tykj.dev.device.user.subject.service.impl;
import com.tykj.dev.device.user.cache.AreaExhibitionCache;
import com.tykj.dev.device.user.subject.dao.AreaExhibitionDao;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.AreaExhibition;
import com.tykj.dev.device.user.subject.service.AreaExhibitionService;
import com.tykj.dev.misc.exception.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @author zjm
* @version 1.0.0
* @ClassName AreaExhibitionServiceImpl.java
* @Description TODO
* @createTime 2021年11月09日 11:13:00
*/
@Service
public class AreaExhibitionServiceImpl implements AreaExhibitionService {
@Autowired
AreaExhibitionDao areaExhibitionDao;
@Autowired
AreaExhibitionCache areaExhibitionCache;
@Override
public List<AreaExhibition> finaAllAreaExhibition() {
List<AreaExhibition> areaExhibitions=areaExhibitionDao.findAll().stream().sorted(Comparator.comparing(AreaExhibition::getOrders)).collect(Collectors.toList());
areaExhibitions.forEach(
areaExhibition -> {
if (areaExhibition.getFatherId()!=null) {
AreaExhibition areaExhibition1= areaExhibitionCache.findById(areaExhibition.getFatherId());
areaExhibition.setFatherName(areaExhibition1.getAreaName());
}
}
);
return areaExhibitions;
}
@Override
public AreaExhibition findById(Integer areaExhibitionId){
Optional<AreaExhibition> optionalAreaExhibition = areaExhibitionDao.findById(areaExhibitionId);
if (optionalAreaExhibition.isPresent()){
return optionalAreaExhibition.get();
}else {
throw new ApiException("[区域展示] 根据id查询对象没找到:"+areaExhibitionId);
}
}
@Override
public AreaExhibition save(AreaExhibition areaExhibition) {
AreaExhibition areaExhibition1= areaExhibitionDao.save(areaExhibition);
areaExhibitionCache.refresh(areaExhibitionDao.findAll());
return areaExhibition1;
}
@Override
public boolean delete(Integer id) {
return false;
}
@Override
public List<AreaExhibition> findAll() {
return areaExhibitionDao.findAll();
}
@Override
public AreaExhibition update(AreaExhibition areaExhibition) {
AreaExhibition areaExhibition1= areaExhibitionDao.save(areaExhibition);
areaExhibitionCache.refresh(areaExhibitionDao.findAll());
return areaExhibition1;
}
}
......@@ -21,8 +21,10 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @author zjm
......@@ -136,6 +138,20 @@ public class AreaServiceImpl implements AreaService {
return area;
}
@Override
public List<Area> findAllArea() {
//过滤掉直属的以及区域的
List<Area> areaList=areaDao.findAll().stream().filter(area -> area.getType() < 3).collect(Collectors.toList());
areaList.forEach(area ->{
if (area.getFatherId()!=null) {
area.setFatherName(areaCache.findById(area.getFatherId()).getName());
}
}
);
areaList= areaList.stream().sorted(Comparator.comparing(Area::getOrders)).collect(Collectors.toList());
return areaList;
}
private List<Integer> areaId(List<Integer> ids,Integer areaId){
List<Area> areas= areaDao.findAllByFatherId(areaId);
......@@ -166,29 +182,6 @@ public class AreaServiceImpl implements AreaService {
return units;
}
// private List<AreaInstitutions> subordinateArea(List<AreaInstitutions> areaInstitutions ,Area area){
// List<Area> list= areaDao.findAllByFatherId(area.getId());
// if (list==null || list.size()==0){
// areaInstitutions.add(new AreaInstitutions(area.getId(), area.getName(), areaInstitutions, unitsDao.findAllByAreaId(area.getId()).stream().map(Units::toVo).collect(Collectors.toList())));
// return areaInstitutions;
// }
// if (area.getType() < 2) {
// areaInstitutions.add(new AreaInstitutions(area.getId(), area.getName(), areaInstitutions, unitsDao.findAllByAreaId(area.getId()).stream().map(Units::toVo).collect(Collectors.toList())));
// }
//
// list.forEach(
// area1 -> {
// List<AreaInstitutions> areaInstitutions1=new ArrayList<>();
// subordinateArea(areaInstitutions1,area1);
// if (area.getType()==2) {
// areaInstitutions1.add(new AreaInstitutions(area.getId(), area.getName(), areaInstitutions, unitsDao.findAllByAreaId(area.getId()).stream().map(Units::toVo).collect(Collectors.toList())));
// }
// areaInstitutions.add(new AreaInstitutions(area1.getId(),area1.getName(),areaInstitutions1,unitsDao.findAllByAreaId(area1.getId()).stream().map(Units::toVo).collect(Collectors.toList())));
// }
// );
// return areaInstitutions;
// }
@Override
public Area save(Area area) {
Optional<Area> optionalArea = areaDao.findById(area.getFatherId());
......
package com.tykj.dev.device.user.subject.service.impl;
import com.tykj.dev.device.user.base.req.UnitStoreLocationVo;
import com.tykj.dev.device.user.subject.dao.UnitStoreLocationDao;
import com.tykj.dev.device.user.subject.entity.UnitStoreLocation;
import com.tykj.dev.device.user.subject.service.UnitStoreLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author zjm
* @version 1.0.0
* @ClassName UnitStoreLocationServiceImpl.java
* @Description TODO
* @createTime 2021年11月08日 13:02:00
*/
@Service
public class UnitStoreLocationServiceImpl implements UnitStoreLocationService {
@Autowired
UnitStoreLocationDao unitStoreLocationDao;
@Override
public List<UnitStoreLocation> findAllByUnitIdAndTypeName(UnitStoreLocationVo unitStoreLocationVo) {
return unitStoreLocationDao.findAllByUnitIdAndTypeName(unitStoreLocationVo.getUnitId(),unitStoreLocationVo.getTypeName());
}
@Override
public Map<Integer, String> findByUnitIdToDeviceMap(Integer unitId) {
return unitStoreLocationDao.findAllByUnitIdAndTypeName(unitId,"存放位置")
.stream()
.collect(Collectors.toMap(UnitStoreLocation::getId,UnitStoreLocation::getStoreName));
}
@Override
public UnitStoreLocation save(UnitStoreLocation unitStoreLocation) {
return unitStoreLocationDao.save(unitStoreLocation);
}
@Override
public boolean delete(Integer id) {
return false;
}
@Override
public List<UnitStoreLocation> findAll() {
return unitStoreLocationDao.findAll();
}
@Override
public UnitStoreLocation update(UnitStoreLocation unitStoreLocation) {
return unitStoreLocationDao.save(unitStoreLocation);
}
}
......@@ -2,13 +2,18 @@ package com.tykj.dev.device.user.subject.service.impl;
import com.tykj.dev.config.service.SystemConfigService;
import com.tykj.dev.device.user.base.req.UnitNameVo;
import com.tykj.dev.device.user.base.req.UnitsAddVo;
import com.tykj.dev.device.user.base.ret.*;
import com.tykj.dev.device.user.cache.AreaCache;
import com.tykj.dev.device.user.cache.AreaExhibitionCache;
import com.tykj.dev.device.user.cache.UnitsCache;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.AreaExhibition;
import com.tykj.dev.device.user.subject.entity.SecurityUser;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.service.AreaExhibitionService;
import com.tykj.dev.device.user.subject.service.UnitsService;
import com.tykj.dev.misc.exception.ApiException;
import com.tykj.dev.misc.utils.DeviceModelSort;
......@@ -41,9 +46,18 @@ public class UnitsServiceImpl implements UnitsService {
@Autowired
UnitsCache unitsCache;
@Autowired
AreaCache areaCache;
@Autowired
AreaExhibitionCache areaExhibitionCache;
@Autowired
SystemConfigService systemConfigService;
@Autowired
AreaExhibitionService areaExhibitionService;
@Override
public Units findById(Integer unitId) {
Optional<Units> unit = unitsDao.findById(unitId);
......@@ -283,29 +297,27 @@ public class UnitsServiceImpl implements UnitsService {
public LeftNavigation findLeftNavigation(SecurityUser securityUser) {
LeftNavigation leftNavigation = new LeftNavigation();
List<LeftNavigation> leftNavigationList = new ArrayList<>();
Integer areaId = securityUser.getCurrentUserInfo().getUnits().getAreaId();
Area belongsArea = areaDao.findById(areaId).get();
if (belongsArea.getType() == 1 || belongsArea.getType() == 2) {
leftNavigation = belongsArea.toLeftNavigation();
leftNavigationList = unitsDao.findAllByAreaId(belongsArea.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList());
}
if (belongsArea.getType() == 1) {
//把省直属组合一下 直属单位(type=2) 处室单位(type=4)
// leftNavigationList.addAll(unitsDao.findAllByType(4).stream().map(Units::toLeftNavigation).collect(Collectors.toList()));
List<LeftNavigation> leftNavigationList2 = unitsDao.findAllByType(2).stream().filter(units1 -> !units1.getName().equals("省应急小组") && !units1.getName().equals("省机科技管理处") && !units1.getName().equals("省机通信报务处") && units1.getEscrow() == 1).map(Units::toLeftNavigation).collect(Collectors.toList());
LeftNavigation leftNavigation2 = new LeftNavigation(0, "省直属", leftNavigationList2, UUID.randomUUID().toString(), 1, 22, null);
leftNavigationList.add(leftNavigation2);
}
List<Area> areas = areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).collect(Collectors.toList());
if (areas.size() != 0) {
provinceAndCity(belongsArea, areas, leftNavigationList);
} else {
leftNavigation = belongsArea.toLeftNavigation();
leftNavigationList = unitsDao.findAllByAreaId(belongsArea.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList());
Units units=securityUser.getCurrentUserInfo().getUnits();
if (units.getLevel()==1 || units.getLevel()==2){
AreaExhibition areaExhibition=areaExhibitionCache.findById(units.getExhibitionId());
AreaExhibition areaExhibitionParent=areaExhibitionCache.findById(areaExhibition.getFatherId());
leftNavigation=areaExhibitionParent.toLeftNavigation();
//根据上级展示区域id查询所有的下级区域展示对象
List<AreaExhibition> areaExhibitions= areaExhibitionCache.findByFatherId(areaExhibitionParent.getId());
for (AreaExhibition areaEx:areaExhibitions){
//生成以及新的展示区域 LeftNavigation type =1
LeftNavigation leftNavigation1 = areaEx.toLeftNavigation();
//根据区域展示ID查询相关的单位且转成单位LeftNavigation type =2
List<LeftNavigation> leftNavigationList1=unitsCache.findAllByAreaExhibitionId(areaEx.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList());
leftNavigation1.setLeftNavigations(leftNavigationList1);
//最大的一级LeftNavigation 进行附值
leftNavigationList.add(leftNavigation1);
leftNavigation.setLeftNavigations(leftNavigationList);
}
}else {
leftNavigation= units.toLeftNavigation();
leftNavigation.setLeftNavigations(leftNavigationList);
}
leftNavigation.setLeftNavigations(leftNavigationList.stream().sorted(Comparator.comparing(LeftNavigation::getOrder, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList()));
return leftNavigation;
}
......@@ -454,6 +466,67 @@ public class UnitsServiceImpl implements UnitsService {
return unitsDao.findByAreaId(areaId).stream().map(Units::getUnitId).distinct().collect(Collectors.toList());
}
@Override
public List<Units> unitManagement() {
List<Units> unitsList=unitsDao.findAll();
unitsList.forEach(
units -> {
AreaExhibition areaExhibition = areaExhibitionService.findById(units.getExhibitionId());
units.setAreaName(areaExhibition.getAreaName());
}
);
unitsList= unitsList.stream().sorted(Comparator.comparing(Units::getShowOrder)).collect(Collectors.toList());
return unitsList;
}
@Override
public List<Units> saveUnits(UnitsAddVo unitsAddVo) {
Units units= unitsAddVo.toUnits();
//查询上级设备的单位
Units parentUnits=unitsCache.findById(unitsAddVo.getParentUnitId());
//查询上级的设备的区域a
Area ParentArea=areaCache.findById(parentUnits.getAreaId());
//创建一个区域b 上级id为a
Area area =new Area();
area.setFatherId(ParentArea.getId());
area.setOrders("999");
area.setName(unitsAddVo.getName());
area.setType(unitsAddVo.getLevel());
area= areaDao.save(area);
//创建单位ub 区域id绑定为b
units.setAreaId(area.getId());
units.setType(levelToType(unitsAddVo.getLevel()));
unitsDao.save(units);
unitsCache.refresh(unitsDao.findAll());
areaCache.refresh(areaDao.findAll());
return unitsCache.findAll();
}
@Override
public List<Units> belongsUnits() {
return unitsDao.findAll().stream().filter(units -> units.getLevel()==1&&units.getLevel()==2).sorted(Comparator.comparing(Units::getShowOrder)).collect(Collectors.toList());
}
/**
* 工具类
* @return 单位类型
*/
private Integer levelToType(Integer level){
switch (level){
case 0:
return 3;
case 1:
return 1;
case 2:
return 1;
case 3:
return 1;
case 4:
return 2;
default:
return null;
}
}
@Override
public Units save(Units units) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论