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.DFService;
import com.sa.ibiz.demo.ibizutil.domain.AutoCompleteItem;
import com.sa.ibiz.demo.demo.domain.DF;
import com.sa.ibiz.demo.demo.service.dto.DFSearchFilter;
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;

@RestController
@RequestMapping("/mob/demo/df")
public class DFController{



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



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

			DF targetEntity =new DF();
			sourceEntity.copyTo(targetEntity);
			form.fromDF(targetEntity,false);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
         }
            DF entity =form.toDF();
            getService().getDraft(entity);
            form.fromDF(entity);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="mobformeditform/get")
	public ResponseEntity<DF_EditForm_MobForm> mobFormEditFormGet(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            DF_EditForm_MobForm form=new DF_EditForm_MobForm();
            DF entity = new DF();
            entity.setDfid(srfkey);
            entity=getService().get(entity);
            form.setSrfuf("1");
            form.fromDF(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="mobformeditform/create")
	public ResponseEntity<DF_EditForm_MobForm> mobFormEditFormCreate(@Validated @RequestBody DF_EditForm_MobForm form){
            DF entity =form.toDF();
            getService().create(entity);
            form.fromDF(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="mobmobmdctrl/searchdefault")
	public ResponseEntity<Page<DF_MOBMDCTRL_Mob>> mobMOBMDCTRLSearchDefault(@Validated @RequestBody DFSearchFilter searchFilter){
			Page<DF> searchResult = this.getService().searchDefault(searchFilter);
			Page<DF_MOBMDCTRL_Mob> searchResult_vo_data =DF_MOBMDCTRL_Mob.fromDF(searchResult);
					return ResponseEntity.ok().body(searchResult_vo_data);
	}
	/**
	 * 移动端列表删除
	 * @param
	 * @return
	 */
	@PostMapping(value="mobmobmdctrl/remove")
	public ResponseEntity<DF> mobMOBMDCTRLRemove(@Validated @RequestBody Map args){
		DF entity =new DF();
		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.setDfid(srfkey);
				this.getService().remove(entity);
				}
			}
		}
		return ResponseEntity.ok().body(entity);
	}
 }