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.OrgUserService;
import com.sa.ibiz.demo.ibizutil.domain.AutoCompleteItem;
import com.sa.ibiz.demo.demo.domain.OrgUser;
import com.sa.ibiz.demo.demo.service.dto.OrgUserSearchFilter;
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/orguser")
public class OrgUserController{



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



	@PostMapping(value="userinfoformeditform/update")
	public ResponseEntity<OrgUser_EditForm_UserInfoForm> userInfoFormEditFormUpdate(@Validated @RequestBody OrgUser_EditForm_UserInfoForm form){
            OrgUser entity =form.toOrgUser();
            getService().update(entity);
            form.fromOrgUser(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="userinfoformeditform/remove")
	public ResponseEntity<OrgUser_EditForm_UserInfoForm> userInfoFormEditFormRemove(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            OrgUser_EditForm_UserInfoForm form=new OrgUser_EditForm_UserInfoForm();
            OrgUser entity = new OrgUser();
            entity.setOrguserid(srfkey);
            getService().remove(entity);
            form.setSrfuf("0");
            form.fromOrgUser(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="userinfoformeditform/getdraft")
	public ResponseEntity<OrgUser_EditForm_UserInfoForm> userInfoFormEditFormGetDraft(@RequestBody OrgUser_EditForm_UserInfoForm form){
        if(!StringUtils.isEmpty(form.getSrfsourcekey()))
        {
            OrgUser sourceEntity =new OrgUser();
            sourceEntity.setOrguserid(form.getSrfsourcekey());
            this.getService().get(sourceEntity);

			OrgUser targetEntity =new OrgUser();
			sourceEntity.copyTo(targetEntity);
			form.fromOrgUser(targetEntity,false);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
         }
            OrgUser entity =form.toOrgUser();
            getService().getDraft(entity);
            form.fromOrgUser(entity);
            form.setSrfuf("0");
            return ResponseEntity.ok().body(form);
	}
	@GetMapping(value="userinfoformeditform/get")
	public ResponseEntity<OrgUser_EditForm_UserInfoForm> userInfoFormEditFormGet(@Validated @NotBlank(message = "srfkey不允许为空") @RequestParam("srfkey")String srfkey){
            OrgUser_EditForm_UserInfoForm form=new OrgUser_EditForm_UserInfoForm();
            OrgUser entity = new OrgUser();
            entity.setOrguserid(srfkey);
            entity=getService().get(entity);
            form.setSrfuf("1");
            form.fromOrgUser(entity);
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="userinfoformeditform/create")
	public ResponseEntity<OrgUser_EditForm_UserInfoForm> userInfoFormEditFormCreate(@Validated @RequestBody OrgUser_EditForm_UserInfoForm form){
            OrgUser entity =form.toOrgUser();
            getService().create(entity);
            form.fromOrgUser(entity);
            form.setSrfuf("1");
            return ResponseEntity.ok().body(form);
	}
	@PostMapping(value="mobmobmdctrl/searchcurorguser")
	public ResponseEntity<Page<OrgUser_MOBMDCTRL_Mob>> mobMOBMDCTRLSearchCurOrgUser(@Validated @RequestBody OrgUserSearchFilter searchFilter){
			Page<OrgUser> searchResult = this.getService().searchCurOrgUser(searchFilter);
			Page<OrgUser_MOBMDCTRL_Mob> searchResult_vo_data =OrgUser_MOBMDCTRL_Mob.fromOrgUser(searchResult);
					return ResponseEntity.ok().body(searchResult_vo_data);
	}
	/**
	 * 移动端列表删除
	 * @param
	 * @return
	 */
	@PostMapping(value="mobmobmdctrl/remove")
	public ResponseEntity<OrgUser> mobMOBMDCTRLRemove(@Validated @RequestBody Map args){
		OrgUser entity =new OrgUser();
		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.setOrguserid(srfkey);
				this.getService().remove(entity);
				}
			}
		}
		return ResponseEntity.ok().body(entity);
	}
 }