提交 c960df7b authored 作者: 黄夏豪's avatar 黄夏豪

项目完善

上级 e4bcff1b
package com.example.personnelmanager;
import com.example.personnelmanager.common.utils.DateCenterUtil;
import com.example.personnelmanager.common.utils.SpringUtils;
import com.example.personnelmanager.dao.SimpleJpaRepositoryImpl;
import gnu.io.CommPortIdentifier;
import org.springframework.boot.SpringApplication;
......@@ -8,9 +10,11 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
......@@ -32,8 +36,17 @@ import javax.persistence.EntityListeners;
@EnableJpaRepositories(repositoryBaseClass = SimpleJpaRepositoryImpl.class)
public class PersonnelmanagerApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(PersonnelmanagerApplication.class, args);
System.out.println("程序运行成功");
DateCenterUtil dateCenterUtil = SpringUtils.getBean("dateCenterUtil");
dateCenterUtil.sendDateToCenter();
}
@Bean
public OpenEntityManagerInViewFilter openEntityManagerInViewFilter() {
return new OpenEntityManagerInViewFilter();
}
}
......@@ -74,24 +74,25 @@ public class CustomJwtAuthenticationFilter extends
@Override
public Authentication attemptAuthentication(HttpServletRequest request,
HttpServletResponse response) throws AuthenticationException {
// JwtAuthencationToken authRequest ;
// User userByJwt;
// //如果请求头中没有jwt凭证的话说明不应该使用该类进行验证,直接报错
// if (!StringUtils.isEmpty(request.getHeader(JWT_KEY))) {
// //通过请求头获取jwt凭证中的用户信息
// userByJwt = getuserbyjwt(request);
// authRequest = new JwtAuthencationToken(
// userByJwt.getUsername().trim());
// //为用于验证的用户注入session信息
// setDetails(request, authRequest);
// //进行验证
// return getAuthenticationManager().authenticate(authRequest);
// } else {
// throw new GlobalException("未设置token");
// }
JwtAuthencationToken authRequest ;
authRequest = new JwtAuthencationToken("admin");
User userByJwt;
//如果请求头中没有jwt凭证的话说明不应该使用该类进行验证,直接报错
if (!StringUtils.isEmpty(request.getHeader(JWT_KEY))) {
//通过请求头获取jwt凭证中的用户信息
userByJwt = getuserbyjwt(request);
authRequest = new JwtAuthencationToken(
userByJwt.getUsername().trim());
//为用于验证的用户注入session信息
setDetails(request, authRequest);
//进行验证
return getAuthenticationManager().authenticate(authRequest);
} else {
throw new GlobalException("未设置token");
}
//以下为测试代码
// JwtAuthencationToken authRequest ;
// authRequest = new JwtAuthencationToken("admin");
// return getAuthenticationManager().authenticate(authRequest);
}
......
package com.example.personnelmanager.common.config;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import javax.servlet.MultipartConfigElement;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
......@@ -39,4 +41,15 @@ public class BeanConfig {
return new BCryptPasswordEncoder();
}
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
//单个文件最大
factory.setMaxFileSize("20480KB"); //KB,MB
/// 设置总上传数据总大小
factory.setMaxRequestSize("1024000KB");
return factory.createMultipartConfig();
}
}
package com.example.personnelmanager.common.utils;
import com.example.personnelmanager.entity.OrganizationNode;
import com.example.personnelmanager.entity.People;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author HuangXiahao
* @version V1.0
* @class DateCenterJsonUtil
* @packageName com.example.personnelmanager.common.utils
**/
@Component
public class DateCenterJsonUtil {
/**
* 将List<people>生成Json字符串
* Json结构
* {
* "tableId": 1308221225377472514,
* "primaryKeyName": "people_id",
* "data": [
* {
* "primaryKeyValue": 1,
* "dataMap": {
* "name": "黄某",
* "age": "24",
* "birthday":"2020-08-17 13:48:21",
* "delete_tag": 0 ,
* "id_card_number":"3333333333333333",
* "post_id":"39",
* "node_id":"11",
* "icon":"124.70.194.194:13245/images/009bc8c1-fc4a-46a5-a7c0-23b67e26a631.jpg"
* }
* }
* ]
* }
* @param allPeople
* @return
*/
public String initAllPeopleJsonStr(List<People> allPeople){
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("tableId",1308221225377472514L);
jsonObject.addProperty("primaryKeyName","people_id");
JsonArray jsonElements = new JsonArray();
allPeople.forEach(people -> {
JsonObject jsonElementPeople = new JsonObject();
jsonElementPeople.addProperty("primaryKeyValue", people.getPeopleId());
JsonObject jsonElementPeopleData = new JsonObject();
jsonElementPeopleData.addProperty("name", people.getName());
jsonElementPeopleData.addProperty("age", people.getAge());
if (people.getBirthday()!=null){
jsonElementPeopleData.addProperty("birthday", DateFormatUtil.DEFAULT_ON_SECOND_FORMAT.format(people.getBirthday().toEpochMilli()));
}
if (people.getIdCardNumber()!=null){
jsonElementPeopleData.addProperty("id_card_number", people.getIdCardNumber());
}
if (people.getPeoplePosts()!=null&&people.getPeoplePosts().size()>0){
jsonElementPeopleData.addProperty("post_id", people.getPeoplePosts().get(0).getPost().getPostId());
jsonElementPeopleData.addProperty("node_id", people.getPeoplePosts().get(0).getPost().getOrganizationNode().getNodeId());
}
jsonElementPeopleData.addProperty("delete_tag", people.getDeleteTag());
jsonElementPeopleData.addProperty("icon",people.getIcon());
jsonElementPeople.add("dataMap",jsonElementPeopleData);
jsonElements.add(jsonElementPeople);
});
jsonObject.add("data",jsonElements);
return jsonObject.toString();
}
/**
* 将List<OrganizationNode>生成Json字符串
* Json结构
* {
* "tableId": 1308221225377472514,
* "primaryKeyName": "people_id",
* "data": [
* {
* "primaryKeyValue": 1,
* "dataMap": {
* "node_id":1
* "name": "开发部",
* "parent_node": "1",
* "delete_tag":"0",
* }
* }
* ]
* }
* @param allNode
* @return
*/
public String initAllOrganizationNodeJsonStr(List<OrganizationNode> allNode){
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("tableId",1308222142906638337L);
jsonObject.addProperty("primaryKeyName","node_id");
JsonArray jsonElements = new JsonArray();
allNode.forEach(node -> {
JsonObject jsonElementPeople = new JsonObject();
jsonElementPeople.addProperty("primaryKeyValue",node.getNodeId());
JsonObject jsonElementPeopleData = new JsonObject();
jsonElementPeopleData.addProperty("name",node.getNodeName());
jsonElementPeopleData.addProperty("parent_node",node.getParentNode());
jsonElementPeopleData.addProperty("delete_tag",node.getDeleteTag());
jsonElementPeople.add("dataMap",jsonElementPeopleData);
jsonElements.add(jsonElementPeople);
});
jsonObject.add("data",jsonElements);
return jsonObject.toString();
}
}
package com.example.personnelmanager.common.utils;
import com.example.personnelmanager.dao.OrganizationNodeRepository;
import com.example.personnelmanager.dao.PeopleRepository;
import com.example.personnelmanager.entity.OrganizationNode;
import com.example.personnelmanager.entity.People;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author HuangXiahao
* @version V1.0
* @class DateCenterUtil
* @packageName com.example.personnelmanager.common.utils
**/
@Component
public class DateCenterUtil {
@Autowired
PeopleRepository peopleRepository;
@Autowired
OrganizationNodeRepository organizationNodeRepository;
@Autowired
HttpClientUtil httpClientUtil;
@Autowired
DateCenterJsonUtil jsonUtil;
public void sendDateToCenter(){
// 将数据库中的人员数据存放到数据中心
List<People> allPeople = peopleRepository.findAll();
httpClientUtil.post("http://124.70.194.194:8090/opt/data", jsonUtil.initAllPeopleJsonStr(allPeople), "utf-8");
// 将数据库中的部门信息存放到数据中心
List<OrganizationNode> allNode = organizationNodeRepository.findAll();
httpClientUtil.post("http://124.70.194.194:8090/opt/data", jsonUtil.initAllOrganizationNodeJsonStr(allNode), "utf-8");
};
}
......@@ -105,6 +105,7 @@ public class HttpClientUtil {
return result;
}
public String delete(String url, List<NameValuePair> param, String encode) {
HttpDeleteWithBody delete = new HttpDeleteWithBody (url);
String result ;
......@@ -234,6 +235,69 @@ public class HttpClientUtil {
return result;
}
public String put(String url, String param, String encode) {
String result = null;
HttpPut post = new HttpPut(url);
CloseableHttpResponse response = null;
try {
if (!StringUtils.isEmpty(param)) {
StringEntity stringEntity = new StringEntity(param, "utf-8");
if (post.getHeaders(HttpHeaders.CONTENT_TYPE).length < 1) {
post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
}
post.setEntity(stringEntity);
}
CallBackThread callBackThread = new CallBackThread(post);
callBackThread.start();
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
response = callBackThread.response;
if (response == null) {
callBackThread.interrupt();
}
if (callBackThread.message == null || callBackThread.message == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
try {
if (post != null) {
post.abort();
post.releaseConnection();
}
if (response != null) {
if (response.getEntity() != null) {
EntityUtils.consumeQuietly(response.getEntity());
}
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}
throw new NullPointerException("请求接口出现错误");
}else {
result = ResponseEntityUtil.entityToString(response, encode);
}
}catch (IOException e){
throw new GlobalException("请求接口出现错误");
}finally {
try {
if (post != null) {
post.abort();
post.releaseConnection();
}
if (response != null) {
if (response.getEntity() != null) {
EntityUtils.consumeQuietly(response.getEntity());
}
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
public String get(String url, String encode) {
HttpGet get = new HttpGet(url);
......
package com.example.personnelmanager.common.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @program: bserver-parent
* @description: TaskExecutePool,
* @EnableAsync:开启异步处理
* @author: LiuJie
* @create: 2019-05-20 16:01
**/
@Configuration
public class TaskExecutePool {
@Bean
public ExecutorService executorService() {
ExecutorService executorService = Executors.newSingleThreadExecutor();
return executorService;
}
}
\ No newline at end of file
......@@ -46,15 +46,15 @@ public class JwtController {
try {
saveFile(jsonObject.getString("publicKey"));
Map result = new HashMap();
result.put("msg","上传成功");
result.put("code","200");
result.put("msg"," 上传成功");
result.put("code",200);
logger.info("公钥信息保存成功");
return result;
} catch (Exception e) {
e.printStackTrace();
Map result = new HashMap();
result.put("msg","接收签名信息失败");
result.put("code","500");
result.put("code",500);
result.put("data","接收签名信息失败"+ ExceptionMessage.getStackTraceInfo(e));
logger.info("公钥信息接收成功");
return result;
......
......@@ -92,16 +92,10 @@ public class PeopleController {
people.setSex(sex);
people.setPhone(phone);
people.setIdCardNumber(idCardNumber);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
String birthdayYear = idCardNumber.substring(6,10);
String birthdayMonth = idCardNumber.substring(10,12);
String birthdayDay = idCardNumber.substring(12,14);
people.setBirthday(simpleDateFormat.parse(birthdayYear+birthdayMonth+birthdayDay).toInstant());
people.setEntryTime(Instant.now());
peopleService.addEntity(people);
}
}
return new ResultObj("成功");
}
......
......@@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.models.auth.In;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Where;
......@@ -26,7 +27,7 @@ import java.util.List;
@DynamicInsert
@DynamicUpdate
@Table(name = "people")
@ToString(exclude = {"enterprise"})
@ToString(exclude = {"enterprise","certificates","peoplePosts","becomeRegularWorkerInformations","workExperiences","leaveInformations","jobTransferInformations","titles","urgents","educationalExperiences","contracts","certificates"})
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler","enterprise"})
@EntityListeners(AuditingEntityListener.class)
@Where(clause = "delete_tag = 0")
......@@ -34,7 +35,7 @@ public class People {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "people_id",columnDefinition = "bigint comment'人员编号' ")
@Column(name = "people_id",columnDefinition = "bigint comment '人员编号' ")
private Long peopleId;
@NotNull(groups = {GroupSave.class},message = "姓名不能为空")
......@@ -200,5 +201,8 @@ public class People {
return 0.00;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
......@@ -9,7 +9,6 @@ import lombok.Data;
import lombok.ToString;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
......
......@@ -25,7 +25,6 @@ import java.time.Instant;
@Table(name = "post")
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler","enterprise","organizationNode.posts"})
@EntityListeners(AuditingEntityListener.class)
@Where(clause = "delete_tag = 0")
public class Post {
@Id
......
......@@ -35,6 +35,7 @@ public class EducationalExperienceServiceImpl implements EducationalExperienceSe
@Override
public EducationalExperience addEntity(EducationalExperience educationalExperience) {
UserDetail userDetails = AuthenticationUtils.getAuthentication();
educationalExperience.setEnterprise(userDetails.getEnterprise());
EducationalExperience save = educationalExperienceRepository.save(educationalExperience);
return save;
}
......
......@@ -2,6 +2,8 @@ package com.example.personnelmanager.service.impl;
import com.example.personnelmanager.common.exception.GlobalException;
import com.example.personnelmanager.common.utils.AuthenticationUtils;
import com.example.personnelmanager.common.utils.DateCenterJsonUtil;
import com.example.personnelmanager.common.utils.HttpClientUtil;
import com.example.personnelmanager.dao.OrganizationNodeRepository;
import com.example.personnelmanager.dao.PostRepository;
import com.example.personnelmanager.entity.OrganizationNode;
......@@ -20,6 +22,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -39,6 +42,15 @@ public class OrganizationNodeServiceImpl implements OrganizationNodeService {
@Autowired
PostRepository postRepository;
@Autowired
DateCenterJsonUtil dateCenterJsonUtil;
@Autowired
HttpClientUtil httpClientUtil;
@Autowired
ExecutorService executorService;
@Override
public OrganizationNode addEntity(OrganizationNode organizationNode) {
UserDetail userDetails = AuthenticationUtils.getAuthentication();
......@@ -53,6 +65,9 @@ public class OrganizationNodeServiceImpl implements OrganizationNodeService {
}
organizationNode.setEnterprise(userDetails.getEnterprise());
OrganizationNode save = organizationNodeRepository.save(organizationNode);
executorService.submit(() -> {
httpClientUtil.post("http://124.70.194.194:8090/opt/data", dateCenterJsonUtil.initAllOrganizationNodeJsonStr(Arrays.asList(save)), "utf-8");
});
return save;
}
......@@ -80,6 +95,7 @@ public class OrganizationNodeServiceImpl implements OrganizationNodeService {
organizationNodeListVo -> Optional.ofNullable(nodeCollect.get(organizationNodeListVo.getParentNode())),
OrganizationNodeListVo::addChildNode
);
return organizationNodeListVos1;
}
......@@ -148,6 +164,10 @@ public class OrganizationNodeServiceImpl implements OrganizationNodeService {
}
}
OrganizationNode after = organizationNodeRepository.save(organizationNode);
//向数据中心修改旧的数据
executorService.submit(() -> {
httpClientUtil.put("http://124.70.194.194:8090/opt/data", dateCenterJsonUtil.initAllOrganizationNodeJsonStr(Arrays.asList(after)), "utf-8");
});
return after;
}
......@@ -170,10 +190,15 @@ public class OrganizationNodeServiceImpl implements OrganizationNodeService {
if (one.getParentNode()== 0L){
throw new GlobalException("根结点不能被删除");
}
one.setDeleteTag(1);
//删除节点以及所有子节点
organizationNodeRepository.deleteorganizationNode(id);
//删除所有被删除节点下的岗位
postRepository.deletePostByNodeId(id);
//向数据中心修改旧的数据
executorService.submit(() -> {
httpClientUtil.put("http://124.70.194.194:8090/opt/data", dateCenterJsonUtil.initAllOrganizationNodeJsonStr(Arrays.asList(one)), "utf-8");
});
return true;
}
......
package com.example.personnelmanager.service.impl;
import com.example.personnelmanager.common.exception.GlobalException;
import com.example.personnelmanager.common.utils.DateCenterJsonUtil;
import com.example.personnelmanager.common.utils.HttpClientUtil;
import com.example.personnelmanager.dao.PeoplePostRepository;
import com.example.personnelmanager.dao.PeopleRepository;
import com.example.personnelmanager.entity.*;
import com.example.personnelmanager.entity.commonEntity.CustomPage;
import com.example.personnelmanager.service.JobTransferInformationService;
......@@ -12,10 +15,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
/**
* @author HuangXiahao
......@@ -29,8 +35,20 @@ import java.util.Optional;
@Service
public class PeoplePostServiceImpl implements PeoplePostService {
@Autowired
DateCenterJsonUtil dateCenterJsonUtil;
@Autowired
HttpClientUtil httpClientUtil;
@Autowired
ExecutorService executorService;
final PeoplePostRepository peoplePostRepository;
@Autowired
PeopleRepository peopleRepository;
final JobTransferInformationService jobTransferInformationService;
public PeoplePostServiceImpl(PeoplePostRepository peoplePostRepository, JobTransferInformationService jobTransferInformationService) {
......@@ -40,11 +58,19 @@ public class PeoplePostServiceImpl implements PeoplePostService {
@Override
public PeoplePost addEntity(PeoplePost peoplePost) {
Page list = getPage(peoplePost, new CustomPage().getPageable());
//查询用的
PeoplePost psSelect = new PeoplePost();
psSelect.setPeople(peoplePost.getPeople());
Page list = getPage(psSelect, new CustomPage().getPageable());
if (list.getContent().size()>0){
throw new GlobalException("该人员已经在该岗位上");
//该位置由一对多变成了一对一 由于前端时间有限 本项目没有设置VO 先不改
throw new GlobalException("该人员已经有岗位上");
}
return peoplePostRepository.save(peoplePost);
PeoplePost save = peoplePostRepository.save(peoplePost);
executorService.submit(() -> {
httpClientUtil.put("http://124.70.194.194:8090/opt/data", dateCenterJsonUtil.initAllPeopleJsonStr(Arrays.asList(peopleRepository.getOne(save.getPeople().getPeopleId()))), "utf-8");
});
return save;
}
@Override
......@@ -61,7 +87,12 @@ public class PeoplePostServiceImpl implements PeoplePostService {
@Override
public PeoplePost update(PeoplePost peoplePost) {
return peoplePostRepository.save(peoplePost);
PeoplePost save = peoplePostRepository.save(peoplePost);
executorService.submit(() -> {
httpClientUtil.put("http://124.70.194.194:8090/opt/data", dateCenterJsonUtil.initAllPeopleJsonStr(Arrays.asList(peopleRepository.getOne(save.getPeople().getPeopleId()))), "utf-8");
});
return save;
}
@Override
......@@ -86,8 +117,12 @@ public class PeoplePostServiceImpl implements PeoplePostService {
@Override
public Specification<PeoplePost> specificationBuild(PeoplePost peoplePost) {
PredicateBuilder<PeoplePost> and = Specifications.and();
if (peoplePost.getPeople()!=null){
and.eq("people",peoplePost.getPeople().getPeopleId());
}
if (peoplePost.getPost()!=null){
and.eq("post",peoplePost.getPost());
}
return and.build();
}
......
......@@ -3,6 +3,8 @@ package com.example.personnelmanager.service.impl;
import com.example.personnelmanager.common.exception.GlobalException;
import com.example.personnelmanager.common.utils.AuthenticationUtils;
import com.example.personnelmanager.common.utils.DateCalculationUtil;
import com.example.personnelmanager.common.utils.DateCenterJsonUtil;
import com.example.personnelmanager.common.utils.HttpClientUtil;
import com.example.personnelmanager.dao.PeopleRepository;
import com.example.personnelmanager.entity.*;
import com.example.personnelmanager.entity.vo.PeopleVo;
......@@ -23,9 +25,13 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
/**
* @author HuangXiahao
......@@ -50,6 +56,15 @@ public class PeopleServiceImpl implements PeopleService {
@Autowired
BecomeRegularWorkerService becomeRegularWorkerService;
@Autowired
DateCenterJsonUtil dateCenterJsonUtil;
@Autowired
HttpClientUtil httpClientUtil;
@Autowired
ExecutorService executorService;
@Override
public People addEntity(People people) {
UserDetail userDetails = AuthenticationUtils.getAuthentication();
......@@ -64,11 +79,26 @@ public class PeopleServiceImpl implements PeopleService {
}else {
people.setJobStatus("在职");
}
if (people.getIdCardNumber()!=null){
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
String birthdayYear = people.getIdCardNumber().substring(6,10);
String birthdayMonth = people.getIdCardNumber().substring(10,12);
String birthdayDay = people.getIdCardNumber().substring(12,14);
people.setBirthday(simpleDateFormat.parse(birthdayYear+birthdayMonth+birthdayDay).toInstant());
} catch (ParseException e) {
e.printStackTrace();
}
}
if (people.getBirthday()!=null){
people.setAge((int) DateCalculationUtil.twoTimeYearCalculation(people.getBirthday(),Instant.now()));
}
people.setEnterprise(userDetails.getEnterprise());
People save = peopleRepository.save(people);
//向数据中心插入新的数据
executorService.submit(() -> {
httpClientUtil.post("http://124.70.194.194:8090/opt/data", dateCenterJsonUtil.initAllPeopleJsonStr(Arrays.asList(save)), "utf-8");
});
return save;
}
......@@ -98,6 +128,10 @@ public class PeopleServiceImpl implements PeopleService {
people.setAge((int) DateCalculationUtil.twoTimeYearCalculation(people.getBirthday(),Instant.now()));
}
People after = peopleRepository.save(people);
//向数据中心修改旧的数据
executorService.submit(() -> {
httpClientUtil.put("http://124.70.194.194:8090/opt/data", dateCenterJsonUtil.initAllPeopleJsonStr(Arrays.asList(after)), "utf-8");
});
return after;
}
......@@ -118,7 +152,11 @@ public class PeopleServiceImpl implements PeopleService {
}
People people = byId.get();
people.setDeleteTag(1);
peopleRepository.save(people);
People after = peopleRepository.save(people);
//向数据中心修改旧的数据
executorService.submit(() -> {
httpClientUtil.put("http://124.70.194.194:8090/opt/data", dateCenterJsonUtil.initAllPeopleJsonStr(Arrays.asList(after)), "utf-8");
});
return true;
}
......
......@@ -4,10 +4,12 @@ import com.example.personnelmanager.common.exception.GlobalException;
import com.example.personnelmanager.common.utils.AuthenticationUtils;
import com.example.personnelmanager.dao.PostRepository;
import com.example.personnelmanager.entity.OrganizationNode;
import com.example.personnelmanager.entity.PeoplePost;
import com.example.personnelmanager.entity.Post;
import com.example.personnelmanager.entity.UserDetail;
import com.example.personnelmanager.entity.vo.PostVo;
import com.example.personnelmanager.service.OrganizationNodeService;
import com.example.personnelmanager.service.PeoplePostService;
import com.example.personnelmanager.service.PostService;
import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications;
......@@ -15,8 +17,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.core.parameters.P;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
......@@ -39,6 +43,9 @@ public class PostServiceImpl implements PostService {
@Autowired
OrganizationNodeService organizationNodeService;
@Autowired
PeoplePostService peoplePostService;
@Override
public Post addEntity(Post post) {
UserDetail userDetails = AuthenticationUtils.getAuthentication();
......@@ -90,13 +97,21 @@ public class PostServiceImpl implements PostService {
}
@Override
@Transactional
public Boolean delete(Long id) {
Optional<Post> byId = postRepository.findById(id);
if (!byId.isPresent()) {
throw new GlobalException("不存在需要被删除的工作地点");
throw new GlobalException("不存在需要被删除的岗位");
}
Post post = byId.get();
post.setDeleteTag(1);
//构建查询条件
PeoplePost peoplePost = new PeoplePost();
peoplePost.setPost(post);
List<PeoplePost> list = peoplePostService.getList(peoplePost);
list.forEach(p->{
peoplePostService.delete(p.getId());
});
postRepository.save(post);
return true;
}
......
......@@ -7,6 +7,8 @@ file:
imagePath: /opt/jar/workbench/personnel/image/
otherDir: /opt/jar/workbench/personnel/other/
jwtFilePath: /opt/jar/workbench/personnel/other/rsa
server:
serverAddress: 124.70.194.194:${server.port}
center:
ip: 124.70.194.194
......
......@@ -9,6 +9,7 @@ spring:
active: prod
datasource:
url: jdbc:mysql://124.70.194.194:3306/PersonnelManager?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
# url: jdbc:mysql://124.70.194.194:3306/personnelManagerTest?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
password: root
username: canal
driver-class-name: com.mysql.jdbc.Driver
......@@ -23,7 +24,7 @@ spring:
database: mysql
properties:
hibernate:
enable_lazy_load_no_trans=true:jooq:
enable_lazy_load_no_trans: true
sql-dialect: MySQL5Dialect
jackson:
date-format: yyyy-MM-dd HH:mm:ss
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论