Commit 94eb5b599de5f7497cd8819aa1aa705e11027fd4

Authored by landong2015
1 parent 2e8d663b45
Exists in master

提交代码

Showing 4 changed files with 100 additions and 174 deletions

mainData/src/main/resources/mainOrm/MedInoculateorder.xml View file @ 94eb5b5
... ... @@ -38,7 +38,7 @@
38 38 and io_id = #{ioId,jdbcType=VARCHAR}
39 39 </if>
40 40 <if test="ioKidId != null and ioKidId != ''">
41   -and io_kidId = #{ioKidId,jdbcType=VARCHAR}
  41 +and io_kidId in (#{ioKidId,jdbcType=VARCHAR})
42 42 </if>
43 43 <if test="ioVaccineId != null and ioVaccineId != ''">
44 44 and io_vaccineId = #{ioVaccineId,jdbcType=VARCHAR}
mainData/src/main/resources/mainOrm/MedInoculaterecord.xml View file @ 94eb5b5
... ... @@ -41,7 +41,7 @@
41 41 and ic_id = #{icId,jdbcType=VARCHAR}
42 42 </if>
43 43 <if test="icKidId != null and icKidId != ''">
44   -and ic_kidId = #{icKidId,jdbcType=VARCHAR}
  44 +and ic_kidId in (#{icKidId,jdbcType=VARCHAR})
45 45 </if>
46 46 <if test="icVaccineId != null and icVaccineId != ''">
47 47 and ic_vaccineId = #{icVaccineId,jdbcType=VARCHAR}
mainData/src/main/resources/mainOrm/MedKids.xml View file @ 94eb5b5
... ... @@ -38,7 +38,7 @@
38 38 <where>
39 39 1 = 1
40 40 <if test="id != null and id != ''">
41   - and ki_id = #{id,jdbcType=VARCHAR}
  41 + and ki_id in (#{id,jdbcType=VARCHAR})
42 42 </if>
43 43 <if test="name != null and name != ''">
44 44 and ki_name = #{name,jdbcType=VARCHAR}
... ... @@ -76,7 +76,7 @@
76 76  
77 77  
78 78 <select id="queryMedKids" resultMap="MedKidsResultMap" parameterType="com.lymsh.yimiao.main.data.model.MedKidsQuery">
79   -select ki_id,ki_name,ki_sex,ki_birthday,ki_guardianid,ki_currentOrganizationid,ki_barCode,phone,ki_buildoper, ki_buildtime,isdelete,fathername,mothername
  79 +select ki_name,ki_id,ki_sex,ki_birthday,ki_guardianid,ki_currentOrganizationid,ki_barCode,phone,ki_buildoper, ki_buildtime,isdelete,fathername,mothername
80 80 from med_kids
81 81 <include refid="MedKidsCondition" />
82 82 <include refid="orderAndLimit" />
webApi/src/main/java/com/lyms/yimiao/web/controller/v1/KidsController.java View file @ 94eb5b5
... ... @@ -13,6 +13,7 @@
13 13 import com.lymsh.yimiao.main.data.util.JsonUtil;
14 14 import com.lymsh.yimiao.main.data.util.LoginContext;
15 15 import org.apache.commons.collections.CollectionUtils;
  16 +import org.apache.commons.lang.StringUtils;
16 17 import org.springframework.beans.factory.annotation.Autowired;
17 18 import org.springframework.beans.factory.annotation.Value;
18 19 import org.springframework.http.MediaType;
... ... @@ -20,6 +21,7 @@
20 21 import org.springframework.web.bind.annotation.RequestMapping;
21 22 import org.springframework.web.bind.annotation.RequestMethod;
22 23 import org.springframework.web.bind.annotation.RequestParam;
  24 +import sun.security.util.Length;
23 25  
24 26  
25 27 import javax.servlet.http.HttpServletRequest;
... ... @@ -127,7 +129,7 @@
127 129 }
128 130  
129 131 /**
130   - * 查询当前登陆账号所关联的宝宝
  132 + * 查询当前登陆账号所关联的宝宝,返回ID
131 133 * @param response
132 134 * @param birthday
133 135 * @param barCode
134 136  
135 137  
136 138  
137 139  
138 140  
139 141  
140 142  
141 143  
142 144  
143 145  
144 146  
145 147  
146 148  
147 149  
... ... @@ -145,167 +147,83 @@
145 147 medKidsQuery.setBarCode(barCode);
146 148 medKidsQuery.setPhone(phone);
147 149 medKidsQuery.setSort("ki_buildtime desc");//时间排序
148   - medKidsQuery.setIsDelete("1");
  150 + medKidsQuery.setIsDelete(isDelete);
149 151 List<MedKids> medKidsList = medKidsService.queryMedKids(medKidsQuery);
150 152  
151 153 List<Map> list = new ArrayList<>();
152 154  
153 155 if (CollectionUtils.isNotEmpty(medKidsList)){
154   - //TODO 查出来的数据,可能会多条一样的和不一样的,有多条一样的情况下,取最新的一条,不一样的正常返回
155 156  
156   - Set<MedKids> set = new HashSet<>();
  157 + List<String> ids = null;
157 158  
158   - Map<MedKids,MedKids> map = new HashMap<>();
  159 + List<String> names = new ArrayList<>();
  160 + for (int i=0;i<medKidsList.size();i++){
  161 + Map<String,String> map = new HashMap<>();
159 162  
160   - for (MedKids data :medKidsList){
  163 + ids = new ArrayList<>();
  164 + if(names.contains(medKidsList.get(i).getName())) continue;
161 165  
162   - if (map.containsKey(data)){
163   - MedKids kids = map.get(data);
164   - Date mapDate = DateUtil.parseYMD(kids.getBuildTime());
165   - Date dataDate = DateUtil.parseYMD(data.getBuildTime());
166   - if(mapDate.after(dataDate)) {
167   - map.put(data, data);
  166 + names.add(medKidsList.get(i).getName());
  167 +
  168 + for (int j=0;j<medKidsList.size();j++){
  169 + String id = medKidsList.get(j).getId();
  170 + if(!ids.contains(medKidsList.get(j).getId()) && i == j) {
  171 + ids.add(id);
168 172 }
169   - }else {
170   - set.add(data);
171   - map.put(data,data);
  173 +
  174 + if(medKidsList.get(i).getName().equals(medKidsList.get(j).getName()) && i != j && !ids.contains(j)){
  175 + ids.add(id);
  176 + }
172 177 }
173   - }
  178 + String tmp = "";
  179 + for(String k : ids) {
  180 + tmp += k + ",";
  181 + }
  182 + map.put("name",medKidsList.get(i).getName());
  183 + map.put("idStr",tmp.substring(0,tmp.length()-1));
174 184  
175   -
176   -
177   -
178   -
179   - }
180   -
181   - ResultUtils.buildSuccessResultAndWrite(response,list);
182   - }
183   -
184   -
185   - public static void main(String[] str) {
186   - final Kids kids = new Kids();
187   - kids.setPhone("110");
188   - kids.setName("罗野");
189   - kids.setFatherName("罗芭");
190   - kids.setMotherName("罗马");
191   - kids.setCreated("2016-05-04");
192   - kids.setNumber(1);
193   -
194   -
195   - Kids kids1 = new Kids();
196   - kids1.setPhone("110");
197   - kids1.setName("罗野");
198   - kids1.setFatherName("罗芭");
199   - kids1.setMotherName("罗马");
200   - kids1.setCreated("2016-05-11");
201   - kids1.setNumber(3);
202   -
203   -
204   - Kids kids2 = new Kids();
205   - kids2.setPhone("110");
206   - kids2.setName("罗小野");
207   - kids2.setFatherName("罗芭");
208   - kids2.setMotherName("罗马");
209   - kids2.setCreated("2016-05-03");
210   - List<Kids> list = new ArrayList<>();
211   - list.add(kids);
212   - list.add(kids1);
213   - list.add(kids2);
214   - Set<Kids> set = new HashSet<>();
215   - Map<Kids,Kids> map = new HashMap<>();
216   -
217   -
218   - List<Kids> list1 = new ArrayList<>();
219   - List<Kids> list2 = new ArrayList<>();
220   -
221   - for (Kids data : list) {
222   -
223   - if (!list1.contains(data)){
224   - list1.add(data);
225   - }else {
226   - list2.add(data);
  185 + list.add(map);
227 186 }
228   -
229   -
230   -// if (map.containsKey(data)) {
231   -// Kids k = map.get(data);
232   -// Date mapDate = DateUtil.parseYMD(k.getCreated());
233   -// Date dataDate = DateUtil.parseYMD(data.getCreated());
234   -// if(mapDate.getTime()> dataDate.getTime()) {
235   -// map.put(data, data);
236   -// }
237   -// } else{
238   -// set.add(data);
239   -// map.put(data,data);
240   -// }
241 187 }
242   -
243   - List<Kids> a = new ArrayList<>(set);
244   -
245   -// Collections.sort(a, new Comparator<Kids>() {
246   -//
247   -// private String key ="created";
248   -//
249   -// @Override
250   -// public int compare(Kids o1, Kids o2) {
251   -// if (o1.getCreated()!=null && o2.getCreated()!=null){
252   -// if (o1.getCreated().getTime() ==o2.getCreated().getTime()) {
253   -// return 0;
254   -// }
255   -// if (o1.getCreated().getTime() >o2.getCreated().getTime()){
256   -// return -1;
257   -// }else {
258   -// return 1;
259   -// }
260   -// }
261   -// return 0;
262   -// }
263   -// });
264   -
265   - for (Kids data :a){
266   - System.out.println(data.getName());
267   - System.out.println(data.getCreated());
268   - System.out.println(data.getNumber());
269   - }
270   -
  188 + ResultUtils.buildSuccessResultAndWrite(response, list);
271 189 }
272 190  
273   -
274 191 /**
275 192 * 添加宝宝接口(当前登陆用户与小孩子进行关联
276 193 * @param response
277   - * @param id 宝宝id
  194 + * @param idStr 宝宝id
278 195 */
279 196 @RequestMapping(value = "/babys", method = RequestMethod.POST)
280 197 @TokenRequired
281 198 public void UserRelateKids(HttpServletResponse response,
282 199 HttpServletRequest request,
283   - @RequestParam("id")String id){
284   -
285   - MedKids kids = medKidsService.getMedKids(id);
286   - if (kids == null) {
287   - ResultUtils.buildParameterErrorResultAndWrite(response, "宝宝id不存在");
288   - return;
  200 + @RequestParam("idStr")String idStr){
  201 + String[] ids = idStr.split("id");
  202 + for (String id : ids){
  203 + MedKids kids = medKidsService.getMedKids(id);
  204 + if (kids == null) {
  205 + ResultUtils.buildParameterErrorResultAndWrite(response, "宝宝id不存在");
  206 + return;
  207 + }
  208 + //取到当前登陆用户的id
  209 + LoginContext loginContext = (LoginContext) request.getAttribute("loginContext");
  210 + YmUsers users = usersService.getYmUsers(loginContext.getId());
  211 + //把查询到的宝宝id与登陆用户关联
  212 + YmUserKidMapsQuery query = new YmUserKidMapsQuery();
  213 + query.setUserId(users.getId());
  214 + query.setKidId(id);
  215 + query.setYn(YnEnum.yes.getId());
  216 + int count = ymUserKidMapsService.queryYmUserKidMapsCount(query);
  217 + if (count!=0){
  218 + continue;
  219 + }
  220 + YmUserKidMaps userKidMaps = new YmUserKidMaps();
  221 + userKidMaps.setUserId(users.getId());
  222 + userKidMaps.setKidId(id);
  223 + userKidMaps.setCreated(new Date());
  224 + userKidMaps.setYn(YnEnum.yes.getId());
  225 + ymUserKidMapsService.addYmUserKidMaps(userKidMaps);
289 226 }
290   - //取到当前登陆用户的id
291   - LoginContext loginContext = (LoginContext) request.getAttribute("loginContext");
292   - YmUsers users = usersService.getYmUsers(loginContext.getId());
293   - //把查询到的宝宝id与登陆用户关联
294   - YmUserKidMapsQuery query = new YmUserKidMapsQuery();
295   - query.setUserId(users.getId());
296   - query.setKidId(id);
297   - query.setYn(YnEnum.yes.getId());
298   - int count = ymUserKidMapsService.queryYmUserKidMapsCount(query);
299   - if (count!=0){
300   - ResultUtils.buildParameterErrorResultAndWrite(response,"这个宝宝已经和用户关联");
301   - return;
302   - }
303   - YmUserKidMaps userKidMaps = new YmUserKidMaps();
304   - userKidMaps.setUserId(users.getId());
305   - userKidMaps.setKidId(id);
306   - userKidMaps.setCreated(new Date());
307   - userKidMaps.setYn(YnEnum.yes.getId());
308   - ymUserKidMapsService.addYmUserKidMaps(userKidMaps);
309 227 ResultUtils.buildSuccessResultAndWrite(response);
310 228 }
311 229  
312 230  
313 231  
314 232  
315 233  
... ... @@ -319,44 +237,52 @@
319 237 @TokenRequired
320 238 public void getKids(HttpServletResponse response,
321 239 @RequestParam("id")String id) {
322   - if (id == null) {
  240 + if (StringUtils.isBlank(id)) {
323 241 ResultUtils.buildIdIsNull(response);
324 242 return;
325 243 }
326   - MedKids kids = medKidsService.getMedKids(id);
327   - if (kids == null) {
328   - ResultUtils.buildParameterErrorResultAndWrite(response, "宝宝信息不存在");
329   - return;
330   - }
  244 +
  245 + MedKidsQuery query = new MedKidsQuery();
  246 + query.setIsDelete(isDelete);
  247 + query.setId(id);
  248 + List<MedKids> medKidList = medKidsService.queryMedKids(query);
  249 +
331 250 Map<String, Object> map = new HashMap<>();
332   - map.put("id", kids.getId());
333   - map.put("name", kids.getName());
334   - map.put("birthday", DateUtil.getSecond(DateUtil.parseYMD(kids.getBirthday())));
335 251  
336   - MedInoculateOrderQuery inoculateorderQuery = new MedInoculateOrderQuery();
337   - inoculateorderQuery.setIoKidId(id);
338   - //时间倒序
339   - inoculateorderQuery.setSort("io_inoculateDate desc");
340   - List<MedInoculateOrder> inoculateorderList = medInoculateorderService.queryMedInoculateOrder(inoculateorderQuery);
341   - if (CollectionUtils.isNotEmpty(inoculateorderList)) {
342   - //取出离现在日期最近的一个预约接种
343   - MedInoculateOrder medInoculateorder = inoculateorderList.get(0);
344   - //下次接种时间
345   - map.put("ioInoculateDate", DateUtil.getSecond(DateUtil.parseYMD(medInoculateorder.getIoInoculateDate())));
346   - //下次接种疫苗
347   - map.put("vaccineId", medInoculateorder.getIoVaccineId());
348   - MedVaccineName medVaccineName = medVaccineNameService.getMedVaccineName(medInoculateorder.getIoVaccineId());
349   - map.put("vaccineName", medVaccineName == null ? "" : medVaccineName.getVnName());
350   - //接种地点
351   - map.put("organizationId", medInoculateorder.getIoOrganizationId());
352   - MedOrganization medOrganization = medOrganizationService.getMedOrganization(medInoculateorder.getIoOrganizationId());
353   - map.put("organizationName", medOrganization == null ? "" : medOrganization.getoName());
  252 + if (CollectionUtils.isNotEmpty(medKidList)){
  253 + MedKids kids = medKidList.get(0);
  254 +
  255 + map.put("id", kids.getId());
  256 + map.put("name", kids.getName());
  257 + map.put("birthday", DateUtil.getSecond(DateUtil.parseYMD(kids.getBirthday())));
  258 +
  259 + MedInoculateOrderQuery inoculateorderQuery = new MedInoculateOrderQuery();
  260 + inoculateorderQuery.setIoKidId(id);
  261 + //时间倒序
  262 + inoculateorderQuery.setSort("io_inoculateDate desc");
  263 + List<MedInoculateOrder> inoculateorderList = medInoculateorderService.queryMedInoculateOrder(inoculateorderQuery);
  264 + if (CollectionUtils.isNotEmpty(inoculateorderList)) {
  265 + //取出离现在日期最近的一个预约接种
  266 + MedInoculateOrder medInoculateorder = inoculateorderList.get(0);
  267 + //下次接种时间
  268 + map.put("ioInoculateDate", DateUtil.getSecond(DateUtil.parseYMD(medInoculateorder.getIoInoculateDate())));
  269 + //下次接种疫苗
  270 + map.put("vaccineId", medInoculateorder.getIoVaccineId());
  271 + MedVaccineName medVaccineName = medVaccineNameService.getMedVaccineName(medInoculateorder.getIoVaccineId());
  272 + map.put("vaccineName", medVaccineName == null ? "" : medVaccineName.getVnName());
  273 + //接种地点
  274 + map.put("organizationId", medInoculateorder.getIoOrganizationId());
  275 + MedOrganization medOrganization = medOrganizationService.getMedOrganization(medInoculateorder.getIoOrganizationId());
  276 + map.put("organizationName", medOrganization == null ? "" : medOrganization.getoName());
  277 + }else {
  278 + map.put("ioInoculateTime", null);
  279 + map.put("vaccineId", null);
  280 + map.put("vaccineName", null);
  281 + map.put("organizationId", null);
  282 + map.put("organizationName", null);
  283 + }
354 284 }else {
355   - map.put("ioInoculateTime", null);
356   - map.put("vaccineId", null);
357   - map.put("vaccineName", null);
358   - map.put("organizationId", null);
359   - map.put("organizationName", null);
  285 + ResultUtils.buildParameterErrorResultAndWrite(response,"宝宝信息不存在");
360 286 }
361 287 writeJson(response, JsonUtil.obj2JsonString(map));
362 288 }