Commit 96b8a46f authored by 赵啸非's avatar 赵啸非

Merge remote-tracking branch 'origin/master'

parents c8fde557 dca6a8b2
......@@ -145,7 +145,14 @@
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dingtalk</artifactId>
<version>2.0.19</version>
<version>2.0.22</version>
</dependency>
<!--dingdingtalk service sdk-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
......
......@@ -2,20 +2,29 @@ package com.mortals.xhx.busiz.dingtalk.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.dingtalk.config.TalkConfiguration;
import com.mortals.xhx.busiz.dingtalk.req.DingTalkBaseReq;
import com.mortals.xhx.busiz.dingtalk.req.UserPageReq;
import com.mortals.xhx.busiz.req.MobileReq;
import com.mortals.xhx.busiz.req.ReviewSaveReq;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.ApiRespPdu;
import lombok.extern.apachecommons.CommonsLog;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import sun.security.krb5.internal.APOptions;
import java.util.List;
/**
* 钉钉相关外部接口
......@@ -29,7 +38,7 @@ public class TalkApiController {
@Autowired
private TalkConfiguration talkConfiguration;
private String dingToken;
/**
* 获取token
......@@ -37,33 +46,194 @@ public class TalkApiController {
* @return
*/
@PostMapping("/dingtalk/gettoken")
public Rest<String> getToken(@RequestBody DingTalkBaseReq dingTalkBaseReq) {
log.info("收到【getToken】请求【请求体】--> {}", JSON.toJSONString(dingTalkBaseReq));
@UnAuth
public ApiRespPdu<String> getToken() {
ApiRespPdu<String> apiRespPdu = new ApiRespPdu<>();
try {
// DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
// OapiGettokenRequest req = new OapiGettokenRequest();
// req.setHttpMethod("GET");
// OapiGettokenResponse rsp = client.execute(req);
/* DingTalkClient client = new DefaultDingTalkClient(talkConfiguration.getGetTokneUrl());
DingTalkClient client = new DefaultDingTalkClient(talkConfiguration.getGetTokneUrl());
OapiGettokenRequest req = new OapiGettokenRequest();
req.setAppkey(apiKey);
req.setAppsecret(appsecret);
req.setAppkey(talkConfiguration.getAppKey());
req.setAppsecret(talkConfiguration.getAppSecret());
req.setHttpMethod("GET");
OapiGettokenResponse rsp = client.execute(req);
log.info("gettoken rsp:" + rsp.getBody());
if (rsp.getErrcode() == 0) {
dingToken = rsp.getAccessToken();
apiRespPdu.setCode(0);
apiRespPdu.setData(rsp.getAccessToken());
apiRespPdu.setMsg(rsp.getMsg());
} else {
throw new AppException(String.format("errorCode:%s,errorMsg:%s", rsp.getErrcode(), rsp.getErrmsg()));
apiRespPdu.setCode(-1);
apiRespPdu.setData("");
apiRespPdu.setMsg(rsp.getMsg());
}
*/
} catch (Exception e) {
log.error("异常", e);
return Rest.fail(e.getMessage());
apiRespPdu.setCode(-1);
apiRespPdu.setData("");
apiRespPdu.setMsg(e.toString());
}
return apiRespPdu;
}
/**
* 获取部门列表
* @return
*/
@PostMapping("/dingtalk/getSubList")
@UnAuth
public ApiRespPdu<List<OapiV2DepartmentListsubResponse.DeptBaseResponse>> getSubList(){
ApiRespPdu<List<OapiV2DepartmentListsubResponse.DeptBaseResponse>> apiRespPdu = new ApiRespPdu<>();
try {
DingTalkClient client = new DefaultDingTalkClient(talkConfiguration.getGetSubList());
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
if(dingToken == null){
dingToken = getToken().getData();
}
OapiV2DepartmentListsubResponse rsp = client.execute(req, dingToken);
if(rsp.getErrcode() == 0){
apiRespPdu.setCode(0);
apiRespPdu.setData(rsp.getResult());
apiRespPdu.setMsg(rsp.getMsg());
}else {
if(getToken().getCode() == 0){
getSubList();
}else {
apiRespPdu.setCode(-1);
apiRespPdu.setData(null);
apiRespPdu.setMsg("获取token失败");
}
}
} catch (Exception e) {
e.printStackTrace();
apiRespPdu.setCode(-1);
apiRespPdu.setData(null);
apiRespPdu.setMsg(e.toString());
}
return apiRespPdu;
}
/**
* 根据部门id查询该部门下所有用户完整信息
* @return
*/
@PostMapping("/dingtalk/getUserList")
@UnAuth
public ApiRespPdu<OapiV2UserListResponse.PageResult> getUserList(@RequestBody UserPageReq res){
ApiRespPdu<OapiV2UserListResponse.PageResult> apiRespPdu = new ApiRespPdu<>();
try {
DingTalkClient client = new DefaultDingTalkClient(talkConfiguration.getGetuserlist());
OapiV2UserListRequest req = new OapiV2UserListRequest();
if(dingToken == null){
dingToken = getToken().getData();
}
req.setDeptId(res.getDeptid());
req.setCursor(res.getCursor());
req.setSize(res.getSize());
OapiV2UserListResponse rsp = client.execute(req, dingToken);
if(rsp.getErrcode() == 0){
apiRespPdu.setCode(0);
apiRespPdu.setData(rsp.getResult());
apiRespPdu.setMsg(rsp.getMsg());
}else {
if(getToken().getCode() == 0){
getUserList(res);
}else {
apiRespPdu.setCode(-1);
apiRespPdu.setData(null);
apiRespPdu.setMsg("获取token失败");
}
}
} catch (Exception e) {
e.printStackTrace();
apiRespPdu.setCode(-1);
apiRespPdu.setData(null);
apiRespPdu.setMsg(e.toString());
}
return Rest.ok();
return apiRespPdu;
}
/**
* 根据手机号查询用户
* @return
*/
@GetMapping("/dingtalk/getByMobile")
@UnAuth
public ApiRespPdu<OapiV2UserGetResponse.UserGetResponse> getByMobile(@RequestBody MobileReq mobile){
ApiRespPdu<OapiV2UserGetResponse.UserGetResponse> apiRespPdu = new ApiRespPdu<>();
try {
DingTalkClient client = new DefaultDingTalkClient(talkConfiguration.getGetbymobile());
OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
if(dingToken == null){
dingToken = getToken().getData();
}
req.setMobile(mobile.getMobile());
OapiV2UserGetbymobileResponse rsp = client.execute(req, dingToken);
if(rsp.getErrcode() == 0){
//根据获取到的userid去获取用户详情
ApiRespPdu<OapiV2UserGetResponse.UserGetResponse> userRsp = getUserInfo(rsp.getResult().getUserid());
if(userRsp.getCode() == 0){
apiRespPdu.setCode(userRsp.getCode());
apiRespPdu.setData(userRsp.getData());
apiRespPdu.setMsg(userRsp.getMsg());
}else {
apiRespPdu.setCode(-1);
apiRespPdu.setData(null);
apiRespPdu.setMsg(userRsp.getMsg());
}
}else {
if(getToken().getCode() == 0){
getByMobile(mobile);
}else {
apiRespPdu.setCode(-1);
apiRespPdu.setData(null);
apiRespPdu.setMsg("获取token失败");
}
}
} catch (Exception e) {
e.printStackTrace();
apiRespPdu.setCode(-1);
apiRespPdu.setData(null);
apiRespPdu.setMsg(e.toString());
}
return apiRespPdu;
}
/**
* 根据userid查询用户详情
* @return
*/
@GetMapping("/dingtalk/getUserInfo")
@UnAuth
public ApiRespPdu<OapiV2UserGetResponse.UserGetResponse> getUserInfo(@RequestBody String userid){
ApiRespPdu<OapiV2UserGetResponse.UserGetResponse> apiRespPdu = new ApiRespPdu<>();
try {
DingTalkClient client = new DefaultDingTalkClient(talkConfiguration.getGetuserinfo());
OapiV2UserGetRequest req = new OapiV2UserGetRequest();
if(dingToken == null){
dingToken = getToken().getData();
}
req.setUserid(userid);
OapiV2UserGetResponse rsp = client.execute(req, dingToken);
apiRespPdu.setCode(0);
apiRespPdu.setData(rsp.getResult());
apiRespPdu.setMsg(rsp.getMsg());
} catch (Exception e) {
e.printStackTrace();
apiRespPdu.setCode(-1);
apiRespPdu.setData(null);
apiRespPdu.setMsg(e.toString());
}
return apiRespPdu;
}
}
......@@ -19,19 +19,47 @@ public class TalkConfiguration {
@Value("${dingtalk.agentId:''}")
private String getAgentId;
/**
* appKey
*/
@Value("${dingtalk.AppKey:''}")
private String AppKey;
/**
* AppSecret
*/
@Value("${dingtalk.AppSecret:''}")
private String AppSecret;
/**
* getToken
*/
@Value("${dingtalk.gettoken:''}")
@Value("${dingtalk.gettoken:https://oapi.dingtalk.com/gettoken}")
private String getTokneUrl;
/**
* getbymobile
* 获取部门列表
*/
@Value("${dingtalk.getbymobile:''}")
private String getbymobile;
@Value("${dingtalk.listsub:https://oapi.dingtalk.com/topapi/v2/department/listsub}")
private String getSubList;
/**
* 根据部门id获取用户详情列表
*/
@Value("${dingtalk.getUserList:https://oapi.dingtalk.com/topapi/v2/user/list}")
private String getuserlist;
/**
* 根据电话查询用户信息
*/
@Value("${dingtalk.getbymobile:https://oapi.dingtalk.com/topapi/v2/user/getbymobile}")
private String getbymobile;
/**
* 根据userid查询用户信息
*/
@Value("${dingtalk.getuserinfo:https://oapi.dingtalk.com/topapi/v2/user/get}")
private String getuserinfo;
/**
* getDeptbyUser
*/
......
package com.mortals.xhx.busiz.dingtalk.req;
/**
* @author ZYW
* @date 2023-07-12 11:38
*/
public class UserPageReq {
//部门id
private Long deptid;
//起始页码
private Long cursor;
//每页条数
private Long size;
public Long getDeptid() {
return deptid;
}
public void setDeptid(Long deptid) {
this.deptid = deptid;
}
public Long getCursor() {
return cursor;
}
public void setCursor(Long cursor) {
this.cursor = cursor;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
}
package com.mortals.xhx.busiz.req;
/**
* @author ZYW
* @date 2023-07-12 13:47
*/
public class MobileReq {
String mobile;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
}
......@@ -13,6 +13,7 @@ import lombok.Data;
@Data
public class PerformDeptConfDetailVo extends BaseEntityLong {
/** 分类Id */
private Long categoryId;
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ import lombok.Data;
@Data
public class PerformStaffConfDetailVo extends BaseEntityLong {
/** 分类Id */
private Long categoryId;
}
\ No newline at end of file
......@@ -5,7 +5,9 @@ import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.perform.model.PerformDeptConfDetailEntity;
import com.mortals.xhx.module.perform.model.PerformDeptConfDetailQuery;
import com.mortals.xhx.module.perform.model.PerformRulesCategoryEntity;
import com.mortals.xhx.module.perform.service.PerformDeptConfDetailService;
import com.mortals.xhx.module.perform.service.PerformRulesCategoryService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -36,6 +38,8 @@ public class PerformDeptConfServiceImpl extends AbstractCRUDServiceImpl<PerformD
private PerformDeptConfDetailService performDeptConfDetailService;
@Autowired
private DeptService deptService;
@Autowired
private PerformRulesCategoryService performRulesCategoryService;
@Override
protected void findAfter(PerformDeptConfEntity params, PageInfo pageInfo, Context context, List<PerformDeptConfEntity> list) throws AppException {
......@@ -93,6 +97,10 @@ public class PerformDeptConfServiceImpl extends AbstractCRUDServiceImpl<PerformD
item.setCreateUser(entity.getCreateUser());
item.setDeptId(entity.getDeptId());
item.setDeptName(entity.getDeptName());
PerformRulesCategoryEntity categoryEntity = performRulesCategoryService.get(item.getCategoryId());
if(categoryEntity!=null){
item.setCategoryName(categoryEntity.getName());
}
item.setId(null);
}
performDeptConfDetailService.save(entity.getDeptConfDetail(),context);
......
package com.mortals.xhx.module.perform.service.impl;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.common.code.CheckTypeEnum;
import com.mortals.xhx.module.perform.model.*;
import com.mortals.xhx.module.perform.service.PerformRulesCategoryService;
import com.mortals.xhx.module.perform.service.PerformStaffConfDetailService;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.model.StaffQuery;
import com.mortals.xhx.module.staff.service.StaffService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -30,52 +35,77 @@ public class PerformStaffConfServiceImpl extends AbstractCRUDServiceImpl<Perform
@Autowired
private PerformStaffConfDetailService performStaffConfDetailService;
@Autowired
private StaffService staffService;
@Autowired
private PerformRulesCategoryService performRulesCategoryService;
@Override
protected void saveBefore(PerformStaffConfEntity entity, Context context) throws AppException {
super.saveBefore(entity,context);
if(StringUtils.isNotEmpty(entity.getStaffIds())){
List<Long> staffIdList = StringUtils.converStr2Long(entity.getStaffIds());
StaffQuery staffQuery = new StaffQuery();
staffQuery.setIdList(staffIdList);
List<StaffEntity> staffEntityList = staffService.find(staffQuery);
if(CollectionUtils.isNotEmpty(staffEntityList)){
String names = "";
for (StaffEntity item:staffEntityList){
names+=item.getName()+",";
}
entity.setStaffNames(names.substring(0,names.length()-1));
entity.setStaffCount(staffEntityList.size());
}else {
entity.setStaffCount(0);
}
}
if(CollectionUtils.isNotEmpty(entity.getStaffConfDetail())){
// Map<Integer,List<PerformStaffConfDetailEntity>> groupMap = entity.getStaffConfDetail().stream().collect(Collectors.groupingBy(PerformStaffConfDetailEntity::getType));
// if(groupMap.containsKey(CheckTypeEnum.考勤绩效.getValue())) {
// entity.setAttendCount(groupMap.get(CheckTypeEnum.考勤绩效.getValue()).size());
// }else {
// entity.setAttendCount(0);
// }
// if(groupMap.containsKey(CheckTypeEnum.评价绩效.getValue())) {
// entity.setAssessCount(groupMap.get(CheckTypeEnum.评价绩效.getValue()).size());
// }else {
// entity.setAssessCount(0);
// }
// if(groupMap.containsKey(CheckTypeEnum.办件绩效.getValue())) {
// entity.setWorkCount(groupMap.get(CheckTypeEnum.办件绩效.getValue()).size());
// }else {
// entity.setWorkCount(0);
// }
// if(groupMap.containsKey(CheckTypeEnum.效能绩效.getValue())) {
// entity.setEffectCount(groupMap.get(CheckTypeEnum.效能绩效.getValue()).size());
// }else {
// entity.setEffectCount(0);
// }
// if(groupMap.containsKey(CheckTypeEnum.其它绩效.getValue())) {
// entity.setOtherCount(groupMap.get(CheckTypeEnum.其它绩效.getValue()).size());
// }else {
// entity.setOtherCount(0);
// }
Map<Integer,List<PerformStaffConfDetailEntity>> groupMap = entity.getStaffConfDetail().stream().collect(Collectors.groupingBy(PerformStaffConfDetailEntity::getType));
if(groupMap.containsKey(CheckTypeEnum.考勤绩效.getValue())) {
entity.setAttendCount(groupMap.get(CheckTypeEnum.考勤绩效.getValue()).size());
}else {
entity.setAttendCount(0);
}
if(groupMap.containsKey(CheckTypeEnum.评价绩效.getValue())) {
entity.setAssessCount(groupMap.get(CheckTypeEnum.评价绩效.getValue()).size());
}else {
entity.setAssessCount(0);
}
if(groupMap.containsKey(CheckTypeEnum.办件绩效.getValue())) {
entity.setWorkCount(groupMap.get(CheckTypeEnum.办件绩效.getValue()).size());
}else {
entity.setWorkCount(0);
}
if(groupMap.containsKey(CheckTypeEnum.效能绩效.getValue())) {
entity.setEffectCount(groupMap.get(CheckTypeEnum.效能绩效.getValue()).size());
}else {
entity.setEffectCount(0);
}
if(groupMap.containsKey(CheckTypeEnum.其它绩效.getValue())) {
entity.setOtherCount(groupMap.get(CheckTypeEnum.其它绩效.getValue()).size());
}else {
entity.setOtherCount(0);
}
}
}
@Override
protected void saveAfter(PerformStaffConfEntity entity, Context context) throws AppException {
if(CollectionUtils.isNotEmpty(entity.getStaffConfDetail())){
// for(PerformStaffConfDetailEntity item:entity.getStaffConfDetail()){
// item.setStaffConfId(entity.getId());
// item.setCreateTime(entity.getCreateTime());
// item.setCreateUser(entity.getCreateUser());
// item.setStaffId(entity.getStaffId());
// item.setStaffName(entity.getStaffName());
// item.setId(null);
// }
// performDeptConfDetailService.save(entity.getDeptConfDetail(),context);
for(PerformStaffConfDetailEntity item:entity.getStaffConfDetail()){
item.setStaffConfId(entity.getId());
item.setCreateTime(entity.getCreateTime());
item.setCreateUser(entity.getCreateUser());
item.setId(null);
PerformRulesCategoryEntity categoryEntity = performRulesCategoryService.get(item.getCategoryId());
if(categoryEntity!=null){
item.setCategoryName(categoryEntity.getName());
}
}
performStaffConfDetailService.save(entity.getStaffConfDetail(),context);
}
}
......@@ -88,4 +118,25 @@ public class PerformStaffConfServiceImpl extends AbstractCRUDServiceImpl<Perform
}
}
}
@Override
public PerformStaffConfEntity get(Long key, Context context) throws AppException {
PerformStaffConfEntity entity = this.dao.get(key);
if(entity!=null) {
List<PerformStaffConfDetailEntity> detailEntityList = performStaffConfDetailService.find(new PerformStaffConfDetailQuery().staffConfId(entity.getId()));
entity.setStaffConfDetail(detailEntityList);
}
return entity;
}
@Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
if(ids != null && ids.length != 0){
for (Long id:ids){
PerformStaffConfDetailEntity condition = new PerformStaffConfDetailEntity();
condition.setStaffConfId(id);
performStaffConfDetailService.remove(condition,context);
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment