AgentAction.java 2.75 KB
package com.cjs.cms.action.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cjs.cms.dao.admin.AgentRoleDao;
import com.cjs.cms.dao.user.AgentInfoDao;
import com.cjs.cms.model.admin.AgentRoleInfo;
import com.cjs.cms.model.user.AgentInfo;
import com.cjs.cms.util.lang.JsonUtil;
import com.cjs.cms.util.lang.PageUtils;

/**
 * 代理商
 * 
 * @author tongyufu
 *
 */
@RestController
@RequestMapping("/admin/agent")
public class AgentAction {

    @Autowired
    private AgentInfoDao agentInfoDao;
    @Autowired
    private AgentRoleDao agentRoleDao;

    /**查询*/
    @RequestMapping("/search")
    public String search(@RequestParam Map<String, Object> params) {
        PageUtils.processPage(params);
        List<AgentRoleInfo> agentrole = agentRoleDao.search(params);
        for (AgentRoleInfo agentRoleInfo : agentrole) {
            params.put("agentNo", agentRoleInfo.getAgentNo());
            AgentInfo agentInfo = agentInfoDao.search(params);
            if (agentInfo != null) {
                agentRoleInfo.setAgentCode(agentInfo.getFundAccount());
                agentRoleInfo.setAgentName(agentInfo.getAgentName());
            }
        }
        return JsonUtil.toPageJson(agentrole, agentRoleDao.searchTotal(params));
    }

    /**添加*/
    @RequestMapping("/addAndUpdateAgentRole")
    public String addAndUpdateAgentRole(AgentRoleInfo agentRole) {
        String resultCode = "0";
        if (agentRole.getId() != null && agentRole.getId() != 0) {
            try {
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("agentNo", agentRole.getAgentNo());
                AgentInfo agentInfo = agentInfoDao.search(params);
                if (agentInfo != null) {
                    agentRoleDao.updateAgentRole(agentRole);
                } else {
                    resultCode = "-2";
                }

            } catch (Exception e) {
                resultCode = "1";
            }
        } else {
            try {
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("agentNo", agentRole.getAgentNo());
                AgentInfo agentInfo = agentInfoDao.search(params);
                if (agentInfo != null) {
                    agentRoleDao.addAgentRole(agentRole);
                } else {
                    resultCode = "-2";
                }

            } catch (Exception e) {
                resultCode = "1";
            }
        }

        return resultCode;
    }

}