package cn.com.countrygarden.bi.main.controller.marketing.backend;

import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.dao.common.CommMapper;
import cn.com.countrygarden.bi.main.exception.ServiceException;
import cn.com.countrygarden.bi.main.model.common.Comm;
import cn.com.countrygarden.bi.main.service.common.CommService;
import cn.com.countrygarden.bi.main.service.marketing.CommOperationHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller("backendProjectOperationController")
@RequestMapping("/api/biapp/marketing/backend/project")
public class ProjectOperationController {


    @Autowired
    private CommService commService;
    @Autowired
    private CommMapper commMapper;

    @Autowired
    private CommOperationHistoryService operationHistoryService;

    /**
     * 查看当前周报
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/operations", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Result operations(@RequestParam(value = "serialNumber", required = true, defaultValue = "") String serialNumber,
                             @RequestParam(value = "page", required = true, defaultValue = "") int page,
                             @RequestParam(value = "pageSize", required = true, defaultValue = "") int pageSize) {
    	 String commId = serialNumber;
         Comm comm = new Comm();
         comm.setCommCode(commId);
          comm = commMapper.selectOne(comm);
         if (comm == null) {
             throw new ServiceException("项目不存在");
         }
        if (comm == null) {
            throw new ServiceException("项目不存在");
        }

        return Response.response(operationHistoryService.search(comm.getId(), page, pageSize));
    }

}
