package com.sa.ibiz.demo.mob.controller.demo;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.sql.Timestamp;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import com.sa.ibiz.demo.ibizutil.domain.ActionResult;
import com.sa.ibiz.demo.demo.service.QJService;
import com.sa.ibiz.demo.ibizutil.domain.AutoCompleteItem;
import com.sa.ibiz.demo.demo.domain.QJ;
import com.sa.ibiz.demo.demo.service.dto.QJSearchFilter;
import com.sa.ibiz.demo.mob.controller.demo.vo.*;
import org.springframework.cglib.beans.BeanGenerator;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.util.StringUtils;
import java.io.IOException;
import com.sa.ibiz.demo.ibizutil.errors.BadRequestAlertException;
import org.springframework.validation.annotation.Validated;
import org.springframework.http.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import com.sa.ibiz.demo.ibizutil.domain.RedirectResult;
import javax.validation.constraints.NotBlank;
import com.sa.ibiz.demo.ibizutil.domain.AutoCompleteItem;
import java.math.BigInteger;
import com.alibaba.fastjson.JSONObject;
import com.sa.ibiz.demo.workflow.WFServiceImpl;
import com.sa.ibiz.demo.ibizutil.security.AuthenticationUser;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import com.alibaba.fastjson.JSONArray;
import org.flowable.bpmn.model.SequenceFlow;

@RestController
@RequestMapping("/mob/demo/qj")
public class QJController{


	private String strWorkflowKey = "QJSP" ;

	@Autowired
	WFServiceImpl wfServiceImpl ;

		@GetMapping(value = "wfdiagram")
	public ResponseEntity<byte[]> wfDiagram(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey") String srfkey) {
		InputStream stream = wfServiceImpl.getProcessInstanceDiagram(strWorkflowKey, srfkey) ;

		HttpHeaders responseHeaders = new HttpHeaders();
		responseHeaders.set("Content-Type", "image/png");
		try {
			if(stream!=null)
				return new ResponseEntity<>(org.apache.commons.io.IOUtils.toByteArray(stream), responseHeaders, HttpStatus.OK);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null ;
	}
	
	@GetMapping(value = "his")
	public ResponseEntity<JSONArray> wfHis(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey") String srfkey) {
		JSONArray json = new JSONArray() ;

		return ResponseEntity.ok().body(json);
	}
	
	@GetMapping(value = "wflinks")
	public ResponseEntity<JSONArray> wfLinks(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey") String srfkey) {
		JSONArray jsonArray = new JSONArray() ;
		List<SequenceFlow> flowElements = wfServiceImpl.findTaskLinkByUser(strWorkflowKey, srfkey, AuthenticationUser.getAuthenticationUser().getUserid()) ;
		for (SequenceFlow sequenceFlow : flowElements) {
			JSONObject json = new JSONObject();
			json.put("id", sequenceFlow.getId()) ;
			json.put("name", sequenceFlow.getName());
			if(StringUtils.isEmpty(sequenceFlow.getAttributeValue("http://flowable.org/bpmn", "approvalOperation"))) {
				json.put("type", "BACKEND") ;
			}else {
				json.put("type", "FRONT") ;
				json.put("page", sequenceFlow.getAttributeValue("http://flowable.org/bpmn", "approvalOperation")) ;
				json.put("mobpage", sequenceFlow.getAttributeValue("http://flowable.org/bpmn", "approvalMobOperation")) ;
			}
			
			jsonArray.add(json);	
		}
		return ResponseEntity.ok().body(jsonArray);
	}
	
	@PostMapping(value = "wflink")
	public ResponseEntity<JSONObject> wfLink(@RequestBody JSONObject request) {

		JSONObject ret = new JSONObject() ;
		if(!request.containsKey("args")) {
			ret.put("ret", "902") ;
			ret.put("errorInfo", "处理参数有误") ;
			return ResponseEntity.ok().body(ret);
		}
		JSONObject params = request.getJSONObject("args") ;
		String srfkey = request.getString("srfkey") ;
		String strLink = request.getString("link") ;
		
		if(params==null || StringUtils.isEmpty(srfkey)||StringUtils.isEmpty(strLink)) {
			ret.put("ret", "902") ;
			ret.put("errorInfo", "处理参数有误") ;
			return ResponseEntity.ok().body(ret);
		}
		
    	
    	params.put("ACTION", strLink) ;
    	try {
    		wfServiceImpl.execTask("complete", strWorkflowKey, srfkey, AuthenticationUser.getAuthenticationUser().getUserid(), params);
    		ret.put("ret", "0") ;
    		return ResponseEntity.ok().body(ret);
    	}
		catch (Exception e) {
			ret.put("ret", "903") ;
			ret.put("errorInfo", "处理参数有误") ;
			return ResponseEntity.ok().body(ret);
		}

	}

    @Autowired
	private QJService qjService;
	/**
	 * 获取服务对象
	*/
	protected QJService getService(){
		return this.qjService;
	}


	//FORM FORM  form
	@PostMapping(value = "mobform10editform/wfstart")
	public ResponseEntity<QJ_EditForm_MobForm10> mobForm10EditFormStart(@Validated @RequestBody QJ_EditForm_MobForm10 form) {
		QJ entity =form.toQJ();
        getService().save(entity);
        form.fromQJ(entity);
		form.setSrfuf("1");
    	
		try {
			JSONObject params = new JSONObject();
	    	wfServiceImpl.start(AuthenticationUser.getAuthenticationUser().getUserid(), strWorkflowKey, entity.getQjid(), params) ;
			return ResponseEntity.ok().body(form);
    	}
		catch (Exception e) {
			e.printStackTrace();
			throw new BadRequestAlertException("启动流程异常","111","900") ;
		}
	}


	@PostMapping(value="mobform10editform/update")
	public ResponseEntity<QJ_EditForm_MobForm10> mobForm10EditFormUpdate(@Validated @RequestBody QJ_EditForm_MobForm10 form){
            QJ entity =form.toQJ();
            getService().update(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="mobform10editform/remove")
	public ResponseEntity<QJ_EditForm_MobForm10> mobForm10EditFormRemove(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_MobForm10 form=new QJ_EditForm_MobForm10();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            getService().remove(entity);
            form.setSrfuf("0");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="mobform10editform/getdraft")
	public ResponseEntity<QJ_EditForm_MobForm10> mobForm10EditFormGetDraft(@RequestBody QJ_EditForm_MobForm10 form){
        if(!StringUtils.isEmpty(form.getSrfsourcekey()))
        {
            QJ sourceEntity =new QJ();
            sourceEntity.setQjid(form.getSrfsourcekey());
            this.getService().get(sourceEntity);

			QJ targetEntity =new QJ();
			sourceEntity.copyTo(targetEntity);
			form.fromQJ(targetEntity,false);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
         }
            QJ entity =form.toQJ();
            getService().getDraft(entity);
            form.fromQJ(entity);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="mobform10editform/get")
	public ResponseEntity<QJ_EditForm_MobForm10> mobForm10EditFormGet(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_MobForm10 form=new QJ_EditForm_MobForm10();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            entity=getService().get(entity);
            form.setSrfuf("1");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="mobform10editform/create")
	public ResponseEntity<QJ_EditForm_MobForm10> mobForm10EditFormCreate(@Validated @RequestBody QJ_EditForm_MobForm10 form){
            QJ entity =form.toQJ();
            getService().create(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}


	//FORM FORM  form
	@PostMapping(value = "startformeditform/wfstart")
	public ResponseEntity<QJ_EditForm_StartForm> startFormEditFormStart(@Validated @RequestBody QJ_EditForm_StartForm form) {
		QJ entity =form.toQJ();
        getService().save(entity);
        form.fromQJ(entity);
		form.setSrfuf("1");
    	
		try {
			JSONObject params = new JSONObject();
	    	wfServiceImpl.start(AuthenticationUser.getAuthenticationUser().getUserid(), strWorkflowKey, entity.getQjid(), params) ;
			return ResponseEntity.ok().body(form);
    	}
		catch (Exception e) {
			e.printStackTrace();
			throw new BadRequestAlertException("启动流程异常","111","900") ;
		}
	}


	@PostMapping(value="startformeditform/update")
	public ResponseEntity<QJ_EditForm_StartForm> startFormEditFormUpdate(@Validated @RequestBody QJ_EditForm_StartForm form){
            QJ entity =form.toQJ();
            getService().update(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="startformeditform/remove")
	public ResponseEntity<QJ_EditForm_StartForm> startFormEditFormRemove(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_StartForm form=new QJ_EditForm_StartForm();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            getService().remove(entity);
            form.setSrfuf("0");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="startformeditform/getdraft")
	public ResponseEntity<QJ_EditForm_StartForm> startFormEditFormGetDraft(@RequestBody QJ_EditForm_StartForm form){
        if(!StringUtils.isEmpty(form.getSrfsourcekey()))
        {
            QJ sourceEntity =new QJ();
            sourceEntity.setQjid(form.getSrfsourcekey());
            this.getService().get(sourceEntity);

			QJ targetEntity =new QJ();
			sourceEntity.copyTo(targetEntity);
			form.fromQJ(targetEntity,false);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
         }
            QJ entity =form.toQJ();
            getService().getDraft(entity);
            form.fromQJ(entity);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="startformeditform/get")
	public ResponseEntity<QJ_EditForm_StartForm> startFormEditFormGet(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_StartForm form=new QJ_EditForm_StartForm();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            entity=getService().get(entity);
            form.setSrfuf("1");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="startformeditform/create")
	public ResponseEntity<QJ_EditForm_StartForm> startFormEditFormCreate(@Validated @RequestBody QJ_EditForm_StartForm form){
            QJ entity =form.toQJ();
            getService().create(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}


	//FORM FORM  form
	@PostMapping(value = "mobform20editform/wfstart")
	public ResponseEntity<QJ_EditForm_MobForm20> mobForm20EditFormStart(@Validated @RequestBody QJ_EditForm_MobForm20 form) {
		QJ entity =form.toQJ();
        getService().save(entity);
        form.fromQJ(entity);
		form.setSrfuf("1");
    	
		try {
			JSONObject params = new JSONObject();
	    	wfServiceImpl.start(AuthenticationUser.getAuthenticationUser().getUserid(), strWorkflowKey, entity.getQjid(), params) ;
			return ResponseEntity.ok().body(form);
    	}
		catch (Exception e) {
			e.printStackTrace();
			throw new BadRequestAlertException("启动流程异常","111","900") ;
		}
	}


	@PostMapping(value="mobform20editform/update")
	public ResponseEntity<QJ_EditForm_MobForm20> mobForm20EditFormUpdate(@Validated @RequestBody QJ_EditForm_MobForm20 form){
            QJ entity =form.toQJ();
            getService().update(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="mobform20editform/remove")
	public ResponseEntity<QJ_EditForm_MobForm20> mobForm20EditFormRemove(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_MobForm20 form=new QJ_EditForm_MobForm20();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            getService().remove(entity);
            form.setSrfuf("0");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="mobform20editform/getdraft")
	public ResponseEntity<QJ_EditForm_MobForm20> mobForm20EditFormGetDraft(@RequestBody QJ_EditForm_MobForm20 form){
        if(!StringUtils.isEmpty(form.getSrfsourcekey()))
        {
            QJ sourceEntity =new QJ();
            sourceEntity.setQjid(form.getSrfsourcekey());
            this.getService().get(sourceEntity);

			QJ targetEntity =new QJ();
			sourceEntity.copyTo(targetEntity);
			form.fromQJ(targetEntity,false);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
         }
            QJ entity =form.toQJ();
            getService().getDraft(entity);
            form.fromQJ(entity);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="mobform20editform/get")
	public ResponseEntity<QJ_EditForm_MobForm20> mobForm20EditFormGet(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_MobForm20 form=new QJ_EditForm_MobForm20();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            entity=getService().get(entity);
            form.setSrfuf("1");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="mobform20editform/create")
	public ResponseEntity<QJ_EditForm_MobForm20> mobForm20EditFormCreate(@Validated @RequestBody QJ_EditForm_MobForm20 form){
            QJ entity =form.toQJ();
            getService().create(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}


	//FORM FORM  form
	@PostMapping(value = "mobformeditform/wfstart")
	public ResponseEntity<QJ_EditForm_MobForm> mobFormEditFormStart(@Validated @RequestBody QJ_EditForm_MobForm form) {
		QJ entity =form.toQJ();
        getService().save(entity);
        form.fromQJ(entity);
		form.setSrfuf("1");
    	
		try {
			JSONObject params = new JSONObject();
	    	wfServiceImpl.start(AuthenticationUser.getAuthenticationUser().getUserid(), strWorkflowKey, entity.getQjid(), params) ;
			return ResponseEntity.ok().body(form);
    	}
		catch (Exception e) {
			e.printStackTrace();
			throw new BadRequestAlertException("启动流程异常","111","900") ;
		}
	}


	@PostMapping(value="mobformeditform/update")
	public ResponseEntity<QJ_EditForm_MobForm> mobFormEditFormUpdate(@Validated @RequestBody QJ_EditForm_MobForm form){
            QJ entity =form.toQJ();
            getService().update(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="mobformeditform/remove")
	public ResponseEntity<QJ_EditForm_MobForm> mobFormEditFormRemove(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_MobForm form=new QJ_EditForm_MobForm();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            getService().remove(entity);
            form.setSrfuf("0");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="mobformeditform/getdraft")
	public ResponseEntity<QJ_EditForm_MobForm> mobFormEditFormGetDraft(@RequestBody QJ_EditForm_MobForm form){
        if(!StringUtils.isEmpty(form.getSrfsourcekey()))
        {
            QJ sourceEntity =new QJ();
            sourceEntity.setQjid(form.getSrfsourcekey());
            this.getService().get(sourceEntity);

			QJ targetEntity =new QJ();
			sourceEntity.copyTo(targetEntity);
			form.fromQJ(targetEntity,false);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
         }
            QJ entity =form.toQJ();
            getService().getDraft(entity);
            form.fromQJ(entity);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="mobformeditform/get")
	public ResponseEntity<QJ_EditForm_MobForm> mobFormEditFormGet(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_MobForm form=new QJ_EditForm_MobForm();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            entity=getService().get(entity);
            form.setSrfuf("1");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="mobformeditform/create")
	public ResponseEntity<QJ_EditForm_MobForm> mobFormEditFormCreate(@Validated @RequestBody QJ_EditForm_MobForm form){
            QJ entity =form.toQJ();
            getService().create(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}


	//FORM FORM  form
	@PostMapping(value = "wfformeditform/wfstart")
	public ResponseEntity<QJ_EditForm_WFForm> wFFormEditFormStart(@Validated @RequestBody QJ_EditForm_WFForm form) {
		QJ entity =form.toQJ();
        getService().save(entity);
        form.fromQJ(entity);
		form.setSrfuf("1");
    	
		try {
			JSONObject params = new JSONObject();
	    	wfServiceImpl.start(AuthenticationUser.getAuthenticationUser().getUserid(), strWorkflowKey, entity.getQjid(), params) ;
			return ResponseEntity.ok().body(form);
    	}
		catch (Exception e) {
			e.printStackTrace();
			throw new BadRequestAlertException("启动流程异常","111","900") ;
		}
	}


	@PostMapping(value="wfformeditform/update")
	public ResponseEntity<QJ_EditForm_WFForm> wFFormEditFormUpdate(@Validated @RequestBody QJ_EditForm_WFForm form){
            QJ entity =form.toQJ();
            getService().update(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="wfformeditform/remove")
	public ResponseEntity<QJ_EditForm_WFForm> wFFormEditFormRemove(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_WFForm form=new QJ_EditForm_WFForm();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            getService().remove(entity);
            form.setSrfuf("0");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="wfformeditform/getdraft")
	public ResponseEntity<QJ_EditForm_WFForm> wFFormEditFormGetDraft(@RequestBody QJ_EditForm_WFForm form){
        if(!StringUtils.isEmpty(form.getSrfsourcekey()))
        {
            QJ sourceEntity =new QJ();
            sourceEntity.setQjid(form.getSrfsourcekey());
            this.getService().get(sourceEntity);

			QJ targetEntity =new QJ();
			sourceEntity.copyTo(targetEntity);
			form.fromQJ(targetEntity,false);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
         }
            QJ entity =form.toQJ();
            getService().getDraft(entity);
            form.fromQJ(entity);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="wfformeditform/get")
	public ResponseEntity<QJ_EditForm_WFForm> wFFormEditFormGet(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_WFForm form=new QJ_EditForm_WFForm();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            entity=getService().get(entity);
            form.setSrfuf("1");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="wfformeditform/create")
	public ResponseEntity<QJ_EditForm_WFForm> wFFormEditFormCreate(@Validated @RequestBody QJ_EditForm_WFForm form){
            QJ entity =form.toQJ();
            getService().create(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}





	//FORM FORM  form
	@PostMapping(value = "maineditform/wfstart")
	public ResponseEntity<QJ_EditForm_Main> mainEditFormStart(@Validated @RequestBody QJ_EditForm_Main form) {
		QJ entity =form.toQJ();
        getService().save(entity);
        form.fromQJ(entity);
		form.setSrfuf("1");
    	
		try {
			JSONObject params = new JSONObject();
	    	wfServiceImpl.start(AuthenticationUser.getAuthenticationUser().getUserid(), strWorkflowKey, entity.getQjid(), params) ;
			return ResponseEntity.ok().body(form);
    	}
		catch (Exception e) {
			e.printStackTrace();
			throw new BadRequestAlertException("启动流程异常","111","900") ;
		}
	}


	@PostMapping(value="maineditform/update")
	public ResponseEntity<QJ_EditForm_Main> mainEditFormUpdate(@Validated @RequestBody QJ_EditForm_Main form){
            QJ entity =form.toQJ();
            getService().update(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="maineditform/remove")
	public ResponseEntity<QJ_EditForm_Main> mainEditFormRemove(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_Main form=new QJ_EditForm_Main();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            getService().remove(entity);
            form.setSrfuf("0");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="maineditform/getdraft")
	public ResponseEntity<QJ_EditForm_Main> mainEditFormGetDraft(@RequestBody QJ_EditForm_Main form){
        if(!StringUtils.isEmpty(form.getSrfsourcekey()))
        {
            QJ sourceEntity =new QJ();
            sourceEntity.setQjid(form.getSrfsourcekey());
            this.getService().get(sourceEntity);

			QJ targetEntity =new QJ();
			sourceEntity.copyTo(targetEntity);
			form.fromQJ(targetEntity,false);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
         }
            QJ entity =form.toQJ();
            getService().getDraft(entity);
            form.fromQJ(entity);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="maineditform/get")
	public ResponseEntity<QJ_EditForm_Main> mainEditFormGet(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            QJ_EditForm_Main form=new QJ_EditForm_Main();
            QJ entity = new QJ();
            entity.setQjid(srfkey);
            entity=getService().get(entity);
            form.setSrfuf("1");
            form.fromQJ(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="maineditform/create")
	public ResponseEntity<QJ_EditForm_Main> mainEditFormCreate(@Validated @RequestBody QJ_EditForm_Main form){
            QJ entity =form.toQJ();
            getService().create(entity);
            form.fromQJ(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="mobmobmdctrl/searchdefault")
	public ResponseEntity<Page<QJ_MOBMDCTRL_Mob>> mobMOBMDCTRLSearchDefault(@Validated @RequestBody QJSearchFilter searchFilter){
			Page<QJ> searchResult = this.getService().searchDefault(searchFilter);
			Page<QJ_MOBMDCTRL_Mob> searchResult_vo_data =QJ_MOBMDCTRL_Mob.fromQJ(searchResult);
					return ResponseEntity.ok().body(searchResult_vo_data);
	}
	/**
	 * 移动端列表删除
	 * @param
	 * @return
	 */
	@PostMapping(value="mobmobmdctrl/remove")
	public ResponseEntity<QJ> mobMOBMDCTRLRemove(@Validated @RequestBody Map args){
		QJ entity =new QJ();
		if ( !StringUtils.isEmpty(args.get("srfkeys"))) {
			String srfkeys=args.get("srfkeys").toString();
			String srfkeyArr[] =srfkeys.split(";");
			for(String srfkey : srfkeyArr)
			{
				if(!StringUtils.isEmpty(srfkey)){
				entity.setQjid(srfkey);
				this.getService().remove(entity);
				}
			}
		}
		return ResponseEntity.ok().body(entity);
	}
 }