package com.mortals.xhx.module.task.web;

import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.model.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.module.task.model.TaskFinishEntity;
import com.mortals.xhx.module.task.service.TaskFinishService;

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


/**
 * <p>Title: 工作已办表</p>
 * <p>Description: TaskFinishController  </p>
 * <p>Copyright: Copyright &reg;  </p>
 * <p>Company: </p>
 *
 * @author zxfei
 * @version 1.0.0
 */
@RestController
@RequestMapping("task/finish")
public class TaskFinishController extends BaseCRUDJsonMappingController<TaskFinishService, TaskFinishForm, TaskFinishEntity, Long> {

    public TaskFinishController() {
        super.setFormClass(TaskFinishForm.class);
        super.setModuleDesc("工作已办表");
    }

    /**
     * 查询已办列表
     */
    @PostMapping(value = "list")
    @Override
    public String list(TaskFinishForm form) {
        Map<String, Object> model = new HashMap();
        JSONObject ret = new JSONObject();
        int code = VALUE_RESULT_SUCCESS;
        String busiDesc = "查询" + this.getModuleDesc();
        try {
            Result result = this.service.finishList(form.getQuery(), form.getPageInfo(), getContext());
            this.init(request, response, form, model, getContext());
            model.put("result", result.getList());
            model.put("pageInfo", result.getPageInfo());
            model.putAll(form.getModel());
            this.recordSysLog(request, busiDesc + " 【成功】");
        } catch (Exception e) {
            log.error("查询已办列表异常", e);
            this.doException(request, busiDesc, model, e);
            code = VALUE_RESULT_FAILURE;
        }

        ret.put("code", code);
        ret.put("query", form.getQuery());
        ret.put("data", model);
        return ret.toJSONString();
    }

}