DzhtController2.java 42.4 KB
Newer Older
yuquan.zhu committed
1 2 3 4 5 6 7 8 9 10 11
package cn.timer.api.controller.dzht;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

12
import org.springframework.beans.factory.annotation.Value;
yuquan.zhu committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
27
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
yuquan.zhu committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;

import cn.timer.api.bean.dzht.DzhtAssoCjlc;
import cn.timer.api.bean.dzht.DzhtAssoGrzc;
import cn.timer.api.bean.dzht.DzhtAssoHtcsr;
import cn.timer.api.bean.dzht.DzhtAssoHtcyr;
import cn.timer.api.bean.dzht.DzhtAssoHtmb;
import cn.timer.api.bean.dzht.DzhtAssoMbzj;
import cn.timer.api.bean.dzht.DzhtAssoQyyz;
import cn.timer.api.bean.dzht.DzhtAssoQyzc;
import cn.timer.api.bean.dzht.DzhtAssoSdgzq;
import cn.timer.api.bean.dzht.DzhtAssoTpyz;
45
import cn.timer.api.bean.qyzx.businessService.QyzxRemainingQuantity;
46
import cn.timer.api.bean.qyzx.businessService.QyzxUseRecord;
yuquan.zhu committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.controller.dzht.cn.tign.hz.comm.FileHelper;
import cn.timer.api.controller.dzht.cn.tign.hz.comm.HttpHelper;
import cn.timer.api.controller.dzht.cn.tign.hz.constant.ConfigConstant;
import cn.timer.api.controller.dzht.cn.tign.hz.domain.component.StructComponent;
import cn.timer.api.controller.dzht.cn.tign.hz.domain.signarea.PosBean;
import cn.timer.api.controller.dzht.cn.tign.hz.domain.signarea.Signfield;
import cn.timer.api.controller.dzht.cn.tign.hz.domain.signflow.ConfigInfo;
import cn.timer.api.controller.dzht.cn.tign.hz.domain.signflow.SignFlowStart;
import cn.timer.api.controller.dzht.cn.tign.hz.enums.RequestType;
import cn.timer.api.controller.dzht.cn.tign.hz.exception.DefineException;
import cn.timer.api.controller.dzht.cn.tign.hz.helper.AccountHelper;
import cn.timer.api.controller.dzht.cn.tign.hz.helper.FileTemplateHelper;
import cn.timer.api.controller.dzht.cn.tign.hz.helper.SealHelper;
import cn.timer.api.controller.dzht.cn.tign.hz.helper.SignHelper;
import cn.timer.api.controller.dzht.cn.tign.hz.helper.TokenHelper;
import cn.timer.api.controller.dzht.cn.tign.hz.param.SealParamUtil;
import cn.timer.api.dto.dzht.DzhtQueryDto;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@Api(tags = "8.1电子合同")
@Transactional
@RequestMapping(value = "/dzhtApi", produces = { "application/json" })
public class DzhtController2 {

78 79 80 81 82 83
	@Value("${config-8timer.esign.callbackUrl}")
	public String callbackUrl; // 回调地址

	@Value("${config-8timer.esign.redirectUrl}")
	public String redirectUrl; // 重定向地址

yuquan.zhu committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
	private String getID(Integer empNum) {
		QueryWrapper<DzhtAssoGrzc> queryWrapper = new QueryWrapper<DzhtAssoGrzc>();
		queryWrapper.eq("emp_num", empNum);
		DzhtAssoGrzc d = DzhtAssoGrzc.builder().build().selectOne(queryWrapper);

		if (d != null) {
			return d.getAccountId();
		}
		return null;
	}

	@GetMapping("/getAccountId")
	@ApiOperation(value = "根据empNum查accountId", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getAccountId(@CurrentUser UserBean userBean, Integer empNum) {
		return ResultUtil.data(getID(empNum), "查詢成功");
	}

	protected String grzc(@CurrentUser UserBean userBean, Integer empNum) {
		JSONObject j = null;
		if (getID(empNum) == null) {

			Integer orgCode = userBean.getOrgCode();

			YgglMainEmp yg = YgglMainEmp.builder().build()
邓实川 committed
108
					.selectOne(new QueryWrapper<YgglMainEmp>().eq("org_code", orgCode).eq("emp_num", empNum));
yuquan.zhu committed
109 110 111 112 113

			String phone = yg.getPhone();
			String name = yg.getName();
			Integer type = yg.getZjType();
			String idType = null;
邓实川 committed
114
			if (type == null)
115
				return "IDCARD-ERROR";
116
			if (type == 0) {
yuquan.zhu committed
117
				idType = "CRED_PSN_CH_IDCARD";// 大陆身份证
118
			} else if (type == 1) {
yuquan.zhu committed
119
				idType = "CRED_PSN_CH_HONGKONG";// 香港通行证
120
			} else if (type == 2) {
yuquan.zhu committed
121
				idType = "CRED_PSN_CH_TWCARD";// 台湾通行证
122
			} else if (type == 3) {
yuquan.zhu committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
				idType = "CRED_PSN_FOREIGN";// 外籍护照
			}
			String idNumber = yg.getZjNum();

			DzhtAssoGrzc grzc = new DzhtAssoGrzc();
			grzc.setThirdPartyUserId(idNumber);
			grzc.setName(name);
			grzc.setIdType(idType);
			grzc.setIdNumber(idNumber);
			grzc.setMobile(phone);
			grzc.setEmpNum(empNum);
			grzc.setOrgCode(orgCode);

			try {
				TokenHelper.getTokenData();
				j = AccountHelper.createPersonAcct(idNumber, name, idType, idNumber, phone, null);
			} catch (DefineException e) {
				e.getStackTrace();
			}
			grzc.setAccountId(j.getString("accountId"));
			grzc.insert();
			return j.getString("accountId");
		}
		return getID(empNum);
	}

	// 新增个人注册
	@PostMapping("/esignGrzc/{empNum}")
	@ApiOperation(value = "e签宝个人注册(通过empNum)", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> esignGrzc(@CurrentUser UserBean userBean, @PathVariable Integer empNum) {
		return ResultUtil.data(grzc(userBean, empNum), "注册成功");
	}

	// 新增e签宝企业注册
	@PostMapping("/addQyzc")
	@ApiOperation(value = "e签宝企业注册", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> esignQyzc(@CurrentUser UserBean userBean, @RequestBody DzhtAssoQyzc qyzc) {
		DzhtAssoQyzc q = DzhtAssoQyzc.builder().build()
				.selectOne(new QueryWrapper<DzhtAssoQyzc>().eq("third_party_user_id", qyzc.getIdNumber()));
		if (q != null) {
			return ResultUtil.data(q.getOrgId(), "机构已存在");
		}
		JSONObject j = null;
		String creator = grzc(userBean, userBean.getEmpNum());
		qyzc.setCreator(creator);
		String thirdPartyUserId = qyzc.getIdNumber();
		qyzc.setThirdPartyUserId(thirdPartyUserId);
		try {
			TokenHelper.getTokenData();
			j = AccountHelper.createOrgAcct(thirdPartyUserId, creator, qyzc.getName(), qyzc.getIdType(),
					qyzc.getIdNumber());
174 175 176
			Integer code = j.getInteger("code");
			if (code != null && code != 0)
				return ResultUtil.error(j.getString("message"));
yuquan.zhu committed
177
		} catch (DefineException e) {
178
			e.getStackTrace();
yuquan.zhu committed
179 180
		}
		String orgId = j.getString("orgId");
181
		String accountId = j.getString("accountId");
yuquan.zhu committed
182 183 184
		qyzc.setOrgId(orgId);
		qyzc.setOrgCode(userBean.getOrgCode());

185
		if (accountId != null)
yuquan.zhu committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
			qyzc.insert();
		return ResultUtil.data(orgId, "创建成功");
	}

	// 查询企业信息
	@GetMapping("/organizations")
	@ApiOperation(value = "查询企业信息", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> organizations(@CurrentUser UserBean userBean, String orgId) {
		JSONObject j = null;
		try {
			TokenHelper.getTokenData();
			j = AccountHelper.qryOrgAcctByOrgId(orgId);
		} catch (DefineException e) {
			e.printStackTrace();
		}
		return ResultUtil.data(j, "查詢成功");
	}

邓实川 committed
204 205 206 207
	// 查询企业信息s
	@GetMapping("/getOrganizations")
	@ApiOperation(value = "查询企业信息s", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getOrganizations(@CurrentUser UserBean userBean) {
邓实川 committed
208 209 210
//		List<QyzxEmpEntAsso> list = QyzxEmpEntAsso.builder().build().selectList(
//				new QueryWrapper<QyzxEmpEntAsso>().lambda().eq(QyzxEmpEntAsso::getEmpNum, userBean.getEmpNum()));
//		List<Integer> orgCodeList = Lists.transform(list, newList -> newList.getOrgCode());
邓实川 committed
211
		List<String> orgIds = new ArrayList<String>();
邓实川 committed
212
//		for (Integer orgCode : orgCodeList) {
邓实川 committed
213
			DzhtAssoQyzc qyzc = DzhtAssoQyzc.builder().build().selectOne(new QueryWrapper<DzhtAssoQyzc>().lambda()
邓实川 committed
214
					.eq(DzhtAssoQyzc::getOrgCode, userBean.getOrgCode()).select(DzhtAssoQyzc::getOrgId));
邓实川 committed
215 216
			if (qyzc != null)
				orgIds.add(qyzc.getOrgId());
邓实川 committed
217
//		}
邓实川 committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231
		JSONObject j = null;
		List<JSONObject> result = new ArrayList<JSONObject>();
		try {
			TokenHelper.getTokenData();
			for (String orgId : orgIds) {
				j = AccountHelper.qryOrgAcctByOrgId(orgId);
				result.add(j);
			}
		} catch (DefineException e) {
			e.printStackTrace();
		}
		return ResultUtil.data(result, "查詢成功");
	}

yuquan.zhu committed
232 233 234 235
	// 创建机构印章
	@PostMapping("/orgTemplate")
	@ApiOperation(value = "创建机构模板印章", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> orgTemplate(@CurrentUser UserBean userBean, @RequestBody DzhtAssoQyyz qyyz) {
邓实川 committed
236 237 238 239 240 241 242 243

		DzhtAssoQyzc yz = DzhtAssoQyzc.builder().build()
				.selectOne(new QueryWrapper<DzhtAssoQyzc>().eq("org_code", userBean.getOrgCode()).select("org_id"));
		if (yz == null) {
			return ResultUtil.error("请先在签约主体中进行企业认证");
		}
		String orgId = yz.getOrgId();// 查询orgId

yuquan.zhu committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
		// String orgId = "dfd84b9a58d345ea90f6711bad853435";// 测试公司账户
		// 印章参数
		String alias = qyyz.getAlias();
		String color = qyyz.getColor();
		Integer height = qyyz.getHeight();
		Integer width = qyyz.getWidth();
		String htext = qyyz.getHtext();
		String qtext = qyyz.getQtext();
		String type = qyyz.getType();
		String central = qyyz.getCentral();
		String j = SealParamUtil.addOrgTemplateSealParam(alias, color, height, width, htext, qtext, type, central);
		String url = ConfigConstant.createOfficialSeal_URL(orgId);
		JSONObject json = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			json = HttpHelper.doCommHttp(RequestType.POST, url, j);
			if (json.get("code") == "0") {
				JSONObject data = json.getJSONObject("data");
				qyyz.setFileKey(data.getString("fileKey"));
				qyyz.setSealId(data.getString("sealId"));
				qyyz.setCreateTime(new Date());
				qyyz.setOrgId(orgId);
				qyyz.insert();
			}
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.data(json, "创建企业印章成功");
	}

	// 查询机构印章
	@GetMapping("/qryOrgSeal")
	@ApiOperation(value = "查询机构模板印章", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> qryOrgSeal(@CurrentUser UserBean userBean, @RequestParam Integer offset,
			@RequestParam Integer size) {
		JSONObject a = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			DzhtAssoQyzc qyzc = DzhtAssoQyzc.builder().build()
					.selectOne(new QueryWrapper<DzhtAssoQyzc>().eq("org_code", userBean.getOrgCode()).select("org_id"));
			if (qyzc != null) {
				String orgId = qyzc.getOrgId();// 查询orgId
				a = SealHelper.qryOrgSeal(orgId, offset, size);
			}
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.data(a, "查询成功");
	}

	/********************************************/
	// 添加输入项组件
	@PostMapping("/addComponents/{templateId}")
	@ApiOperation(value = "添加输入项组件", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> addComponents(@PathVariable String templateId,
			@RequestBody List<StructComponent> structComponents) {

		List<String> l = new ArrayList<String>();
		for (StructComponent structComponent : structComponents) {
			String key = structComponent.getKey();
			l.add(key);
		}
		String str2 = String.join(",", l);

		List<String> list = null;
		try {
			// List<StructComponent> structComponents = new ArrayList<StructComponent>();
			// // 位置信息
			// Pos pos = new Pos(1, 170, 682);
			// // 组件样式
			// Style style = new Style(100, 24, null, null, null);
			// // 上下文信息
			// Context context = new Context(name, null, null, style, pos);
			// // 组件包装
			// StructComponent structComponent = new StructComponent(null, name, 1,
			// context);
			// structComponents.add(structComponent);

			TokenHelper.getTokenData();// 获取鉴权
			list = FileTemplateHelper.addComponents(templateId, structComponents);

			String str = String.join(",", list);

			QueryWrapper<DzhtAssoMbzj> q = new QueryWrapper<DzhtAssoMbzj>();
			q.eq("template_id", templateId);
			DzhtAssoMbzj mbzj = DzhtAssoMbzj.builder().build().selectOne(q);
			if (mbzj != null) {
				UpdateWrapper<DzhtAssoMbzj> u = new UpdateWrapper<DzhtAssoMbzj>();
				u.eq("template_id", templateId).set("zjid", mbzj.getZjid() + "," + str);
				mbzj.update(u);

			} else {
				DzhtAssoMbzj mbzj2 = new DzhtAssoMbzj();
				mbzj2.setTemplateId(templateId);
				mbzj2.setZjid(str);
				mbzj2.setZjkey(str2);
				mbzj2.insert();
			}
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.data(list);
	}

	// 删除合同模板
	@DeleteMapping("/delHtmb")
	@ApiOperation(value = "删除合同模版", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<Object> delHtmb(@RequestParam String templateId) {
		DzhtAssoHtmb htmb = new DzhtAssoHtmb();
		htmb.setIsDel(1);
		htmb.update(new UpdateWrapper<DzhtAssoHtmb>().eq("template_id", templateId));
		return ResultUtil.success("删除成功");
	}

	// 删除输入项组件
	@DeleteMapping("/delComponents")
	@ApiOperation(value = "删除输入项组件", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<Object> delComponents(@RequestParam String templateId, String ids) {
		try {
			TokenHelper.getTokenData();// 获取鉴权
			FileTemplateHelper.delComponents(templateId, ids);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}

		// 更新数据库组件id
		List<String> list = new ArrayList<String>(Arrays.asList(DzhtAssoMbzj.builder().build()
				.selectOne(new QueryWrapper<DzhtAssoMbzj>().eq("template_id", templateId)).getZjid().split(",")));
		for (String id : ids.split(",")) {
			if (list.contains(id)) {
				list.remove(id);
			}
		}
		String newZjid = String.join(",", list);
		UpdateWrapper<DzhtAssoMbzj> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("template_id", templateId).set("zjid", newZjid);
		DzhtAssoMbzj.builder().build().update(updateWrapper);

		return ResultUtil.success();
	}

	// 查询当前用户合同模板列表
	@PostMapping("/qryComponentList")
	@ApiOperation(value = "查询当前用户合同模板列表", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> qryComponentList(@CurrentUser UserBean userBean, @RequestBody DzhtQueryDto dzhtQueryDto) {
		String mbmc = dzhtQueryDto.getQuery();
		Page<DzhtAssoHtmb> page = new Page<DzhtAssoHtmb>(
				dzhtQueryDto.getCurrentPage() == null ? 1 : dzhtQueryDto.getCurrentPage(),
				dzhtQueryDto.getTotalPage() == null ? 10 : dzhtQueryDto.getTotalPage());
		QueryWrapper<DzhtAssoHtmb> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("is_del", 0).eq("emp_num", userBean.getEmpNum()).like(mbmc != null, "mbmc", mbmc)
邓实川 committed
399 400
				.eq("org_code", userBean.getOrgCode()).select("template_id", "mbmc", "file_name", "created_time")
				.orderByDesc("created_time");
yuquan.zhu committed
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
		IPage<DzhtAssoHtmb> dPage = DzhtAssoHtmb.builder().build().selectPage(page, queryWrapper);
		List<DzhtAssoHtmb> htmbs = dPage.getRecords();
		dPage.getCurrent();
		dPage.getPages();
		dPage.getTotal();
		dPage.getSize();
		return ResultUtil.data(dPage, htmbs, "查询成功");
	}

	// 查询合同模板/组件
	@GetMapping("/qryComponents")
	@ApiOperation(value = "查询合同模板/组件", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> qryComponents(@RequestParam String templateId) {
		JSONObject j = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			j = FileTemplateHelper.qryComponents(templateId);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.data(j);
	}

	// 查询模板组件id
	@GetMapping("/qryMbzjid")
	@ApiOperation(value = "查询 模板组件id", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> qryMbzjid(@RequestParam String templateId) {
		String zjid = DzhtAssoMbzj.builder().build()
				.selectOne(new QueryWrapper<DzhtAssoMbzj>().eq("template_id", templateId)).getZjid();
		String[] a = StringUtils.delimitedListToStringArray(zjid, ",");
		return ResultUtil.data(a);
	}

	// 查询文件详情/下载文件
	/**
	 * status 文件状态(返回参数) 0:文件未上传; 1:文件上传中 ; 2:文件上传已完成,; 3:文件上传失败 ; 4:文件等待转pdf ;
	 * 5:文件已转换pdf 。 6:加水印中 7:加水印完毕
	 */
	@GetMapping("/getDownLoadUrl")
	@ApiOperation(value = "查询文件详情/下载文件", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getDownLoadUrl(@RequestParam String fileId) {
		JSONObject j = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			j = FileTemplateHelper.getDownLoadUrl(fileId);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.data(j);
	}

	// 创建签署流程
455
	@Transactional
yuquan.zhu committed
456 457 458
	@PostMapping("/signflows")
	@ApiOperation(value = "创建签署流程", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> signflows(@CurrentUser UserBean userBean, @RequestBody DzhtAssoCjlc lc) {
459
		Integer empNum = userBean.getEmpNum();
460
		Integer orgCode = userBean.getOrgCode();
461
		String flowId = null;
462 463 464 465 466 467 468 469 470 471 472
		QyzxRemainingQuantity quantity = QyzxRemainingQuantity.builder().build().selectOne(
				new LambdaQueryWrapper<QyzxRemainingQuantity>().eq(QyzxRemainingQuantity::getOrgCode, orgCode)
						.eq(QyzxRemainingQuantity::getPmid, 2).gt(QyzxRemainingQuantity::getRemainder, 0));
		Integer remainder = null;
		Date date = null;
		if (quantity != null) {
			remainder = quantity.getRemainder();
			date = quantity.getExpireDate();
		}

		if (quantity == null || remainder == null || remainder <= 0) {
邓实川 committed
473
			return ResultUtil.error("当前企业套餐余额不足,请充值购买后使用");
474 475
		}
		if (date != null && date.getTime() <= new Date().getTime()) {
邓实川 committed
476
			return ResultUtil.error("当前企业电子合同套餐已过期");
477 478
		}

yuquan.zhu committed
479 480 481 482
		// ConfigInfo cfgInfo = new ConfigInfo(null, "1,2", null, null);
		// SignFlowStart sfs = new SignFlowStart(null, "测试签署流程开启", null, null, null,
		// null, null, cfgInfo);

483 484 485 486 487 488 489 490 491 492 493
		String a = null;
		if (callbackUrl != null) {
			a = callbackUrl;
		}
//				lc.getNoticeDeveloperUrl(); // 回调地址
		String c = null;
		if (redirectUrl != null) {
			c = redirectUrl;
		}
//				lc.getRedirectUrl(); // 签署完成回调地址

yuquan.zhu committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
		String b = lc.getNoticeType();
		String d = lc.getSignPlatform();
		ConfigInfo cfgInfo = new ConfigInfo(a, b, c, d);

		Boolean e = lc.getAutoArchive();
		String f = lc.getBusinessScene();

		Long g = lc.getContractValidity();
		Integer h = lc.getContractRemind();
		Long i = lc.getSignValidity();
		DzhtAssoGrzc grzc = DzhtAssoGrzc.builder().build()
				.selectOne(new QueryWrapper<DzhtAssoGrzc>().eq("emp_num", userBean.getEmpNum()));
		String j = null;
		if (grzc != null) {
			j = grzc.getAccountId();
		}
		lc.setInitiatorAccountId(j);
		String k = lc.getInitiatorAuthorizedAccountId();

		SignFlowStart sfs = new SignFlowStart(e, f, g, h, i, j, k, cfgInfo);
		JSONObject jsonObject = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			jsonObject = SignHelper.createSignFlow(sfs);
518 519 520
			flowId = jsonObject.getString("flowId");
			lc.setFlowId(flowId);
			lc.setCreater(empNum);
yuquan.zhu committed
521
			lc.setCreatedTime(new Date());
522
			lc.setOrgCode(orgCode);
yuquan.zhu committed
523 524 525 526 527
			lc.insert();
		} catch (DefineException e1) {
			e1.printStackTrace();
			return ResultUtil.error();
		}
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
		QyzxUseRecord qyzxUseRecord = new QyzxUseRecord();
		qyzxUseRecord.setCreateTime(new Date());

		YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda()
				.eq(YgglMainEmp::getEmpNum, empNum).select(YgglMainEmp::getName));
		String name = null;
		if (ygglMainEmp != null) {
			name = ygglMainEmp.getName();
		}
		qyzxUseRecord.setCreateUser(name);
		qyzxUseRecord.setOriginalTotalNum(remainder);
		qyzxUseRecord.setNowTotalNum(--remainder);
		qyzxUseRecord.setOrderNo(quantity.getOrderNo());
		qyzxUseRecord.setOrgCode(orgCode);
		qyzxUseRecord.setUseNum(1);
		qyzxUseRecord.setScene("签署中");
邓实川 committed
544
		qyzxUseRecord.setPmid(2);
545
		qyzxUseRecord.setFlowId(flowId);
邓实川 committed
546
		qyzxUseRecord.setFlowName(f);
547 548 549 550 551
		qyzxUseRecord.insert();

		quantity.setRemainder(remainder);
		quantity.updateById();

yuquan.zhu committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
		return ResultUtil.data(jsonObject, "创建签署流程成功");
	}

	// 签署流程查询
	// 0-草稿 1-签署中 2-完成 3-撤销 5-过期(签署截至日志到期后触发) 7-拒签
	@GetMapping("/qrySignFlow")
	@ApiOperation(value = "签署流程查询", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> qrySignFlow(@RequestParam String flowId) {
		JSONObject json = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			json = SignHelper.qrySignFlow(flowId);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.data(json, "查询成功");
	}

	// 流程签署人列表
	@GetMapping("/qryFlowSigners")
	@ApiOperation(value = "流程签署人列表", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> qryFlowSigners(@RequestParam String flowId) {
		JSONObject json = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			json = SignHelper.qryFlowSigners(flowId);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.data(json, "查询成功");
	}

	// 流程签署人列表(签署人姓名、AccountId)
	@GetMapping("/getQsr")
	@ApiOperation(value = "流程签署人列表(签署人姓名、AccountId)", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> flowSigners(@RequestParam String flowId) {
		JSONObject json = null;
		List<Map<String, String>> l = new ArrayList<Map<String, String>>();
		try {
			TokenHelper.getTokenData();// 获取鉴权
			json = SignHelper.qryFlowSigners(flowId);

			JSONArray j = json.getJSONArray("signers");
			if (j != null) {
				for (int i = 0; i < j.size(); i++) {
					Map<String, String> map = new HashMap<String, String>();
					String signerAccountId = j.getJSONObject(i).getString("signerAccountId");
					String signerName = j.getJSONObject(i).getString("signerName");
					map.put("signerAccountId", signerAccountId);
					map.put("signerName", signerName);
					l.add(map);
				}
			}
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.data(l, "查询成功");
	}

	// 流程文档添加
	@PostMapping("/addFlowDoc")
	@ApiOperation(value = "流程文档添加", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> addFlowDoc(@RequestParam String fileIds, @RequestParam String flowId) {
		try {
			TokenHelper.getTokenData();// 获取鉴权
			SignHelper.addFlowDoc(flowId, fileIds);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.success("添加成功");
	}

	// 流程文档删除
	@DeleteMapping("/delFlowDoc")
	@ApiOperation(value = "流程文档删除", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<Object> delFlowDoc(@RequestParam String fileIds, @RequestParam String flowId) {
		try {
			TokenHelper.getTokenData();// 获取鉴权
			SignHelper.delFlowDoc(flowId, fileIds);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.success("删除成功");
	}

	// 保存参与人信息
	@PostMapping("/saveCyr")
	@ApiOperation(value = "保存参与人信息", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> saveCyr(@CurrentUser UserBean userBean, @RequestBody List<DzhtAssoHtcyr> htcyrs) {
		for (DzhtAssoHtcyr htcyr : htcyrs) {
			Integer empNum = htcyr.getEmpNum();
			DzhtAssoGrzc grzc = DzhtAssoGrzc.builder().build()
					.selectOne(new QueryWrapper<DzhtAssoGrzc>().eq("emp_num", empNum));
			if (grzc != null) {
				htcyr.setSignerAccountId(grzc.getAccountId());
			} else {
				htcyr.setSignerAccountId(grzc(userBean, empNum));// 没有就注册一个
			}
			DzhtAssoHtcyr cyr = DzhtAssoHtcyr.builder().build().selectOne(
					new QueryWrapper<DzhtAssoHtcyr>().eq("emp_num", empNum).eq("template_id", htcyr.getTemplateId()));
			if (cyr == null) {
				htcyr.insert();
			}
		}

		return ResultUtil.data(htcyrs, "保存成功");
	}

	// 获取参与人信息
	@GetMapping("/getCyr")
	@ApiOperation(value = "获取参与人信息", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getCyr(@CurrentUser UserBean userBean, String templateId) {
		List<DzhtAssoHtcyr> dzht = DzhtAssoHtcyr.builder().build()
				.selectList(new QueryWrapper<DzhtAssoHtcyr>().eq("template_id", templateId));
		return ResultUtil.data(dzht, "查询成功");
	}

	// 保存抄送人信息
	@PostMapping("/saveCsr")
	@ApiOperation(value = "保存抄送人信息", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> saveCsr(@CurrentUser UserBean userBean, @RequestBody List<DzhtAssoHtcsr> htcsrs) {
		for (DzhtAssoHtcsr htcsr : htcsrs) {
			Integer empNum = htcsr.getEmpNum();
			DzhtAssoGrzc grzc = DzhtAssoGrzc.builder().build()
					.selectOne(new QueryWrapper<DzhtAssoGrzc>().eq("emp_num", empNum));
			if (grzc != null) {
				htcsr.setSignerAccountId(grzc.getAccountId());
			} else {
				htcsr.setSignerAccountId(grzc(userBean, empNum));// 没有就注册一个
			}
			DzhtAssoHtcsr cyr = DzhtAssoHtcsr.builder().build().selectOne(
					new QueryWrapper<DzhtAssoHtcsr>().eq("emp_num", empNum).eq("template_id", htcsr.getTemplateId()));
			if (cyr == null) {
				htcsr.insert();
			}
		}
		return ResultUtil.data(htcsrs, "保存成功");
	}

	// 获取抄送人信息
	@GetMapping("/getCsr")
	@ApiOperation(value = "获取抄送人信息", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getCsr(@CurrentUser UserBean userBean, String templateId) {
		List<DzhtAssoHtcsr> dzht = DzhtAssoHtcsr.builder().build()
				.selectList(new QueryWrapper<DzhtAssoHtcsr>().eq("template_id", templateId));
		return ResultUtil.data(dzht, "查询成功");
	}

//	// 保存手动盖章签署区
//	@PostMapping("/saveSign")
//	@ApiOperation(value = "保存手动盖章区信息", httpMethod = "POST", notes = "接口发布说明")
//	public Result<Object> saveSign(@CurrentUser UserBean userBean, @RequestBody List<DzhtAssoSdgzq> sdgzqs) {
//		for (DzhtAssoSdgzq sdgzq : sdgzqs) {
//			sdgzq.setCreater(userBean.getEmpNum());
//			sdgzq.setCreatedTime(new Date());
//			sdgzq.setOrgCode(userBean.getOrgCode());
//			sdgzq.insert();
//		}
//		return ResultUtil.data(sdgzqs);
//
//	}

	// 添加手动盖章签署区
	@PostMapping("/handSign")
	@ApiOperation(value = "添加手动盖章区", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> handSign(@CurrentUser UserBean userBean, @RequestBody List<DzhtAssoSdgzq> sdgzqs) {

		List<String> list = new ArrayList<String>();

		// 这里举一个签署区的例子
		// String fileId1 = fileIds.get(0);
		// String signerAccountId1 = signerAccountIds.get(0);
		// String authorizedAccountId1 =
		// CollectionUtils.isNotEmpty(authorizedAccountIds) ?
		// authorizedAccountIds.get(0) : null;
		//
		// List<Signfield> list = Lists.newArrayList();
		// PosBean posBean1 = new PosBean("1", 500f, 100f, null, null);
		// Signfield signfield1 = new Signfield(fileId1, signerAccountId1, null,
		// authorizedAccountId1, null, 1, posBean1,
		// null, null, null);
		//
		// list.add(signfield1);

		// List<DzhtAssoSdgzq> sdgzqs = DzhtAssoSdgzq.builder().build().selectList(new
		// QueryWrapper<DzhtAssoSdgzq>()
		// .eq("org_code", userBean.getOrgCode()).eq("emp_num",
		// userBean.getEmpNum()).orderByDesc("created_time"));

		List<Signfield> signfields = new ArrayList<Signfield>();
		JSONObject json = null;
		for (DzhtAssoSdgzq sdgzq : sdgzqs) {

			String flowId = sdgzq.getFlowId();
751 752 753 754
			DzhtAssoCjlc lc = DzhtAssoCjlc.builder().build()
					.selectOne(new QueryWrapper<DzhtAssoCjlc>().eq("flow_id", flowId).select("business_scene"));
			sdgzq.setBusinessScene(lc.getBusinessScene());// 文件主题

yuquan.zhu committed
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
			String fileId = sdgzq.getFileId();
			String signerAccountId = sdgzq.getSignerAccountId();

			list.add(signerAccountId);

			String authorizedAccountId = sdgzq.getAuthorizedAccountId();
			Integer actorIndentityType = sdgzq.getActorIndentityType();
			Boolean assignedPosbean = sdgzq.getAssignedPosbean();
			Integer order = sdgzq.getSignOrder();
			String posPage = sdgzq.getPosPage();
			Float posX = sdgzq.getPosX();
			Float posY = sdgzq.getPosY();
			Float width = sdgzq.getWidth();
			Boolean addSignTime = sdgzq.getAddSignTime();
			String sealType = sdgzq.getSealType();
			// String sealId = sdgzq.getSealId();
			Integer signType = sdgzq.getSignType();
			String thirdOrderNo = sdgzq.getThirdOrderNo();

			PosBean posBean = new PosBean(posPage, posX, posY, width, addSignTime);
			Signfield signfield = new Signfield(fileId, signerAccountId, actorIndentityType, authorizedAccountId,
					assignedPosbean, order, posBean, sealType, signType, thirdOrderNo);

			signfields.add(signfield);
			try {
				DzhtAssoGrzc grzc = DzhtAssoGrzc.builder().build()
						.selectOne(new QueryWrapper<DzhtAssoGrzc>().eq("account_id", signerAccountId));
				if (grzc != null) {
					Integer signerEmpNum = grzc.getEmpNum();
784
					sdgzq.setSignerEmpNum(signerEmpNum);// 签署人员工号
yuquan.zhu committed
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
				}
				sdgzq.setCreater(userBean.getEmpNum());
				sdgzq.setCreatedTime(new Date());
				sdgzq.setOrgCode(userBean.getOrgCode());

				TokenHelper.getTokenData();
				json = SignHelper.addSignerHandSignArea(flowId, signfields);
				JSONObject jsonObject = json.getJSONArray("signfieldBeans").getJSONObject(0);
				sdgzq.setSignfieldId(jsonObject.getString("signfieldId"));

			} catch (DefineException e) {
				e.printStackTrace();
				return ResultUtil.error();
			}
//			String str = String.join(",", list);
//
//			DzhtAssoCjlc lc = DzhtAssoCjlc.builder().build()
//					.selectOne(new QueryWrapper<DzhtAssoCjlc>().eq("flow_id", flowId));
//			String accountId = lc.getSingerAccountId();
//
//			if (accountId != null) {
//				accountId = accountId + "," + str;
//			}
//			DzhtAssoCjlc.builder().singerAccountId(accountId).build()
//					.update(new QueryWrapper<DzhtAssoCjlc>().eq("flow_id", flowId)); // 更新创建流程签署人
			sdgzq.insert();
		}

		return ResultUtil.data(json, "添加成功");
	}

	// 创建个人/机构图片印章
	@PostMapping("/image")
	@ApiOperation(value = "创建个人/机构图片印章", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> image(@CurrentUser UserBean userBean, @RequestBody DzhtAssoTpyz tpyz) {

		// 下载oss文件到服务器
		String ossUrl = tpyz.getOssUrl();
		String fileName = System.currentTimeMillis() + UUID.randomUUID().toString()
				+ ossUrl.substring(ossUrl.lastIndexOf("."));

		String filePath = null;
		try {
邓实川 committed
828
			filePath = FileHelper.downLoadFromUrl(ossUrl, fileName, DzhtController.savePath());
yuquan.zhu committed
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
			tpyz.setFilePath(filePath);
		} catch (IOException e1) {
			e1.printStackTrace();
		}

		final String type = "BASE64";
		tpyz.setType(type);// 数据类型
		String accountId = tpyz.getAccountId();// 个人账户
		String alias = tpyz.getAlias();// 印章别名
		Integer height = tpyz.getHeight();// 高
		Integer width = tpyz.getWidth();// 宽
		Boolean transparentFlag = tpyz.getTransparentFlag();// 是否透明化

		String data = null;
		JSONObject json = null;
		try {
			data = FileHelper.getBase64Str(filePath);
			tpyz.setData(data);// 图片BASE64数据

			TokenHelper.getTokenData();// 获取鉴权
			json = SealHelper.createPicSeal(accountId, alias, height, width, type, data, transparentFlag);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		tpyz.setSealId(json.getString("sealId"));
		tpyz.setFileKey(json.getString("fileKey"));
		tpyz.setHeight(json.getInteger("height"));
		tpyz.setWidth(json.getInteger("width"));
		tpyz.setEmpNum(userBean.getEmpNum());
		tpyz.setOrgCode(userBean.getOrgCode());
		tpyz.setCreatedTime(new Date());
		tpyz.insert();
		return ResultUtil.data(json, "创建成功");

	}

	// 查询签署区列表
	@GetMapping("/qrySignArea")
	@ApiOperation(value = "查询签署区列表", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> qrySignArea(@RequestParam String flowId, @RequestParam(required = false) String accountId,
			@RequestParam(required = false) String signfieldIds) {
		JSONObject json = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			json = SignHelper.qrySignArea(flowId, accountId, signfieldIds);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.data(json, "查询成功");
	}

	// 删除签署区
	@DeleteMapping("/delSignArea")
	@ApiOperation(value = "删除签署区", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<Object> delSignArea(@RequestParam String flowId, @RequestParam String signfieldIds) {
		JSONObject json = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			json = SignHelper.delSignArea(flowId, signfieldIds);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.data(json, "删除成功");
	}

	// 开启签署流程
	@PutMapping("/startSignFlow")
	@ApiOperation(value = "开启签署流程", httpMethod = "PUT", notes = "接口发布说明")
	public Result<Object> startSignFlow(@CurrentUser UserBean userBean, @RequestParam String flowId) {
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920

		Integer orgCode = userBean.getOrgCode();

		QyzxRemainingQuantity quantity = QyzxRemainingQuantity.builder().build().selectOne(
				new LambdaQueryWrapper<QyzxRemainingQuantity>().eq(QyzxRemainingQuantity::getOrgCode, orgCode)
						.eq(QyzxRemainingQuantity::getPmid, 2).gt(QyzxRemainingQuantity::getRemainder, 0));
		Integer remainder = null;
		Date date = null;
		if (quantity != null) {
			remainder = quantity.getRemainder();
			date = quantity.getExpireDate();
		}

		if (quantity == null || remainder == null || remainder <= 0) {
			return ResultUtil.error("企业 " + orgCode + " :套餐余额不足,请充值购买后使用");
		}
		if (date != null && date.getTime() <= new Date().getTime()) {
			return ResultUtil.error("企业 " + orgCode + " :电子合同套餐已过期");
		}

yuquan.zhu committed
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
		try {
			TokenHelper.getTokenData();// 获取鉴权
			SignHelper.startSignFlow(flowId);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.success();
	}

	// 获取签署地址
	@GetMapping("/qrySignUrl")
	@ApiOperation(value = "获取签署地址", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> qrySignUrl(@CurrentUser UserBean userBean, @RequestParam String flowId,
			@RequestParam(required = false) String organizeId, @RequestParam(required = false) String urlType) {
936
		JSONObject json = null;
yuquan.zhu committed
937 938 939 940 941 942
		try {
			QueryWrapper<DzhtAssoGrzc> queryWrapper = new QueryWrapper<DzhtAssoGrzc>();
			queryWrapper.eq("emp_num", userBean.getEmpNum()).select("account_id");
			String accountId = DzhtAssoGrzc.builder().build().selectOne(queryWrapper).getAccountId();

			TokenHelper.getTokenData();// 获取鉴权
943
			json = SignHelper.qrySignUrl(flowId, accountId, organizeId, urlType);
yuquan.zhu committed
944 945 946 947
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
948 949 950
		if (json != null && json.getLong("code") != 0)
			return ResultUtil.error(json.getString("message"));
		return ResultUtil.data(json.getJSONObject("data"), "成功");
yuquan.zhu committed
951 952 953 954 955 956 957 958 959 960 961
	}

	// 流程签署人催签
	@PutMapping("/rushsign")
	@ApiOperation(value = "流程签署人催签", httpMethod = "PUT", notes = "接口发布说明")
	public Result<Object> rushsign(@CurrentUser UserBean userBean, @RequestParam String flowId,
			@RequestParam(required = false) String noticeTypes,
			@RequestParam(required = false) String rushsignAccountId) {
		try {
			TokenHelper.getTokenData();// 获取鉴权

962 963 964 965
			JSONObject json = SignHelper.rushSign(flowId, getID(userBean.getEmpNum()), noticeTypes, rushsignAccountId);
			if (json != null && json.getLong("code") != 0) {
				return ResultUtil.error(json.getString("message"));
			}
yuquan.zhu committed
966
		} catch (DefineException e) {
967
//			return ResultUtil.error("当前用户非流程发起人, 不能执行催签操作");
yuquan.zhu committed
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
			e.printStackTrace();
		}
		return ResultUtil.success();
	}

	// 撤回签署流程
	@PutMapping("/revoke")
	@ApiOperation(value = "撤回签署流程", httpMethod = "PUT", notes = "接口发布说明")
	public Result<Object> revoke(@CurrentUser UserBean userBean, @RequestParam String flowId,
			@RequestParam(required = false) String revokeReason) {
		String operatorId = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			DzhtAssoGrzc grzc = DzhtAssoGrzc.builder().build()
					.selectOne(new QueryWrapper<DzhtAssoGrzc>().eq("emp_num", userBean.getEmpNum()));
			if (grzc != null) {
				operatorId = grzc.getAccountId();
			}
986 987 988 989 990
			JSONObject json = SignHelper.revokeSignFlow(flowId, revokeReason, operatorId);

			if (json != null && json.getLong("code") != 0) {
				return ResultUtil.error(json.getString("message"));
			}
yuquan.zhu committed
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.success();
	}

	// 签署流程归档
	@PutMapping("/archiveSignFlow")
	@ApiOperation(value = "签署流程归档", httpMethod = "PUT", notes = "接口发布说明")
	public Result<Object> archiveSignFlow(@CurrentUser UserBean userBean, @RequestParam String flowId) {
		try {
			TokenHelper.getTokenData();// 获取鉴权
			SignHelper.archiveSignFlow(flowId);
		} catch (DefineException e) {
			e.printStackTrace();
			return ResultUtil.error();
		}
		return ResultUtil.success();
	}

	// 流程文档下载
	@GetMapping("/downloadFlowDoc")
	@ApiOperation(value = "流程文档下载", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> downloadFlowDoc(@RequestParam String flowId) {
		JSONObject json = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			json = SignHelper.downloadFlowDoc(flowId);
		} catch (DefineException e) {
			e.printStackTrace();
		}
1023 1024 1025
		if (json != null && json.getLong("code") != 0)
			return ResultUtil.error(json.getString("message"));
		return ResultUtil.data(json.getJSONObject("data"), "成功");
yuquan.zhu committed
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
	}

	/**
	 * 获取当前用户发起的签署流程
	 * 
	 * @param flowId
	 * @return
	 */
	@GetMapping("/getFqlc")
	@ApiOperation(value = "当前用户发起的签署流程", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getFqlc(@CurrentUser UserBean userBean,
			@RequestParam(required = false, defaultValue = "1") Integer currPage,
			@RequestParam(required = false, defaultValue = "10") Integer pageSize,
			@RequestParam(required = false) String query) {
		com.github.pagehelper.Page<Object> page = PageHelper.startPage(currPage, pageSize);
1041 1042 1043
		List<DzhtAssoCjlc> cjlcs = DzhtAssoCjlc.builder().build()
				.selectList(new QueryWrapper<DzhtAssoCjlc>().like(query != null, "business_scene", query)
						.eq("org_code", userBean.getOrgCode()).eq("creater", userBean.getEmpNum()).select("flow_id"));
yuquan.zhu committed
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
		List<Object> l = new ArrayList<Object>();
		for (DzhtAssoCjlc lc : cjlcs) {
			l.add(qryFlow(lc.getFlowId()));
		}
//		com.github.pagehelper.Page<Object> page = PageHelper.startPage(currPage, pageSize);
//		List<DzhtAssoCjlc> cjlcs = DzhtAssoCjlc.builder().build()
//				.selectList(new QueryWrapper<DzhtAssoCjlc>().eq("org_code", userBean.getOrgCode())
//						.eq("creater", userBean.getEmpNum())
//						.select("initiator_authorized_account_id", "flow_id", "singer_account_id"));
//		List<Object> l = new ArrayList<Object>();
//
//		for (DzhtAssoCjlc cjlc : cjlcs) {
//			Map<String, Object> map = new HashMap<String, Object>();
//			List<Object> singerInfo = new ArrayList<Object>();
//			String initiatorAuthorizedAccountId = cjlc.getInitiatorAuthorizedAccountId();
//			if (initiatorAuthorizedAccountId != null) {
//				Map<String, Object> maps = new HashMap<String, Object>();
//				DzhtAssoQyzc qyzc = DzhtAssoQyzc.builder().build().selectOne(
//						new QueryWrapper<DzhtAssoQyzc>().eq("org_id", initiatorAuthorizedAccountId).select("name"));
//				if (qyzc != null) {
//					String name = qyzc.getName();
//					maps.put("initiatorAuthorizedAccountId", initiatorAuthorizedAccountId);
//					maps.put("name", name);
//					singerInfo.add(maps);
//				}
//			}
//			String singerAccountIds = cjlc.getSingerAccountId();
//			if (singerAccountIds != null) {
//				for (String accountId : singerAccountIds.split(",")) {
//					DzhtAssoGrzc grzc = DzhtAssoGrzc.builder().build().selectOne(
//							new QueryWrapper<DzhtAssoGrzc>().eq("account_id", accountId).select("emp_num", "name"));
//
//					Map<String, Object> maps = new HashMap<String, Object>();
//					maps.put("name", grzc.getName());
//					maps.put("empNum", grzc.getEmpNum());
//					singerInfo.add(maps);
//				}
//			}
//			map.put("flowInfo", qryFlow(cjlc.getFlowId()));
//			map.put("singerInfo", singerInfo);
//			l.add(map);
//		}

		return ResultUtil.pageData(l, page.getTotal(), "查询成功");
	}

	/**
	 * 获取当前用户收到的签署流程
	 * 
	 * @param currPage
	 * 
	 * @param flowId
	 * @return
	 */
	@GetMapping("/getSdlc")
	@ApiOperation(value = "当前用户收到的签署流程", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getSdlc(@CurrentUser UserBean userBean,
			@RequestParam(required = false, defaultValue = "1") Integer currPage,
			@RequestParam(required = false, defaultValue = "10") Integer pageSize,
1103 1104
			@RequestParam(required = false) String query) {

yuquan.zhu committed
1105 1106 1107
		List<JSONObject> json = new ArrayList<JSONObject>();
		com.github.pagehelper.Page<Object> page = PageHelper.startPage(currPage, pageSize);
		List<DzhtAssoSdgzq> list = DzhtAssoSdgzq.builder().build()
1108
				.selectList(new QueryWrapper<DzhtAssoSdgzq>().select("distinct flow_id")
yuquan.zhu committed
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
						.eq("signer_emp_num", userBean.getEmpNum()).like(query != null, "business_scene", query));
		List<String> flowIdList = Lists.transform(list, newList -> newList.getFlowId());
		for (String flowId : flowIdList) {
			json.add(qryFlow(flowId));
		}
		return ResultUtil.pageData(json, page.getTotal(), "查询成功");
	}

	/**********************************************************/
	// 签署流程查询
	private JSONObject qryFlow(@RequestParam String flowId) {
		JSONObject json = null;
		try {
			TokenHelper.getTokenData();// 获取鉴权
			json = SignHelper.qrySignFlow(flowId);
		} catch (DefineException e) {
			e.printStackTrace();
		}
		return json;
	}

}