/**
* 文件：AssetFlowEventFieldController.java
* 版本：1.0.0
* 日期：
* Copyright &reg; 
* All right reserved.
*/
package com.mortals.xhx.module.asset.web;

import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.code.YesNo;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.common.code.EventFieldInputTypeEnum;
import com.mortals.xhx.module.asset.model.AssetFlowEventEntity;
import com.mortals.xhx.module.asset.model.AssetFlowEventFieldEntity;
import com.mortals.xhx.module.asset.model.AssetFlowEventQuery;
import com.mortals.xhx.module.asset.service.AssetFlowEventFieldService;
import com.mortals.xhx.module.asset.service.AssetFlowEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * Title: 字段配置
 * </p>
 * <p>
 * Description: AssetFlowEventFieldController
 * </p>
 * <p>
 * Copyright: Copyright &reg;
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author
 * @version 1.0.0
 */
@RestController
@RequestMapping("asset/flow/eventfield")
public class AssetFlowEventFieldController extends
		BaseCRUDJsonMappingController<AssetFlowEventFieldService, AssetFlowEventFieldForm, AssetFlowEventFieldEntity, Long> {

	@Autowired
	private AssetFlowEventService assetFlowEventService;

	public AssetFlowEventFieldController() {
		super.setFormClass(AssetFlowEventFieldForm.class);
		super.setModuleDesc("字段配置");
	}

	@Override
	protected void init(HttpServletRequest request, HttpServletResponse response, AssetFlowEventFieldForm form,
			Map<String, Object> model, Context context) {

		this.addDict(model, "fieldNull", IBaseEnum.getEnumMap(YesNo.class));
		this.addDict(model, "enabled", IBaseEnum.getEnumMap(YesNo.class));
		this.addDict(model, "inputType", IBaseEnum.getEnumMap(EventFieldInputTypeEnum.class));

		Map<String, String> fieldType = new HashMap<>();
		fieldType.put(String.class.getSimpleName(), String.class.getSimpleName());
		fieldType.put(Integer.class.getSimpleName(), Integer.class.getSimpleName());
		fieldType.put(Long.class.getSimpleName(), Long.class.getSimpleName());
		fieldType.put(Float.class.getSimpleName(), Float.class.getSimpleName());
		fieldType.put(Double.class.getSimpleName(), Double.class.getSimpleName());
		this.addDict(model, "fieldType", fieldType);


		AssetFlowEventQuery query = new AssetFlowEventQuery();
		query.setOrderColList(new ArrayList<OrderCol>() {
			{
				add(new OrderCol("orderNo", OrderCol.ASCENDING));
			}
		});
		this.addDict(model, "eventCode", assetFlowEventService.find(query, context).stream()
				.collect(Collectors.toMap(AssetFlowEventEntity::getCode, y -> y.getCode() + y.getName(), (o, n) -> n)));
		super.init(request, response, form, model, context);
	}

}