Pārlūkot izejas kodu

Merge branch 'dev' of yeshijie/patient-co-management into dev

yeshijie 7 gadi atpakaļ
vecāks
revīzija
a4a80f283c

+ 58 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/clean/ImCleanController.java

@ -0,0 +1,58 @@
package com.yihu.wlyy.web.third.clean;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
 * @author yeshijie on 2018/7/18.
 */
@RestController
@RequestMapping(value = "/imclean",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "im清理")
public class ImCleanController  extends BaseController {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Value("${im.data_base_name}")
    private String imDb;
    @RequestMapping(value = "/clean",method = RequestMethod.POST)
    @ApiOperation("清理")
    public String clean(){
        try {
            String sql1 = "SELECT * from wlyy_sign_family WHERE `status`>0 and patient in(SELECT DISTINCT patient from wlyy_consult_team)";
            List<Map<String,Object>> list = jdbcTemplate.queryForList(sql1);
            list.stream().forEach(one->{
                String patient = one.get("patient").toString();
                String teamCode = one.get("team_code").toString();
                String sessionId = patient+"_"+teamCode+"_2";
                String doctor = one.get("doctor").toString();
                String doctor_health = null;
                String sql2 = "";
                if(one.get("doctor_health")!=null){
                    doctor_health = one.get("doctor_health").toString();
                    sql2 = "delete from "+imDb+".participants where session_id = '"+sessionId+"' and participant_id not in ('"+patient+"','"+doctor+"','"+doctor_health+"')" ;
                }else {
                    sql2 = "delete from "+imDb+".participants where session_id = '"+sessionId+"' and participant_id not in ('"+patient+"','"+doctor+"')" ;
                }
                jdbcTemplate.execute(sql2);
            });
            return success("清理成功");
        }catch (Exception e){
            error(e);
            return error(-1, e.getMessage());
        }
    }
}