package cn.com.countrygarden.bi.main.service.dup.impl;

import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.dao.dup.CaseFieldInfoMapper;
import cn.com.countrygarden.bi.main.dao.dup.CaseFieldMapper;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.dup.CaseField;
import cn.com.countrygarden.bi.main.model.dup.CaseFieldInfo;
import cn.com.countrygarden.bi.main.model.twerp.ErpCommunity;
import cn.com.countrygarden.bi.main.model.twerp.hm.TbSysOrgan;
import cn.com.countrygarden.bi.main.model.twerp.hm.TbSysUser;
import cn.com.countrygarden.bi.main.service.dup.CaseFieldService;
import cn.com.countrygarden.bi.main.service.twerp.hm.TbHsprCommunityService;
import cn.com.countrygarden.bi.main.service.twerp.hm.TbSysOrganService;
import cn.com.countrygarden.bi.main.service.twerp.hm.TbSysUserService;
import cn.com.countrygarden.bi.main.util.DateFormatter;
import cn.com.countrygarden.bi.main.util.ExDateUtils;
import com.github.pagehelper.PageRowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by huangzhengjun on 2018/2/7.
 */
@Service
@Transactional
public class CaseFieldServiceImpl implements CaseFieldService {

    private final Logger logger = LoggerFactory.getLogger(CaseFieldServiceImpl.class);

    @Autowired
    private CaseFieldMapper caseFieldMapper;

    @Autowired
    private CaseFieldInfoMapper caseFieldInfoMapper;

    @Autowired
    private TbSysUserService tbSysUserService;

    @Autowired
    private TbSysOrganService tbSysOrganService;

    @Autowired
    private TbHsprCommunityService tbHsprCommunityService;

    @Override
    public int insertCaseField(Map<String, Object> paramMap) {
//        DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        DateFormatter dateFormatter = new DateFormatter();
        CaseField caseField = new CaseField();

        caseField.setAdvancedDeeds(paramMap.get("advancedDeeds") == null ? "" : String.valueOf(paramMap.get("advancedDeeds")));

        caseField.setCaseField(paramMap.get("caseField") == null ? "" : String.valueOf(paramMap.get("caseField")));
        caseField.setCaseFieldAuthorized(paramMap.get("caseFieldAuthorized") == null ? null : Integer.parseInt(String.valueOf(paramMap.get("caseFieldAuthorized"))));
        caseField.setCaseFieldManager(paramMap.get("caseFieldManager") == null ? "" : String.valueOf(paramMap.get("caseFieldManager")));
        caseField.setComm(paramMap.get("commId") == null ? "" : String.valueOf(paramMap.get("commId")));
        caseField.setCommManager(paramMap.get("commManager") == null ? "" : String.valueOf(paramMap.get("commManager")));
        caseField.setCommManagerRate(paramMap.get("commManagerRate") == null ? "" : String.valueOf(paramMap.get("commManagerRate")));
        caseField.setCaseFieldManager(paramMap.get("caseFieldManager") == null ? "" : String.valueOf(paramMap.get("caseFieldManager")));

        caseField.setCreateDate(paramMap.get("createDate") == null ? new Date() : ExDateUtils.parseDate(String.valueOf(paramMap.get("createDate"))));

        caseField.setCreatedBy(paramMap.get("createdBy") == null ? "" : String.valueOf(paramMap.get("createdBy")));

        caseField.setDeedsImages(paramMap.get("deedsImages") == null ? "" : String.valueOf(paramMap.get("deedsImages")));
        caseField.setDevelopManCount(paramMap.get("developManCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("developManCount"))));

        caseField.setImage(paramMap.get("image") == null ? "" : String.valueOf(paramMap.get("image")));

        DateFormat monthFmt = new SimpleDateFormat("yyyy-MM-dd");
        caseField.setMonthDate(paramMap.get("monthDate") == null ? null : ExDateUtils.parseDate(String.valueOf(paramMap.get("monthDate"))));

        caseField.setMonthlyDevelopCount(paramMap.get("monthlyDevelopCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("monthlyDevelopCount"))));
        caseField.setMonthlyOpenCount(paramMap.get("monthlyOpenCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("monthlyOpenCount"))));

        caseField.setOfficialAccountPushCount(paramMap.get("officialAccountPushCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("officialAccountPushCount"))));
        caseField.setOndutyPeopleCount(paramMap.get("ondutyPeopleCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("ondutyPeopleCount"))));
        caseField.setOpenHelpCount(paramMap.get("openHelpCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("openHelpCount"))));
        caseField.setOtherPaiseCount(paramMap.get("otherPaiseCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("otherPaiseCount"))));
        caseField.setOpenCoordinateRate(paramMap.get("openCoordinateRate") == null ? "" : String.valueOf(paramMap.get("openCoordinateRate")));
        caseField.setOpenCoordinateRateFiles(paramMap.get("openCoordinateRateFiles") == null ? "" : String.valueOf(paramMap.get("openCoordinateRateFiles")));
        caseField.setOrgan(paramMap.get("organCode") == null ? "" : String.valueOf(paramMap.get("organCode")));

        caseField.setPeopleCount(paramMap.get("peopleCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("peopleCount"))));
        caseField.setPosition(paramMap.get("position") == null ? "" : String.valueOf(paramMap.get("position")));
        caseField.setPraiseLetterCount(paramMap.get("praiseLetterCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("praiseLetterCount"))));

        caseField.setSaleBeginDate(paramMap.get("saleBeginDate") == null ? null : ExDateUtils.parseDate(String.valueOf(paramMap.get("saleBeginDate"))));
        caseField.setSaleEndDate(paramMap.get("saleEndDate") == null ? null : ExDateUtils.parseDate(String.valueOf(paramMap.get("saleEndDate"))));

        caseField.setSaleManagerRate(paramMap.get("saleManagerRate") == null ? "" : String.valueOf(paramMap.get("saleManagerRate")));

        try {
            //巡游/两会展示时间
            caseField.setShowTime((paramMap.get("showTime") == null || "".equals(paramMap.get("showTime"))) ? null : ExDateUtils.parseDate(String.valueOf(paramMap.get("showTime"))));
        } catch (Exception e) {
            caseField.setShowTime(null);

        }
        //巡游/两会展示次数
        caseField.setShowCount((paramMap.get("showCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("showCount")))));

        caseField.setSilkBannerCount((paramMap.get("silkBannerCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("silkBannerCount")))));

        caseField.setUpdateDate(paramMap.get("updateDate") == null ? null : ExDateUtils.parseDate(String.valueOf(paramMap.get("updateDate"))));

        caseField.setUpdatedBy(paramMap.get("updatedBy") == null ? "" : String.valueOf(paramMap.get("updatedBy")));

        caseField.setInnovationService(paramMap.get("innovationService") == null ? "" : String.valueOf(paramMap.get("innovationService")));

        caseField.setInnovationServiceImages(paramMap.get("innovationServiceImages") == null ? "" : String.valueOf(paramMap.get("innovationServiceImages")));

        caseField.setExhibitionArea(paramMap.get("exhibitionArea") == null ? "" : String.valueOf(paramMap.get("exhibitionArea")));


        int i = caseFieldMapper.insertCaseField(caseField);
        return i;
    }

    @Override
    public Result queryByKeys(Map<String, Object> paramMap) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        DateFormatter dateFormatter = new DateFormatter();

        if (paramMap != null) {
            String organ = paramMap.get("organCode") == null ? null : String.valueOf(paramMap.get("organCode"));
            List<String> organs = paramMap.get("organs") == null ? null : (List<String>) paramMap.get("organs");
            String comm = paramMap.get("commId") == null ? null : String.valueOf(paramMap.get("commId"));
            List<String> comms = paramMap.get("comms") == null ? null : (List<String>) paramMap.get("comms");
            String caseFieldId = paramMap.get("caseField") == null ? null : String.valueOf(paramMap.get("caseField"));
            String beginDate = paramMap.get("beginDate") == null ? null : String.valueOf(paramMap.get("beginDate"));
            String endDate = paramMap.get("endDate") == null ? null : String.valueOf(paramMap.get("endDate"));
            int page = paramMap.get("page") == null ? null : Integer.parseInt(String.valueOf(paramMap.get("page")));
            int size = paramMap.get("size") == null ? null : Integer.parseInt(String.valueOf(paramMap.get("size")));
            List<CaseField> caseFieldList = caseFieldMapper.queryByKeys(organ, organs, comm, comms, caseFieldId, beginDate, endDate, (page - 1) * size, size);
            int total = caseFieldMapper.queryTotal(organ, organs, comm, comms, caseFieldId, beginDate, endDate);
            PageRowBounds pageRowBounds = new PageRowBounds(page, size);
            pageRowBounds.setCount(true);
            pageRowBounds.setTotal((long) total);
            if (caseFieldList != null && caseFieldList.size() > 0) {
                for (int i = 0; i < caseFieldList.size(); i++) {
//                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                    SimpleDateFormat monthSdf = new SimpleDateFormat("yyyy-MM-dd");

                    CaseField caseField = caseFieldList.get(i);
                    Map<String, Object> tempMap = new HashMap<>();
                    tempMap.put("id", caseField.getId());
                    tempMap.put("advancedDeeds", caseField.getAdvancedDeeds());
                    //查询一下案场名称
                    String caseFieldName = caseField.getCaseField();
                    if (caseField.getCaseField() != null && !"".equals(caseField.getCaseField())) {
                        CaseFieldInfo caseFieldInfo = caseFieldInfoMapper.queryById(Integer.parseInt(caseField.getCaseField()));
                        if (caseFieldInfo != null) {
                            caseFieldName = caseFieldInfo.getCaseFieldName();
                        }
                    }
                    tempMap.put("caseFieldName", caseFieldName);
                    tempMap.put("caseField", caseField.getCaseField() == null ? null : Integer.parseInt(String.valueOf(caseField.getCaseField())));
                    tempMap.put("caseFieldAuthorized", caseField.getCaseFieldAuthorized());
                    tempMap.put("caseFieldManager", caseField.getCaseFieldManager());
                    //查询一下项目名称
                    String commName = caseField.getComm();
                    if (caseField.getComm() != null) {
                        ErpCommunity baseCommByCommId = tbHsprCommunityService.findBaseCommByCommId(caseField.getComm());
                        if (baseCommByCommId != null) {
                            commName = baseCommByCommId.getCommName();
                        }
                    }
                    tempMap.put("commName", commName);
                    tempMap.put("commId", caseField.getComm());
                    tempMap.put("commManager", caseField.getCommManager());
                    try {

                        tempMap.put("commManagerRate", (caseField.getCommManagerRate() == null || "".equals(caseField.getCommManagerRate())) ? null : Double.parseDouble(caseField.getCommManagerRate()));
                    } catch (Exception e) {
                        tempMap.put("commManagerRate", null);
                    }
                    tempMap.put("createDate", caseField.getCreateDate() == null ? null : ExDateUtils.formatDateTime(caseField.getCreateDate()));
                    //查询一下用户名称
                    String createdBy = caseField.getCreatedBy();
                    if (caseField.getCreatedBy() != null && !"".equals(caseField.getCreatedBy())) {

                        TbSysUser byUserCode = tbSysUserService.findByUserCodeNew(caseField.getCreatedBy());
                        if (byUserCode != null) {

                            createdBy = byUserCode.getUserName();
                        }

                    }
                    tempMap.put("createdCode", caseField.getCreatedBy());
                    tempMap.put("createdName", createdBy);
                    tempMap.put("deedsImages", caseField.getDeedsImages());
                    tempMap.put("developManCount", caseField.getDevelopManCount());
                    tempMap.put("image", caseField.getImage());
                    tempMap.put("isDelete", caseField.getIsDelete());
                    tempMap.put("monthDate", caseField.getMonthDate() == null ? null : ExDateUtils.formatDate(caseField.getMonthDate()).substring(0, 7));
                    tempMap.put("monthlyDevelopCount", caseField.getMonthlyDevelopCount());
                    tempMap.put("monthlyOpenCount", caseField.getMonthlyOpenCount());
                    tempMap.put("officialAccountPushCount", caseField.getOfficialAccountPushCount());
                    tempMap.put("ondutyPeopleCount", caseField.getOndutyPeopleCount());
                    try {

                        tempMap.put("openCoordinateRate", (caseField.getOpenCoordinateRate() == null || "".equals(caseField.getOpenCoordinateRate())) ? null : Double.parseDouble(caseField.getOpenCoordinateRate()));
                    } catch (Exception e) {
                        tempMap.put("openCoordinateRate", null);

                    }
                    tempMap.put("openCoordinateRateFiles", caseField.getOpenCoordinateRateFiles());
                    tempMap.put("openHelpCount", caseField.getOpenHelpCount());
                    //查询一下区域名称
                    String organstr = caseField.getOrgan();
                    if (caseField.getOrgan() != null) {
                        TbSysOrgan byOrganCode = tbSysOrganService.findByOrganCode(caseField.getOrgan());
                        if (byOrganCode != null) {

                            organstr = byOrganCode.getOrganName();
                        }
                    }
                    tempMap.put("organName", organstr);
                    tempMap.put("organCode", caseField.getOrgan());
                    tempMap.put("otherPaiseCount", caseField.getOtherPaiseCount());
                    tempMap.put("peopleCount", caseField.getPeopleCount());
                    tempMap.put("position", caseField.getPosition());
                    tempMap.put("praiseLetterCount", caseField.getPraiseLetterCount());
                    tempMap.put("saleBeginDate", caseField.getSaleBeginDate() == null ? null : ExDateUtils.formatDate(caseField.getSaleBeginDate()));
                    tempMap.put("saleEndDate", caseField.getSaleEndDate() == null ? null : ExDateUtils.formatDate(caseField.getSaleEndDate()));
                    try {

                        tempMap.put("saleManagerRate", (caseField.getSaleManagerRate() == null || "".equals(caseField.getSaleManagerRate())) ? null : Double.parseDouble(caseField.getSaleManagerRate()));
                    } catch (Exception e) {
                        tempMap.put("saleManagerRate", null);

                    }
                    try {

                        tempMap.put("showTime", (caseField.getShowTime() == null) ? null : ExDateUtils.formatDateTime(caseField.getShowTime()));
                    } catch (Exception e) {
                        tempMap.put("showTime", null);

                    }
                    tempMap.put("silkBannerCount", caseField.getSilkBannerCount());
                    tempMap.put("updateDate", caseField.getUpdateDate() == null ? null : ExDateUtils.formatDateTime(caseField.getUpdateDate()));

                    //查询一下用户名称
                    String updatedBy = caseField.getUpdatedBy();
                    if (caseField.getUpdatedBy() != null && !"".equals(caseField.getUpdatedBy())) {
                        TbSysUser byUserCode = tbSysUserService.findByUserCodeNew(caseField.getUpdatedBy());
                        if (byUserCode != null) {

                            updatedBy = byUserCode.getUserName();
                        }
                    }
                    tempMap.put("updatedCode", caseField.getUpdatedBy());
                    tempMap.put("updatedName", updatedBy);
                    tempMap.put("showCount", caseField.getShowCount());
                    tempMap.put("innovationService", caseField.getInnovationService());
                    tempMap.put("innovationServiceImages", caseField.getInnovationServiceImages());
                    tempMap.put("exhibitionArea", caseField.getExhibitionArea());
                    
                    //审批
                    tempMap.put("approvalState", caseField.getApprovalState());
                    tempMap.put("approvalOpinion", caseField.getApprovalOpinion());
                    String approver = caseField.getApprover();
                    if(caseField.getApprover()!=null && "".equals(caseField.getApprover())) {
                    	TbSysUser userName = tbSysUserService.findByUserCodeNew(caseField.getApprover());
                    	if(userName != null) {
                    		approver = userName.getUserName();
                    	}
                    }
                    tempMap.put("approver", approver);
                    tempMap.put("approvalDate", ExDateUtils.formatDateTime(caseField.getApprovalDate()));
                    
                    resultList.add(tempMap);
                }
                PageData pageData = new PageData(resultList, pageRowBounds);
                return Response.response(pageData);
            }
        } else {
            PageRowBounds pageRowBounds = new PageRowBounds(1, 10);
            PageData pageData = new PageData(resultList, pageRowBounds);
            return Response.response(pageData);
        }
        int page = paramMap.get("page") == null ? null : Integer.parseInt(String.valueOf(paramMap.get("page")));
        int size = paramMap.get("size") == null ? null : Integer.parseInt(String.valueOf(paramMap.get("size")));
        PageRowBounds pageRowBounds = new PageRowBounds(page, size);
        pageRowBounds.setCount(true);
        pageRowBounds.setTotal(0L);
        PageData pageData = new PageData(resultList, pageRowBounds);
        return Response.response(pageData);
    }

    @Override
    public int softDeleteById(Map<String, Object> paramMap) {
        int id = Integer.parseInt(String.valueOf(paramMap.get("id")));
        String userCode = String.valueOf(paramMap.get("userCode"));
        int i = caseFieldMapper.softDeleteById(id, userCode);

        return i;
    }

    @Override
    public Map<String, Object> modifyCaseFieldById(Map<String, Object> paramMap) {


        CaseField caseField = new CaseField();

        caseField.setAdvancedDeeds(paramMap.get("advancedDeeds") == null ? "" : String.valueOf(paramMap.get("advancedDeeds")));

        caseField.setCaseField(paramMap.get("caseField") == null ? "" : String.valueOf(paramMap.get("caseField")));
        caseField.setCaseFieldAuthorized(paramMap.get("caseFieldAuthorized") == null ? null : Integer.parseInt(String.valueOf(paramMap.get("caseFieldAuthorized"))));
        caseField.setCaseFieldManager(paramMap.get("caseFieldManager") == null ? "" : String.valueOf(paramMap.get("caseFieldManager")));
        caseField.setComm(paramMap.get("commId") == null ? "" : String.valueOf(paramMap.get("commId")));
        caseField.setCommManager(paramMap.get("commManager") == null ? "" : String.valueOf(paramMap.get("commManager")));
        caseField.setCommManagerRate(paramMap.get("commManagerRate") == null ? "" : String.valueOf(paramMap.get("commManagerRate")));
        caseField.setCaseFieldManager(paramMap.get("caseFieldManager") == null ? "" : String.valueOf(paramMap.get("caseFieldManager")));

        caseField.setDeedsImages(paramMap.get("deedsImages") == null ? "" : String.valueOf(paramMap.get("deedsImages")));
        caseField.setDevelopManCount(paramMap.get("developManCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("developManCount"))));

        caseField.setImage(paramMap.get("image") == null ? "" : String.valueOf(paramMap.get("image")));

        caseField.setMonthDate(paramMap.get("monthDate") == null ? null : ExDateUtils.parseDate(String.valueOf(paramMap.get("monthDate"))));

        caseField.setMonthlyDevelopCount(paramMap.get("monthlyDevelopCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("monthlyDevelopCount"))));
        caseField.setMonthlyOpenCount(paramMap.get("monthlyOpenCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("monthlyOpenCount"))));

        caseField.setOfficialAccountPushCount(paramMap.get("officialAccountPushCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("officialAccountPushCount"))));
        caseField.setOndutyPeopleCount(paramMap.get("ondutyPeopleCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("ondutyPeopleCount"))));
        caseField.setOpenHelpCount(paramMap.get("openHelpCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("openHelpCount"))));
        caseField.setOtherPaiseCount(paramMap.get("otherPaiseCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("otherPaiseCount"))));
        caseField.setOpenCoordinateRate(paramMap.get("openCoordinateRate") == null ? "" : String.valueOf(paramMap.get("openCoordinateRate")));
        caseField.setOpenCoordinateRateFiles(paramMap.get("openCoordinateRateFiles") == null ? "" : String.valueOf(paramMap.get("openCoordinateRateFiles")));
        caseField.setOrgan(paramMap.get("organCode") == null ? "" : String.valueOf(paramMap.get("organCode")));

        caseField.setPeopleCount(paramMap.get("peopleCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("peopleCount"))));
        caseField.setPosition(paramMap.get("position") == null ? "" : String.valueOf(paramMap.get("position")));
        caseField.setPraiseLetterCount(paramMap.get("praiseLetterCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("praiseLetterCount"))));

        caseField.setSaleBeginDate(paramMap.get("saleBeginDate") == null ? null : ExDateUtils.parseDate(String.valueOf(paramMap.get("saleBeginDate"))));


        caseField.setSaleEndDate(paramMap.get("saleEndDate") == null ? null : ExDateUtils.parseDate(String.valueOf(paramMap.get("saleEndDate"))));

        caseField.setSaleManagerRate(paramMap.get("saleManagerRate") == null ? "" : String.valueOf(paramMap.get("saleManagerRate")));

        try {

            caseField.setShowTime((paramMap.get("showTime") == null || "".equals(paramMap.get("showTime"))) ? null : ExDateUtils.parseDate(String.valueOf(paramMap.get("showTime"))));
        } catch (Exception e) {
            caseField.setShowTime(null);

        }
        caseField.setSilkBannerCount((paramMap.get("silkBannerCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("silkBannerCount")))));

//        caseField.setUpdateDate((Date) paramMap.get("updateDate"));

        caseField.setUpdatedBy(paramMap.get("updatedBy") == null ? "" : String.valueOf(paramMap.get("updatedBy")));

        caseField.setId((paramMap.get("id") == null ? null : Integer.parseInt(String.valueOf(paramMap.get("id")))));

        //巡游/两会展示次数
        caseField.setShowCount((paramMap.get("showCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("showCount")))));

        caseField.setSilkBannerCount((paramMap.get("silkBannerCount") == null ? 0 : Integer.parseInt(String.valueOf(paramMap.get("silkBannerCount")))));

        caseField.setUpdateDate(paramMap.get("updateDate") == null ? null : ExDateUtils.parseDate(String.valueOf(paramMap.get("updateDate"))));

        caseField.setUpdatedBy(paramMap.get("updatedBy") == null ? "" : String.valueOf(paramMap.get("updatedBy")));

        caseField.setInnovationService(paramMap.get("innovationService") == null ? "" : String.valueOf(paramMap.get("innovationService")));

        caseField.setInnovationServiceImages(paramMap.get("innovationServiceImages") == null ? "" : String.valueOf(paramMap.get("innovationServiceImages")));

        caseField.setExhibitionArea(paramMap.get("exhibitionArea") == null ? "" : String.valueOf(paramMap.get("exhibitionArea")));
        
        caseField.setApprovalState(0); 
        caseField.setApprovalOpinion("");
        
        int i = caseFieldMapper.modifyCaseFieldById(caseField);
        
        
        int id = Integer.parseInt(String.valueOf(paramMap.get("id")));
        Map<String, Object> stringObjectMap = this.queryById(id);
        if (i > 0) {
            stringObjectMap.put("result", "修改成功");
        } else {
            stringObjectMap.put("result", "修改失败");
        }

        //回查该ID的记录并返回


        return stringObjectMap;
    }

    @Override
    public Map<String, Object> queryById(int id) {
        CaseField caseField = caseFieldMapper.queryById(id);

        Map<String, Object> tempMap = new HashMap<>();

        tempMap.put("id", caseField.getId());
        tempMap.put("advancedDeeds", caseField.getAdvancedDeeds());
        //查询一下案场名称
        String caseFieldName = caseField.getCaseField();
        if (caseField.getCaseField() != null && !"".equals(caseField.getCaseField())) {
            CaseFieldInfo caseFieldInfo = caseFieldInfoMapper.queryById(Integer.parseInt(caseField.getCaseField()));
            if (caseFieldInfo != null) {
                caseFieldName = caseFieldInfo.getCaseFieldName();
            }
        }
        tempMap.put("caseFieldName", caseFieldName);
        tempMap.put("caseField", caseField.getCaseField() == null ? null : Integer.parseInt(String.valueOf(caseField.getCaseField())));
        tempMap.put("caseFieldAuthorized", caseField.getCaseFieldAuthorized());
        tempMap.put("caseFieldManager", caseField.getCaseFieldManager());
        //查询一下项目名称
        String commName = caseField.getComm();
        if (caseField.getComm() != null) {
            ErpCommunity baseCommByCommId = tbHsprCommunityService.findBaseCommByCommId(caseField.getComm());
            if (baseCommByCommId != null) {
                commName = baseCommByCommId.getCommName();
            }
        }
        tempMap.put("commName", commName);
        tempMap.put("commId", caseField.getComm());
        tempMap.put("commManager", caseField.getCommManager());
        try {

            tempMap.put("commManagerRate", (caseField.getCommManagerRate() == null || "".equals(caseField.getCommManagerRate())) ? null : Double.parseDouble(caseField.getCommManagerRate()));
        } catch (Exception e) {
            tempMap.put("commManagerRate", null);

        }
        tempMap.put("createDate", caseField.getCreateDate() == null ? null : ExDateUtils.formatDateTime(caseField.getCreateDate()));
        //查询一下用户名称
        String createdBy = caseField.getCreatedBy();
        if (caseField.getCreatedBy() != null && !"".equals(caseField.getCreatedBy())) {

            TbSysUser byUserCode = tbSysUserService.findByUserCodeNew(caseField.getCreatedBy());
            if (byUserCode != null) {

                createdBy = byUserCode.getUserName();
            }

        }
        tempMap.put("createdCode", caseField.getCreatedBy());
        tempMap.put("createdName", createdBy);
        tempMap.put("deedsImages", caseField.getDeedsImages());
        tempMap.put("developManCount", caseField.getDevelopManCount());
        tempMap.put("image", caseField.getImage());
        tempMap.put("isDelete", caseField.getIsDelete());
        tempMap.put("monthDate", caseField.getMonthDate() == null ? null : ExDateUtils.formatDate(caseField.getMonthDate()).substring(0, 7));
        tempMap.put("monthlyDevelopCount", caseField.getMonthlyDevelopCount());
        tempMap.put("monthlyOpenCount", caseField.getMonthlyOpenCount());
        tempMap.put("officialAccountPushCount", caseField.getOfficialAccountPushCount());
        tempMap.put("ondutyPeopleCount", caseField.getOndutyPeopleCount());
        try {

            tempMap.put("openCoordinateRate", (caseField.getOpenCoordinateRate() == null || "".equals(caseField.getOpenCoordinateRate())) ? null : Double.parseDouble(caseField.getOpenCoordinateRate()));
        } catch (Exception e) {
            tempMap.put("openCoordinateRate", null);

        }
        tempMap.put("openCoordinateRateFiles", caseField.getOpenCoordinateRateFiles());
        tempMap.put("openHelpCount", caseField.getOpenHelpCount());
        //查询一下区域名称
        String organstr = caseField.getOrgan();
        if (caseField.getOrgan() != null) {
            TbSysOrgan byOrganCode = tbSysOrganService.findByOrganCode(caseField.getOrgan());
            if (byOrganCode != null) {

                organstr = byOrganCode.getOrganName();
            }
        }
        tempMap.put("organName", organstr);
        tempMap.put("organCode", caseField.getOrgan());
        tempMap.put("otherPaiseCount", caseField.getOtherPaiseCount());
        tempMap.put("peopleCount", caseField.getPeopleCount());
        tempMap.put("position", caseField.getPosition());
        tempMap.put("praiseLetterCount", caseField.getPraiseLetterCount());
        tempMap.put("saleBeginDate", caseField.getSaleBeginDate() == null ? null : ExDateUtils.formatDate(caseField.getSaleBeginDate()));
        tempMap.put("saleEndDate", caseField.getSaleEndDate() == null ? null : ExDateUtils.formatDate(caseField.getSaleEndDate()));
        try {

            tempMap.put("saleManagerRate", (caseField.getSaleManagerRate() == null || "".equals(caseField.getSaleManagerRate())) ? null : Double.parseDouble(caseField.getSaleManagerRate()));
        } catch (Exception e) {
            tempMap.put("saleManagerRate", null);

        }
        try {

            tempMap.put("showTime", caseField.getShowTime() == null ? null : ExDateUtils.formatDateTime(caseField.getShowTime()));
        } catch (Exception e) {
            tempMap.put("showTime", null);

        }
        tempMap.put("silkBannerCount", caseField.getSilkBannerCount());
        tempMap.put("updateDate", caseField.getUpdateDate() == null ? null : ExDateUtils.formatDateTime(caseField.getUpdateDate()));
        //查询一下用户名称
        String updatedBy = caseField.getCreatedBy();
        if (caseField.getUpdatedBy() != null && !"".equals(caseField.getUpdatedBy())) {
            TbSysUser byUserCode = tbSysUserService.findByUserCodeNew(caseField.getUpdatedBy());
            if (byUserCode != null) {

                updatedBy = byUserCode.getUserName();
            }
        }

        tempMap.put("updatedCode", caseField.getUpdatedBy());
        tempMap.put("updatedName", updatedBy);

        tempMap.put("showCount", caseField.getShowCount());
        tempMap.put("innovationService", caseField.getInnovationService());
        tempMap.put("innovationServiceImages", caseField.getInnovationServiceImages());
        tempMap.put("exhibitionArea", caseField.getExhibitionArea());

        return tempMap;

    }

	
	
	
	

}
