package com.bzd.web.controller.dtp;

import com.baidu.aip.ocr.AipOcr;
import com.bzd.common.annotation.Log;
import com.bzd.common.config.HealthConfig;
import com.bzd.common.config.dao.PageData;
import com.bzd.common.core.controller.BaseController;
import com.bzd.common.core.domain.AjaxResult;
import com.bzd.common.core.page.TableDataInfo;
import com.bzd.common.enums.BusinessType;
import com.bzd.common.utils.ServletUtils;
import com.bzd.common.utils.StringUtils;
import com.bzd.common.utils.file.FileUploadUtils;
import com.bzd.common.utils.file.MimeTypeUtils;
import com.bzd.system.service.PharmaceuticalService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

import static com.bzd.common.config.datasource.DynamicDataSourceContextHolder.log;

/**
 * 药事服务管理
 * creator wsp
 */
@Controller
@RequestMapping("/dtp/pmService")
public class PharmaceuticalServiceController extends BaseController {

    // 档案馆
    private String prefix_archives = "dtp/archives";

    // 随访任务
    private String prefix_followUp = "dtp/followUp";

    // 随访人员分配
    private String prefix_followUp_assign = "dtp/followUpAssign";

    //患者咨询
    private String prefix_patient_counseling = "dtp/patientCounseling";

    //患者咨询
    private String prefix_followUp_evaluation = "dtp/followUpEvaluation";

    @Autowired
    private PharmaceuticalService pharmaceuticalService;

    private final AipOcr client;
    /**
     * 档案管理页
     *
     * @return
     */
    @RequiresPermissions("dtp:pmService:view")
    @GetMapping("/archives")
    public String archives() {
        return prefix_archives + "/archivesList";
    }

    /**
     * 档案管理数据查询
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/archivesList")
    @ResponseBody
    public TableDataInfo archivesList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.findArchivesList(pd);
        return getDataTable(pageData);
    }
    /**
     * 档案管理数据查询
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/slectPatientByNameOrPhone")
    @ResponseBody
    public TableDataInfo slectPatientByNameOrPhone() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.slectPatientByNameOrPhone(pd);
        return getDataTable(pageData);
    }
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/slectPatientByNameOrPhoneOrIdCard")
    @ResponseBody
    public AjaxResult slectPatientByNameOrPhoneOrIdCard() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData>  pageData = pharmaceuticalService.slectPatientByNameOrPhoneOrIdCard(pd);

        return AjaxResult.success(pageData);
    }

    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/slectPatientById")
    @ResponseBody
    public AjaxResult slectPatientById() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData>  pageData = pharmaceuticalService.slectPatientById(pd);

        return AjaxResult.success(pageData);
    }

    /**
     * 档案管理数据删除 根据id
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:remove")
    @Log(title = "档案管理删除", businessType = BusinessType.DELETE)
    @PostMapping("/archivesRemove")
    @ResponseBody
    public AjaxResult archivesRemove() throws Exception {
        PageData pd = this.getPageData();
        Integer integer = pharmaceuticalService.archivesRemove(pd);
        return toAjax(integer);
    }

    /**
     * 档案管理数据编辑
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/archivesEdit/{id}")
    public String archivesView(@PathVariable("id") String Id, ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        pd.put("id", Id);
        PageData pageData = pharmaceuticalService.findArchivesList(pd).get(0);
        /*Object updatePatientBasicInfo =  pharmaceuticalService.findBasicInfoById(pd);
        if(StringUtils.isNotNull(updatePatientBasicInfo)){
            PageData BasicpageData = (PageData) updatePatientBasicInfo;
            mmap.putAll(BasicpageData);
            pd.put("archiveId", Id);
            List<PageData>  records =pharmaceuticalService.findrecordsByarchiveId(pd);
            mmap.put("recordsData",records);
            List<PageData>  history =  pharmaceuticalService.findhistoryByarchiveId(pd);
            mmap.put("historyData",history);
            List<PageData>  contacts =  pharmaceuticalService.findcontactsByarchiveId(pd);
            mmap.put("contactsData",contacts);
        }*/
        pd.put("archiveId", Id);
        List<PageData>  records =pharmaceuticalService.findrecordsByarchiveId(pd);
        mmap.put("recordsData",records);
        mmap.put("dl",pageData.get("dl"));
        mmap.put("xl",pageData.get("xl"));

        mmap.putAll(pageData);
        return prefix_archives + "/archivesEdit";
    }


    /**
     * 档案管理数据编辑2
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/archivesyygyList")
    public String archivesyygyList( ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        return prefix_archives + "/archivesyygyList";
    }
    /**
     * 患者建档
     *
     * @return
     * @throws Exception
     */


    @GetMapping("/archivesAdd")
    public String archivesAdd(ModelMap mmap) {
        mmap.put("posts", 1);
        return prefix_archives + "/archivesAdd";
    }

    /**
     * 保存处方照片
     */
    @Log(title = "处方信息", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIdcardImg")
    @ResponseBody
    public AjaxResult updatePrescriptionImg(@RequestParam("idcardImgfile") MultipartFile file)
    {
        try
        {
            if (!file.isEmpty())
            {
                String idCardImg = FileUploadUtils.upload(HealthConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
                return success(idCardImg);
            }
            return error();
        }
        catch (Exception e)
        {
            log.error("修改处方信息失败！", e);
            return error(e.getMessage());
        }
    }
    public PharmaceuticalServiceController() {
        this.client = new AipOcr("116175151", "kCf9zQbSFkHmqKlo2bewI7Fe", "IHaSX3X76k0vLBTcOT3Z8SKJ1q6SF07i");
    }
    @RequiresPermissions("dtp:pmService:add")
    @PostMapping("/idCard")
    @ResponseBody
    public AjaxResult recognizeIdCard(@RequestParam("image") MultipartFile file) {
        try {
            byte[] imageBytes = file.getBytes();
            HashMap<String, String> options = new HashMap<>();
            options.put("detect_direction", "true");
            options.put("detect_risk", "false");
            String idCardSide = "front";
            JSONObject res = client.idcard(imageBytes, idCardSide, options);
            return AjaxResult.success(res.toMap());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
    /**
     * 患者建档新增保存
     */
    @Log(title = "患者建档新增保存", businessType = BusinessType.INSERT)
    @PostMapping("/archivesAdd")
    @ResponseBody
    public AjaxResult addSave() throws Exception {
        PageData pd = new PageData();
        pd = this.getPageData();
       Object dateBirth= pd.get("dateBirth");
       if(StringUtils.isNotNull(dateBirth)){
          Integer age = ServletUtils.calculateAge(dateBirth.toString());//根据出生日期字符串计算年龄
           pd.put("age",age);
       }
        if (pharmaceuticalService.checkPatientIsExist(pd))
        {
            return error("患者建档新增保存： '" + pd.getString("name") +"+"+ pd.getString("documentNumber") +"+" +pd.getString("phoneNumber")+"'失败，患者姓,身份证名或电话已存在");
        }
        Integer integer = pharmaceuticalService.addArchives(pd);
        return toAjax(integer);
    }

    /**
     * 扫码上翻
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "档案管理修改", businessType = BusinessType.UPDATE)
    @PostMapping("/ShaoMaShangFan")
    @ResponseBody
    public AjaxResult ShaoMaShangFan() throws Exception {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {
            Object openId = pd.get("openId");
            Object patientId = pd.get("patientId");
            if(patientId != null && !pd.get("patientId").toString().isEmpty()){
                pd.put("id", patientId);
            }
            if(openId != null && !pd.get("openId").toString().isEmpty()){
                Integer updateResult = pharmaceuticalService.ShaoMaShangFan(pd);
                if (updateResult == 1) {
                    // 成功更新
                    return AjaxResult.success("上翻成功");
                } else {
                    // 更新失败
                    logger.error("Failed to update archives with ID: {}", pd.get("id"));
                    return AjaxResult.error("上翻失败");
                }
            }else{
                logger.error("Failed to update archives with openId: {}", pd.get("openId"));
                return AjaxResult.error("上翻失败");
            }

        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }
    /**
     * 解绑
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "解绑", businessType = BusinessType.UPDATE)
    @PostMapping("/unbound")
    @ResponseBody
    public AjaxResult unbound() throws Exception {
        PageData pd = this.getPageData();
        pd.put("up", "up");
            try {
                Object id = pd.get("id");
                if(StringUtils.isNull(id)){
                    return AjaxResult.error("未获取患者id 无法解绑");
                }
                    pd.put("noFlipCause", "患者已解绑");//未扫码原因之一
                    Integer updateResult = pharmaceuticalService.unbound(pd);
                    if (updateResult == 1) {
                        // 成功更新
                        return AjaxResult.success("解绑成功");
                    } else {
                        // 更新失败
                        logger.error("解绑 操作 Failed to update archives with ID: {}", pd.get("id"));
                        return AjaxResult.error("解绑失败");
                    }
            } catch (Exception e) {
                // 异常处理
                logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
                return AjaxResult.error("系统异常：" + e.getMessage());
            }
      }

    /**
     * 保存档案管理数据修改
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "档案管理修改", businessType = BusinessType.UPDATE)
    @PostMapping("/archivesEdit")
    @ResponseBody
    public AjaxResult archivesEditSave() throws Exception {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {

            Integer updateResult = pharmaceuticalService.updateArchives(pd);

            if (updateResult == 1) {
                // 成功更新
                return AjaxResult.success("修改成功");
            } else {
                // 更新失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }
    /**
     * 获取对应患者的用药购药信息
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/getDrugPurchaseList")
    @ResponseBody
    public TableDataInfo getDrugPurchaseList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.getDrugPurchaseList(pd);
        return getDataTable(pageData);
    }

    /**
     * 随访任务页
     * @return
     */
    @RequiresPermissions("dtp:pmService:view")
    @GetMapping("/followUp")
    public String followUp() {
        return prefix_followUp + "/followUpList";
    }

    /**
     * 随访任务数据查询
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/followUpList")
    @ResponseBody
    public TableDataInfo followUpList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.findFollowUpList(pd);
        return getDataTable(pageData);
    }

    /**
     * 随访任务数据删除 根据id
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:remove")
    @Log(title = "档案管理删除", businessType = BusinessType.DELETE)
    @PostMapping("/followUpRemove")
    @ResponseBody
    public AjaxResult followUpRemove() throws Exception {
        PageData pd = this.getPageData();
        try {
            Integer deleteResult = pharmaceuticalService.followUpRemove(pd);
            if (deleteResult == 1) {
                // 删除成功
                return AjaxResult.success("删除成功");
            } else {
                // 删除失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("删除失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 随访任务数据修改
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/followUpEdit/{followUpId}")
    public String followUpView(@PathVariable("followUpId") Long followUpId, ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        pd.put("id", followUpId);
        PageData pageData = pharmaceuticalService.findFollowUpList(pd).get(0);
        mmap.putAll(pageData);
        return prefix_followUp + "/followUpEdit";
    }

    /**
     * 保存随访任务数据修改
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "档案管理修改", businessType = BusinessType.UPDATE)
    @PostMapping("/followUpEdit")
    @ResponseBody
    public AjaxResult followUpEditSave() {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {
            Integer updateResult = pharmaceuticalService.updateFollowUp(pd);
            if (updateResult == 1) {
                // 成功更新
                return AjaxResult.success("修改成功");
            } else {
                // 更新失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 随访任务页
     * @return
     */
    @RequiresPermissions("dtp:pmService:view")
    @GetMapping("/followUpAssign")
    public String followUpAssign() {
        return prefix_followUp_assign + "/followUpAssignList";
    }

    /**
     * 随访任务数据查询
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:followUpAssignList")
    @PostMapping("/followUpAssignList")
    @ResponseBody
    public TableDataInfo followUpAssignList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.findFollowUpAssignList(pd);
        return getDataTable(pageData);
    }

    /**
     * 随访任务数据删除 根据id
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:remove")
    @Log(title = "档案管理删除", businessType = BusinessType.DELETE)
    @PostMapping("/followUpAssignRemove")
    @ResponseBody
    public AjaxResult followUpAssignRemove() throws Exception {
        PageData pd = this.getPageData();
        try {
            Integer deleteResult = pharmaceuticalService.followUpAssignRemove(pd);
            if (deleteResult == 1) {
                // 删除成功
                return AjaxResult.success("删除成功");
            } else {
                // 删除失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("删除失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 随访任务数据修改
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/followUpAssignEdit/{followUpAssignId}")
    public String followUpAssignView(@PathVariable("followUpAssignId") Long followUpAssignId, ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        pd.put("id", followUpAssignId);
        PageData pageData = pharmaceuticalService.findFollowUpAssignList(pd).get(0);
        mmap.putAll(pageData);
        return prefix_followUp_assign + "/followUpAssignEdit";
    }

    /**
     * 保存随访任务数据修改
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "档案管理修改", businessType = BusinessType.UPDATE)
    @PostMapping("/followUpAssignEdit")
    @ResponseBody
    public AjaxResult followUpAssignEditSave() {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {
            Integer updateResult = pharmaceuticalService.updateFollowUpAssign(pd);
            if (updateResult == 1) {
                // 成功更新
                return AjaxResult.success("修改成功");
            } else {
                // 更新失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 患者咨询 页面
     * @return
     */
    @RequiresPermissions("dtp:pmService:view")
    @GetMapping("/patientCounseling")
    public String patientCounseling() {
        return prefix_patient_counseling + "/patientCounselingList";
    }

    /**
     * 患者咨询数据查询
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:patientCounselingList")
    @PostMapping("/patientCounselingList")
    @ResponseBody
    public TableDataInfo patientCounselingList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.findPatientCounselingList(pd);
        return getDataTable(pageData);
    }

    /**
     * 患者咨询数据删除 根据id
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:remove")
    @Log(title = "患者咨询删除", businessType = BusinessType.DELETE)
    @PostMapping("/patientCounselingRemove")
    @ResponseBody
    public AjaxResult patientCounselingRemove() throws Exception {
        PageData pd = this.getPageData();
        try {
            Integer deleteResult = pharmaceuticalService.patientCounselingRemove(pd);
            if (deleteResult == 1) {
                // 删除成功
                return AjaxResult.success("删除成功");
            } else {
                // 删除失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("删除失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 患者咨询数据修改
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/patientCounselingEdit/{id}")
    public String patientCounselingView(@PathVariable("id") Long id, ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        if (id != null && id != 0) {
            pd.put("id", id);
            PageData pageData = pharmaceuticalService.findPatientCounselingById(pd).get(0);
            mmap.putAll(pageData);
        }else {
            mmap.put("null","暂无数据");
        }
        return prefix_patient_counseling + "/patientCounselingEdit";
    }

    /**
     * 患者咨询添加跳转页面
     */
    @RequiresPermissions("dtp:pmService:add")
    @GetMapping("/patientCounselingAdd")
    public String patientCounselingAdd(ModelMap mmap) throws Exception {
        mmap.put("userid", getSysUser().getUserId());

        PageData pd = new PageData();
        pd.put("DeptId", getSysUser().getDeptId());
        List<PageData> patients = pharmaceuticalService.getAllPatients(pd);
        mmap.addAttribute("patients", patients);
        mmap.put("patients", patients);
        return prefix_patient_counseling + "/patientCounselingAdd";
    }


    /**
     * 患者咨询信息保存
     */
    @RequiresPermissions("dtp:pmService:add")
    @Log(title = "患者咨询信息新增", businessType = BusinessType.INSERT)
    @PostMapping("/patientCounselingAdd")
    @ResponseBody
    public AjaxResult patientCounselingSave() throws Exception {
        PageData pd = new PageData();
        pd = this.getPageData();
        try {

            Integer result= pharmaceuticalService.insertPatientConsultation(pd);
            if(result>0){
                return AjaxResult.success("添加成功：");
            }else {
                return AjaxResult.error("添加失败");
            }
        }catch (Exception e) {
            return AjaxResult.error("添加失败" + e.getMessage());
        }
    }


    /**
     * 患者咨询数据修改
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "档案管理修改", businessType = BusinessType.UPDATE)
    @PostMapping("/patientCounselingEdit")
    @ResponseBody
    public AjaxResult patientCounselingEditSave() {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {
            Integer updateResult = pharmaceuticalService.updatePatientCounseling(pd);
            if (updateResult == 1) {
                // 成功更新
                return AjaxResult.success("修改成功");
            } else {
                // 更新失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }


    /**
     * 随访满意度评价 页面
     * @return
     */
    @RequiresPermissions("dtp:pmService:view")
    @GetMapping("/followUpEvaluation")
    public String followUpEvaluation() {
        return prefix_followUp_evaluation + "/followUpEvaluationList";
    }

    /**
     * 随访满意度评价 数据查询
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:patientCounselingList")
    @PostMapping("/followUpEvaluationList")
    @ResponseBody
    public TableDataInfo followUpEvaluationList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.findFollowUpEvaluationList(pd);
        return getDataTable(pageData);
    }

    /**
     * 随访满意度评价 数据删除 根据id
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:remove")
    @Log(title = "随访满意度评价删除", businessType = BusinessType.DELETE)
    @PostMapping("/followUpEvaluationRemove")
    @ResponseBody
    public AjaxResult followUpEvaluationRemove() throws Exception {
        PageData pd = this.getPageData();
        try {
            Integer deleteResult = pharmaceuticalService.followUpEvaluationRemove(pd);
            if (deleteResult == 1) {
                // 删除成功
                return AjaxResult.success("删除成功");
            } else {
                // 删除失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("删除失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 随访满意度评价数据修改
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/followUpEvaluationEdit/{followUpEvaluationId}")
    public String followUpEvaluationView(@PathVariable("followUpEvaluationId") Long followUpEvaluationId, ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        pd.put("id", followUpEvaluationId);
        PageData pageData = pharmaceuticalService.findFollowUpEvaluationList(pd).get(0);
        mmap.putAll(pageData);
        return prefix_followUp_evaluation + "/followUpEvaluationEdit";
    }

    /**
     * 保存随访满意度评价数据修改
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "随访满意度评价修改", businessType = BusinessType.UPDATE)
    @PostMapping("/followUpEvaluationEdit")
    @ResponseBody
    public AjaxResult followUpEvaluationEditSave() {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {
            Integer updateResult = pharmaceuticalService.updateFollowUpEvaluation(pd);
            if (updateResult == 1) {
                // 成功更新
                return AjaxResult.success("修改成功");
            } else {
                // 更新失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }
}
