提交 c7bde80a authored 作者: 133's avatar 133

[用户] 开放进出记录的接口以及添加地区、单位管理接口

上级 a1a82e98
package com.tykj.dev.device.user.base.ret;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.Units;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName RolePage.java
* @Description TODO
* @createTime 2020年08月12日 10:18:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "地区分页对象", description = "角色分页对象")
@Builder
public class AreaPage {
@ApiModelProperty(value = "总数", example = "10")
private Integer total;
@ApiModelProperty(value = "页数,0开始", example = "0")
private Integer page;
@ApiModelProperty(value = "大小", example = "10")
private Integer size;
@ApiModelProperty(value = "数据内容", example = "略")
private List<Area> data;
}
package com.tykj.dev.device.user.base.ret;
import com.tykj.dev.device.user.subject.entity.Role;
import com.tykj.dev.device.user.subject.entity.Units;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName RolePage.java
* @Description TODO
* @createTime 2020年08月12日 10:18:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "单位分页对象", description = "角色分页对象")
@Builder
public class UnitsPage {
@ApiModelProperty(value = "总数", example = "10")
private Integer total;
@ApiModelProperty(value = "页数,0开始", example = "0")
private Integer page;
@ApiModelProperty(value = "大小", example = "10")
private Integer size;
@ApiModelProperty(value = "数据内容", example = "略")
private List<Units> data;
}
......@@ -107,15 +107,17 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.cors()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/** ").permitAll()
.withObjectPostProcessor(new ObjectPostProcessor<FilterSecurityInterceptor>() {
@Override
public <O extends FilterSecurityInterceptor> O postProcess(O o) {
o.setSecurityMetadataSource(urlFilterInvocationSecurityMetadataSource);
o.setAccessDecisionManager(urlAccessDecisionManager);
return o;
}
})
// .withObjectPostProcessor(new ObjectPostProcessor<FilterSecurityInterceptor>() {
// @Override
// public <O extends FilterSecurityInterceptor> O postProcess(O o) {
// o.setSecurityMetadataSource(urlFilterInvocationSecurityMetadataSource);
// o.setAccessDecisionManager(urlAccessDecisionManager);
// return o;
// }
// })
.anyRequest().authenticated()
.and()
.formLogin()
.loginProcessingUrl("/userLogin")
......@@ -147,7 +149,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) {
//swagger静态资源访问
web.ignoring().antMatchers("/v2/api-docs", "/v2/api-docs-ext", "/configuration/ui", "/swagger-resources/**", "/configuration/security", "/swagger-ui/", "/swagger-ui/**", "/swagger-ui.html", "/doc.html", "/webjars/**", "/swagger-resources/configuration/ui", "**/swagge‌​r-ui.html", "/static/**", "/**/index.html", "index.html", "/js/**", "/css/**", "/fonds/**", "/img/**");
web.ignoring().antMatchers("/v2/api-docs", "/v2/api-docs-ext", "/configuration/ui", "/swagger-resources/**", "/configuration/security", "/swagger-ui/", "/swagger-ui/**", "/swagger-ui.html", "/doc.html", "/webjars/**", "/swagger-resources/configuration/ui", "**/swagge‌​r-ui.html", "/static/**", "/**/index.html", "index.html", "/js/**", "/css/**", "/fonds/**", "/img/**","/access/send");
}
@Bean
......
......@@ -19,10 +19,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Optional;
......@@ -56,6 +53,25 @@ public class AreaController {
} else {
throw new ApiException(ResponseEntity.status(500).body("areaId查询不到"));
}
}
@PostMapping("/save")
@ApiOperation(value = "添加区域对象", notes = "成功返回区域对象")
public ResponseEntity saveArea(@RequestBody Area area){
return ResponseEntity.ok( areaService.save(area));
}
@GetMapping("/select/oneAndTwo")
@ApiOperation(value = "查询省、市级区域的接口(下拉列表)", notes = "成功返回区域对象")
public ResponseEntity selectOneAndTwo(){
return ResponseEntity.ok(areaService.findOneAndTwoArea());
}
@GetMapping("/page/{page}/{size}")
@ApiOperation(value = "分页查询area对象", notes = "成功返回区域对象")
public ResponseEntity selectPage(@PathVariable Integer page, @PathVariable Integer size){
return ResponseEntity.ok(areaService.selectPage(page,size));
}
}
......@@ -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.subject.entity.SecurityUser;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.service.UnitsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -9,10 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
/**
......@@ -50,7 +48,7 @@ public class UnitsController {
}
@GetMapping(value = "/area")
@ApiOperation(value = "根据等级查询对应等级的单位集合", notes = "单位集合")
@ApiOperation(value = "查询装备库、专管员左侧的区域单位列表", notes = "单位组织结构集合")
public ResponseEntity selectOrganizationUnits(@ApiIgnore @AuthenticationPrincipal SecurityUser securityUser) {
log.info("数据星系:{}",securityUser);
return ResponseEntity.ok(unitsService.findListAreaUnitsVo(securityUser));
......@@ -68,4 +66,17 @@ public class UnitsController {
public ResponseEntity findLastUnits(@PathVariable Integer unitsId) {
return ResponseEntity.ok(unitsService.findByAreaId(unitsId));
}
@PostMapping(value = "/save")
@ApiOperation(value = "添加单位接口", notes = "单位")
public ResponseEntity saveUnits(@RequestBody Units units){
return ResponseEntity.ok(unitsService.save(units));
}
@GetMapping("/page/{page}/{size}")
@ApiOperation(value = "分页查询units对象", notes = "成功返回区域对象")
public ResponseEntity selectPage(@PathVariable Integer page, @PathVariable Integer size){
return ResponseEntity.ok(unitsService.selectPage(page,size));
}
}
......@@ -18,6 +18,8 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.UUID;
/**
* @author zjm
* @version 1.0.0
......@@ -171,4 +173,11 @@ public class UserController {
return ResponseEntity.ok(userService.findUserSuperiorVo(securityUser.getCurrentUserInfo().getUserId()));
}
@GetMapping("/uuid")
@ApiOperation(value = "获取uuid电子签章使用", notes = "uuid")
public ResponseEntity getUuid(@ApiIgnore @AuthenticationPrincipal SecurityUser securityUser) {
return ResponseEntity.ok(UUID.randomUUID().toString());
}
}
......@@ -25,4 +25,6 @@ public interface AreaDao extends JpaRepository<Area, Integer>, JpaSpecificationE
@Query("select o.name from Area o where o.id=?1")
String findNameById(int id);
List<Area> findAllByTypeInOrderByTypeAsc(List<Integer> types);
}
......@@ -8,10 +8,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import org.modelmapper.ModelMapper;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;
/**
* @author zjm
......@@ -48,14 +45,23 @@ public class Area {
*/
private String orders;
/**
* 父类id
*/
private Integer fatherId;
/**
* 父类名称
*/
@Transient
private String fatherName;
// @Transient
// private List<Units> units;
public static Area empty() {
return new Area(0, "不存在的地区", 0, "0", 0);
return new Area(0, "不存在的地区", 0, "0", 0,"");
}
public AreaVo toVo() {
......
......@@ -71,6 +71,10 @@ public class Units {
@ApiModelProperty(value = "区域id", name = "areaId", example = "12321L")
private Integer areaId;
@ApiModelProperty(value = "区域名称", name = "areaName", example = "12321L")
@Transient
private String areaName;
/**
* 区域对象
*/
......@@ -86,6 +90,7 @@ public class Units {
0,
"1234",
1,
null,
null
);
}
......
......@@ -45,4 +45,9 @@ public class UserRole {
*/
@ApiModelProperty(value = "角色id", name = "roleId", example = "12321L")
private Integer roleId;
public UserRole(Integer userId, Integer roleId) {
this.userId = userId;
this.roleId = roleId;
}
}
......@@ -2,6 +2,7 @@ package com.tykj.dev.device.user.subject.service;
import com.tykj.dev.device.user.base.ret.AreaInstitutions;
import com.tykj.dev.device.user.base.ret.AreaPage;
import com.tykj.dev.device.user.base.ret.AreaVo;
import com.tykj.dev.device.user.subject.entity.Area;
......@@ -18,6 +19,15 @@ public interface AreaService extends PublicService<Area> {
List<AreaInstitutions> findAllUserUnitsIdAreaList(Integer areaId);
/**
* 根据id查询所有下级区域对象
* @param areaId 区域id
* @return
*/
List<AreaVo> findAll(Integer areaId);
List<Area> findOneAndTwoArea();
AreaPage selectPage(Integer page,Integer size);
}
package com.tykj.dev.device.user.subject.service;
import com.tykj.dev.device.user.base.ret.AreaVo;
import com.tykj.dev.device.user.base.ret.UnitsPage;
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.SecurityUser;
......@@ -69,4 +70,6 @@ public interface UnitsService extends PublicService<Units> {
*/
Units findByAreaId(Integer unitsId);
UnitsPage selectPage(Integer page, Integer size);
}
package com.tykj.dev.device.user.subject.service.impl;
import com.tykj.dev.device.user.base.ret.AreaInstitutions;
import com.tykj.dev.device.user.base.ret.AreaVo;
import com.tykj.dev.device.user.base.ret.UnitsVo;
import com.tykj.dev.device.user.base.ret.*;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.Role;
import com.tykj.dev.device.user.subject.service.AreaService;
import com.tykj.dev.device.user.subject.service.UnitsService;
import com.tykj.dev.misc.exception.ApiException;
import com.tykj.dev.misc.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
......@@ -83,6 +87,31 @@ public class AreaServiceImpl implements AreaService {
}
@Override
public List<Area> findOneAndTwoArea() {
List<Integer> types=new ArrayList<>();
types.add(1);
types.add(2);
return areaDao.findAllByTypeInOrderByTypeAsc(types);
}
@Override
public AreaPage selectPage(Integer page, Integer size) {
Pageable pageable = PageRequest.of(page, size, Sort.Direction.ASC, "type");
Page<Area> areaPage = areaDao.findAll(pageable);
List<Area> areas= areaPage.getContent();
areas.forEach(area -> {
if (area.getFatherId()!=null) {
area.setFatherName(areaDao.findById(area.getFatherId()).get().getName());
}
});
return AreaPage.builder().data(areas)
.page(page)
.size(size)
.total(Math.toIntExact(areaPage.getTotalElements()))
.build();
}
private List<UnitsVo> subordinateAllUnits(List<UnitsVo> units, Area area) {
List<Area> list = areaDao.findAllByFatherId(area.getId());
if (list.size() == 0) {
......@@ -124,6 +153,12 @@ public class AreaServiceImpl implements AreaService {
@Override
public Area save(Area area) {
Optional<Area> optionalArea = areaDao.findById(area.getFatherId());
if (optionalArea.isPresent()){
area.setType(optionalArea.get().getType()+1);
}else {
throw new ApiException(ResponseEntity.ok("[区域] 没有找到对应的所属区域id"));
}
return areaDao.save(area);
}
......
package com.tykj.dev.device.user.subject.service.impl;
import com.tykj.dev.device.user.base.ret.AreaVo;
import com.tykj.dev.device.user.base.ret.UnitsTrainVo;
import com.tykj.dev.device.user.base.ret.UnitsVo;
import com.tykj.dev.device.user.base.ret.*;
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.SecurityUser;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.service.UnitsService;
import com.tykj.dev.misc.exception.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
......@@ -69,9 +73,9 @@ public class UnitsServiceImpl implements UnitsService {
AreaVo areaVo = area.toVo();
areaVo.setFrontEnd(i++);
List<UnitsVo> unitsList = unitsDao.findAllByAreaId(area.getId()).stream().map(Units::toVo).collect(Collectors.toList());
List<Area> countys = areaDao.findAllByFatherId(areaId);
List<Area> countys = areaDao.findAllByFatherId(area.getId());
if (countys != null && countys.size() != 0) {
List<UnitsVo> countyUnitsList = unitsDao.findAllByAreaId(area.getId()).stream().map(Units::toVo).collect(Collectors.toList());
List<UnitsVo> countyUnitsList = unitsDao.findAllByAreaId(countys.get(0).getId()).stream().map(Units::toVo).collect(Collectors.toList());
unitsList.addAll(countyUnitsList);
}
for (UnitsVo unitsVo : unitsList) {
......@@ -141,15 +145,36 @@ public class UnitsServiceImpl implements UnitsService {
public Units findByAreaId(Integer unitsId) {
return unitsDao.findAllByAreaId(
areaDao.findById(
findById(unitsId).getAreaId()
).get().getFatherId()
).get(0);
areaDao.findById(
findById(unitsId).getAreaId()
).get().getFatherId()
).get(0);
}
@Override
public UnitsPage selectPage(Integer page, Integer size) {
Pageable pageable = PageRequest.of(page, size, Sort.Direction.ASC, "level");
Page<Units> unitsPage = unitsDao.findAll(pageable);
List<Units> list=unitsPage.getContent();
list.forEach(units -> {
units.setAreaName(areaDao.findById(units.getAreaId()).get().getName());
});
return UnitsPage.builder().data(list)
.page(page)
.size(size)
.total(Math.toIntExact(unitsPage.getTotalElements()))
.build();
}
@Override
public Units save(Units units) {
Optional<Area> optionalArea = areaDao.findById(units.getAreaId());
if (optionalArea.isPresent()){
units.setLevel(optionalArea.get().getType());
}else {
throw new ApiException(ResponseEntity.ok("[单位] 没找到对应的区域,请检查"));
}
return unitsDao.save(units);
}
......
......@@ -7,9 +7,11 @@ import com.tykj.dev.device.user.subject.dao.UserRoleDao;
import com.tykj.dev.device.user.subject.entity.Mgrcert;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.entity.User;
import com.tykj.dev.device.user.subject.entity.UserRole;
import com.tykj.dev.device.user.subject.service.UnitsService;
import com.tykj.dev.device.user.subject.service.UserService;
import com.tykj.dev.misc.utils.JacksonUtil;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
......@@ -26,6 +28,7 @@ import java.util.stream.Collectors;
* @createTime 2020年07月27日 15:07:00
*/
@Service
@Slf4j
public class UserServiceImpl implements UserService {
@Autowired
UserDao userDao;
......@@ -38,15 +41,33 @@ public class UserServiceImpl implements UserService {
@Autowired
UserRoleDao userRoleDao;
/**
* 给密码加密bCryptPasswordEncoder
* 在根据创建用户单位 给予不同的角色关联
* @param user
* @return
*/
@Override
public User save(User user) {
String encode = bCryptPasswordEncoder.encode("qwer1234");
user.setPassword(encode);
Units units = unitsService.findById(user.getUnitsId());
List<User> users= userDao.findAllByUnitsId(units.getUnitId());
User user1 = userDao.save(user);
switch (units.getLevel()){
case 1:
userRoleDao.save(new UserRole(user1.getUserId(),1));
break;
case 2:
userRoleDao.save(new UserRole(user1.getUserId(),2));
break;
case 3:
userRoleDao.save(new UserRole(user1.getUserId(),3));
break;
default:
log.info("[user] 添加转管员单位等级不存在:{}",units.getLevel());
return userDao.save(user);
}
return user1;
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论