package cn.autoform.web.controller.formsetting;
|
|
import cn.autoform.bean.ProcessState;
|
import cn.autoform.bean.power.AutoPowerButton;
|
import cn.autoform.db.entity.*;
|
import cn.autoform.factory.FormFactory;
|
import cn.autoform.factory.product.ProductMethod.IOType;
|
import cn.autoform.fw.exception.FormClientException;
|
import cn.autoform.fw.exception.RestResult;
|
import cn.autoform.fw.utility.RestResultGenerator;
|
import cn.autoform.util.thread.Keys;
|
import cn.autoform.util.thread.ThreadData;
|
import cn.autoform.util.tool.JSONTool;
|
import cn.autoform.util.tool.RequestContext;
|
import cn.autoform.web.client.CscApiService;
|
import cn.autoform.web.client.WorkflowClient;
|
import cn.autoform.web.client.util.WorkflowTool;
|
import cn.autoform.web.controller.workflow.WorkflowController;
|
import cn.autoform.web.mapper.formset.FormSetMapper;
|
import cn.autoform.web.service.customButton.CustomButtonService;
|
import cn.autoform.web.service.formresource.FormResourceService;
|
import cn.autoform.web.service.formsetting.FormsettingService;
|
import cn.autoform.web.service.process.ProcessInstanceService;
|
import cn.autoform.web.service.process.ProcessStateService;
|
import com.google.common.base.Objects;
|
import lombok.extern.slf4j.Slf4j;
|
import net.sf.json.JSONObject;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import java.io.IOException;
|
import java.util.*;
|
import java.util.concurrent.TimeoutException;
|
import java.util.stream.Collectors;
|
|
@Slf4j
|
@RestController
|
public class FormsettingController<T> {
|
|
@Autowired
|
FormsettingService formsettingService = null;
|
|
@Autowired
|
CustomButtonService customButtonService = null;
|
|
@Autowired
|
FormResourceService formResoureService;
|
|
@Autowired
|
WorkflowController workflowController;
|
|
@Autowired
|
FormFactory formFactory;
|
|
@Resource
|
FormSetMapper FormSetMapper;
|
|
@Autowired
|
private WorkflowClient workflowClient;
|
|
@Autowired
|
private WorkflowTool workflowTool;
|
|
@Autowired
|
private CscApiService cscApi;
|
|
@Resource(name = "processStateServiceImpl")
|
private ProcessStateService process;
|
|
@Autowired
|
private ProcessInstanceService processInstance;
|
|
/**
|
* 获取当前表单工具栏设置信息
|
* @param entity
|
* @return
|
* @throws IOException
|
* @throws TimeoutException
|
* @throws FormClientException
|
*/
|
@SuppressWarnings({ "rawtypes", "unchecked" })//重写
|
@RequestMapping(value = "${requset.formsetting01}", method = RequestMethod.POST)
|
public RestResult<FormsettingEntity> getFormsettingInfoService(@RequestBody CustomButtonEntity entity) throws Exception,TimeoutException, IOException, FormClientException {
|
FormsettingEntity re = formsettingService.getFormsettingInfo(entity);
|
FormsettingEntity results = re!=null?re:new FormsettingEntity();
|
//判断表单撤回是否启用
|
String recallState = "0";
|
if(results!=null){
|
recallState = results.getRecallable()==null?"0":results.getRecallable();
|
}
|
|
FormsettingEntity result = results==null?new FormsettingEntity():results;
|
|
|
List<FormresourceEntity> path = formResoureService.getFormresourcePath(entity.getTenantID(), entity.getFormID());
|
ProcessState process =new ProcessState(entity.getFormID(),
|
entity.getDataRowNum(), entity.getTenantID());
|
ProcessState state = this.process.selectState(process);
|
// System.err.println(state);
|
// String orderStatus = state.getOrderStatus();
|
if(path!=null){
|
for(FormresourceEntity f:path){
|
result.setResourceFilePath(f.getResourceFilepath());
|
}
|
}
|
|
AutoPowerButton autoPowerButton = customButtonService.selectName(entity, state == null ? process : state);
|
if(entity.getType()!=null && !(entity.getType().equals(""))){
|
CustomButtonExtend cust = new CustomButtonExtend();
|
//把单据状态放进去
|
cust.subCustomButton(autoPowerButton.getShow(),state,entity.getSetting()==null?"":entity.getSetting());
|
result.setSubCustomButton(cust);
|
}else{
|
result.setCustomButtons(autoPowerButton.getShow());
|
}
|
|
//当是详细页的时候
|
if(entity.getDataRowNum() != null && entity.getType() !=null && !(entity.getType().equals("")) && "XX".equals(entity.getType())){
|
|
//获得当前用户名及创建数据用户名
|
|
String flag = FormSetMapper.getFlagByFormID(entity.getFormID(), RequestContext.getTenantId());
|
IOType where = "services".equals(flag) ? IOType.services : IOType.cloud;
|
String userName = ThreadData.get(Keys.OPEN_ID);
|
String parpantName = cscApi.getUserId(ThreadData.get(Keys.OPEN_ID));
|
String createName = this.formFactory.createFormMethod(where).getUserName( entity.getFormID()
|
, entity.getTenantID()
|
, entity.getDataRowNum());
|
|
//用户名不一致的时候就~
|
System.out.println("用户名:"+userName+"---"+createName);
|
if(!userName.equals(createName)){
|
this.setZore(result, results);
|
}
|
|
//PARAM
|
ProcessInstance pros = new ProcessInstance(entity.getFormID()
|
,entity.getTenantID(),entity.getDataRowNum());
|
pros = processInstance.selectInst(pros);
|
//查询是否创建流程 60 50 结束 61 结束 ,首先判断流程
|
if(Objects.equal("20",state.getProcessState())){
|
System.out.println("进入判断1");
|
result.setEditablel("0",results);//不编辑
|
result.setSubmitablel("0",results);//不提交
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("pageNum", 1);
|
jsonObject.put("pageSize", 100);
|
jsonObject.put("processInstId", pros.getProcessInstId());
|
Map<String, Object> workflowResult = workflowClient.instSeacheHandle(workflowTool.getProcess(jsonObject));
|
// Map<String, Object> workflowResult = workflowController.instLog(JSONTool.toJson(pros).toString(),null);
|
if(Objects.equal("00000",workflowResult.get("resCode"))){
|
|
List<Map> data = Optional.ofNullable(workflowResult)
|
.map(d->d.get("data"))
|
.map(d->(Map)d)
|
.map(d->d.get("data"))
|
.map(d->(List)d)
|
.orElse(Collections.EMPTY_LIST);
|
//当前待办人
|
Set<String> currUsers = data
|
.stream()
|
// .findFirst()
|
.map(map-> map.get("openId"))
|
.map(Object::toString)
|
.collect(Collectors.toSet());
|
String processState = data
|
.stream()
|
.findFirst()
|
.map(map-> map.get("processState"))
|
.map(Object::toString)
|
.orElse("");
|
|
//如果提交了流程 但未结束
|
if(data != null && processState != null &&
|
!(processState.equals(60)
|
|| processState.equals(50)
|
|| processState.equals(0)
|
|| processState.equals(61))){
|
//提交,审批,退回,撤回,---逻辑操作
|
//单独判断审批按钮
|
log.debug("按钮权限-当前登录人:{}, 当前待办人:{}, 单据创建人:{}", userName, currUsers, createName);
|
if(currUsers.contains(userName)){
|
System.out.println("进入判断4");
|
results.setRejectable("1");
|
results.setAuditable("1");
|
result.setRejectablel("1",results);//审批
|
result.setAuditablel("1",results);//退回
|
}else{
|
result.setRejectablel("0",results);//审批
|
result.setAuditablel("0",results);//退回
|
}
|
|
|
|
if(Objects.equal(userName, state.getProcessUser()) && currUsers.contains(userName)
|
|| getLog(pros.getProcessInstId()).equals(userName)
|
// (
|
// ObjectUtil.empty(state.getProcessLog())
|
// ||
|
// Optional.ofNullable(data)
|
// .filter(d->d.size() > 1)
|
// .map(d->d.get(d.size()-1))
|
// .map(m->m.get("openId"))
|
// .map(Object::toString)
|
// .map(s-> Objects.equal(s, userName))
|
// .orElse(false)
|
// )
|
){
|
result.setRecallablel("1",results);//可撤回
|
}else{
|
result.setRecallablel("0",results);//不可撤回
|
}
|
|
}
|
}else{
|
this.setZore(result, results);
|
}
|
System.out.println("当前按钮:"+JSONTool.toJson(result));
|
}else if(Objects.equal("30",state.getProcessState())){
|
System.out.println("进入判断2");
|
this.setZore(result, results);
|
}else if(Objects.equal("10",state.getProcessState())){//没有提交流程
|
//判断是否是自动审单中
|
System.out.println("进入判断3");
|
|
if("10".equals(state.getOrderStatus())){
|
//如果为自动审单中, 关闭编辑和提交按钮
|
result.setEditablel("0",results);//不编辑
|
result.setSubmitablel("0",results);//不提交
|
}else{
|
result.setSubmitablel("1",results);//提交
|
result.setEditablel("1",results);//编辑
|
}
|
result.setRejectablel("0",results);//不审批
|
result.setAuditablel("0",results);//不退回
|
result.setRecallablel("0",results);//不可撤回
|
}
|
|
}
|
autoPowerButton.hide(result);
|
return RestResultGenerator.genSuccessResult(result);
|
}
|
|
public String getLog(String processInstId) throws TimeoutException {
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("processInstId", processInstId);
|
Map<String, Object> workflowResult = workflowClient.instLog(workflowTool.getProcess(jsonObject));
|
return Optional.ofNullable(workflowResult)
|
.map(d->d.get("data"))
|
.map(d->(Map)d)
|
.map(d->d.get("data"))
|
.map(d->(List)d)
|
.filter(d->d.size()>1)
|
.map(d->d.get(1))
|
.map(d->((Map)d).get("openId"))
|
.map(Object::toString)
|
.orElse("");
|
}
|
|
public void setZore(FormsettingEntity result,FormsettingEntity results){
|
result.setEditablel("0",results);//不编辑
|
result.setSubmitablel("0",results);//不提交
|
result.setRejectablel("0",results);//不审批
|
result.setAuditablel("0",results);//不退回
|
result.setRecallablel("0",results);//不可撤回
|
}
|
|
/**
|
* 保存表单工具栏信息
|
* @param entity
|
* @return
|
*/
|
@RequestMapping(value = "${requset.formsetting02}", method = RequestMethod.POST)
|
public RestResult<Integer> saveFormsettingInfo(@RequestBody FormsettingEntity entity) {
|
System.err.println(JSONTool.toJson(entity));
|
int rs = 0;
|
CustomButtonEntity cust = new CustomButtonEntity();
|
cust.setTenantID(entity.getTenantID());
|
cust.setFormID(entity.getFormID());
|
FormsettingEntity result = formsettingService.getFormsettingInfo(cust);
|
|
List<CustomButtonEntity> customButtons = entity.getCustomButtons();
|
if(!customButtons.isEmpty()){
|
this.customButtonService.addCustomButton(customButtons);
|
}
|
if(result == null) {
|
rs = formsettingService.createFormsetting(entity);
|
} else {
|
rs = formsettingService.updateFormsetting(entity);
|
}
|
|
return RestResultGenerator.genSuccessResult(rs);
|
}
|
|
/**
|
* 删除工具栏信息
|
*/
|
@RequestMapping(value = "${requset.formsetting03}", method = RequestMethod.POST)
|
public int deleteCustomButton(@RequestBody CustomButtonEntity customButton){
|
return customButtonService.deleteCustomButton(customButton.getId());
|
}
|
|
/**
|
* 修改工具栏信息
|
*/
|
@RequestMapping(value = "${requset.formsetting04}", method = RequestMethod.POST)
|
public int updateCustomButton(@RequestBody List<CustomButtonEntity> list){
|
return customButtonService.updateCustomButton(list);
|
}
|
|
}
|